Validate unit experience thresholds
This commit is contained in:
@@ -115,9 +115,7 @@ function validateUnits(errors, scenario, classKeys, itemKeys, equipmentSlots, co
|
||||
if (!classKeys.has(unit.classKey)) {
|
||||
errors.push(`${unitContext}: unknown classKey "${unit.classKey}"`);
|
||||
}
|
||||
if (!Number.isInteger(unit.level) || unit.level < 1) {
|
||||
errors.push(`${unitContext}: invalid level ${unit.level}`);
|
||||
}
|
||||
validateCharacterProgress(errors, unit, unitContext);
|
||||
if (!Number.isInteger(unit.hp) || !Number.isInteger(unit.maxHp) || unit.hp < 1 || unit.maxHp < 1 || unit.hp > unit.maxHp) {
|
||||
errors.push(`${unitContext}: invalid hp ${unit.hp}/${unit.maxHp}`);
|
||||
}
|
||||
@@ -192,6 +190,19 @@ function validateObjectives(errors, scenario, context) {
|
||||
});
|
||||
}
|
||||
|
||||
function validateCharacterProgress(errors, unit, context) {
|
||||
if (!Number.isInteger(unit.level) || unit.level < 1) {
|
||||
errors.push(`${context}: invalid level ${unit.level}`);
|
||||
}
|
||||
if (!Number.isInteger(unit.exp) || unit.exp < 0) {
|
||||
errors.push(`${context}: invalid exp ${unit.exp}`);
|
||||
} else if (Number.isInteger(unit.level) && unit.level < 99 && unit.exp >= 100) {
|
||||
errors.push(`${context}: exp ${unit.exp} should be below 100 before max level`);
|
||||
} else if (Number.isInteger(unit.level) && unit.level >= 99 && unit.exp > 100) {
|
||||
errors.push(`${context}: max level exp ${unit.exp} should be at most 100`);
|
||||
}
|
||||
}
|
||||
|
||||
function validateSortie(errors, scenario, classKeys, formationRoles, terrainRules, context) {
|
||||
const sortie = scenario.sortie;
|
||||
if (!sortie) {
|
||||
|
||||
@@ -82,12 +82,7 @@ function validateRecruitTemplates(errors, recruitTemplates, classKeys, itemKeys,
|
||||
if (!classKeys.has(unit.classKey)) {
|
||||
errors.push(`${context}: unknown classKey "${unit.classKey}"`);
|
||||
}
|
||||
if (!Number.isInteger(unit.level) || unit.level < 1) {
|
||||
errors.push(`${context}: invalid level ${unit.level}`);
|
||||
}
|
||||
if (!Number.isInteger(unit.exp) || unit.exp < 0) {
|
||||
errors.push(`${context}: invalid exp ${unit.exp}`);
|
||||
}
|
||||
validateCharacterProgress(errors, unit, context);
|
||||
if (!Number.isInteger(unit.hp) || !Number.isInteger(unit.maxHp) || unit.hp < 1 || unit.maxHp < 1 || unit.hp > unit.maxHp) {
|
||||
errors.push(`${context}: invalid hp ${unit.hp}/${unit.maxHp}`);
|
||||
}
|
||||
@@ -121,6 +116,19 @@ function validateStats(errors, stats, context) {
|
||||
});
|
||||
}
|
||||
|
||||
function validateCharacterProgress(errors, unit, context) {
|
||||
if (!Number.isInteger(unit.level) || unit.level < 1) {
|
||||
errors.push(`${context}: invalid level ${unit.level}`);
|
||||
}
|
||||
if (!Number.isInteger(unit.exp) || unit.exp < 0) {
|
||||
errors.push(`${context}: invalid exp ${unit.exp}`);
|
||||
} else if (Number.isInteger(unit.level) && unit.level < 99 && unit.exp >= 100) {
|
||||
errors.push(`${context}: exp ${unit.exp} should be below 100 before max level`);
|
||||
} else if (Number.isInteger(unit.level) && unit.level >= 99 && unit.exp > 100) {
|
||||
errors.push(`${context}: max level exp ${unit.exp} should be at most 100`);
|
||||
}
|
||||
}
|
||||
|
||||
function validateEquipment(errors, equipment, itemKeys, itemCatalog, equipmentSlots, context) {
|
||||
if (!equipment || typeof equipment !== 'object') {
|
||||
errors.push(`${context}: missing equipment`);
|
||||
|
||||
Reference in New Issue
Block a user