Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/Events/Missions/ScanMission.cs
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 
6 namespace Barotrauma
7 {
8  partial class ScanMission : Mission
9  {
10  public override IEnumerable<Entity> HudIconTargets
11  {
12  get
13  {
14  if (State == 0)
15  {
16  return scanTargets.Where(kvp => !kvp.Value).Select(kvp => kvp.Key);
17  }
18  else
19  {
20  return Enumerable.Empty<Entity>();
21  }
22  }
23  }
24 
25  public override bool DisplayAsCompleted => false;
26  public override bool DisplayAsFailed => false;
27 
28  public override void ClientReadInitial(IReadMessage msg)
29  {
30  base.ClientReadInitial(msg);
31  startingItems.Clear();
32  ushort itemCount = msg.ReadUInt16();
33  for (int i = 0; i < itemCount; i++)
34  {
35  startingItems.Add(Item.ReadSpawnData(msg));
36  }
37  if (startingItems.Contains(null))
38  {
39  throw new Exception($"Error in ScanMission.ClientReadInitial: item list contains null (mission: {Prefab.Identifier})");
40  }
41  if (startingItems.Count != itemCount)
42  {
43  throw new Exception($"Error in ScanMission.ClientReadInitial: item count does not match the server count ({itemCount} != {startingItems.Count}, mission: {Prefab.Identifier})");
44  }
45  scanners.Clear();
46  GetScanners();
47  ClientReadScanTargetStatus(msg);
48  }
49 
50  public override void ClientRead(IReadMessage msg)
51  {
52  base.ClientRead(msg);
53  ClientReadScanTargetStatus(msg);
54  }
55 
56  private void ClientReadScanTargetStatus(IReadMessage msg)
57  {
58  scanTargets.Clear();
59  byte targetsToScan = msg.ReadByte();
60  for (int i = 0; i < targetsToScan; i++)
61  {
62  ushort id = msg.ReadUInt16();
63  bool scanned = msg.ReadBoolean();
64  Entity entity = Entity.FindEntityByID(id);
65  if (!(entity is WayPoint wayPoint))
66  {
67  string errorMsg = $"Failed to find a waypoint in ScanMission.ClientReadScanTargetStatus. Entity {id} was {(entity?.ToString() ?? null)}";
68  DebugConsole.ThrowError(errorMsg);
69  GameAnalyticsManager.AddErrorEventOnce("ScanMission.ClientReadScanTargetStatus", GameAnalyticsManager.ErrorSeverity.Error, errorMsg);
70  }
71  else
72  {
73  scanTargets.Add(wayPoint, scanned);
74  }
75  }
76  }
77  }
78 }
static Entity FindEntityByID(ushort ID)
Find an entity based on the ID
Definition: Entity.cs:204
static Item ReadSpawnData(IReadMessage msg, bool spawn=true)