-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
1337 lines (1162 loc) · 40.4 KB
/
main.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package main
import (
//"bufio"
"fmt"
"io/ioutil"
"math"
"os"
"path/filepath"
"strconv"
"strings"
dem "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs"
common "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/common"
events "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/events"
)
//TODO
//"Catch up on the score" - dont remember what this is lol
//BUG fix
//add verification for missed event triggers if someone DCs/Cs after the redundant event that is stale
//csgo bots all have same steamID, need to use something else just in case for bots
//MM bug?
//add support for esea games? need to change validation and how we determine what round it is (gamestats rounds doesnt work)
//FUNCTIONAL CHANGES
//add verification for if a round event has triggered so far in the round (avoid double roundEnds)
//check for game start without pistol (if we have bad demo)
//Add backend support
//Add anchor stuff
//Add team economy round stats (ecos, forces, etc)
//Add various nil checking
//CLEAN CODE
//create a outputPlayer function to clean up output.go
//convert rating calculations to a function
//actually use killValues lmao
const DEBUG = false
//const suppressNormalOutput = false
//globals
const printChatLog = true
const printDebugLog = true
const tradeCutoff = 4 // in seconds
var multikillBonus = [...]float64{0, 0, 0.3, 0.7, 1.2, 2}
var clutchBonus = [...]float64{0, 0.2, 0.6, 1.2, 2, 3}
var killValues = map[string]float64{
"attacking": 1.2, //base values
"defending": 1.0,
"bombDefense": 1.0,
"retake": 1.2,
"chase": 0.8,
"exit": 0.6,
"t_consolation": 0.5,
"gravy": 0.6,
"punish": 0.8,
"entry": 0.8, //multipliers
"t_opener": 0.3,
"ct_opener": 0.5,
"trade": 0.3,
"flashAssist": 0.2,
"assist": 0.15,
}
type game struct {
//winnerID int
winnerClanName string
rounds []*round
potentialRound *round
teams map[string]*team
flags flag
mapName string
tickRate int
tickLength int
roundsToWin int //30 or 16
totalPlayerStats map[uint64]*playerStats
totalTeamStats map[string]*teamStats
playerOrder []uint64
teamOrder []string
totalRounds int
}
type flag struct {
//all our sentinals and shit
hasGameStarted bool
isGameLive bool
isGameOver bool
inRound bool
prePlant bool
postPlant bool
postWinCon bool
roundIntegrityStart int
roundIntegrityEnd int
roundIntegrityEndOfficial int
//for the round (gets reset on a new round) maybe should be in a new struct
tAlive int
ctAlive int
tMoney bool
tClutchVal int
ctClutchVal int
tClutchSteam uint64
ctClutchSteam uint64
openingKill bool
lastTickProcessed int
ticksProcessed int
didRoundEndFire bool
roundStartedAt int
haveInitRound bool
}
type team struct {
//id int //meaningless?
name string
score int
}
type teamStats struct {
winPoints float64
impactPoints float64
tWinPoints float64
ctWinPoints float64
tImpactPoints float64
ctImpactPoints float64
_4v5w int
_4v5s int
_5v4w int
_5v4s int
pistols int
pistolsW int
saves int
clutches int
traded int
fass int
ef int
ud int
util int
ctR int
ctRW int
tR int
tRW int
deaths int
//kinda garbo
normalizer int
}
type round struct {
//round value
roundNum int8
startingTick int
endingTick int
playerStats map[uint64]*playerStats
teamStats map[string]*teamStats
initTerroristCount int
initCTerroristCount int
winnerClanName string
//winnerID int //this is the unique ID which should not change BUT IT DOES
winnerENUM int //this effectively represents the side that won: 2 (T) or 3 (CT)
integrityCheck bool
planter uint64
defuser uint64
endDueToBombEvent bool
winTeamDmg int
serverNormalizer int
serverImpactPoints float64
}
type playerStats struct {
name string
steamID uint64
isBot bool
//teamID int
teamENUM int
teamClanName string
side int
rounds int
//playerPoints float32
//teamPoints float32
damage int
kills uint8
assists uint8
deaths uint8
deathTick int
deathPlacement float64
ticksAlive int
trades int
traded int
ok int
ol int
cl_1 int
cl_2 int
cl_3 int
cl_4 int
cl_5 int
_2k int
_3k int
_4k int
_5k int
nadeDmg int
infernoDmg int
utilDmg int
ef int
fAss int
enemyFlashTime float64
hs int
kastRounds float64
saves int
entries int
killPoints float64
impactPoints float64
winPoints float64
awpKills int
RF int
RA int
nadesThrown int
firesThrown int
flashThrown int
smokeThrown int
damageTaken int
suppRounds int
suppDamage int
lurkerBlips int
distanceToTeammates int
lurkRounds int
wlp float64
mip float64
rws float64 //round win shares
rwk int //rounds with kills
//derived
utilThrown int
atd int
kast float64
killPointAvg float64
iiwr float64
adr float64
drDiff float64
kR float64
tr float64 //trade ratio
impactRating float64
rating float64
//side specific
tDamage int
ctDamage int
tImpactPoints float64
tWinPoints float64
tOK int
tOL int
ctImpactPoints float64
ctWinPoints float64
ctOK int
ctOL int
tKills uint8
tDeaths uint8
tKAST float64
tKASTRounds float64
tADR float64
ctKills uint8
ctDeaths uint8
ctKAST float64
ctKASTRounds float64
ctADR float64
tTeamsWinPoints float64
ctTeamsWinPoints float64
tWinPointsNormalizer int
ctWinPointsNormalizer int
tRounds int
ctRounds int
ctRating float64
tRating float64
tADP float64
ctADP float64
tRF int
ctAWP int
//kinda garbo
teamsWinPoints float64
winPointsNormalizer int
//"flags"
health int
tradeList map[uint64]int
mostRecentFlasher uint64
mostRecentFlashVal float64
damageList map[uint64]int
}
func main() {
input_dir := "in"
files, _ := ioutil.ReadDir(input_dir)
for _, file := range files {
filename := file.Name()
if strings.HasSuffix(filename, ".dem") {
fmt.Println("processing", file.Name())
go processDemo(filepath.Join(input_dir, filename))
}
}
var input string
fmt.Scanln(&input)
//authenticate()
}
func initGameObject() *game {
g := game{}
g.rounds = make([]*round, 0)
g.potentialRound = &round{}
g.flags.hasGameStarted = false
g.flags.isGameLive = false
g.flags.isGameOver = false
g.flags.inRound = false
g.flags.prePlant = true
g.flags.postPlant = false
g.flags.postWinCon = false
//these three vars to check if we have a complete round
g.flags.roundIntegrityStart = -1
g.flags.roundIntegrityEnd = -1
g.flags.roundIntegrityEndOfficial = -1
return &g
}
func processDemo(demoName string) {
game := initGameObject()
/*
var errLog = "";
*/
f, err := os.Open(demoName)
//f, err := os.Open("league1.dem")
if err != nil {
panic(err)
}
defer f.Close()
p := dem.NewParser(f)
defer p.Close()
//must parse header to get header info
header, err := p.ParseHeader()
if err != nil {
panic(err)
}
//set map name
game.mapName = strings.Title((header.MapName)[3:])
fmt.Println("Map is", game.mapName)
//set tick rate
game.tickRate = int(math.Round(p.TickRate()))
fmt.Println("Tick rate is", game.tickRate)
game.tickLength = header.PlaybackTicks
//creating a file to dump chat log into
fmt.Printf("Creating chatLog file.\n")
os.Mkdir("out", 0777)
chatFile, chatFileErr := os.Create("out/chatLog.txt")
if chatFileErr != nil {
fmt.Printf("Error in opening chatLog file.\n")
}
defer chatFile.Close()
fmt.Printf("Creating debug file.\n")
debugFile, debugFileErr := os.Create("out/debug.txt")
if debugFileErr != nil {
fmt.Printf("Error in opening debug file.\n")
}
defer debugFile.Close()
//---------------FUNCTIONS---------------
initGameStart := func() {
game.flags.hasGameStarted = true
game.flags.isGameLive = true
fmt.Println("GAME HAS STARTED!!!")
game.teams = make(map[string]*team)
teamTemp := p.GameState().TeamTerrorists()
game.teams[teamTemp.ClanName()] = &team{name: validateTeamName(game, teamTemp.ClanName())}
teamTemp = p.GameState().TeamCounterTerrorists()
game.teams[teamTemp.ClanName()] = &team{name: validateTeamName(game, teamTemp.ClanName())}
//to handle short and long matches
if p.GameState().ConVars()["mp_maxrounds"] != "30" {
maxRounds, fuckOFF := strconv.Atoi(p.GameState().ConVars()["mp_maxrounds"])
if fuckOFF == nil {
game.roundsToWin = maxRounds/2 + 1
} else {
//ADD TO ERROR LOG
game.roundsToWin = maxRounds/2 + 1
//maybe this gives us a way to check for short vs long match
}
} else {
game.roundsToWin = 16 //we will assume long match in case convar is not set
}
}
//reset various flags
resetRoundFlags := func() {
game.flags.prePlant = true
game.flags.postPlant = false
game.flags.postWinCon = false
game.flags.tClutchVal = 0
game.flags.ctClutchVal = 0
game.flags.tClutchSteam = 0
game.flags.ctClutchSteam = 0
game.flags.tMoney = false
game.flags.openingKill = true
game.flags.lastTickProcessed = 0
game.flags.ticksProcessed = 0
game.flags.didRoundEndFire = false
game.flags.roundStartedAt = 0
game.flags.haveInitRound = false
}
initTeamPlayer := func(team *common.TeamState, currRoundObj *round) {
for _, teamMember := range team.Members() {
player := &playerStats{name: teamMember.Name, steamID: teamMember.SteamID64, isBot: teamMember.IsBot, side: int(team.Team()), teamENUM: team.ID(), teamClanName: validateTeamName(game, team.ClanName()), health: 100, tradeList: make(map[uint64]int), damageList: make(map[uint64]int)}
currRoundObj.playerStats[player.steamID] = player
}
}
initRound := func() {
game.flags.roundIntegrityStart = p.GameState().TotalRoundsPlayed() + 1
fmt.Println("We are starting round", game.flags.roundIntegrityStart)
newRound := &round{roundNum: int8(game.flags.roundIntegrityStart), startingTick: p.GameState().IngameTick()}
newRound.playerStats = make(map[uint64]*playerStats)
newRound.teamStats = make(map[string]*teamStats)
//set players in playerStats for the round
terrorists := p.GameState().TeamTerrorists()
counterTerrorists := p.GameState().TeamCounterTerrorists()
initTeamPlayer(terrorists, newRound)
initTeamPlayer(counterTerrorists, newRound)
//set teams in teamStats for the round
newRound.teamStats[validateTeamName(game, p.GameState().TeamTerrorists().ClanName())] = &teamStats{tR: 1}
newRound.teamStats[validateTeamName(game, p.GameState().TeamCounterTerrorists().ClanName())] = &teamStats{ctR: 1}
// Reset round
game.potentialRound = newRound
//track the number of people alive for clutch checking and record keeping
game.flags.tAlive = len(terrorists.Members())
game.flags.ctAlive = len(counterTerrorists.Members())
game.potentialRound.initTerroristCount = game.flags.tAlive
game.potentialRound.initCTerroristCount = game.flags.ctAlive
resetRoundFlags()
}
processRoundOnWinCon := func(winnerClanName string) {
game.flags.roundIntegrityEnd = p.GameState().TotalRoundsPlayed() + 1
fmt.Println("We are processing round win con stuff", game.flags.roundIntegrityEnd)
game.totalRounds = game.flags.roundIntegrityEnd
game.flags.prePlant = false
game.flags.postPlant = false
game.flags.postWinCon = true
//set winner
game.potentialRound.winnerClanName = winnerClanName
game.teams[game.potentialRound.winnerClanName].score += 1
//fmt.Println("We think this team won", game.teams[game.potentialRound.winnerID].name)
//check clutch
}
processRoundFinal := func(lastRound bool) {
game.flags.inRound = false
game.potentialRound.endingTick = p.GameState().IngameTick()
game.flags.roundIntegrityEndOfficial = p.GameState().TotalRoundsPlayed()
if lastRound {
game.flags.roundIntegrityEndOfficial += 1
game.totalRounds = game.flags.roundIntegrityEndOfficial
}
fmt.Println("We are processing round final stuff", game.flags.roundIntegrityEndOfficial)
fmt.Println(len(game.rounds))
//we have the entire round uninterrupted
if game.flags.roundIntegrityStart == game.flags.roundIntegrityEnd && game.flags.roundIntegrityEnd == game.flags.roundIntegrityEndOfficial {
game.potentialRound.integrityCheck = true
//check team stats
if game.potentialRound.teamStats[game.potentialRound.winnerClanName].pistols == 1 {
game.potentialRound.teamStats[game.potentialRound.winnerClanName].pistolsW = 1
}
if game.potentialRound.teamStats[game.potentialRound.winnerClanName]._4v5s == 1 {
game.potentialRound.teamStats[game.potentialRound.winnerClanName]._4v5w = 1
} else if game.potentialRound.teamStats[game.potentialRound.winnerClanName]._5v4s == 1 {
game.potentialRound.teamStats[game.potentialRound.winnerClanName]._5v4w = 1
}
if game.potentialRound.teamStats[game.potentialRound.winnerClanName].tR == 1 {
game.potentialRound.teamStats[game.potentialRound.winnerClanName].tRW = 1
} else if game.potentialRound.teamStats[game.potentialRound.winnerClanName].ctR == 1 {
game.potentialRound.teamStats[game.potentialRound.winnerClanName].ctRW = 1
}
//set the clutch
if game.potentialRound.winnerENUM == 2 && game.flags.tClutchSteam != 0 {
game.potentialRound.teamStats[game.potentialRound.winnerClanName].clutches = 1
game.potentialRound.playerStats[game.flags.tClutchSteam].impactPoints += clutchBonus[game.flags.tClutchVal]
switch game.flags.tClutchVal {
case 1:
game.potentialRound.playerStats[game.flags.tClutchSteam].cl_1 = 1
case 2:
game.potentialRound.playerStats[game.flags.tClutchSteam].cl_2 = 1
case 3:
game.potentialRound.playerStats[game.flags.tClutchSteam].cl_3 = 1
case 4:
game.potentialRound.playerStats[game.flags.tClutchSteam].cl_4 = 1
case 5:
game.potentialRound.playerStats[game.flags.tClutchSteam].cl_5 = 1
}
} else if game.potentialRound.winnerENUM == 3 && game.flags.ctClutchSteam != 0 {
game.potentialRound.teamStats[game.potentialRound.winnerClanName].clutches = 1
game.potentialRound.playerStats[game.flags.ctClutchSteam].impactPoints += clutchBonus[game.flags.ctClutchVal]
switch game.flags.ctClutchVal {
case 1:
game.potentialRound.playerStats[game.flags.ctClutchSteam].cl_1 = 1
case 2:
game.potentialRound.playerStats[game.flags.ctClutchSteam].cl_2 = 1
case 3:
game.potentialRound.playerStats[game.flags.ctClutchSteam].cl_3 = 1
case 4:
game.potentialRound.playerStats[game.flags.ctClutchSteam].cl_4 = 1
case 5:
game.potentialRound.playerStats[game.flags.ctClutchSteam].cl_5 = 1
}
}
//add multikills & saves & misc
highestImpactPoints := 0.0
mipPlayers := 0
for _, player := range (game.potentialRound).playerStats {
if player.deaths == 0 {
player.kastRounds = 1
if player.teamENUM != game.potentialRound.winnerENUM {
player.saves = 1
game.potentialRound.teamStats[player.teamClanName].saves = 1
}
}
game.potentialRound.playerStats[player.steamID].impactPoints += player.killPoints
game.potentialRound.playerStats[player.steamID].impactPoints += float64(player.damage) / float64(250)
game.potentialRound.playerStats[player.steamID].impactPoints += multikillBonus[player.kills]
switch player.kills {
case 2:
player._2k = 1
case 3:
player._3k = 1
case 4:
player._4k = 1
case 5:
player._5k = 1
}
if player.impactPoints > highestImpactPoints {
highestImpactPoints = player.impactPoints
}
if player.teamENUM == game.potentialRound.winnerENUM {
player.winPoints = player.impactPoints
player.RF = 1
} else {
player.RA = 1
}
}
for _, player := range (game.potentialRound).playerStats {
if player.impactPoints == highestImpactPoints {
mipPlayers += 1
}
}
for _, player := range (game.potentialRound).playerStats {
if player.impactPoints == highestImpactPoints {
player.mip = 1.0 / float64(mipPlayers)
}
}
//check the lurk
var susLurker uint64
susLurkBlips := 0
invalidLurk := false
for _, player := range game.potentialRound.playerStats {
if player.side == 2 {
if player.lurkerBlips > susLurkBlips {
susLurkBlips = player.lurkerBlips
susLurker = player.steamID
}
}
}
for _, player := range game.potentialRound.playerStats {
if player.side == 2 {
if player.lurkerBlips == susLurkBlips && player.steamID != susLurker {
invalidLurk = true
}
}
}
if !invalidLurk && susLurkBlips > 3 {
game.potentialRound.playerStats[susLurker].lurkRounds = 1
}
//add our valid round
game.rounds = append(game.rounds, game.potentialRound)
}
//endRound function functionality
}
//-------------ALL OUR EVENTS---------------------
p.RegisterEventHandler(func(e events.FrameDone) {
if game.flags.roundStartedAt > 0 && game.flags.roundStartedAt+(1*game.tickRate) > p.GameState().IngameTick() && !game.flags.haveInitRound {
pistol := false
//we are going to check to see if the first pistol is actually starting
membersT := p.GameState().TeamTerrorists().Members()
membersCT := p.GameState().TeamCounterTerrorists().Members()
if len(membersT) != 0 && len(membersCT) != 0 {
if membersT[0].Money()+membersT[0].MoneySpentThisRound() == 800 && membersCT[0].Money()+membersCT[0].MoneySpentThisRound() == 800 {
//start the game
if !game.flags.hasGameStarted {
initGameStart()
}
//track the pistol
pistol = true
}
}
//fmt.Println("Has the Game Started?", game.flags.hasGameStarted)
if game.flags.isGameLive {
//init round stats
initRound()
game.flags.haveInitRound = true
if pistol {
for _, team := range game.potentialRound.teamStats {
team.pistols = 1
}
}
}
}
if game.flags.inRound && game.flags.lastTickProcessed+(4*game.tickRate) < p.GameState().IngameTick() {
game.flags.lastTickProcessed = p.GameState().IngameTick()
game.flags.ticksProcessed += 1
//this will be triggered every 4 seconds of in round time after the first 10 seconds
//check for lurker
if game.flags.tAlive > 2 && !game.flags.postWinCon && p.GameState().IngameTick() > (18*game.tickRate)+game.potentialRound.startingTick {
membersT := p.GameState().TeamTerrorists().Members()
for _, terrorist := range membersT {
if terrorist.IsAlive() {
for _, teammate := range membersT {
if terrorist.SteamID64 != teammate.SteamID64 && teammate.IsAlive() {
dist := int(terrorist.Position().Distance(teammate.Position()))
if dist < 500 {
//invalidate the lurk blip b/c we have a close teammate
game.potentialRound.playerStats[terrorist.SteamID64].distanceToTeammates = -999999
}
if game.potentialRound.playerStats[terrorist.SteamID64] != nil {
game.potentialRound.playerStats[terrorist.SteamID64].distanceToTeammates += dist
} else {
fmt.Println("THIS IS WHERE WE BROKE_______________________________---------------------------------------------------")
}
}
}
}
}
var lurkerSteam uint64
lurkerDist := 999999
for _, terrorist := range membersT {
if terrorist.IsAlive() {
if game.potentialRound.playerStats[terrorist.SteamID64] == nil {
fmt.Println(terrorist.Name)
}
dist := game.potentialRound.playerStats[terrorist.SteamID64].distanceToTeammates
if dist < lurkerDist && dist > 0 {
lurkerDist = dist
lurkerSteam = terrorist.SteamID64
}
}
}
if lurkerSteam != 0 {
game.potentialRound.playerStats[lurkerSteam].lurkerBlips += 1
}
}
}
})
p.RegisterEventHandler(func(e events.RoundStart) {
fmt.Println("Round Start", p.GameState().TotalRoundsPlayed())
game.flags.roundStartedAt = p.GameState().IngameTick()
})
p.RegisterEventHandler(func(e events.RoundFreezetimeEnd) {
fmt.Printf("Round Freeze Time End\n")
pistol := false
//we are going to check to see if the first pistol is actually starting
membersT := p.GameState().TeamTerrorists().Members()
membersCT := p.GameState().TeamCounterTerrorists().Members()
if len(membersT) != 0 && len(membersCT) != 0 {
if membersT[0].Money()+membersT[0].MoneySpentThisRound() == 800 && membersCT[0].Money()+membersCT[0].MoneySpentThisRound() == 800 {
//start the game
if !game.flags.hasGameStarted {
initGameStart()
}
//track the pistol
pistol = true
}
}
fmt.Println("Has the Game Started?", game.flags.hasGameStarted)
if game.flags.isGameLive {
//init round stats
game.flags.inRound = true
initRound()
if pistol {
for _, team := range game.potentialRound.teamStats {
team.pistols = 1
}
}
}
})
p.RegisterEventHandler(func(e events.RoundEnd) {
if game.flags.isGameLive {
game.flags.didRoundEndFire = true
fmt.Println("Round", p.GameState().TotalRoundsPlayed()+1, "End", e.WinnerState.ClanName(), "won", "this determined from e.WinnerState.ClanName()")
fmt.Println("e.WinnerState.ID()", e.WinnerState.ID(), "and", "e.Winner", e.Winner, "and", "e.WinnerState.Team()", e.WinnerState.Team())
validWinner := true
if e.Winner < 2 {
validWinner = false
//and set the integrity flag to false
} else if e.Winner == 2 {
game.flags.tMoney = true
} else {
//we need to check if the game is over
}
//we want to actually process the round
if game.flags.isGameLive && validWinner && game.flags.roundIntegrityStart == p.GameState().TotalRoundsPlayed()+1 {
game.potentialRound.winnerENUM = int(e.Winner)
processRoundOnWinCon(validateTeamName(game, e.WinnerState.ClanName()))
//check last round
roundWinnerScore := game.teams[validateTeamName(game, e.WinnerState.ClanName())].score
roundLoserScore := game.teams[validateTeamName(game, e.LoserState.ClanName())].score
fmt.Println("winner Rounds", roundWinnerScore)
fmt.Println("loser Rounds", roundLoserScore)
if game.roundsToWin == 16 {
//check for normal win
if roundWinnerScore == 16 && roundLoserScore < 15 {
//normal win
game.winnerClanName = game.potentialRound.winnerClanName
processRoundFinal(true)
} else if roundWinnerScore > 15 { //check for OT win
overtime := ((roundWinnerScore+roundLoserScore)-30-1)/6 + 1
//OT win
if (roundWinnerScore-15-1)/3 == overtime {
game.winnerClanName = game.potentialRound.winnerClanName
processRoundFinal(true)
}
}
} else if game.roundsToWin == 9 {
//check for normal win
if roundWinnerScore == 9 && roundLoserScore < 8 {
//normal win
game.winnerClanName = game.potentialRound.winnerClanName
processRoundFinal(true)
} else if roundWinnerScore == 8 && roundLoserScore == 8 { //check for tie
//tie
game.winnerClanName = game.potentialRound.winnerClanName
processRoundFinal(true)
}
}
}
//check last round
//or check overtime win
}
})
//round end official doesnt fire on the last round
p.RegisterEventHandler(func(e events.ScoreUpdated) {
fmt.Printf("Score Updated\n")
if game.flags.isGameLive && !game.flags.didRoundEndFire && e.NewScore > e.OldScore && game.winnerClanName == "" {
//we are replicating RoundEndEvent functionality because it did not fire
//this TeamState will "always" be the winner, why update the losing team?
winnerEnum := e.TeamState.Team()
winnerClanName := e.TeamState.ClanName()
loserClanName := ""
for teamName, _ := range game.teams {
if teamName != validateTeamName(game, winnerClanName) {
loserClanName = teamName
}
}
fmt.Println("Round", p.GameState().TotalRoundsPlayed()+1, "End", winnerClanName, "won", "this determined from e.WinnerState.ClanName()")
validWinner := true
if winnerEnum < 2 {
validWinner = false
//and set the integrity flag to false
} else if winnerEnum == 2 {
game.flags.tMoney = true
} else {
//we need to check if the game is over
}
fmt.Println("ris", game.flags.roundIntegrityStart, "p.GS.TotalRounds", p.GameState().TotalRoundsPlayed())
//we want to actually process the round
if game.flags.isGameLive && validWinner && game.flags.roundIntegrityStart == p.GameState().TotalRoundsPlayed() {
game.potentialRound.winnerENUM = int(winnerEnum)
processRoundOnWinCon(validateTeamName(game, winnerClanName))
//check last round
roundWinnerScore := game.teams[validateTeamName(game, winnerClanName)].score
roundLoserScore := game.teams[validateTeamName(game, loserClanName)].score
fmt.Println("winner Rounds", roundWinnerScore)
fmt.Println("loser Rounds", roundLoserScore)
if game.roundsToWin == 16 {
//check for normal win
if roundWinnerScore == 16 && roundLoserScore < 15 {
//normal win
game.winnerClanName = game.potentialRound.winnerClanName
processRoundFinal(true)
} else if roundWinnerScore > 15 { //check for OT win
overtime := ((roundWinnerScore+roundLoserScore)-30-1)/6 + 1
//OT win
if (roundWinnerScore-15-1)/3 == overtime {
game.winnerClanName = game.potentialRound.winnerClanName
processRoundFinal(true)
}
}
} else if game.roundsToWin == 9 {
//check for normal win
if roundWinnerScore == 9 && roundLoserScore < 8 {
//normal win
game.winnerClanName = game.potentialRound.winnerClanName
processRoundFinal(true)
} else if roundWinnerScore == 8 && roundLoserScore == 8 { //check for tie
//tie
game.winnerClanName = game.potentialRound.winnerClanName
processRoundFinal(true)
}
}
}
//check last round
//or check overtime win
}
})
//round end official doesnt fire on the last round
p.RegisterEventHandler(func(e events.RoundEndOfficial) {
fmt.Printf("Round End Official\n")
if !game.flags.didRoundEndFire {
game.flags.roundIntegrityEnd -= 1
}
fmt.Println("isGameLive", game.flags.isGameLive, "roundIntegrityEnd", game.flags.roundIntegrityEnd, "pTotalRoundsPlayed", p.GameState().TotalRoundsPlayed())
if game.flags.isGameLive && game.flags.roundIntegrityEnd == p.GameState().TotalRoundsPlayed() {
processRoundFinal(false)
}
})
// Register handler on kill events
p.RegisterEventHandler(func(e events.Kill) {
if game.flags.isGameLive && isDuringExpectedRound(game, p) {
pS := game.potentialRound.playerStats
tick := p.GameState().IngameTick()
killerExists := false
victimExists := false
assisterExists := false
if e.Killer != nil && pS[e.Killer.SteamID64] != nil {
killerExists = true
}
if e.Victim != nil && pS[e.Victim.SteamID64] != nil {
victimExists = true
}
if e.Assister != nil && pS[e.Assister.SteamID64] != nil {
assisterExists = true
}
killValue := 1.0
multiplier := 1.0
traded := false
assisted := false
flashAssisted := false
//death logic (traded here)
if victimExists {
pS[e.Victim.SteamID64].deaths += 1
pS[e.Victim.SteamID64].deathTick = tick
if e.Victim.Team == 2 {
game.flags.tAlive -= 1
pS[e.Victim.SteamID64].deathPlacement = float64(game.potentialRound.initTerroristCount - game.flags.tAlive)
//pS[e.Victim.SteamID64].tADP = float64(game.potentialRound.initTerroristCount - game.flags.tAlive)
} else if e.Victim.Team == 3 {
game.flags.ctAlive -= 1
pS[e.Victim.SteamID64].deathPlacement = float64(game.potentialRound.initCTerroristCount - game.flags.ctAlive)
//pS[e.Victim.SteamID64].ctADP = float64(game.potentialRound.initCTerroristCount - game.flags.ctAlive)
} else {
//else log an error
}
//do 4v5 calc
if game.flags.openingKill && game.potentialRound.initCTerroristCount+game.potentialRound.initTerroristCount == 10 {
//the 10th player died
_4v5Team := pS[e.Victim.SteamID64].teamClanName
game.potentialRound.teamStats[_4v5Team]._4v5s = 1
for teamName, team := range game.potentialRound.teamStats {
if teamName != _4v5Team {
team._5v4s = 1
}
}
}
//add support damage
for suppSteam, suppDMG := range pS[e.Victim.SteamID64].damageList {
if killerExists && suppSteam != e.Killer.SteamID64 {
pS[suppSteam].suppDamage += suppDMG
if pS[suppSteam].suppDamage > 60 {
pS[suppSteam].suppRounds = 1
}
} else if !killerExists {
pS[suppSteam].suppDamage += suppDMG
if pS[suppSteam].suppDamage > 60 {
pS[suppSteam].suppRounds = 1
}
}
}
//check clutch start
if !game.flags.postWinCon {
if game.flags.tAlive == 1 && game.flags.tClutchVal == 0 {
game.flags.tClutchVal = game.flags.ctAlive
membersT := p.GameState().TeamTerrorists().Members()
for _, terrorist := range membersT {
if terrorist.IsAlive() && e.Victim.SteamID64 != terrorist.SteamID64 {
game.flags.tClutchSteam = terrorist.SteamID64
fmt.Println("Clutch opportunity:", terrorist.Name, game.flags.tClutchVal)
}
}
}
if game.flags.ctAlive == 1 && game.flags.ctClutchVal == 0 {
game.flags.ctClutchVal = game.flags.tAlive