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"; } from "./splatnet3.ts";
import { import {
BattleExporter, BattleExporter,
ChallengeProgress,
HistoryGroups, HistoryGroups,
VsBattle, VsBattle,
VsHistoryDetail, VsHistoryDetail,
@ -84,6 +85,7 @@ class BattleFetcher {
if (!group) { if (!group) {
return { return {
challengeProgress: null,
bankaraMatchChallenge: null, bankaraMatchChallenge: null,
listNode: null, listNode: null,
}; };
@ -92,10 +94,27 @@ class BattleFetcher {
const { bankaraMatchChallenge } = group; const { bankaraMatchChallenge } = group;
const listNode = group.historyDetails.nodes.find((i) => i._bid === bid) ?? const listNode = group.historyDetails.nodes.find((i) => i._bid === bid) ??
null; 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 { return {
bankaraMatchChallenge, bankaraMatchChallenge,
listNode, listNode,
challengeProgress,
}; };
} }
async getBattleDetail(id: string): Promise<VsHistoryDetail> { async getBattleDetail(id: string): Promise<VsHistoryDetail> {

View File

@ -1,7 +1,7 @@
import type { StatInkPostBody, VsHistoryDetail } from "./types.ts"; import type { StatInkPostBody, VsHistoryDetail } from "./types.ts";
export const AGENT_NAME = "s3si.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 NSOAPP_VERSION = "2.3.1";
export const WEB_VIEW_VERSION = "1.0.0-216d0219"; export const WEB_VIEW_VERSION = "1.0.0-216d0219";

View File

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

View File

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