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