Client LuaCsForBarotrauma
AbilityCondition.cs
1 using System;
2 using System.Collections.Generic;
3 
5 {
6  abstract class AbilityCondition
7  {
9  protected Character character;
10  protected bool invert;
11 
12  public virtual bool AllowClientSimulation => true;
13 
15  {
16  this.characterTalent = characterTalent ?? throw new ArgumentNullException(nameof(characterTalent));
18  invert = conditionElement.GetAttributeBool("invert", false);
19  }
20  public abstract bool MatchesCondition(AbilityObject abilityObject);
21  public abstract bool MatchesCondition();
22 
23 
24  // tools
25  protected enum TargetType
26  {
27  Any = 0,
28  Enemy = 1,
29  Ally = 2,
30  NotSelf = 3,
31  Alive = 4,
32  Monster = 5,
33  InFriendlySubmarine = 6
34  };
35 
36  protected List<TargetType> ParseTargetTypes(string[] targetTypeStrings)
37  {
38  List<TargetType> targetTypes = new List<TargetType>();
39  foreach (string targetTypeString in targetTypeStrings)
40  {
41  if (!Enum.TryParse(targetTypeString, true, out TargetType targetType))
42  {
43  DebugConsole.ThrowError("Invalid target type type \"" + targetTypeString + "\" in CharacterTalent (" + characterTalent.DebugIdentifier + ")",
44  contentPackage: characterTalent.Prefab.ContentPackage);
45  }
46  targetTypes.Add(targetType);
47  }
48  return targetTypes;
49  }
50 
51  protected bool IsViableTarget(IEnumerable<TargetType> targetTypes, Character targetCharacter)
52  {
53  if (targetCharacter == null) { return false; }
54 
55  bool isViable = true;
56  foreach (TargetType targetType in targetTypes)
57  {
58  if (!IsViableTarget(targetType, targetCharacter))
59  {
60  isViable = false;
61  break;
62  }
63  }
64  return isViable;
65  }
66 
67  private bool IsViableTarget(TargetType targetType, Character targetCharacter)
68  {
69  switch (targetType)
70  {
71  case TargetType.Enemy:
72  return !HumanAIController.IsFriendly(character, targetCharacter);
73  case TargetType.Ally:
74  return HumanAIController.IsFriendly(character, targetCharacter);
75  case TargetType.NotSelf:
76  return targetCharacter != character;
77  case TargetType.Alive:
78  return !targetCharacter.IsDead;
79  case TargetType.Monster:
80  return !targetCharacter.IsHuman;
81  case TargetType.InFriendlySubmarine:
82  return targetCharacter.Submarine != null && targetCharacter.Submarine.TeamID == character.TeamID;
83  default:
84  return true;
85  }
86  }
87 
88  }
89 }
List< TargetType > ParseTargetTypes(string[] targetTypeStrings)
abstract bool MatchesCondition(AbilityObject abilityObject)
AbilityCondition(CharacterTalent characterTalent, ContentXElement conditionElement)
bool IsViableTarget(IEnumerable< TargetType > targetTypes, Character targetCharacter)
readonly TalentPrefab Prefab
bool GetAttributeBool(string key, bool def)
Submarine Submarine
Definition: Entity.cs:53
static bool IsFriendly(Character me, Character other, bool onlySameTeam=false)
ContentPackage? ContentPackage
Definition: Prefab.cs:37