Client LuaCsForBarotrauma
AbilityConditionLocation.cs
1 using System;
2 using System.Linq;
3 using System.Xml.Linq;
4 
5 namespace Barotrauma.Abilities
6 {
8  {
9  private readonly bool? hasOutpost;
10  private readonly Identifier[] locationIdentifiers;
11  private readonly bool isPositiveReputation;
12 
13  public AbilityConditionLocation(CharacterTalent characterTalent, ContentXElement conditionElement) : base(characterTalent, conditionElement)
14  {
15  if (conditionElement.GetAttribute("hasoutpost") != null)
16  {
17  hasOutpost = conditionElement.GetAttributeBool("hasoutpost", false);
18  }
19  locationIdentifiers = conditionElement.GetAttributeIdentifierArray("locationtype", Array.Empty<Identifier>());
20 
21  isPositiveReputation = conditionElement.GetAttributeBool("ispositivereputation", false);
22  }
23 
24  protected override bool MatchesConditionSpecific(AbilityObject abilityObject)
25  {
26  if (abilityObject is IAbilityLocation abilityLocation)
27  {
28  if (isPositiveReputation)
29  {
30  if (abilityLocation.Location?.Reputation is not { } reputation) { return false; }
31  if (reputation.Value <= 0) { return false; }
32  }
33 
34  if (locationIdentifiers.Any())
35  {
36  if (!locationIdentifiers.Contains(abilityLocation.Location.Type.Identifier)) { return false; }
37  }
38  if (hasOutpost.HasValue)
39  {
40  if (hasOutpost.Value != abilityLocation.Location.HasOutpost()) { return false; }
41  }
42  return true;
43  }
44  else
45  {
46  LogAbilityConditionError(abilityObject, typeof(IAbilityItemPrefab));
47  return false;
48  }
49  }
50  }
51 }
void LogAbilityConditionError(AbilityObject abilityObject, Type expectedData)
AbilityConditionLocation(CharacterTalent characterTalent, ContentXElement conditionElement)
override bool MatchesConditionSpecific(AbilityObject abilityObject)
Identifier[] GetAttributeIdentifierArray(Identifier[] def, params string[] keys)
bool GetAttributeBool(string key, bool def)
XAttribute? GetAttribute(string name)