Client LuaCsForBarotrauma
GodModeAction.cs
1 namespace Barotrauma
2 {
7  {
8  [Serialize(true, IsPropertySaveable.Yes, description: "Should the godmode be enabled or disabled?")]
9  public bool Enabled { get; set; }
10 
11  [Serialize(false, IsPropertySaveable.Yes, description: "Should the character's active afflictions be updated (e.g. applying visual effects of the afflictions)")]
12  public bool UpdateAfflictions { get; set; }
13 
14  [Serialize("", IsPropertySaveable.Yes, description: "Tag of the character whose godmode to enable/disable.")]
15  public Identifier TargetTag { get; set; }
16 
17  public GodModeAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
18 
19  private bool isFinished = false;
20 
21  public override bool IsFinished(ref string goTo)
22  {
23  return isFinished;
24  }
25 
26  public override void Reset()
27  {
28  isFinished = false;
29  }
30 
31  public override void Update(float deltaTime)
32  {
33  if (isFinished) { return; }
34  var targets = ParentEvent.GetTargets(TargetTag);
35  foreach (var target in targets)
36  {
37  if (target != null && target is Character character)
38  {
40  {
41  character.CharacterHealth.Unkillable = Enabled;
42  }
43  else
44  {
45  character.GodMode = Enabled;
46  }
47  }
48  }
49  isFinished = true;
50  }
51 
52  public override string ToDebugString()
53  {
54  return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(GodModeAction)} -> (TargetTag: {TargetTag.ColorizeObject()}, " +
55  (Enabled ? "Enable godmode" : "Disable godmode");
56  }
57  }
58 }
readonly ScriptedEvent ParentEvent
Definition: EventAction.cs:106
Makes a specific character invulnerable to damage and unable to die.
Definition: GodModeAction.cs:7
override void Reset()
GodModeAction(ScriptedEvent parentEvent, ContentXElement element)
override string ToDebugString()
Rich test to display in debugdraw
override bool IsFinished(ref string goTo)
Has the action finished.
override void Update(float deltaTime)
IEnumerable< Entity > GetTargets(Identifier tag)