Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/Events/Missions/MineralMission.cs
4 using System.Collections.Generic;
5 
6 namespace Barotrauma
7 {
8  partial class MineralMission : Mission
9  {
10  public override bool DisplayAsCompleted => false;
11  public override bool DisplayAsFailed => false;
12 
13  public override int State
14  {
15  get => base.State;
16  set
17  {
18  base.State = value;
19  if (base.State > 0)
20  {
21  caves.ForEach(c => c.MissionsToDisplayOnSonar.Remove(this));
22  }
23  }
24  }
25 
26  public override void ClientReadInitial(IReadMessage msg)
27  {
28  base.ClientReadInitial(msg);
29  byte caveCount = msg.ReadByte();
30  for (int i = 0; i < caveCount; i++)
31  {
32  byte selectedCaveIndex = msg.ReadByte();
33  if (selectedCaveIndex < 255 && Level.Loaded != null)
34  {
35  if (selectedCaveIndex < Level.Loaded.Caves.Count)
36  {
37  var selectedCave = Level.Loaded.Caves[selectedCaveIndex];
38  selectedCave.MissionsToDisplayOnSonar.Add(this);
39  caves.Add(selectedCave);
40  }
41  else
42  {
43  DebugConsole.ThrowError($"Cave index out of bounds when reading nest mission data. Index: {selectedCaveIndex}, number of caves: {Level.Loaded.Caves.Count}");
44  }
45  }
46  }
47 
48  for (int i = 0; i < resourceAmounts.Count; i++)
49  {
50  var amount = msg.ReadByte();
51  var rotation = msg.ReadSingle();
52  for (int j = 0; j < amount; j++)
53  {
54  var item = Item.ReadSpawnData(msg);
55  if (item.GetComponent<Holdable>() is Holdable h)
56  {
57  h.AttachToWall();
58  item.Rotation = rotation;
59  }
60  if (spawnedResources.TryGetValue(item.Prefab.Identifier, out var resources))
61  {
62  resources.Add(item);
63  }
64  else
65  {
66  spawnedResources.Add(item.Prefab.Identifier, new List<Item>() { item });
67  }
68  }
69  }
70 
71  CalculateMissionClusterPositions();
72 
73  for(int i = 0; i < resourceAmounts.Count; i++)
74  {
75  var identifier = msg.ReadIdentifier();
76  var count = msg.ReadByte();
77  var resources = new Item[count];
78  for (int j = 0; j < count; j++)
79  {
80  var id = msg.ReadUInt16();
81  var entity = Entity.FindEntityByID(id);
82  if (!(entity is Item item)) { continue; }
83  resources[j] = item;
84  }
85  relevantLevelResources.Add(identifier, resources);
86  }
87  }
88  }
89 }
static Entity FindEntityByID(ushort ID)
Find an entity based on the ID
Definition: Entity.cs:204
static Item ReadSpawnData(IReadMessage msg, bool spawn=true)