Client LuaCsForBarotrauma
ShipIssueWorker.cs
3 using Microsoft.Xna.Framework;
4 
5 namespace Barotrauma
6 {
7  abstract class ShipIssueWorker
8  {
9  public const float MaxImportance = 100f;
10  public const float MinImportance = 0f;
11  public Order SuggestedOrder { get; }
12 
13  private float importance;
14  public float Importance
15  {
16  get
17  {
18  return importance;
19  }
20  set
21  {
22  importance = MathHelper.Clamp(value, MinImportance, MaxImportance);
23  }
24  }
25  public float CurrentRedundancy { get; set; }
26 
28  public Identifier Option => SuggestedOrder.Option;
29  public Character OrderedCharacter { get; set; }
30  public Order CurrentOrder { get; private set; }
33  public bool Active { get; protected set; } = true; // used to turn off the instance if errors are detected
34 
36  public virtual float TimeSinceLastAttempt { get; set; }
37  public virtual float RedundantIssueModifier => 0.5f;
38  public virtual bool StopDuringEmergency => true; // limit certain issue assessments when invaded by the enemies
39  public virtual bool AllowEasySwitching => false;
40 
42  {
43  this.shipCommandManager = shipCommandManager;
44  SuggestedOrder = suggestedOrder;
45  }
46 
47  public void SetOrder(Character orderedCharacter)
48  {
49  OrderedCharacter = orderedCharacter;
51  humanAI.ObjectiveManager.CurrentOrders.None(o => o.MatchesOrder(SuggestedOrder.Identifier, Option) && o.TargetEntity == TargetItem))
52  {
53  if (orderedCharacter != CommandingCharacter)
54  {
56  minDurationBetweenSimilar: 5,
57  identifier: ("GiveOrder." + SuggestedOrder.Prefab.Identifier).ToIdentifier());
58  }
65  OrderedCharacter.Speak(TextManager.Get("DialogAffirmative").Value, delay: 1.0f,
66  minDurationBetweenSimilar: 5,
67  identifier: ("ReceiveOrder." + SuggestedOrder.Prefab.Identifier).ToIdentifier());
68  }
70  }
71 
72  public void RemoveOrder()
73  {
74  OrderedCharacter = null;
75  CurrentOrder = null;
76  }
77 
78  protected virtual bool IsIssueViable()
79  {
80  return true;
81  }
82 
83  public float CalculateImportance(bool isEmergency)
84  {
85  Importance = 0f; // reset anything that needs resetting
86 
87  if (!Active)
88  {
89  return Importance;
90  }
91 
93 
94  if (isEmergency && StopDuringEmergency)
95  {
96  return Importance;
97  }
98 
100 
101  // if there are other orders of the same type already being attended to, such as fixing leaks
102  // reduce the relative importance of this issue
103  CurrentRedundancy = 1f;
104  foreach (ShipIssueWorker shipIssueWorker in shipCommandManager.ShipIssueWorkers)
105  {
106  if (shipIssueWorker.GetType() == GetType() && shipIssueWorker != this && shipIssueWorker.OrderAttendedTo())
107  {
109  }
110  }
112 
113  return Importance;
114  }
115 
116  public bool OrderAttendedTo(float timeSinceLastCheck = 0f)
117  {
119  {
120  return false;
121  }
122 
123  // accept only the highest priority order
125  {
126 #if DEBUG
127  ShipCommandManager.ShipCommandLog($"{this} is no longer the top priority of {OrderedCharacter}, considering the issue unattended.");
128 #endif
129  return false;
130  }
131 
133  {
134 #if DEBUG
135  ShipCommandManager.ShipCommandLog(OrderedCharacter + " was unable to perform assigned order in " + this);
136 #endif
137  return false;
138  }
139  return true;
140  }
141  public abstract void CalculateImportanceSpecific();
142  }
143 }
void Speak(string message, ChatMessageType? messageType=null, float delay=0.0f, Identifier identifier=default, float minDurationBetweenSimilar=0.0f)
void SetOrder(Order order, bool isNewOrder, bool speak=true, bool force=false)
Force an order to be set for the character, bypassing hearing checks
Stores information about the Character that is needed between rounds in the menu etc....
static bool IsActive(Character c)
The base class for components holding the different functionalities of the item
Order WithOption(Identifier option)
Definition: Order.cs:700
readonly Entity TargetEntity
Definition: Order.cs:491
string GetChatMessage(string targetCharacterName, string targetRoomName, bool givingOrderToSelf, Identifier orderOption=default, bool isNewOrder=true)
readonly Identifier Option
Definition: Order.cs:478
Order WithManualPriority(int newPriority)
Definition: Order.cs:705
Order WithItemComponent(Item item, ItemComponent component=null)
Definition: Order.cs:745
Identifier Identifier
Definition: Order.cs:536
readonly OrderPrefab Prefab
Definition: Order.cs:477
readonly ItemComponent TargetItemComponent
Definition: Order.cs:492
Order WithOrderGiver(Character orderGiver)
Definition: Order.cs:710
readonly Identifier Identifier
Definition: Prefab.cs:34
static void ShipCommandLog(string text)
readonly List< ShipIssueWorker > ShipIssueWorkers
bool AbleToTakeOrder(Character character)
bool OrderAttendedTo(float timeSinceLastCheck=0f)
ShipIssueWorker(ShipCommandManager shipCommandManager, Order suggestedOrder)
void SetOrder(Character orderedCharacter)
virtual float TimeSinceLastAttempt
ItemComponent TargetItemComponent
virtual Character CommandingCharacter
float CalculateImportance(bool isEmergency)
virtual float RedundantIssueModifier
abstract void CalculateImportanceSpecific()
readonly ShipCommandManager shipCommandManager