Skip to content

Commit f8c8737

Browse files
committed
Amongus
1 parent dbdd77a commit f8c8737

File tree

4 files changed

+55
-24
lines changed

4 files changed

+55
-24
lines changed

src/gameserver/command/ProcessRankedMatch/process-ranked-match-handler.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe("MatchController", () => {
182182

183183
for (let change of changes) {
184184
const pim = pims.find((pim) => pim.playerId === change.playerId);
185-
// console.log("Amogus!", change, pim)
185+
console.log("Amogus!", change, pim)
186186
if (pim?.abandoned) {
187187
expect(change.change).toBeLessThan(0);
188188
} else if (pim.team === DotaTeam.RADIANT) {

src/rest/dto/player.dto.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { BanReason } from 'gateway/shared-types/ban';
22
import { PlayerId } from 'gateway/shared-types/player-id';
33
import { Page } from 'gateway/shared-types/page';
44
import { ApiProperty } from '@nestjs/swagger';
5+
import { MatchAccessLevel } from 'rest/service/player.service';
56

67
export class LeaderboardEntryDto {
78
rank: number | null;
@@ -26,13 +27,17 @@ export class LeaderboardEntryPageDto extends Page<LeaderboardEntryDto> {
2627
pages: number;
2728
}
2829

30+
31+
32+
2933
export class PlayerSummaryDto extends LeaderboardEntryDto {
3034
newbieUnrankedGamesLeft: number;
3135
playedAnyGame: boolean;
3236
calibrationGamesLeft: number;
3337

34-
3538
hasUnrankedAccess: boolean;
39+
40+
accessLevel: MatchAccessLevel
3641
}
3742

3843
export class BanStatusDto {

src/rest/player.controller.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { CommandBus, EventBus } from '@nestjs/cqrs';
1717
import { MakeSureExistsCommand } from 'gameserver/command/MakeSureExists/make-sure-exists.command';
1818
import { PlayerId } from 'gateway/shared-types/player-id';
1919
import { GameServerService } from 'gameserver/gameserver.service';
20-
import { PlayerService, Summary } from 'rest/service/player.service';
20+
import { MatchAccessLevel, PlayerService, Summary } from 'rest/service/player.service';
2121
import { HeroStatsDto } from 'rest/dto/hero.dto';
2222
import { UNRANKED_GAMES_REQUIRED_FOR_RANKED } from 'gateway/shared-types/timings';
2323
import { BanStatus } from 'gateway/queries/GetPlayerInfo/get-player-info-query.result';
@@ -172,7 +172,6 @@ offset $2 limit $3`,
172172
};
173173
}
174174

175-
176175
@CacheTTL(120)
177176
@Get("/summary/:version/:id")
178177
async playerSummary(
@@ -185,9 +184,9 @@ offset $2 limit $3`,
185184
where: { steam_id },
186185
});
187186

188-
189187
// Crucial thing for newbie:
190-
const hasUnrankedAccess = await this.playerService.hasUnrankedAccess(steam_id)
188+
const matchAccessLevel =
189+
await this.playerService.getMatchAccessLevel(steam_id);
191190

192191
// if it exists in the view, we happy
193192
if (lb) {
@@ -207,7 +206,9 @@ offset $2 limit $3`,
207206
play_time: lb.play_time,
208207
playedAnyGame: lb.any_games > 0,
209208

210-
hasUnrankedAccess: hasUnrankedAccess,
209+
accessLevel: matchAccessLevel,
210+
211+
hasUnrankedAccess: matchAccessLevel === MatchAccessLevel.HUMAN_GAMES,
211212

212213
newbieUnrankedGamesLeft:
213214
lb.ranked_games > 0
@@ -241,7 +242,9 @@ offset $2 limit $3`,
241242

242243
playedAnyGame: summary && summary.any_games > 0,
243244

244-
hasUnrankedAccess: (summary?.bot_wins || 0) > 0,
245+
hasUnrankedAccess: matchAccessLevel === MatchAccessLevel.HUMAN_GAMES,
246+
247+
accessLevel: matchAccessLevel,
245248

246249
newbieUnrankedGamesLeft:
247250
(summary?.ranked_games || 0) > 0

src/rest/service/player.service.ts

+39-16
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,32 @@ import { PlayerSummaryDto } from 'rest/dto/player.dto';
99
import PlayerInMatchEntity from 'gameserver/model/player-in-match.entity';
1010
import { VersionPlayerEntity } from 'gameserver/model/version-player.entity';
1111

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+
};
2038

2139
// TODO: we probably need to orm this shit up
2240
@Injectable()
@@ -153,11 +171,11 @@ order by score desc`;
153171
]);
154172
}
155173

156-
async fullSummary(steam_id: string): Promise<Summary> {
174+
async fullSummary(steam_id: string): Promise<Summary | undefined> {
157175
const some = await this.playerInMatchRepository.query(
158176
`with cte as (select plr."playerId" as steam_id,
159177
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,
161179
sum((m.matchmaking_mode in (0, 1))::int)::int as games,
162180
sum((m.winner = plr.team and m.matchmaking_mode in (0, 1))::int)::int as wins,
163181
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,
171189
p.wins,
172190
p.games,
173191
p.any_games,
174-
p.bot_wins,
192+
p.any_wins,
175193
p.mmr as mmr,
176194
avg(pim.kills)::float as kills,
177195
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,
189207
return some[0];
190208
}
191209

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 }[] =
194212
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],
197219
);
198-
return result[0].count > 0;
220+
221+
return getMatchAccessLevel(result[0].any_games, result[0].any_wins);
199222
}
200223
}

0 commit comments

Comments
 (0)