Client LuaCsForBarotrauma
SetPriceMultiplierAction.cs
1 using System;
2 
3 namespace Barotrauma
4 {
9  {
10  public enum OperationType
11  {
12  Set,
13  Multiply,
14  Min,
15  Max
16  }
17 
18  public enum PriceMultiplierType
19  {
20  Store,
21  Mechanical
22  }
23 
24  [Serialize(1.0f, IsPropertySaveable.Yes, description: "Value to set as the multiplier, or to multiply, min or max the current multiplier with.")]
25  public float Multiplier { get; set; }
26 
27  [Serialize(OperationType.Set, IsPropertySaveable.Yes, description: "Do you want to set the value as the multiplier, multiply the existing multiplier with it, or take the smaller or larger of the values.")]
28  public OperationType Operation { get; set; }
29 
30  [Serialize(PriceMultiplierType.Store, IsPropertySaveable.Yes, description: "Do you want to set the price multiplier for stores or for mechanical services (hull and item repairs and restoring lost shuttles)?")]
32 
33  public SetPriceMultiplierAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
34 
35  private bool isFinished = false;
36 
37  public override bool IsFinished(ref string goTo)
38  {
39  return isFinished;
40  }
41  public override void Reset()
42  {
43  isFinished = false;
44  }
45 
46  public override void Update(float deltaTime)
47  {
48  if (isFinished) { return; }
49  if (GameMain.GameSession?.GameMode is CampaignMode campaign && campaign.Map?.CurrentLocation != null)
50  {
51  float newMultiplier = GetCurrentMultiplier(campaign.Map.CurrentLocation);
52 
53  switch (Operation)
54  {
55  case OperationType.Set:
56  newMultiplier = Multiplier;
57  break;
58  case OperationType.Multiply:
59  newMultiplier *= Multiplier;
60  break;
61  case OperationType.Min:
62  newMultiplier = Math.Min(Multiplier, campaign.Map.CurrentLocation.PriceMultiplier);
63  break;
64  case OperationType.Max:
65  newMultiplier = Math.Max(Multiplier, campaign.Map.CurrentLocation.PriceMultiplier);
66  break;
67  default:
68  throw new NotImplementedException();
69  }
70 
71  SetCurrentMultiplier(campaign.Map.CurrentLocation, newMultiplier);
72  }
73  isFinished = true;
74  }
75 
76  private float GetCurrentMultiplier(Location location)
77  {
78  return TargetMultiplier switch
79  {
80  PriceMultiplierType.Store => location.PriceMultiplier,
81  PriceMultiplierType.Mechanical => location.MechanicalPriceMultiplier,
82  _ => throw new NotImplementedException()
83  };
84  }
85 
86  private void SetCurrentMultiplier(Location location, float value)
87  {
88  switch (TargetMultiplier)
89  {
90  case PriceMultiplierType.Store:
91  location.PriceMultiplier = value;
92  break;
93  case PriceMultiplierType.Mechanical:
94  location.MechanicalPriceMultiplier = value;
95  break;
96  default:
97  throw new NotImplementedException();
98  }
99  }
100 
101  public override string ToDebugString()
102  {
103  return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(SetPriceMultiplierAction)} -> (Multiplier: {Multiplier.ColorizeObject()}, " +
104  $"Operation: {Operation.ColorizeObject()}, Target: {TargetMultiplier})";
105  }
106  }
107 }
static GameSession?? GameSession
Definition: GameMain.cs:88
float MechanicalPriceMultiplier
Definition: Location.cs:506
Adjusts the price multiplier for stores or mechanical repairs in the current location.
override void Update(float deltaTime)
override bool IsFinished(ref string goTo)
Has the action finished.
override string ToDebugString()
Rich test to display in debugdraw
SetPriceMultiplierAction(ScriptedEvent parentEvent, ContentXElement element)