-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscore.go
265 lines (223 loc) · 6.58 KB
/
score.go
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package main
import "log"
type Player struct {
steamID, username, team string
kills, deaths, assists, bombPlanted, bombDropped, bombPickedUp, rounds, matches, targetBombed, bombDefused, bombDefuseAttemptWithKit, bombDefuseAttemptWithoutKit int
}
const (
BOMB_PLANTED = iota
BOMB_DROPPED
BOMB_PICKED_UP
TARGET_BOMBED
BOMB_DEFUSED
BOMB_DEFUSE_ATTEMPTED_WITH_KIT
BOMB_DEFUSE_ATTEMPTED_WITHOUT_KIT
ROUND_FINISHED
MATCH_FINISHED
)
type ScoreManager struct {
firstHalfStarted, secondHalfStarted, matchCompleted bool
firstHalfT, firstHalfCT int
players []Player
playersStatsFirstHalf []Player
playersStatsSecondHalf []Player
CTScore, TScore int
CTsLeft, TsLeft int
}
func (sm *ScoreManager) AddPlayer(steamID, username string) {
if sm.DoesPlayerExist(steamID, username) {
return
}
player := Player{}
player.steamID = steamID
player.username = username
player.team = ""
player.kills = 0
player.deaths = 0
player.assists = 0
player.rounds = 0
player.matches = 0
player.bombDefused = 0
player.bombPlanted = 0
player.targetBombed = 0
sm.players = append(sm.players, player)
log.Printf("Added player: %s %s\n", steamID, username)
}
func (sm *ScoreManager) RemovePlayer(steamID, username string) {
if !sm.DoesPlayerExist(steamID, username) {
return
}
for i := range sm.players {
if sm.players[i].steamID == steamID && steamID != "BOT" || sm.players[i].steamID == "BOT" && sm.players[i].username == username{
sm.players = append(sm.players[:i], sm.players[i+1:]...)
log.Printf("Removed player: %s %s\n", steamID, username)
return
}
}
return
}
func (sm *ScoreManager) DoesPlayerExist(steamID, username string) (bool) {
for i := range sm.players {
if sm.players[i].steamID == steamID && steamID != "BOT" || sm.players[i].steamID == "BOT" && sm.players[i].username == username {
return true
}
}
return false
}
func (sm *ScoreManager) AddEventStatsAll(eventType int) {
for i := range sm.players {
switch eventType {
case ROUND_FINISHED:
sm.players[i].rounds += 1
case MATCH_FINISHED:
sm.players[i].matches = 1
}
}
}
func (sm *ScoreManager) AddEventStats(eventType int, steamID, username string) {
for i := range sm.players {
if sm.players[i].steamID == steamID && steamID != "BOT" || sm.players[i].steamID == "BOT" && sm.players[i].username == username {
switch eventType {
case BOMB_PLANTED:
sm.players[i].bombPlanted += 1
case BOMB_DROPPED:
sm.players[i].bombDropped += 1
case BOMB_PICKED_UP:
sm.players[i].bombPickedUp += 1
case TARGET_BOMBED:
sm.players[i].targetBombed += 1
case BOMB_DEFUSED:
sm.players[i].bombDefused += 1
case BOMB_DEFUSE_ATTEMPTED_WITH_KIT:
sm.players[i].bombDefuseAttemptWithKit += 1
case BOMB_DEFUSE_ATTEMPTED_WITHOUT_KIT:
sm.players[i].bombDefuseAttemptWithoutKit += 1
}
}
}
}
func (sm *ScoreManager) AddKillAndDeathStats(p1steamID, p1username, p2steamID, p2username string) {
for i := range sm.players {
if sm.players[i].steamID == p1steamID && p1steamID != "BOT" || sm.players[i].steamID == "BOT" && sm.players[i].username == p1username {
sm.players[i].kills += 1
}
if sm.players[i].steamID == p2steamID && p2steamID != "BOT" || sm.players[i].steamID == "BOT" && sm.players[i].username == p2username {
sm.players[i].deaths += 1
}
}
}
func (sm *ScoreManager) ResetPlayerStats() {
for i := range sm.players {
sm.players[i].kills = 0
sm.players[i].deaths = 0
sm.players[i].assists = 0
sm.players[i].bombPlanted = 0
sm.players[i].bombDropped = 0
sm.players[i].bombPickedUp = 0
sm.players[i].targetBombed = 0
sm.players[i].bombDefused = 0
sm.players[i].bombDefuseAttemptWithKit = 0
sm.players[i].bombDefuseAttemptWithoutKit = 0
}
}
func (sm *ScoreManager) EnumerateStats() {
for i := range sm.players {
log.Printf("==============================================================\n")
log.Printf("Player %s (%s)\n", sm.players[i].username, sm.players[i].steamID)
log.Printf("Kills: %d\n", sm.players[i].kills)
log.Printf("Deaths: %d\n", sm.players[i].deaths)
log.Printf("Assists: %d\n", sm.players[i].assists)
log.Printf("Bombs planted: %d\n", sm.players[i].bombPlanted)
log.Printf("Bombs dropped: %d\n", sm.players[i].bombDropped)
log.Printf("Bombs picked up: %d\n", sm.players[i].bombPickedUp)
log.Printf("Target bombed: %d\n", sm.players[i].targetBombed)
log.Printf("Bombs defused: %d\n", sm.players[i].bombDefused)
log.Printf("Bombs defuse attempts with kit %d\n", sm.players[i].bombDefuseAttemptWithKit)
log.Printf("Bombs defuse attempts without kit %d\n", sm.players[i].bombDefuseAttemptWithoutKit)
}
}
func (sm *ScoreManager) PreservePlayerStatsFirstHalf() {
copy(sm.playersStatsFirstHalf, sm.players)
}
func (sm *ScoreManager) SaveMatchData() {
//todo
}
func (sm *ScoreManager) FirstHalfStarted() (bool) {
return sm.firstHalfStarted;
}
func (sm *ScoreManager) SetFirstHalfStarted(started bool) {
sm.firstHalfStarted = started
}
func (sm *ScoreManager) SecondHalfStarted() (bool) {
return sm.secondHalfStarted
}
func (sm *ScoreManager) SetSecondHalfStarted(started bool) {
sm.secondHalfStarted = started
}
func (sm *ScoreManager) MatchCompleted() (bool) {
return sm.matchCompleted
}
func (sm *ScoreManager) SetMatchCompleted(completed bool) {
sm.matchCompleted = completed
copy(sm.playersStatsSecondHalf, sm.players)
}
func (sm *ScoreManager) SetCTScore(i int) {
sm.CTScore = i
}
func (sm *ScoreManager) SetTScore(i int) {
sm.TScore = i
}
func (sm *ScoreManager) GetCTScore() (int) {
return sm.CTScore
}
func (sm *ScoreManager) GetTScore() (int) {
return sm.TScore
}
func (sm *ScoreManager) SetCTsLeft(i int) {
sm.CTsLeft = i
}
func (sm *ScoreManager) SetTsLeft(i int) {
sm.TsLeft = i
}
func (sm *ScoreManager) GetCTsLeft() (int) {
return sm.CTsLeft
}
func (sm *ScoreManager) GetTsLeft() (int) {
return sm.TsLeft
}
func (sm *ScoreManager) GetFirstHalfT() (int) {
return sm.firstHalfT
}
func (sm *ScoreManager) SetFirstHalfT(firstHalfT int) {
sm.firstHalfT = firstHalfT;
}
func (sm *ScoreManager) GetFirstHalfCT() (int) {
return sm.firstHalfCT
}
func (sm *ScoreManager) SetFirstHalfCT(firstHalfCT int) {
sm.firstHalfCT = firstHalfCT;
}
func (sm *ScoreManager) ResetRoundPlayersLeft() {
sm.CTsLeft = 5
sm.TsLeft = 5
}
func (sm *ScoreManager) ResetRoundCounter() {
sm.CTsLeft = 5
sm.TsLeft = 5
sm.CTScore = 0
sm.TScore = 0
}
func (sm *ScoreManager) Reset() {
sm.CTsLeft = 5
sm.TsLeft = 5
sm.CTScore = 0
sm.TScore = 0
sm.players = nil
sm.playersStatsFirstHalf = nil
sm.playersStatsSecondHalf = nil
sm.firstHalfStarted = false
sm.secondHalfStarted = false
sm.matchCompleted = false
sm.firstHalfT = 0
sm.firstHalfCT = 0
}