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