Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Beds as targets when wandering, depending on health #1

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public enum BehaviorType

private Character tooCloseCharacter;

const float chairCheckInterval = 5.0f;
const float chairCheckInterval = 4.0f;
private float chairCheckTimer;

private float autonomousObjectiveRetryTimer = 10;
Expand Down Expand Up @@ -382,12 +382,18 @@ public void Wander(float deltaTime)
{
foreach (Item item in Item.ItemList)
{
if (item.CurrentHull != currentHull || !item.HasTag(Tags.ChairItem)) { continue; }
//not possible in vanilla game, but a mod might have holdable/attachable chairs

if (item.CurrentHull != currentHull) { continue; }
//not possible in vanilla game, but a mod might have holdable/attachable ones
if (item.ParentInventory != null || item.body is { Enabled: true }) { continue; }
var controller = item.GetComponent<Controller>();
if (controller == null || controller.User != null) { continue; }
item.TryInteract(character, forceSelectKey: true);
//make it more likely to seek a bed when hurt, (68% chance after 10 checks at 80% health, 40% at 90%H 10th try, 5% at 90%H first try, 56% at 20%H first try...)
if(item.HasTag(Tags.BedItem) && Rand.Value() > Math.Sqrt(character.HealthPercentage/100)){
item.TryInteract(character, forceSelectKey: true);
} else if (item.HasTag(Tags.ChairItem) && Rand.Value() > 0.4){
item.TryInteract(character, forceSelectKey: true);
}
}
chairCheckTimer = chairCheckInterval;
}
Expand Down
1 change: 1 addition & 0 deletions Barotrauma/BarotraumaShared/SharedSource/Tags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static class Tags
public static readonly Identifier IdCardTag = "identitycard".ToIdentifier();
public static readonly Identifier WireItem = "wire".ToIdentifier();
public static readonly Identifier ChairItem = "chair".ToIdentifier();
public static readonly Identifier BedItem = "bed".ToIdentifier();
public static readonly Identifier ArtifactHolder = "artifactholder".ToIdentifier();
public static readonly Identifier Thalamus = "thalamus".ToIdentifier();

Expand Down