diff --git a/CHANGELOG.md b/CHANGELOG.md index ae0c220..5da0df5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.1.26 + +fix: missing title_before +([#28](https://github.com/spacemeowx2/s3si.ts/issues/28)) + ## 0.1.25 fix: missing king_smell diff --git a/src/constant.ts b/src/constant.ts index 458d99f..d9df823 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -1,7 +1,7 @@ import type { StatInkPostBody, VsHistoryDetail } from "./types.ts"; export const AGENT_NAME = "s3si.ts"; -export const S3SI_VERSION = "0.1.25"; +export const S3SI_VERSION = "0.1.26"; export const NSOAPP_VERSION = "2.3.1"; export const WEB_VIEW_VERSION = "1.0.0-433ec0e8"; export const S3SI_LINK = "https://github.com/spacemeowx2/s3si.ts"; diff --git a/src/exporters/stat.ink.ts b/src/exporters/stat.ink.ts index 6dd9242..daf4745 100644 --- a/src/exporters/stat.ink.ts +++ b/src/exporters/stat.ink.ts @@ -28,10 +28,17 @@ import { } from "../types.ts"; import { msgpack, Mutex } from "../../deps.ts"; import { APIError } from "../APIError.ts"; -import { b64Number, gameId, s3siGameId } from "../utils.ts"; +import { b64Number, gameId, nonNullable, s3siGameId } from "../utils.ts"; import { Env } from "../env.ts"; import { KEY_DICT } from "../dict/stat.ink.ts"; +const COOP_POINT_MAP: Record = { + 0: -20, + 1: -10, + 2: 0, + 3: 20, +}; + class StatInkAPI { FETCH_LOCK = new Mutex(); cache: Record = {}; @@ -553,10 +560,32 @@ export class StatInkExporter implements GameExporter { defeated_by_me: i.defeatCount, }]), ); + const title_after = detail.afterGrade + ? b64Number(detail.afterGrade.id).toString() + : undefined; + const title_exp_after = detail.afterGradePoint; const clear_waves = detail.waveResults.filter((i) => i.waveNumber < 4).length - 1 + (resultWave === 0 ? 1 : 0); + let title_before = undefined; + let title_exp_before = undefined; + const expDiff = COOP_POINT_MAP[clear_waves]; + + if (nonNullable(title_exp_after) && nonNullable(expDiff)) { + if (title_exp_after === 40 && expDiff === 20) { + // 20 -> 40 or ?(rank up) -> 40 + } else if (title_exp_after === 40 && expDiff < 0 && title_after !== "8") { + // 60,50 -> 40 or ?(rank down) to 40 + } else if (title_exp_after === 999 && expDiff !== 0) { + // 980,990 -> 999 + title_before = title_after; + } else { + title_before = title_after; + title_exp_before = title_exp_after - expDiff; + } + } + const result: StatInkCoopPostBody = { uuid: await gameId(detail.id), private: groupInfo?.mode === "PRIVATE_CUSTOM" ? "yes" : "no", @@ -568,10 +597,10 @@ export class StatInkExporter implements GameExporter { king_smell: smellMeter, king_salmonid: this.mapKing(detail.bossResult?.boss.id), clear_extra: bossResult?.hasDefeatBoss ? "yes" : "no", - title_after: detail.afterGrade - ? b64Number(detail.afterGrade.id).toString() - : undefined, - title_exp_after: detail.afterGradePoint, + title_before, + title_exp_before, + title_after, + title_exp_after, golden_eggs, power_eggs, gold_scale: scale?.gold, diff --git a/src/utils.ts b/src/utils.ts index bbb5e52..e0babf0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -159,3 +159,7 @@ export function b64Number(id: string): number { const [_, num] = text.split("-"); return parseInt(num); } + +export function nonNullable(v: T | null | undefined): v is T { + return v !== null && v !== undefined; +}