forked from ZeroK-RTS/Zero-K-Infrastructure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserBattleStatus.cs
116 lines (86 loc) · 2.78 KB
/
UserBattleStatus.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#region using
using System;
using System.Net;
using Newtonsoft.Json;
#endregion
namespace LobbyClient
{
public enum SyncStatuses
{
Unknown = 0,
Synced = 1,
Unsynced = 2
}
public class UserBattleStatus
{
public int AllyNumber;
public bool IsSpectator;
[JsonIgnore]
public DateTime JoinTime = DateTime.Now;
public string Name;
public string ScriptPassword; // HACK reimplement this
public SyncStatuses SyncStatus = SyncStatuses.Unknown;
[JsonIgnore]
public User LobbyUser;
public int TeamNumber;
public void UpdateWith(UpdateUserBattleStatus u)
{
if (u != null) {
if (u.Name != Name) throw new Exception(string.Format("Applying update of {0} to user {1}", u.Name, Name));
if (u.AllyNumber.HasValue) AllyNumber = u.AllyNumber.Value;
if (u.TeamNumber.HasValue) TeamNumber = u.TeamNumber.Value;
if (u.IsSpectator.HasValue) IsSpectator = u.IsSpectator.Value;
if (u.Sync.HasValue) SyncStatus = u.Sync.Value;
}
}
public UpdateUserBattleStatus ToUpdateBattleStatus()
{
return new UpdateUserBattleStatus() {
Name = Name,
AllyNumber = AllyNumber,
IsSpectator = IsSpectator,
Sync = SyncStatus,
TeamNumber = TeamNumber
};
}
public UserBattleStatus() {}
public UserBattleStatus(string name, User lobbyUser, string password= null)
{
Name = name;
if (password != null) ScriptPassword = password;
else ScriptPassword = name;
LobbyUser = lobbyUser;
}
public virtual UserBattleStatus Clone()
{
return (UserBattleStatus)MemberwiseClone();
}
public bool Equals(UserBattleStatus other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return other.AllyNumber == AllyNumber && other.IsSpectator.Equals(IsSpectator) &&
other.JoinTime.Equals(JoinTime) && Equals(other.Name, Name) &&
Equals(other.SyncStatus, SyncStatus) && other.TeamNumber == TeamNumber;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof(UserBattleStatus)) return false;
return Equals((UserBattleStatus)obj);
}
public override string ToString()
{
return Name;
}
public static bool operator ==(UserBattleStatus left, UserBattleStatus right)
{
return Equals(left, right);
}
public static bool operator !=(UserBattleStatus left, UserBattleStatus right)
{
return !Equals(left, right);
}
} ;
}