Restrict battle save attack intents
This commit is contained in:
@@ -11351,6 +11351,8 @@ export class BattleScene extends Phaser.Scene {
|
||||
mapWidth: battleMap.width,
|
||||
mapHeight: battleMap.height,
|
||||
validUnitIds: new Set(battleUnits.map((unit) => unit.id)),
|
||||
validAllyUnitIds: new Set(battleUnits.filter((unit) => unit.faction === 'ally').map((unit) => unit.id)),
|
||||
validEnemyUnitIds: new Set(battleUnits.filter((unit) => unit.faction === 'enemy').map((unit) => unit.id)),
|
||||
validUsableIds: new Set(Object.keys(usableCatalog)),
|
||||
validItemIds: new Set(
|
||||
Object.values(usableCatalog)
|
||||
|
||||
@@ -73,6 +73,8 @@ type BattleSaveValidationOptions = {
|
||||
mapWidth?: number;
|
||||
mapHeight?: number;
|
||||
validUnitIds?: ReadonlySet<string>;
|
||||
validAllyUnitIds?: ReadonlySet<string>;
|
||||
validEnemyUnitIds?: ReadonlySet<string>;
|
||||
validUsableIds?: ReadonlySet<string>;
|
||||
validItemIds?: ReadonlySet<string>;
|
||||
validEquipmentItemIds?: ReadonlySet<string>;
|
||||
@@ -159,7 +161,7 @@ export function isValidBattleSaveState(state: unknown, options: BattleSaveValida
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!areAttackIntentsTargetingLiveUnits(attackIntents, units)) {
|
||||
if (!areAttackIntentsTargetingLiveUnits(attackIntents, units, options)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -281,9 +283,19 @@ function areSavedBattleUnitsValid(units: unknown[], options: BattleSaveValidatio
|
||||
return [...seenUnitIds].every((unitId) => options.validUnitIds?.has(unitId));
|
||||
}
|
||||
|
||||
function areAttackIntentsTargetingLiveUnits(attackIntents: BattleSaveAttackIntent[], units: SavedBattleUnitState[]) {
|
||||
function areAttackIntentsTargetingLiveUnits(
|
||||
attackIntents: BattleSaveAttackIntent[],
|
||||
units: SavedBattleUnitState[],
|
||||
options: BattleSaveValidationOptions
|
||||
) {
|
||||
const liveUnitIds = new Set(units.filter((unit) => unit.hp > 0).map((unit) => unit.id));
|
||||
return attackIntents.every((intent) => liveUnitIds.has(intent.attackerId) && liveUnitIds.has(intent.targetId));
|
||||
return attackIntents.every(
|
||||
(intent) =>
|
||||
liveUnitIds.has(intent.attackerId) &&
|
||||
liveUnitIds.has(intent.targetId) &&
|
||||
(!options.validAllyUnitIds || options.validAllyUnitIds.has(intent.attackerId)) &&
|
||||
(!options.validEnemyUnitIds || options.validEnemyUnitIds.has(intent.targetId))
|
||||
);
|
||||
}
|
||||
|
||||
function areEffectsTargetingLiveUnits(
|
||||
|
||||
Reference in New Issue
Block a user