Client LuaCsForBarotrauma
AIObjectiveEscapeHandcuffs.cs
1 using System;
2 using System.Linq;
3 
4 namespace Barotrauma
5 {
7  {
8  // Used for prisoner escorts to allow them to escape their binds
9  public override Identifier Identifier { get; set; } = "escape handcuffs".ToIdentifier();
10  public override bool AllowAutomaticItemUnequipping => true;
11  protected override bool AllowOutsideSubmarine => true;
12  protected override bool AllowInAnySub => true;
13 
14  private int escapeProgress;
15  private bool isBeingWatched;
16 
17  private readonly bool shouldSwitchTeams;
18 
19  const string EscapeTeamChangeIdentifier = "escape";
20 
21  public AIObjectiveEscapeHandcuffs(Character character, AIObjectiveManager objectiveManager, bool shouldSwitchTeams = true, bool beginInstantly = false, float priorityModifier = 1) : base(character, objectiveManager, priorityModifier)
22  {
23  this.shouldSwitchTeams = shouldSwitchTeams;
24  if (beginInstantly)
25  {
26  escapeTimer = EscapeIntervalTimer;
27  }
28  }
29 
30  public override bool CanBeCompleted => true;
31  protected override bool CheckObjectiveState() => false;
32 
33  // escape timer is set to 60 by default to allow players to locate prisoners in time
34  private float escapeTimer = 60f;
35  private const float EscapeIntervalTimer = 7.5f;
36 
37  private float updateTimer;
38  private const float UpdateIntervalTimer = 4f;
39 
40  protected override float GetPriority()
41  {
42  Priority = !isBeingWatched && character.LockHands ? AIObjectiveManager.LowestOrderPriority - 1 : 0;
43  return Priority;
44  }
45 
46  public override void Update(float deltaTime)
47  {
48  updateTimer -= deltaTime;
49  if (updateTimer <= 0.0f)
50  {
51  if (shouldSwitchTeams)
52  {
53  if (!character.LockHands)
54  {
55  if (!character.HasTeamChange(EscapeTeamChangeIdentifier))
56  {
58  }
59  }
60  else
61  {
62  character.TryRemoveTeamChange(EscapeTeamChangeIdentifier);
63  }
64  }
65 
66  isBeingWatched = false;
67  foreach (Character otherCharacter in Character.CharacterList)
68  {
69  if (HumanAIController.IsActive(otherCharacter) && otherCharacter.TeamID == CharacterTeamType.Team1 && HumanAIController.VisibleHulls.Contains(otherCharacter.CurrentHull)) // hasn't been tested yet
70  {
71  isBeingWatched = true; // act casual when player characters are around
72  escapeProgress = 0;
73  break;
74  }
75  }
76  updateTimer = UpdateIntervalTimer * Rand.Range(0.75f, 1.25f);
77  }
78  }
79 
80  protected override void Act(float deltaTime)
81  {
83 
84  escapeTimer -= deltaTime;
85  if (escapeTimer <= 0.0f)
86  {
87  escapeProgress += Rand.Range(2, 5);
88  if (escapeProgress > 15)
89  {
90  foreach (var it in character.HeldItems)
91  {
92  if (it.HasTag(Tags.HandLockerItem) && it.IsInteractable(character))
93  {
94  it.Drop(character);
95  }
96  }
97  }
98  escapeTimer = EscapeIntervalTimer * Rand.Range(0.75f, 1.25f);
99  }
100  }
101  public override void Reset()
102  {
103  base.Reset();
104  escapeProgress = 0;
105  }
106  }
107 }
IEnumerable< Hull > VisibleHulls
Returns hulls that are visible to the character, including the current hull. Note that this is not an...
AIObjectiveEscapeHandcuffs(Character character, AIObjectiveManager objectiveManager, bool shouldSwitchTeams=true, bool beginInstantly=false, float priorityModifier=1)
override bool CheckObjectiveState()
Should return whether the objective is completed or not.
float Priority
Final priority value after all calculations.
const float LowestOrderPriority
Maximum priority of an order given to the character (rightmost order in the crew list)
bool TryAddNewTeamChange(string identifier, ActiveTeamChange newTeamChange)
IEnumerable< Item >?? HeldItems
Items the character has in their hand slots. Doesn't return nulls and only returns items held in both...
static bool IsActive(Character c)