forked from WikiDeck/wikideck
132 lines
6.9 KiB
TypeScript
132 lines
6.9 KiB
TypeScript
/**
|
||
* Effect templates by type and subtype (designer review §3.5; DUEL_DESIGN.md wins where they differ).
|
||
* Effects are plain data for duel-core's interpreter. k = ceil(cost / 2), 1–3, from the derived (fame) cost.
|
||
* Owner: duel-cards.
|
||
*/
|
||
import type { CardProfile, CardType } from './classify.ts';
|
||
import type { Keyword, Portal } from './derive.ts';
|
||
|
||
export type EffectTrigger = 'onPlay' | 'onEnter' | 'startOfTurn' | 'onDestroyed' | 'static' | 'onCombatDamageToPlayer';
|
||
export type EffectOp = 'damage' | 'damageEach' | 'createToken' | 'pump' | 'fight' | 'draw' | 'attach' | 'gainLife';
|
||
export type EffectTarget = 'figure' | 'figureOrLocation' | 'ownFigure' | 'opponentFigure' | 'each' | 'self' | 'attached' | 'ownFigures';
|
||
|
||
export interface EffectSpec {
|
||
trigger: EffectTrigger;
|
||
op: EffectOp;
|
||
target?: EffectTarget;
|
||
amount?: number;
|
||
power?: number;
|
||
toughness?: number;
|
||
duration?: 'turn' | 'permanent';
|
||
token?: { name: string; power: number; toughness: number; portal: Portal };
|
||
/** 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])[];
|
||
|
||
/**
|
||
* Subtype rules per type (DUEL_DESIGN §5), run over P31 labels, P279 labels, the description, then
|
||
* categories. First match in list order wins; no match is the type's default template.
|
||
* Additions beyond §5 (marked +): bands/associations count as organisations; 'flood' etc. as listed.
|
||
*/
|
||
export const SUBTYPE_RULES: Readonly<Record<CardType, Subtypes>> = {
|
||
Event: [
|
||
['conflict', /battle|war\b|siege|annexation|protest|riot|uprising|massacre|coup/],
|
||
['disaster', /storm|nor.easter|cyclone|hurricane|earthquake|flood|tornado|wildfire|eruption|famine|epidemic/],
|
||
['election', /election|referendum|straw poll/],
|
||
['sport', /match|final\b|season|tournament|championship|grand prix|\brace\b/],
|
||
],
|
||
Institution: [
|
||
['organisation', /company|organi[sz]ation|party|agency|studio|military|university|diocese|council|band\b|musical group|association|business|school|college|institute|manufacturer/],
|
||
['work', /film|album|song|\bbook|novel|series|video game|painting|software|typeface|newspaper|magazine/],
|
||
],
|
||
Doctrine: [
|
||
['pathology', /disease|clinical sign|pathogen|syndrome|disorder|toxin|poison/],
|
||
['language', /language|software|programming/],
|
||
['mathematics', /mathemat|theorem|algebra|geometr|polytope|polyhedron|equation|number theory|structure/],
|
||
['ideology', /ideology|religion|belief|doctrine|philosophy|theology/],
|
||
],
|
||
Figure: [],
|
||
Location: [],
|
||
};
|
||
|
||
/** Default template names, for the info panel (null subtype). */
|
||
export const DEFAULT_SUBTYPE: Readonly<Record<CardType, string | null>> = {
|
||
Figure: null, Location: null, Event: 'other', Institution: 'other', Doctrine: 'adopt',
|
||
};
|
||
|
||
export function subtypeFor(type: CardType, profile: Pick<CardProfile, 'instanceOf' | 'subclassOf' | 'description' | 'categories'>): string | null {
|
||
const groups = [
|
||
[...profile.instanceOf.map(c => c.label), ...(profile.subclassOf ?? []).map(c => c.label)],
|
||
[profile.description ?? ''],
|
||
[...(profile.categories ?? []).filter(c => !/stubs$/i.test(c))],
|
||
].map(g => g.map(t => t.toLowerCase()).filter(Boolean));
|
||
for (const texts of groups) for (const [name, rx] of SUBTYPE_RULES[type]) if (texts.some(t => rx.test(t))) return name;
|
||
return DEFAULT_SUBTYPE[type];
|
||
}
|
||
|
||
/** 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':
|
||
switch (subtype) {
|
||
case 'conflict': return [{ trigger: 'onPlay', op: 'damage', target: 'figureOrLocation', amount: k + 1 }];
|
||
case 'disaster': return [{ trigger: 'onPlay', op: 'damageEach', target: 'each', amount: Math.max(1, k - 1) }];
|
||
case 'election': return [{ trigger: 'onPlay', op: 'createToken', amount: k,
|
||
token: { name: 'Elected Member', power: 1, toughness: 1, portal: 'Society' } }];
|
||
case 'sport': return [
|
||
{ trigger: 'onPlay', op: 'pump', target: 'ownFigure', power: k, toughness: 0, duration: 'turn' },
|
||
{ trigger: 'onPlay', op: 'fight', target: 'opponentFigure' },
|
||
];
|
||
default: return [{ trigger: 'onPlay', op: 'draw', amount: k }];
|
||
}
|
||
case 'Institution':
|
||
switch (subtype) {
|
||
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: 3 } }]
|
||
: [{ trigger: 'onEnter', op: 'createToken', amount: 1, token }];
|
||
}
|
||
case 'work': return [
|
||
{ trigger: 'onEnter', op: 'draw', amount: 1 },
|
||
{ trigger: 'static', op: 'pump', target: 'ownFigures', power: 1, toughness: 1, condition: { connected: true } },
|
||
];
|
||
default: return [{ trigger: 'static', op: 'pump', target: 'ownFigures', power: 1, toughness: 0, condition: { maxPower: 2 } }];
|
||
}
|
||
case 'Doctrine': {
|
||
// DUEL_API "Doctrine": `attach` picks the Figure; the buff is a static pump on `attached`.
|
||
const pathology = subtype === 'pathology';
|
||
const attach: EffectSpec = { trigger: 'onPlay', op: 'attach', target: pathology ? 'figure' : 'ownFigure' };
|
||
const buff: EffectSpec = { trigger: 'static', op: 'pump', target: 'attached', power: pathology ? -k : k, toughness: pathology ? -k : k };
|
||
if (pathology) return [attach, buff];
|
||
if (subtype === 'mathematics') return [attach, { ...buff, grant: ['Well-sourced'] }];
|
||
if (subtype === 'language') return [attach, buff, { trigger: 'onCombatDamageToPlayer', op: 'draw', amount: 1 }];
|
||
if (subtype === 'ideology') return [attach, buff, { trigger: 'static', op: 'pump', target: 'ownFigures', power: 1, toughness: 0, condition: { samePortal: true } }];
|
||
return [attach, buff];
|
||
}
|
||
default: return [];
|
||
}
|
||
}
|