Connect bounded Reinforcements Battle Plan
This commit is contained in:
1 parent
763749f25e
commit
23ce406872
19 files changed
+745
-35
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import type { Card } from './cards';
|
||||
import { ecazTreacheryDefinition } from './ecaz-cards';
|
||||
|
||||
export const REINFORCEMENTS_CARD = 'ecaz-reinforcements' as const;
|
||||
|
||||
export class ReinforcementsError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'ReinforcementsError';
|
||||
}
|
||||
}
|
||||
|
||||
/** A matching id alone does not establish the physical variant card's identity. */
|
||||
export function isReinforcements(card: Card | undefined): boolean {
|
||||
return !!card && card.id === REINFORCEMENTS_CARD &&
|
||||
Object.keys(card).sort().join(',') === 'effect,id,kind,name' &&
|
||||
ecazTreacheryDefinition(card)?.card.effect === 'reinforcements';
|
||||
}
|
||||
|
||||
/** Spend exactly three own reserve counters, ordinary before elite; never dial them. */
|
||||
export function quoteReinforcements(
|
||||
normalReserves: number,
|
||||
eliteReserves: number,
|
||||
): { normal: number; elite: number; bonus: 2 } {
|
||||
if (![normalReserves, eliteReserves].every(n => typeof n === 'number' && Number.isSafeInteger(n) && n >= 0))
|
||||
throw new ReinforcementsError('Reinforcements needs valid nonnegative reserve counts.');
|
||||
if (normalReserves < 3 && eliteReserves < 3 - normalReserves)
|
||||
throw new ReinforcementsError('Reinforcements needs at least three own forces in reserves.');
|
||||
const normal = Math.min(3, normalReserves);
|
||||
return { normal, elite: 3 - normal, bonus: 2 };
|
||||
}
|
||||
Reference in new issue
Block a user