fix: wrong win/lose count in challenge (0.1.4)

main
spacemeowx2 2022-10-22 18:12:49 +08:00
parent f1799f25f4
commit c2d20eeaaf
4 changed files with 33 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import {
} from "./splatnet3.ts";
import {
BattleExporter,
ChallengeProgress,
HistoryGroups,
VsBattle,
VsHistoryDetail,
@ -84,6 +85,7 @@ class BattleFetcher {
if (!group) {
return {
challengeProgress: null,
bankaraMatchChallenge: null,
listNode: null,
};
@ -92,10 +94,27 @@ class BattleFetcher {
const { bankaraMatchChallenge } = group;
const listNode = group.historyDetails.nodes.find((i) => i._bid === bid) ??
null;
const index = group.historyDetails.nodes.indexOf(listNode!);
let challengeProgress: null | ChallengeProgress = null;
if (bankaraMatchChallenge) {
const pastBattles = group.historyDetails.nodes.slice(0, index);
const { winCount, loseCount } = bankaraMatchChallenge;
challengeProgress = {
index,
winCount: winCount -
pastBattles.filter((i) => i.judgement == "WIN").length,
loseCount: loseCount -
pastBattles.filter((i) =>
["LOSE", "DEEMED_LOSE"].includes(i.judgement)
).length,
};
}
return {
bankaraMatchChallenge,
listNode,
challengeProgress,
};
}
async getBattleDetail(id: string): Promise<VsHistoryDetail> {

View File

@ -1,7 +1,7 @@
import type { StatInkPostBody, VsHistoryDetail } from "./types.ts";
export const AGENT_NAME = "s3si.ts";
export const S3SI_VERSION = "0.1.3";
export const S3SI_VERSION = "0.1.4";
export const NSOAPP_VERSION = "2.3.1";
export const WEB_VIEW_VERSION = "1.0.0-216d0219";

View File

@ -164,7 +164,8 @@ export class StatInkExporter implements BattleExporter<VsBattle> {
return result;
}
async mapBattle(
{ bankaraMatchChallenge, listNode, detail: vsDetail }: VsBattle,
{ challengeProgress, bankaraMatchChallenge, listNode, detail: vsDetail }:
VsBattle,
): Promise<StatInkPostBody> {
const {
knockout,
@ -256,11 +257,13 @@ export class StatInkExporter implements BattleExporter<VsBattle> {
result.rank_after = result.rank_before;
result.rank_after_s_plus = result.rank_before_s_plus;
}
result.challenge_win = bankaraMatchChallenge.winCount;
result.challenge_lose = bankaraMatchChallenge.loseCount;
result.rank_exp_change = bankaraMatchChallenge.earnedUdemaePoint ??
undefined;
}
if (challengeProgress) {
result.challenge_win = challengeProgress.winCount;
result.challenge_lose = challengeProgress.loseCount;
}
return result;
}

View File

@ -44,6 +44,7 @@ export type BattleListNode = {
_bid: string;
id: string;
udemae: string;
judgement: "LOSE" | "WIN" | "DEEMED_LOSE" | "EXEMPTED_LOSE";
};
export type HistoryGroups = {
nodes: {
@ -89,10 +90,16 @@ export type VsRule =
| "CLAM"
| "TRI_COLOR";
export type ChallengeProgress = {
index: number;
winCount: number;
loseCount: number;
};
// With challenge info
export type VsBattle = {
listNode: null | BattleListNode;
bankaraMatchChallenge: null | BankaraMatchChallenge;
challengeProgress: null | ChallengeProgress;
detail: VsHistoryDetail;
};
export type VsHistoryDetail = {