Client LuaCsForBarotrauma
CheckTalentAction.cs
1 #nullable enable
2 
3 namespace Barotrauma
4 {
8  internal sealed class CheckTalentAction : BinaryOptionAction
9  {
10  [Serialize("", IsPropertySaveable.Yes, description: "Identifier of the talent to check for.")]
11  public Identifier TalentIdentifier { get; set; }
12 
13  [Serialize("", IsPropertySaveable.Yes, description: "Tag of the character to check.")]
14  public Identifier TargetTag { get; set; }
15 
16  public CheckTalentAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
17 
18  protected override bool? DetermineSuccess()
19  {
20  if (TargetTag.IsEmpty)
21  {
22  return false;
23  }
24 
25  Character? matchingCharacter = null;
26 
27  foreach (Entity entity in ParentEvent.GetTargets(TargetTag))
28  {
29  if (entity is Character character)
30  {
31  matchingCharacter = character;
32  break;
33  }
34  }
35 
36  return matchingCharacter is not null && matchingCharacter.HasTalent(TalentIdentifier);
37  }
38 
39  public override string ToDebugString()
40  {
41  string subActionStr = "";
42  if (succeeded.HasValue)
43  {
44  subActionStr = $"\n Sub action: {(succeeded.Value ? Success : Failure)?.CurrentSubAction.ColorizeObject()}";
45  }
46 
47  return $"{ToolBox.GetDebugSymbol(DetermineFinished())} {nameof(CheckTalentAction)} -> (Talent: {TalentIdentifier.ColorizeObject()}" +
48  $" Succeeded: {(succeeded.HasValue ? succeeded.Value.ToString() : "not determined").ColorizeObject()})" +
49  subActionStr;
50  }
51  }
52 }
readonly ScriptedEvent ParentEvent
Definition: EventAction.cs:106
IEnumerable< Entity > GetTargets(Identifier tag)
@ Character
Characters only