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  {
55  CommandingCharacter.Speak(SuggestedOrder.GetChatMessage(OrderedCharacter.Name, "", givingOrderToSelf: false), minDurationBetweenSimilar: 5);
56  }
63  OrderedCharacter.Speak(TextManager.Get("DialogAffirmative").Value, delay: 1.0f, minDurationBetweenSimilar: 5);
64  }
66  }
67 
68  public void RemoveOrder()
69  {
70  OrderedCharacter = null;
71  CurrentOrder = null;
72  }
73 
74  protected virtual bool IsIssueViable()
75  {
76  return true;
77  }
78 
79  public float CalculateImportance(bool isEmergency)
80  {
81  Importance = 0f; // reset anything that needs resetting
82 
83  if (!Active)
84  {
85  return Importance;
86  }
87 
89 
90  if (isEmergency && StopDuringEmergency)
91  {
92  return Importance;
93  }
94 
96 
97  // if there are other orders of the same type already being attended to, such as fixing leaks
98  // reduce the relative importance of this issue
99  CurrentRedundancy = 1f;
100  foreach (ShipIssueWorker shipIssueWorker in shipCommandManager.ShipIssueWorkers)
101  {
102  if (shipIssueWorker.GetType() == GetType() && shipIssueWorker != this && shipIssueWorker.OrderAttendedTo())
103  {
105  }
106  }
108 
109  return Importance;
110  }
111 
112  public bool OrderAttendedTo(float timeSinceLastCheck = 0f)
113  {
115  {
116  return false;
117  }
118 
119  // accept only the highest priority order
121  {
122 #if DEBUG
123  ShipCommandManager.ShipCommandLog($"{this} is no longer the top priority of {OrderedCharacter}, considering the issue unattended.");
124 #endif
125  return false;
126  }
127 
129  {
130 #if DEBUG
131  ShipCommandManager.ShipCommandLog(OrderedCharacter + " was unable to perform assigned order in " + this);
132 #endif
133  return false;
134  }
135  return true;
136  }
137  public abstract void CalculateImportanceSpecific();
138  }
139 }
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:704
readonly Entity TargetEntity
Definition: Order.cs:495
string GetChatMessage(string targetCharacterName, string targetRoomName, bool givingOrderToSelf, Identifier orderOption=default, bool isNewOrder=true)
readonly Identifier Option
Definition: Order.cs:482
Order WithManualPriority(int newPriority)
Definition: Order.cs:709
Order WithItemComponent(Item item, ItemComponent component=null)
Definition: Order.cs:749
Identifier Identifier
Definition: Order.cs:540
readonly ItemComponent TargetItemComponent
Definition: Order.cs:496
Order WithOrderGiver(Character orderGiver)
Definition: Order.cs:714
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