feat: upload rank point to stat.ink
parent
8180de928c
commit
d2d04c703d
|
|
@ -62,7 +62,7 @@ export class GameFetcher {
|
|||
return finalState;
|
||||
}
|
||||
|
||||
getRankStateById(id: string): Promise<RankState | undefined> {
|
||||
getRankStateById(id: string) {
|
||||
return this.rankTracker.getRankStateById(id);
|
||||
}
|
||||
|
||||
|
|
@ -140,6 +140,7 @@ export class GameFetcher {
|
|||
bankaraMatchChallenge: null,
|
||||
listNode: null,
|
||||
rankState: null,
|
||||
rankBeforeState: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -164,12 +165,15 @@ export class GameFetcher {
|
|||
};
|
||||
}
|
||||
|
||||
const { before, after } = await this.rankTracker.getRankStateById(id) ?? {};
|
||||
|
||||
return {
|
||||
type: "VsInfo",
|
||||
bankaraMatchChallenge,
|
||||
listNode,
|
||||
challengeProgress,
|
||||
rankState: await this.rankTracker.getRankStateById(id) ?? null,
|
||||
rankState: after ?? null,
|
||||
rankBeforeState: before ?? null,
|
||||
};
|
||||
}
|
||||
cacheDetail<T>(
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ type Delta = {
|
|||
isChallengeFirst: boolean;
|
||||
};
|
||||
|
||||
// TODO: auto rank up using rank params and delta.
|
||||
function addRank(state: RankState, delta: Delta): RankState {
|
||||
const { rank, rankPoint } = state;
|
||||
const { gameId, rankAfter, isRankUp, isChallengeFirst } = delta;
|
||||
|
|
@ -148,22 +149,29 @@ export class RankTracker {
|
|||
|
||||
constructor(protected state: RankState | undefined) {}
|
||||
|
||||
async getRankStateById(id: string): Promise<RankState | undefined> {
|
||||
async getRankStateById(
|
||||
id: string,
|
||||
): Promise<{ before: RankState; after: RankState } | undefined> {
|
||||
if (!this.state) {
|
||||
return;
|
||||
}
|
||||
const gid = await gameId(id);
|
||||
|
||||
let cur = this.state;
|
||||
let before = cur;
|
||||
while (cur.gameId !== gid) {
|
||||
const delta = this.deltaMap.get(cur.gameId);
|
||||
if (!delta) {
|
||||
return;
|
||||
}
|
||||
before = cur;
|
||||
cur = addRank(cur, delta);
|
||||
}
|
||||
|
||||
return cur;
|
||||
return {
|
||||
before,
|
||||
after: cur,
|
||||
};
|
||||
}
|
||||
|
||||
setState(state: RankState | undefined) {
|
||||
|
|
@ -240,7 +248,7 @@ export class RankTracker {
|
|||
// open
|
||||
delta = {
|
||||
...delta,
|
||||
// TODO: is this right?
|
||||
// TODO: rankAfter should be undefined in open battle
|
||||
rankAfter: i.detail.udemae,
|
||||
rankPoint: i.detail.bankaraMatch?.earnedUdemaePoint,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -173,8 +173,14 @@ export class StatInkExporter implements GameExporter {
|
|||
return result;
|
||||
}
|
||||
async mapBattle(
|
||||
{ challengeProgress, bankaraMatchChallenge, listNode, detail: vsDetail }:
|
||||
VsInfo,
|
||||
{
|
||||
challengeProgress,
|
||||
bankaraMatchChallenge,
|
||||
listNode,
|
||||
detail: vsDetail,
|
||||
rankBeforeState,
|
||||
rankState,
|
||||
}: VsInfo,
|
||||
): Promise<StatInkPostBody> {
|
||||
const {
|
||||
knockout,
|
||||
|
|
@ -276,6 +282,19 @@ export class StatInkExporter implements GameExporter {
|
|||
result.challenge_lose = challengeProgress.loseCount;
|
||||
}
|
||||
|
||||
if (rankBeforeState) {
|
||||
result.rank_before_exp = rankBeforeState.rankPoint;
|
||||
}
|
||||
|
||||
if (rankState) {
|
||||
result.rank_after_exp = rankState.rankPoint;
|
||||
if (!result.rank_after) {
|
||||
[result.rank_after, result.rank_after_s_plus] = parseUdemae(
|
||||
rankState.rank,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ export type VsInfo = {
|
|||
bankaraMatchChallenge: null | BankaraMatchChallenge;
|
||||
challengeProgress: null | ChallengeProgress;
|
||||
rankState: null | RankState;
|
||||
rankBeforeState: null | RankState;
|
||||
detail: VsHistoryDetail;
|
||||
};
|
||||
// Salmon run
|
||||
|
|
|
|||
Loading…
Reference in New Issue