Client LuaCsForBarotrauma
BarotraumaShared/SharedSource/GameSession/ReadyCheck.cs
1 #nullable enable
2 using System;
3 using System.Collections.Generic;
4 
5 namespace Barotrauma
6 {
7  internal enum ReadyStatus
8  {
9  Unanswered,
10  Yes,
11  No,
12  }
13 
14  internal partial class ReadyCheck
15  {
16  private readonly DateTime endTime;
17  private readonly DateTime startTime;
18  public readonly Dictionary<byte, ReadyStatus> Clients;
19  public bool IsFinished = false;
20 
21  public ReadyCheck(List<byte> clients, DateTime startTime, DateTime endTime)
22  : this(clients)
23  {
24  this.startTime = startTime;
25  this.endTime = endTime;
26  }
27 
28  public ReadyCheck(List<byte> clients, float duration)
29  : this(clients)
30  {
31  startTime = DateTime.Now;
32  endTime = startTime + new TimeSpan(0, 0, 0, 0, (int)(duration * 1000));
33  }
34 
35  private ReadyCheck(List<byte> clients)
36  {
37  Clients = new Dictionary<byte, ReadyStatus>();
38  foreach (byte client in clients)
39  {
40  if (Clients.ContainsKey(client)) { continue; }
41 
42  Clients.Add(client, ReadyStatus.Unanswered);
43  }
44  }
45 
46  partial void EndReadyCheck();
47 
48  public void Update(float deltaTime)
49  {
50  if (DateTime.Now < endTime)
51  {
52 #if CLIENT
53  UpdateBar();
54 #endif
55  return;
56  }
57 
58  EndReadyCheck();
59 
60 #if CLIENT
61  msgBox?.Close();
62 #endif
63  }
64  }
65 }