Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/Events/Missions/CargoMission.cs
2 using System.Globalization;
3 
4 namespace Barotrauma
5 {
6  partial class CargoMission : Mission
7  {
8  public override bool DisplayAsCompleted => false;
9  public override bool DisplayAsFailed => false;
10 
12  {
13  LocalizedString rewardText = GetRewardAmountText(sub);
14  LocalizedString retVal;
15  if (rewardPerCrate.HasValue) // If every crate has the same value
16  {
17  LocalizedString rewardPerCrateText = TextManager.GetWithVariable("currencyformat", "[credits]", string.Format(CultureInfo.InvariantCulture, "{0:N0}", rewardPerCrate.Value));
18  retVal = TextManager.GetWithVariables("missionrewardcargopercrate",
19  ("[rewardpercrate]", rewardPerCrateText),
20  ("[itemcount]", itemsToSpawn.Count.ToString()),
21  ("[maxitemcount]", maxItemCount.ToString()),
22  ("[totalreward]", $"‖color:gui.orange‖{rewardText}‖end‖"));
23  }
24  else // Crates have differing values, so only show the total value
25  {
26  retVal = TextManager.GetWithVariables("missionrewardcargo",
27  ("[totalreward]", $"‖color:gui.orange‖{rewardText}‖end‖"),
28  ("[itemcount]", itemsToSpawn.Count.ToString()),
29  ("[maxitemcount]", maxItemCount.ToString()));
30  }
31 
32  return RichString.Rich(retVal);
33  }
34  public override void ClientReadInitial(IReadMessage msg)
35  {
36  base.ClientReadInitial(msg);
37  items.Clear();
38  ushort itemCount = msg.ReadUInt16();
39  for (int i = 0; i < itemCount; i++)
40  {
41  items.Add(Item.ReadSpawnData(msg));
42  }
43  if (items.Contains(null))
44  {
45  throw new System.Exception("Error in CargoMission.ClientReadInitial: item list contains null (mission: " + Prefab.Identifier + ")");
46  }
47  if (items.Count != itemCount)
48  {
49  throw new System.Exception("Error in CargoMission.ClientReadInitial: item count does not match the server count (" + itemCount + " != " + items.Count + ", mission: " + Prefab.Identifier + ")");
50  }
51  if (requiredDeliveryAmount == 0) { requiredDeliveryAmount = items.Count; }
52  if (requiredDeliveryAmount > items.Count)
53  {
54  DebugConsole.AddWarning($"Error in mission \"{Prefab.Identifier}\". Required delivery amount is {requiredDeliveryAmount} but there's only {items.Count} items to deliver.",
55  contentPackage: Prefab.ContentPackage);
56  requiredDeliveryAmount = items.Count;
57  }
58  }
59  }
60 }
override RichString GetMissionRewardText(Submarine sub)
Returns the full reward text of the mission (e.g. "Reward: 2,000 mk" or "Reward: 500 mk x 2 (out of m...
static Item ReadSpawnData(IReadMessage msg, bool spawn=true)
LocalizedString GetRewardAmountText(Submarine sub)
Returns the amount of marks you get from the reward (e.g. "3,000 mk")
ContentPackage? ContentPackage
Definition: Prefab.cs:37
readonly Identifier Identifier
Definition: Prefab.cs:34
static RichString Rich(LocalizedString str, Func< string, string >? postProcess=null)
Definition: RichString.cs:67