From 68960d6fd760ebd1bd99340fa5c802e0dbcd3c3f Mon Sep 17 00:00:00 2001 From: Wickedness Date: Sun, 5 Jul 2026 13:27:20 +0900 Subject: [PATCH] Reject self targeting battle intents --- scripts/verify-battle-save-normalization.mjs | 1 + src/game/state/battleSaveState.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts/verify-battle-save-normalization.mjs b/scripts/verify-battle-save-normalization.mjs index e7a2b44..3be028c 100644 --- a/scripts/verify-battle-save-normalization.mjs +++ b/scripts/verify-battle-save-normalization.mjs @@ -52,6 +52,7 @@ try { ['too long battle log entry', { battleLog: ['x'.repeat(97)] }], ['invalid attackIntents', { attackIntents: [{ attackerId: 'liu-bei' }] }], ['unknown attack intent unit id', { attackIntents: [{ attackerId: 'liu-bei', targetId: 'ghost-unit' }] }], + ['self-targeting attack intent', { attackIntents: [{ attackerId: 'liu-bei', targetId: 'liu-bei' }] }], ['duplicate attack intent attacker id', { attackIntents: [{ attackerId: 'liu-bei', targetId: 'rebel-1' }, { attackerId: 'liu-bei', targetId: 'rebel-1' }] }], ['invalid units array', { units: {} }], ['invalid unit exp threshold', { units: patchUnit(0, { exp: 100 }) }], diff --git a/src/game/state/battleSaveState.ts b/src/game/state/battleSaveState.ts index e1a1732..e083fde 100644 --- a/src/game/state/battleSaveState.ts +++ b/src/game/state/battleSaveState.ts @@ -210,6 +210,7 @@ function isAttackIntentArray(value: unknown, options: BattleSaveValidationOption isRecord(intent) && typeof intent.attackerId === 'string' && typeof intent.targetId === 'string' && + intent.attackerId !== intent.targetId && isKnownUnitId(intent.attackerId, options) && isKnownUnitId(intent.targetId, options) )