[duel-cards] Match duel-core's contract (#72): template ids, description, maxTokens = fewer than N

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 21:58:37 -05:00
co-authored by Claude Opus 5.5
parent a8468dd96c
commit 57d2fc2fc7
4 changed files with 645 additions and 319 deletions
File diff suppressed because it is too large Load Diff
+3
View File
@@ -48,6 +48,8 @@ export interface DuelCard {
pageId: number;
revisionId: number;
title: string;
/** Wikidata short description, for log first mentions (omitted when absent). */
description?: string;
type: CardType;
/** Template family within the type, e.g. 'conflict', 'election', 'organisation', 'pathology'. */
subtype: string | null;
@@ -291,6 +293,7 @@ export function derive(chain: CardOnChain, profile: CardProfile, rules: DeriveRu
rarity: rarityOf(chain.tokenId), deriveVersion: DERIVE_VERSION, typedBy: source,
basis: { pctAttention: p.attention, pctDepth: p.depth, pctReach: p.reach, fame, magnitude },
};
if (profile.description) card.description = profile.description;
card.rulesText = rulesTextFor(card);
return card;
}
+21 -2
View File
@@ -19,8 +19,11 @@ export interface EffectSpec {
toughness?: number;
duration?: 'turn' | 'permanent';
token?: { name: string; power: number; toughness: number; portal: Portal };
condition?: { maxPower?: number; samePortal?: boolean; connected?: boolean; maxTokens?: number; whileAttacking?: boolean };
/** maxTokens: createToken only if the controller controls fewer than this many tokens (duel-core types.ts). */
condition?: { maxPower?: number; samePortal?: boolean; connected?: boolean; maxTokens?: number };
grant?: Keyword[];
/** Template id (DUEL_DESIGN §5, T3–T12) for rules text and log wording. */
template?: string;
}
type Subtypes = readonly (readonly [string, RegExp])[];
@@ -67,7 +70,23 @@ export function subtypeFor(type: CardType, profile: Pick<CardProfile, 'instanceO
}
/** The effect list for a card (T1–T12). Figures and Locations have none beyond keywords and stats. */
/** DUEL_DESIGN §5 template id by type and subtype. */
export function templateFor(type: CardType, subtype: string | null): string | null {
switch (type) {
case 'Figure': return 'T1';
case 'Location': return 'T2';
case 'Event': return ({ conflict: 'T3', disaster: 'T4', election: 'T5', sport: 'T6' } as Record<string, string>)[subtype ?? ''] ?? 'T7';
case 'Institution': return subtype === 'organisation' ? 'T8' : subtype === 'work' ? 'T9' : 'T10';
case 'Doctrine': return subtype === 'pathology' ? 'T12' : 'T11';
}
}
export function effectsFor(type: CardType, subtype: string | null, cost: number): EffectSpec[] {
const template = templateFor(type, subtype);
return baseEffects(type, subtype, cost).map(e => (template ? { ...e, template } : e));
}
function baseEffects(type: CardType, subtype: string | null, cost: number): EffectSpec[] {
const k = Math.ceil(cost / 2);
switch (type) {
case 'Event':
@@ -87,7 +106,7 @@ export function effectsFor(type: CardType, subtype: string | null, cost: number)
case 'organisation': {
const token = { name: 'Staff Member', power: 1, toughness: 1, portal: 'Neutral' as const };
return cost >= 4
? [{ trigger: 'startOfTurn', op: 'createToken', amount: 1, token, condition: { maxTokens: 2 } }]
? [{ trigger: 'startOfTurn', op: 'createToken', amount: 1, token, condition: { maxTokens: 3 } }]
: [{ trigger: 'onEnter', op: 'createToken', amount: 1, token }];
}
case 'work': return [
+2 -2
View File
@@ -41,7 +41,7 @@ function staticText(e: EffectSpec): string {
if (c.connected) who = 'Figures you control that are Connected to this';
if (c.samePortal) who = 'Other Figures you control of its Portal';
if (e.grant?.length && !e.power && !e.toughness) {
return `${who} have ${keywordsAsText(e.grant)}${c.whileAttacking ? ' while attacking' : ''}.`;
return `${who} have ${keywordsAsText(e.grant)}.`;
}
return `${who} get ${pt(e.power, e.toughness)}.`;
}
@@ -90,7 +90,7 @@ export function effectText(effects: readonly EffectSpec[]): string[] {
case 'onDestroyed': lines.push(`When this is destroyed, ${actionText(e)}.`); break;
case 'startOfTurn': {
const max = e.condition?.maxTokens;
const cond = max !== undefined ? `, if you control fewer than ${max + 1} tokens` : '';
const cond = max !== undefined ? `, if you control fewer than ${max} tokens` : '';
lines.push(`At the start of your turn${cond}, ${actionText(e)}.`);
break;
}