MatchMaster/assets/Script/module/Config/BattlePassSettlementModel.ts
2026-10-09 10:03:29 +08:00

37 lines
2.2 KiB
TypeScript

import { normalizePass, canClaimPass } from './BattlePassModel';
/** Persist only the lanes actually awarded, so a delayed tier upgrade cannot re-award them. */
export function settlementClaimFlags(snapshot: any, rows: any[], purchase = false): any {
const stage = normalizePass({ ...snapshot.stage, ...(purchase ? { tier: 18, activate: true } : {}) }, rows);
const flags = { free: [...stage.free], passCheck: [...stage.passCheck] };
rows.forEach((_, i) => {
if (!purchase && canClaimPass(stage, i, true)) flags.free[i] = 0;
if (canClaimPass(stage, i, false)) flags.passCheck[i] = 0;
});
return flags;
}
/** The latest client table intentionally applies to every archived season. */
export function settlementRewards(snapshot: any, rows: any[], purchase = false): Array<{ type: string; count: number }> {
const stage = normalizePass({ ...snapshot.stage, ...(purchase ? { tier: 18, activate: true } : {}) }, rows);
const totals: { [type: string]: number } = {};
const types = { 1001: 'coin', 2001: 'freeze', 2002: 'hammer', 2003: 'magic' };
rows.forEach((row, index) => {
for (const left of purchase ? [false] : [true, false]) {
if (!canClaimPass(stage, index, left)) continue;
const parts = String(row[left ? 'free' : 'paid']).split(':').map(Number);
const id = parts[0], amount = parts[1];
const type = types[id] || (id >= 3001 && id <= 3005 ? 'infinite_health' : '');
if (!type || !Number.isSafeInteger(amount) || amount <= 0) throw new Error('战令奖励配置无效');
const count = type === 'infinite_health' ? [900, 1800, 3600, 7200, 10800][id - 3001] * amount : amount;
totals[type] = (totals[type] || 0) + count;
}
});
return ['coin','freeze','magic','hammer','infinite_health'].filter(type => totals[type] > 0).map(type => ({ type, count: totals[type] }));
}
export function settlementSteps(rows: any[], latestEnd: number, now: number): any[] {
return rows.slice().sort((a, b) => a.end - b.end).filter(row => !row.claimed && !row.emptySeen
|| row.end === latestEnd && row.end > now - 30 * 86400000 && row.offer === 'unused' && !row.stage.activate && !row.stage.tier && !row.purchase);
}