fix: missing title_before (#28)

main
spacemeowx2 2022-11-25 20:20:47 +08:00
parent 47a3425627
commit a4d4f23263
4 changed files with 44 additions and 6 deletions

View File

@ -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

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.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";

View File

@ -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<number, number | undefined> = {
0: -20,
1: -10,
2: 0,
3: 20,
};
class StatInkAPI {
FETCH_LOCK = new Mutex();
cache: Record<string, unknown> = {};
@ -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,

View File

@ -159,3 +159,7 @@ export function b64Number(id: string): number {
const [_, num] = text.split("-");
return parseInt(num);
}
export function nonNullable<T>(v: T | null | undefined): v is T {
return v !== null && v !== undefined;
}