You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.3 KiB
41 lines
1.3 KiB
|
3 weeks ago
|
/**
|
||
|
|
* 玩家匹配连胜/连败(需求 §4.5)。
|
||
|
|
* 跨天不清零;胜→清连败,负→清连胜。
|
||
|
|
*/
|
||
|
|
export class MatchStreakStats {
|
||
|
|
/** 当前连胜 */
|
||
|
|
static getWinStreak(): number {
|
||
|
|
return Math.max(0, Math.floor(Number(gg.data.doc.matchWinStreak) || 0));
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 当前连败 */
|
||
|
|
static getLoseStreak(): number {
|
||
|
|
return Math.max(0, Math.floor(Number(gg.data.doc.matchLoseStreak) || 0));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 结算一场后的 streak 更新(不写总胜负场)。
|
||
|
|
* @param playerWin 玩家是否获胜
|
||
|
|
* @param opts.save 是否立刻存档;默认 true
|
||
|
|
*/
|
||
|
|
static applyBattleResult(playerWin: boolean, opts?: { save?: boolean }): void {
|
||
|
|
if (playerWin) {
|
||
|
|
gg.data.doc.matchWinStreak = this.getWinStreak() + 1;
|
||
|
|
gg.data.doc.matchLoseStreak = 0;
|
||
|
|
} else {
|
||
|
|
gg.data.doc.matchLoseStreak = this.getLoseStreak() + 1;
|
||
|
|
gg.data.doc.matchWinStreak = 0;
|
||
|
|
}
|
||
|
|
if (opts?.save !== false) gg.data.saveLocal();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Const 15~18 生效份数:连续场次 ≥3 时 `份数 = 连续 - 2`。
|
||
|
|
* @param streak 连胜或连败
|
||
|
|
*/
|
||
|
|
static effectiveShares(streak: number): number {
|
||
|
|
const n = Math.max(0, Math.floor(Number(streak) || 0));
|
||
|
|
return Math.max(0, n - 2);
|
||
|
|
}
|
||
|
|
}
|