Files
the-beacon/reference/guardrails.js
Alexander Whitestone aadd8109f0
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Successful in 14s
Smoke Test / smoke (pull_request) Failing after 24s
chore: move dormant prototypes to reference/ directory
- game/npc-logic.js → reference/npc-logic.js (added REFERENCE PROTOTYPE header)
- scripts/guardrails.js → reference/guardrails.js (added REFERENCE PROTOTYPE header)
- New reference/README.md with integration instructions

Closes #196
2026-04-15 21:45:53 -04:00

36 lines
1.1 KiB
JavaScript

/**
* REFERENCE PROTOTYPE — NOT LOADED BY RUNTIME
*
* This file is dormant. It contains inline test code at the bottom
* and is not production-ready.
*
* To integrate: remove the inline test block, add <script src="reference/guardrails.js">
* to index.html, and wire Guardrails into the game engine lifecycle.
*/
/**
* Symbolic Guardrails for The Beacon
* Ensures game logic consistency.
*/
class Guardrails {
static validateStats(stats) {
const required = ['hp', 'maxHp', 'mp', 'maxMp', 'level'];
required.forEach(r => {
if (!(r in stats)) throw new Error(`Missing stat: ${r}`);
});
if (stats.hp > stats.maxHp) return { valid: false, reason: 'HP exceeds MaxHP' };
return { valid: true };
}
static validateDebuff(debuff, stats) {
if (debuff.type === 'drain' && stats.hp <= 1) {
return { valid: false, reason: 'Drain debuff on critical HP' };
}
return { valid: true };
}
}
// Test
const playerStats = { hp: 50, maxHp: 100, mp: 20, maxMp: 50, level: 1 };
console.log('Stats check:', Guardrails.validateStats(playerStats));