1
1
import { SqlAttribute , TableSchema } from './tableSchema' ;
2
- import { createTableDB } from './storage' ;
2
+ import { createTableDB , queryDB , updateDB } from './storage' ;
3
3
4
- const PLAYERS_TABLE = 'players' ;
5
- const MATCHES_TABLE = 'matches' ;
6
- const PLAYER_MATCH_STATS_TABLE = 'playerMatchStats' ;
4
+ export const PLAYERS_TABLE = 'players' ;
5
+ export const MATCHES_TABLE = 'matches' ;
6
+ export const PLAYER_MATCH_STATS_TABLE = 'playerMatchStats' ;
7
7
8
8
export const setup = async ( ) => {
9
9
// Create players global stats table
@@ -14,7 +14,15 @@ export const setup = async () => {
14
14
{ name : 'tDeaths' , type : 'INTEGER' } ,
15
15
{ name : 'tAssists' , type : 'INTEGER' } ,
16
16
{ name : 'tDiff' , type : 'INTEGER' } ,
17
+ { name : 'tHits' , type : 'INTEGER' } ,
17
18
{ name : 'tHeadshots' , type : 'INTEGER' } ,
19
+ {
20
+ name : 'tHsPct' ,
21
+ type : 'FLOAT' ,
22
+ constraints : 'CHECK (tHeadshots >= 0 AND tHeadshots <= 100)' ,
23
+ } ,
24
+ { name : 'tRounds' , type : 'INTEGER' } ,
25
+ { name : 'tDamages' , type : 'INTEGER' } ,
18
26
{ name : 'tAdr' , type : 'INTEGER' } ,
19
27
] as SqlAttribute [ ] ;
20
28
const playersTableSchema = new TableSchema ( PLAYERS_TABLE , playersAttributes , [ 'steamId' ] ) ;
@@ -49,11 +57,15 @@ export const setup = async () => {
49
57
{ name : 'deaths' , type : 'INTEGER' } ,
50
58
{ name : 'assists' , type : 'INTEGER' } ,
51
59
{ name : 'diff' , type : 'INTEGER' } ,
60
+ { name : 'hits' , type : 'INTEGER' } ,
61
+ { name : 'headshots' , type : 'INTEGER' } ,
52
62
{
53
- name : 'headshots ' ,
63
+ name : 'hsPct ' ,
54
64
type : 'FLOAT' ,
55
65
constraints : 'CHECK (headshots >= 0 AND headshots <= 100)' ,
56
66
} ,
67
+ { name : 'rounds' , type : 'INTEGER' } ,
68
+ { name : 'damages' , type : 'INTEGER' } ,
57
69
{ name : 'adr' , type : 'FLOAT' } ,
58
70
] as SqlAttribute [ ] ;
59
71
const playerMatchStatsTableSchema = new TableSchema (
@@ -63,3 +75,91 @@ export const setup = async () => {
63
75
) ;
64
76
await createTableDB ( playerMatchStatsTableSchema ) ;
65
77
} ;
78
+
79
+ export const onDamage = async (
80
+ matchId : string ,
81
+ attackerId : string ,
82
+ victimId : string ,
83
+ damage : number ,
84
+ damageArmor : number ,
85
+ headshot : boolean
86
+ ) => {
87
+ // TODO
88
+ } ;
89
+
90
+ export const onKill = async ( matchId : string , killerId : string , victimId : string ) => {
91
+ const currentKillerMatchStats = ( await queryDB (
92
+ `SELECT kills FROM ${ PLAYER_MATCH_STATS_TABLE } WHERE steamId = '${ killerId } ' AND matchId = '${ matchId } '`
93
+ ) ) as number ;
94
+ const currentVictimMatchStats = ( await queryDB (
95
+ `SELECT deaths FROM ${ PLAYER_MATCH_STATS_TABLE } WHERE steamId = '${ victimId } ' AND matchId = '${ matchId } '`
96
+ ) ) as number ;
97
+ const currentKillerGlobalStats = ( await queryDB (
98
+ `SELECT tKills FROM ${ PLAYERS_TABLE } WHERE steamId = '${ killerId } '`
99
+ ) ) as number ;
100
+ const currentVictimGlobalStats = ( await queryDB (
101
+ `SELECT tDeaths FROM ${ PLAYERS_TABLE } WHERE steamId = '${ victimId } '`
102
+ ) ) as number ;
103
+ await updateDB (
104
+ PLAYER_MATCH_STATS_TABLE ,
105
+ new Map < string , number > ( [ [ 'kills' , currentKillerMatchStats + 1 ] ] ) ,
106
+ `steamId = '${ killerId } ' AND matchId = '${ matchId } '`
107
+ ) ;
108
+ await updateDB (
109
+ PLAYER_MATCH_STATS_TABLE ,
110
+ new Map < string , number > ( [ [ 'deaths' , currentVictimMatchStats + 1 ] ] ) ,
111
+ `steamId = '${ victimId } ' AND matchId = '${ matchId } '`
112
+ ) ;
113
+ await updateDB (
114
+ PLAYERS_TABLE ,
115
+ new Map < string , number > ( [ [ 'tKills' , currentKillerGlobalStats + 1 ] ] ) ,
116
+ `steamId = '${ killerId } '`
117
+ ) ;
118
+ await updateDB (
119
+ PLAYERS_TABLE ,
120
+ new Map < string , number > ( [ [ 'tDeaths' , currentVictimGlobalStats + 1 ] ] ) ,
121
+ `steamId = '${ victimId } '`
122
+ ) ;
123
+ } ;
124
+
125
+ export const onAssist = async ( matchId : string , attackerId : string ) => {
126
+ const currentAttackerMatchStats = ( await queryDB (
127
+ `SELECT assists FROM ${ PLAYER_MATCH_STATS_TABLE } WHERE steamId = '${ attackerId } ' AND matchId = '${ matchId } '`
128
+ ) ) as number ;
129
+ const currentAttackerGlobalStats = ( await queryDB (
130
+ `SELECT tAssists FROM ${ PLAYERS_TABLE } WHERE steamId = '${ attackerId } '`
131
+ ) ) as number ;
132
+ await updateDB (
133
+ PLAYER_MATCH_STATS_TABLE ,
134
+ new Map < string , number > ( [ [ 'assists' , currentAttackerMatchStats + 1 ] ] ) ,
135
+ `steamId = '${ attackerId } ' AND matchId = '${ matchId } '`
136
+ ) ;
137
+ await updateDB (
138
+ PLAYERS_TABLE ,
139
+ new Map < string , number > ( [ [ 'tAssists' , currentAttackerGlobalStats + 1 ] ] ) ,
140
+ `steamId = '${ attackerId } '`
141
+ ) ;
142
+ } ;
143
+
144
+ export const onOtherDeath = async ( matchId : string , victimId : string ) => {
145
+ const currentVictimMatchStats = ( await queryDB (
146
+ `SELECT deaths FROM ${ PLAYER_MATCH_STATS_TABLE } WHERE steamId = '${ victimId } ' AND matchId = '${ matchId } '`
147
+ ) ) as number ;
148
+ const currentVictimGlobalStats = ( await queryDB (
149
+ `SELECT tDeaths FROM ${ PLAYERS_TABLE } WHERE steamId = '${ victimId } '`
150
+ ) ) as number ;
151
+ await updateDB (
152
+ PLAYER_MATCH_STATS_TABLE ,
153
+ new Map < string , number > ( [ [ 'deaths' , currentVictimMatchStats + 1 ] ] ) ,
154
+ `steamId = '${ victimId } ' AND matchId = '${ matchId } '`
155
+ ) ;
156
+ await updateDB (
157
+ PLAYERS_TABLE ,
158
+ new Map < string , number > ( [ [ 'tDeaths' , currentVictimGlobalStats + 1 ] ] ) ,
159
+ `steamId = '${ victimId } '`
160
+ ) ;
161
+ } ;
162
+
163
+ export const updateRoundCount = async ( matchId : string ) => {
164
+ //TODO
165
+ } ;
0 commit comments