Validate battle save bond state

This commit is contained in:
2026-07-05 13:57:44 +09:00
parent 1145ef14aa
commit 11e42fd54f
2 changed files with 5 additions and 5 deletions

View File

@@ -95,6 +95,7 @@ const maxBattleUnitStatValue = 999999;
const maxBattleUnitHp = 9999;
const maxBattleUnitAttack = 9999;
const maxBattleUnitMove = 99;
const maxBattleBondBattleExp = 999999;
const maxStatusKindsPerUnit = 2;
const maxBattleItemStockById: Record<string, number> = {
bean: 3,
@@ -181,10 +182,6 @@ function isNonNegativeFiniteNumber(value: unknown) {
return typeof value === 'number' && Number.isFinite(value) && value >= 0;
}
function isNonNegativeInteger(value: unknown) {
return Number.isInteger(value) && Number(value) >= 0;
}
function isFiniteNumber(value: unknown) {
return typeof value === 'number' && Number.isFinite(value);
}
@@ -352,9 +349,10 @@ function isBondArray(value: unknown, options: BattleSaveValidationOptions) {
bond.id.length > 0 &&
Array.isArray(bond.unitIds) &&
bond.unitIds.length === 2 &&
bond.unitIds[0] !== bond.unitIds[1] &&
bond.unitIds.every((unitId) => typeof unitId === 'string' && isKnownUnitId(unitId, options)) &&
isValidBondProgress(bond.level, bond.exp) &&
isNonNegativeInteger(bond.battleExp)
isIntegerInRange(bond.battleExp, 0, maxBattleBondBattleExp)
)
);
}