@@ -9,14 +9,32 @@ import { PlayerSummaryDto } from 'rest/dto/player.dto';
9
9
import PlayerInMatchEntity from 'gameserver/model/player-in-match.entity' ;
10
10
import { VersionPlayerEntity } from 'gameserver/model/version-player.entity' ;
11
11
12
- export type Summary =
13
- | undefined
14
- | ( Omit < PlayerSummaryDto , "rank" | "newbieUnrankedGamesLeft" > & {
15
- ranked_games : number ;
16
- unranked_games : number ;
17
- any_games : number ;
18
- bot_wins : number ;
19
- } ) ;
12
+ /**
13
+ * EDUCATION = need to finish education, either win or lose
14
+ * SIMPLE_MODES = 1+ games, 0 wins
15
+ * HUMAN_GAMES = 1+ wins
16
+ */
17
+ export enum MatchAccessLevel {
18
+ EDUCATION ,
19
+ SIMPLE_MODES ,
20
+ HUMAN_GAMES ,
21
+ }
22
+
23
+ export function getMatchAccessLevel ( anyGames : number , anyWins : number ) {
24
+ if ( anyWins ) return MatchAccessLevel . HUMAN_GAMES ;
25
+ if ( anyGames ) return MatchAccessLevel . SIMPLE_MODES ;
26
+ return MatchAccessLevel . EDUCATION ;
27
+ }
28
+
29
+ export type Summary = Omit <
30
+ PlayerSummaryDto ,
31
+ "rank" | "newbieUnrankedGamesLeft"
32
+ > & {
33
+ ranked_games : number ;
34
+ unranked_games : number ;
35
+ any_games : number ;
36
+ any_wins : number ;
37
+ } ;
20
38
21
39
// TODO: we probably need to orm this shit up
22
40
@Injectable ( )
@@ -153,11 +171,11 @@ order by score desc`;
153
171
] ) ;
154
172
}
155
173
156
- async fullSummary ( steam_id : string ) : Promise < Summary > {
174
+ async fullSummary ( steam_id : string ) : Promise < Summary | undefined > {
157
175
const some = await this . playerInMatchRepository . query (
158
176
`with cte as (select plr."playerId" as steam_id,
159
177
count(*)::int as any_games,
160
- sum((m.winner = plr.team )::int)::int as bot_wins ,
178
+ sum((m.winner = plr.team )::int)::int as any_wins ,
161
179
sum((m.matchmaking_mode in (0, 1))::int)::int as games,
162
180
sum((m.winner = plr.team and m.matchmaking_mode in (0, 1))::int)::int as wins,
163
181
sum((m.matchmaking_mode = 0 and m.timestamp > now() - '14 days'::interval)::int) as recent_ranked_games,
@@ -171,7 +189,7 @@ select p.steam_id,
171
189
p.wins,
172
190
p.games,
173
191
p.any_games,
174
- p.bot_wins ,
192
+ p.any_wins ,
175
193
p.mmr as mmr,
176
194
avg(pim.kills)::float as kills,
177
195
avg(pim.deaths)::float as deaths,
@@ -189,12 +207,17 @@ group by p.steam_id, p.recent_ranked_games, p.mmr, p.games, p.wins, p.any_games,
189
207
return some [ 0 ] ;
190
208
}
191
209
192
- public async hasUnrankedAccess ( steam_id : string ) : Promise < boolean > {
193
- const result : { count : number } [ ] =
210
+ public async getMatchAccessLevel ( steamId : string ) : Promise < MatchAccessLevel > {
211
+ const result : { any_wins : number ; any_games : number } [ ] =
194
212
await this . playerInMatchRepository . query (
195
- `select count(*) from player_activity pa where pa.win and pa.steam_id = $1` ,
196
- [ steam_id ] ,
213
+ `
214
+ select sum(pa.win::int)::int as any_wins, count(pa)::int as any_games
215
+ from player_activity pa
216
+ where pa.steam_id = $1
217
+ ` ,
218
+ [ steamId ] ,
197
219
) ;
198
- return result [ 0 ] . count > 0 ;
220
+
221
+ return getMatchAccessLevel ( result [ 0 ] . any_games , result [ 0 ] . any_wins ) ;
199
222
}
200
223
}
0 commit comments