Client LuaCsForBarotrauma
GiveExpAction.cs
1 using System.Linq;
2 
3 namespace Barotrauma
4 {
9  {
10  [Serialize(0, IsPropertySaveable.Yes, description: "The amount of experience to give. Cannot be negative.")]
11  public int Amount { get; set; }
12 
13  [Serialize("", IsPropertySaveable.Yes, description: "Tag of the character(s) to give the experience to.")]
14  public Identifier TargetTag { get; set; }
15 
16  public GiveExpAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
17  {
18  if (TargetTag.IsEmpty)
19  {
20  DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\": {nameof(GiveExpAction)} without a target tag (the action needs to know whose skill to check).",
21  contentPackage: element.ContentPackage);
22  }
23  }
24 
25  private bool isFinished = false;
26 
27  public override bool IsFinished(ref string goTo)
28  {
29  return isFinished;
30  }
31  public override void Reset()
32  {
33  isFinished = false;
34  }
35 
36  public override void Update(float deltaTime)
37  {
38  if (isFinished) { return; }
39  var targets = ParentEvent.GetTargets(TargetTag).Where(e => e is Character).Select(e => e as Character);
40  foreach (var target in targets)
41  {
42  target.Info?.GiveExperience(Amount);
43  }
44  isFinished = true;
45  }
46 
47  public override string ToDebugString()
48  {
49  return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(GiveExpAction)} -> (TargetTag: {TargetTag.ColorizeObject()}, " +
50  $"Amount: {Amount.ColorizeObject()})";
51  }
52  }
53 }
ContentPackage? ContentPackage
readonly ScriptedEvent ParentEvent
Definition: EventAction.cs:106
Gives experience to a specific character.
Definition: GiveExpAction.cs:9
override bool IsFinished(ref string goTo)
Has the action finished.
override void Reset()
override void Update(float deltaTime)
override string ToDebugString()
Rich test to display in debugdraw
GiveExpAction(ScriptedEvent parentEvent, ContentXElement element)
IEnumerable< Entity > GetTargets(Identifier tag)