Client LuaCsForBarotrauma
SkillCheckAction.cs
1 using System.Linq;
2 
3 namespace Barotrauma
4 {
9  {
10  [Serialize("", IsPropertySaveable.Yes, description: "The identifier of the skill to check.")]
11  public Identifier RequiredSkill { get; set; }
12 
13  [Serialize(0.0f, IsPropertySaveable.Yes, description: "The required skill level for the check to succeed.")]
14  public float RequiredLevel { get; set; }
15 
16  [Serialize(true, IsPropertySaveable.Yes, description: "Should the skill check be probability-based (i.e. if you have half the required skill level, the chance of success is 50%), or should the check always fail when under the required level and always succeed when above? ")]
17  public bool ProbabilityBased { get; set; }
18 
19  [Serialize("", IsPropertySaveable.Yes, description: "Tag of the character(s) whose skill to check. If there are multiple targets, the action succeeds if any of their skill checks succeeds.")]
20  public Identifier TargetTag { get; set; }
21 
22  public SkillCheckAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
23  {
24  if (TargetTag.IsEmpty)
25  {
26  DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\": SkillCheckAction without a target tag (the action needs to know whose skill to check).",
27  contentPackage: element.ContentPackage);
28  }
29  }
30 
31  protected override bool? DetermineSuccess()
32  {
33  var potentialTargets = ParentEvent.GetTargets(TargetTag).Where(e => e is Character).Select(e => e as Character);
34 
35  if (ProbabilityBased)
36  {
37  return potentialTargets.Any(chr => chr.GetSkillLevel(RequiredSkill) / RequiredLevel > Rand.Range(0.0f, 1.0f, Rand.RandSync.Unsynced));
38  }
39  else
40  {
41  return potentialTargets.Any(chr => chr.GetSkillLevel(RequiredSkill) >= RequiredLevel);
42  }
43  }
44 
45  public override string ToDebugString()
46  {
47  return $"{ToolBox.GetDebugSymbol(HasBeenDetermined())} {nameof(SkillCheckAction)} -> (Target: {TargetTag.ColorizeObject()}, " +
48  $"Skill: {RequiredSkill.ColorizeObject()}, Level: {RequiredLevel.ColorizeObject()}, " +
49  $"Succeeded: {succeeded.ColorizeObject()})";
50  }
51  }
52 }
ContentPackage? ContentPackage
readonly ScriptedEvent ParentEvent
Definition: EventAction.cs:106
IEnumerable< Entity > GetTargets(Identifier tag)
Performs a skill check and executes either the Success or Failure child actions depending on whether ...
override? bool DetermineSuccess()
override string ToDebugString()
Rich test to display in debugdraw
SkillCheckAction(ScriptedEvent parentEvent, ContentXElement element)