Use the signed i64 profile encoding identified in PR #13. Make attached backups selectable in LocalMP after the daily quota, and debit backups only after the engine confirms the selected slot entered play. Record the stock daily allowance once per room and slot. Settle owned backups using the confirmed spawn facts and keep repeat settlement from charging the same battle again. Verified server and launcher types, MSVC compilation, three client builds for patch and Quirrel checks, and a temporary 2.61.0.58 build. In-game acceptance is pending. Co-authored-by: duduyagame <[email protected]>
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
import { ensureBlock, findBlock, findParam, setParam, type BlkBlock } from '@wto/blk';
|
|
|
|
export const DAILY_SPARES_BLOCK = 'wtoDailySpares';
|
|
|
|
// Stock quota from the Spearhead release notes and aces.exe 2.61.0.58 at 0x967a8d.
|
|
const FREE_SPARES_PER_DAY = 5;
|
|
const DAY_SECONDS = 24 * 60 * 60;
|
|
|
|
function utcDay(seconds: number): string {
|
|
return String(Math.floor(seconds / DAY_SECONDS));
|
|
}
|
|
|
|
function dayOf(profile: BlkBlock, startedAtSec: number): BlkBlock | undefined {
|
|
const ledger = findBlock(profile, DAILY_SPARES_BLOCK);
|
|
return ledger && findBlock(ledger, utcDay(startedAtSec));
|
|
}
|
|
|
|
export function dailySparesLeft(profile: BlkBlock, startedAtSec: number): number {
|
|
return Math.max(0, FREE_SPARES_PER_DAY - (dayOf(profile, startedAtSec)?.params.length ?? 0));
|
|
}
|
|
|
|
export function usedDailySpare(profile: BlkBlock, startedAtSec: number, key: string): boolean {
|
|
const day = dayOf(profile, startedAtSec);
|
|
return day !== undefined && findParam(day, key) !== undefined;
|
|
}
|
|
|
|
/** One receipt per room and crew slot, shared by the live and settlement writes. */
|
|
export function recordDailySpare(profile: BlkBlock, startedAtSec: number, key: string): boolean {
|
|
if (usedDailySpare(profile, startedAtSec, key) || dailySparesLeft(profile, startedAtSec) === 0) return false;
|
|
const day = ensureBlock(ensureBlock(profile, DAILY_SPARES_BLOCK), utcDay(startedAtSec));
|
|
setParam(day, key, { type: 'bool', value: true });
|
|
return true;
|
|
}
|