fix(battle): unblock LocalMP backup respawns and normalize unit names
Store the selected LocalMP backup token in a separate wtoLastBackup handler field instead of mutating requestData.wtoBackup. Mutating requestData caused respawn.nut checkReady() u.isEqual(lastRequestData, getSelectedRequestData()) to always evaluate false for backup spawns, preventing doRespawnPlayer() from ever running. Also fix downstream ground and naval backup accounting where native UnitInfo::name carries folder prefixes (e.g. tankModels/cn_type_59) that mismatched bare unit IDs in session.spareSlots, by stripping path prefixes in local_mp_awards.c, record-local-battle-awards, battle-spares.ts, and battle-queue-requests.ts. Update hook_is_slot_ready_at_host to check USED_SPARES_MASK rather than BROKEN_SLOTS_MASK so unrepaired slots remain eligible for a backup spawn. Verified root and launcher typecheck, 2.61.0.37 and 2.61.0.58 check-gui (50 patches / 37 .nut), check-patches (14/14), checkPatchSet, battle-spares runnable check, and MSVC temp build of wto_ws.dll (0 warnings in project C sources). Pending regular-terminal build of build/native/wto_ws.dll and in-game acceptance.
This commit is contained in:
1 parent
c3cf4e3707
commit
647eff35fe
11 files changed
+49
-16
No files matched your search
@@ -16,12 +16,19 @@ export interface BackupSpawn {
|
||||
readonly backup: string;
|
||||
}
|
||||
|
||||
/** Strip native model folder prefixes (e.g. "tankModels/cn_type_59" -> "cn_type_59"). */
|
||||
export function normalizeBackupUnitName(unit: string): string {
|
||||
const slash = unit.lastIndexOf('/');
|
||||
return slash >= 0 ? unit.slice(slash + 1) : unit;
|
||||
}
|
||||
|
||||
function receiptKey(session: BattleSession, slot: number): string {
|
||||
return `${session.sessionId}_${slot}`;
|
||||
}
|
||||
|
||||
export function recordDailyBackupSpawn(profile: BlkBlock, session: BattleSession, spawn: BackupSpawn): boolean {
|
||||
return spawn.backup === DAILY_BACKUP && session.spareSlots?.get(spawn.slot) === spawn.unit
|
||||
const unit = normalizeBackupUnitName(spawn.unit);
|
||||
return spawn.backup === DAILY_BACKUP && session.spareSlots?.get(spawn.slot) === unit
|
||||
&& recordDailySpare(profile, session.startedAtSec, receiptKey(session, spawn.slot));
|
||||
}
|
||||
|
||||
@@ -32,11 +39,12 @@ export function consumeBattleSpares(
|
||||
const seenSlots = new Set<number>();
|
||||
const consumed = new Map<string, number>();
|
||||
for (const spawn of spawns) {
|
||||
const { slot, unit, backup } = spawn;
|
||||
const { slot, backup } = spawn;
|
||||
const unit = normalizeBackupUnitName(spawn.unit);
|
||||
if (session.spareSlots?.get(slot) !== unit || seenSlots.has(slot)) continue;
|
||||
seenSlots.add(slot);
|
||||
if (backup === DAILY_BACKUP) {
|
||||
recordDailyBackupSpawn(profile, session, spawn);
|
||||
recordDailyBackupSpawn(profile, session, { slot, unit, backup });
|
||||
continue;
|
||||
}
|
||||
if (dailySparesLeft(profile, session.startedAtSec) > 0
|
||||
|
||||
@@ -12,7 +12,7 @@ import { economyDifficulty, type BattleEconomy } from '../battle/battle-economy.
|
||||
import type { BattleMatchmaker } from '../battle/battle-matchmaker.ts';
|
||||
import { maxModeMrank, unitClassOfExpClass, unitClassOfTypeCode, type CraftRankEntry } from '../battle/battle-ranks.ts';
|
||||
import type { BattleSession, BattleSessionStore } from '../battle/battle-session-store.ts';
|
||||
import { DAILY_BACKUP, recordDailyBackupSpawn } from '../battle/battle-spares.ts';
|
||||
import { DAILY_BACKUP, normalizeBackupUnitName, recordDailyBackupSpawn } from '../battle/battle-spares.ts';
|
||||
import type { GameModes, OfferedGameMode } from '../game-modes/game-modes.ts';
|
||||
import { crewSlotVehicleOfCountry, crewVehiclesOfCountry } from '../profile/profile-crews.ts';
|
||||
import { dailySparesLeft } from '../profile/profile-daily-spares.ts';
|
||||
@@ -50,8 +50,9 @@ export function battleQueueRequests(deps: BattleQueueDependencies): Array<[strin
|
||||
return { error: 'BAD_PARAMS' };
|
||||
}
|
||||
const battle = deps.sessions.findForUser(sessionId, userId);
|
||||
if (!battle || battle.settled || battle.spareSlots?.get(slot) !== unit) return { error: 'BAD_PARAMS' };
|
||||
deps.profiles.updateWhen(userId, (profile) => recordDailyBackupSpawn(profile, battle, { slot, unit, backup: DAILY_BACKUP }));
|
||||
const normalizedUnit = normalizeBackupUnitName(unit);
|
||||
if (!battle || battle.settled || battle.spareSlots?.get(slot) !== normalizedUnit) return { error: 'BAD_PARAMS' };
|
||||
deps.profiles.updateWhen(userId, (profile) => recordDailyBackupSpawn(profile, battle, { slot, unit: normalizedUnit, backup: DAILY_BACKUP }));
|
||||
return {};
|
||||
}],
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user