Client LuaCsForBarotrauma
CheckMoneyAction.cs
2 using System.Collections.Generic;
3 using System.Linq;
4 
5 namespace Barotrauma
6 {
11  {
12  [Serialize(0, IsPropertySaveable.Yes, description: "Minimum amount of money the crew or the player must have.")]
13  public int Amount { get; set; }
14 
15  [Serialize("", IsPropertySaveable.Yes, description: "Tag of the player to check. If omitted, the crew's shared wallet is checked instead.")]
16  public Identifier TargetTag { get; set; }
17 
18  public CheckMoneyAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
19  {
20  }
21 
22  protected override bool? DetermineSuccess()
23  {
24  Client matchingClient = null;
25  bool hasTag = !TargetTag.IsEmpty;
26 #if SERVER
27  IEnumerable<Entity> targets = ParentEvent.GetTargets(TargetTag);
28 
29  if (hasTag)
30  {
31  foreach (Entity entity in targets)
32  {
33  if (entity is Character && GameMain.Server?.ConnectedClients.FirstOrDefault(c => c.Character == entity) is { } matchingCharacter)
34  {
35  matchingClient = matchingCharacter;
36  break;
37  }
38  }
39  }
40 #endif
41 
42  if (GameMain.GameSession?.GameMode is CampaignMode campaign)
43  {
44  return !hasTag ? campaign.Bank.CanAfford(Amount) : campaign.GetWallet(matchingClient).CanAfford(Amount);
45  }
46  return false;
47  }
48 
49  public override string ToDebugString()
50  {
51  string subActionStr = "";
52  if (succeeded.HasValue)
53  {
54  subActionStr = $"\n Sub action: {(succeeded.Value ? Success : Failure)?.CurrentSubAction.ColorizeObject()}";
55  }
56  return $"{ToolBox.GetDebugSymbol(DetermineFinished())} {nameof(CheckMoneyAction)} -> (Amount: {Amount.ColorizeObject()}" +
57  $" Succeeded: {(succeeded.HasValue ? succeeded.Value.ToString() : "not determined").ColorizeObject()})" +
58  subActionStr;
59  }
60  }
61 }
Check whether the crew or a specific player has enough money.
override string ToDebugString()
Rich test to display in debugdraw
override? bool DetermineSuccess()
CheckMoneyAction(ScriptedEvent parentEvent, ContentXElement element)
readonly ScriptedEvent ParentEvent
Definition: EventAction.cs:106
static GameSession?? GameSession
Definition: GameMain.cs:88
IEnumerable< Entity > GetTargets(Identifier tag)