2 using System.Collections.Generic;
10 internal class CheckAfflictionAction : BinaryOptionAction
13 public Identifier Identifier {
get;
set; } = Identifier.Empty;
16 public Identifier TargetTag {
get;
set; } = Identifier.Empty;
18 [Serialize(
"",
IsPropertySaveable.Yes, description:
"Tag referring to the character who caused the affliction. Can be used to require the affliction to be caused by a specific character.")]
19 public Identifier SourceCharacter {
get;
set; } = Identifier.Empty;
22 public LimbType TargetLimb {
get;
set; }
24 [Serialize(
true,
IsPropertySaveable.Yes,
"When set to false, limb-specific afflictions are ignored when not checking a specific limb.")]
25 public bool AllowLimbAfflictions {
get;
set; }
28 public float MinStrength {
get;
set; }
30 public CheckAfflictionAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
32 protected override bool? DetermineSuccess()
34 if (Identifier.IsEmpty || TargetTag.IsEmpty) {
return false; }
37 foreach (var target
in targets)
39 if (target.CharacterHealth ==
null) {
continue; }
42 if (target.CharacterHealth.GetAfflictionStrengthByIdentifier(Identifier, AllowLimbAfflictions) >= MinStrength) {
return true; }
44 IEnumerable<Affliction> afflictions = target.CharacterHealth.GetAllAfflictions().Where(affliction =>
46 if (affliction.Prefab.LimbSpecific)
48 LimbType? limbType = target.CharacterHealth.GetAfflictionLimb(affliction)?.type;
49 if (limbType == null || limbType != TargetLimb) { return false; }
51 if (!SourceCharacter.IsEmpty)
53 if (!ParentEvent.GetTargets(SourceCharacter).Contains(affliction.Source)) { return false; }
56 return affliction.Strength >= MinStrength;
58 if (afflictions.Any(a => a.Identifier == Identifier)) {
return true; }
63 public override string ToDebugString()
65 return $
"{ToolBox.GetDebugSymbol(HasBeenDetermined())} {nameof(CheckAfflictionAction)} -> (TargetTag: {TargetTag.ColorizeObject()}, " +
66 $
"AfflictionIdentifier: {Identifier.ColorizeObject()}, " +
67 $
"TargetLimb: {TargetLimb.ColorizeObject()}, " +
68 $
"Succeeded: {succeeded.ColorizeObject()})";
readonly ScriptedEvent ParentEvent
IEnumerable< Entity > GetTargets(Identifier tag)
@ Character
Characters only