Client LuaCsForBarotrauma
AIObjectiveFightIntruders.cs
2 using System.Collections.Generic;
3 using System.Linq;
4 
5 namespace Barotrauma
6 {
8  {
9  public override Identifier Identifier { get; set; } = "fight intruders".ToIdentifier();
10  protected override float IgnoreListClearInterval => 30;
11  public override bool IgnoreUnsafeHulls => true;
12  protected override float TargetUpdateTimeMultiplier => 0.2f;
13  public bool TargetCharactersInOtherSubs { get; init; }
14 
15  protected override bool AllowInAnySub => TargetCharactersInOtherSubs;
16 
17  public AIObjectiveFightIntruders(Character character, AIObjectiveManager objectiveManager, float priorityModifier = 1)
18  : base(character, objectiveManager, priorityModifier) { }
19 
20  protected override bool IsValidTarget(Character target) => IsValidTarget(target, character, TargetCharactersInOtherSubs);
21 
22  protected override IEnumerable<Character> GetList() => Character.CharacterList;
23 
24  protected override float GetTargetPriority()
25  {
26  if (Targets.None()) { return 0; }
27  if (!character.IsOnPlayerTeam && !character.IsOriginallyOnPlayerTeam) { return 100; }
28  if (character.IsSecurity) { return 100; }
29  if (objectiveManager.IsOrder(this)) { return 100; }
30  // If there's any security officers onboard, leave fighting for them.
31  return HumanAIController.IsTrueForAnyCrewMember(c => c.IsSecurity, onlyActive: true, onlyConnectedSubs: true) ? 0 : 100;
32  }
33 
34  protected override AIObjective ObjectiveConstructor(Character target)
35  {
37  if (character.IsOnPlayerTeam && target is { IsEscorted: true })
38  {
39  // Try to arrest escorted characters, instead of killing them.
40  combatMode = AIObjectiveCombat.CombatMode.Arrest;
41  }
42  var combatObjective = new AIObjectiveCombat(character, target, combatMode, objectiveManager, PriorityModifier);
43  if (character.TeamID == CharacterTeamType.FriendlyNPC && target.TeamID == CharacterTeamType.Team1 && GameMain.GameSession?.GameMode is CampaignMode { CurrentLocation.IsFactionHostile: true })
44  {
45  combatObjective.holdFireCondition = () =>
46  {
47  //hold fire while the enemy is in the airlock (except if they've attacked us)
48  if (character.GetDamageDoneByAttacker(target) > 0.0f) { return false; }
49  return target.CurrentHull == null || target.CurrentHull.OutpostModuleTags.Any(t => t == "airlock");
50  };
51  character.Speak(TextManager.Get("dialogenteroutpostwarning").Value, null, Rand.Range(0.5f, 1.0f), "leaveoutpostwarning".ToIdentifier(), 30.0f);
52  }
53  return combatObjective;
54  }
55 
56  protected override void OnObjectiveCompleted(AIObjective objective, Character target)
57  => HumanAIController.RemoveTargets<AIObjectiveFightIntruders, Character>(character, target);
58 
59  public static bool IsValidTarget(Character target, Character character, bool targetCharactersInOtherSubs)
60  {
61  if (target == null || target.Removed) { return false; }
62  if (target.IsDead) { return false; }
63  if (target.IsUnconscious && target.Params.Health.ConstantHealthRegeneration <= 0.0f) { return false; }
64  if (target == character) { return false; }
65  if (target.Submarine == null) { return false; }
66  if (character.Submarine == null) { return false; }
67  if (target.CurrentHull == null) { return false; }
68  if (HumanAIController.IsFriendly(character, target)) { return false; }
69  if (!character.Submarine.IsConnectedTo(target.Submarine)) { return false; }
70  if (!targetCharactersInOtherSubs)
71  {
72  if (character.Submarine.TeamID != target.Submarine.TeamID && character.OriginalTeamID != target.Submarine.TeamID)
73  {
74  return false;
75  }
76  }
77  if (target.HasAbilityFlag(AbilityFlags.IgnoredByEnemyAI)) { return false; }
78  if (target.IsHandcuffed && target.IsKnockedDown) { return false; }
79  if (EnemyAIController.IsLatchedToSomeoneElse(target, character)) { return false; }
80  return true;
81  }
82  }
83 }
override bool IsValidTarget(Character target)
override AIObjective ObjectiveConstructor(Character target)
override IEnumerable< Character > GetList()
List of all possible items of the specified type. Used for filtering the removed objectives.
AIObjectiveFightIntruders(Character character, AIObjectiveManager objectiveManager, float priorityModifier=1)
override void OnObjectiveCompleted(AIObjective objective, Character target)
override float GetTargetPriority()
Returns a priority value based on the current targets (e.g. high prio when there's lots of severe fir...
static bool IsValidTarget(Character target, Character character, bool targetCharactersInOtherSubs)
An objective that creates specific kinds of subobjectives for specific types of targets,...
bool IsKnockedDown
Is the character knocked down regardless whether the technical state is dead, unconcious,...
static bool IsLatchedToSomeoneElse(Character target, Character character)
Submarine Submarine
Definition: Entity.cs:53
static GameSession?? GameSession
Definition: GameMain.cs:88
IEnumerable< Identifier > OutpostModuleTags
Inherited flags from outpost generation.
bool IsTrueForAnyCrewMember(Func< Character, bool > predicate, bool onlyActive=true, bool onlyConnectedSubs=false)
Including the player characters in the same team.
static bool IsFriendly(Character me, Character other, bool onlySameTeam=false)
bool IsConnectedTo(Submarine otherSub)
Returns true if the sub is same as the other, or connected to it via docking ports.
AbilityFlags
AbilityFlags are a set of toggleable flags that can be applied to characters.
Definition: Enums.cs:641