- Turn-order track: names coloured by PC, NPC or monster, this round, a flag where it ends, and the next round - Target by clicking a name on the track, the card, or keys 1-9; whoever is on turn and every target show what they have in hand - Attacks and spells are declared, rolled and applied: type or roll the d20 and the app says hit, miss or critical; a save spell asks each target for its save against the caster's DC; the DM overrules anything and applies - Critical damage by the campaign's rule; a spell spends its slot; a concentration save is called for - Auto-rolled monster and NPC attacks: aimed (weighted), rolled, and offered to the DM to accept, edit or discard; hidden from players until accepted - Monsters can have named attacks and multiattacks; spells say how they land - A "What now" line tells the DM (and each player) what the scene waits on Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
2.6 KiB
TypeScript
58 lines
2.6 KiB
TypeScript
import { ABILITY_ORDER } from './previewCalc';
|
|
import { formatMoney } from './format';
|
|
import type { Ability, Monster, Npc } from '../api/types';
|
|
|
|
// One thing in a campaign's lists that opens in a pop-out.
|
|
export type EntryKind = 'weapon' | 'item' | 'spell' | 'monster' | 'npc';
|
|
export interface EntryRef {
|
|
kind: EntryKind;
|
|
id: string;
|
|
// It was added by hand a moment ago: its pop-out offers to add another.
|
|
isNew?: boolean;
|
|
}
|
|
|
|
export type MonsterInput = Omit<Monster, 'id' | 'campaignId'>;
|
|
export type AbilityScores = Pick<Monster, 'strScore' | 'dexScore' | 'conScore' | 'intScore' | 'wisScore' | 'chaScore'>;
|
|
export const scoreField = (ability: string) => `${ability.toLowerCase()}Score` as keyof AbilityScores;
|
|
|
|
// "STR 8 · DEX 14 · …", in stat-block order.
|
|
export function abilityLine(scores: AbilityScores): string {
|
|
return ABILITY_ORDER.map((a) => `${a} ${scores[scoreField(a)]}`).join(' · ');
|
|
}
|
|
|
|
// "1 gp = $5": the rate an NPC changes gold and cash at, or null if they don't.
|
|
export function rateLabel(npc: Pick<Npc, 'exchangeGold' | 'exchangeCash'>): string | null {
|
|
if (!npc.exchangeGold || !npc.exchangeCash) return null;
|
|
return `${formatMoney(npc.exchangeGold, 'GOLD')} = ${formatMoney(npc.exchangeCash, 'CASH')}`;
|
|
}
|
|
|
|
// Whether every word of a search is somewhere in the text given: "fire bolt"
|
|
// finds "Fire Bolt", and "bolt fire" does too.
|
|
export function matchesSearch(query: string, ...fields: (string | number | null | undefined)[]): boolean {
|
|
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
const text = fields.filter((f) => f !== null && f !== undefined).join(' ').toLowerCase();
|
|
return words.every((word) => text.includes(word));
|
|
}
|
|
|
|
// How a spell lands in a battle, as one choice: it just takes effect, the
|
|
// caster rolls a spell attack, or each target makes a save with an ability
|
|
// (taking half damage on a success, or none). `landingValue` and
|
|
// `landingFrom` turn it into the value of a select and back.
|
|
export interface SpellLanding {
|
|
attackRoll: boolean;
|
|
saveAbility: Ability | null;
|
|
halfOnSave: boolean;
|
|
}
|
|
|
|
export function landingValue(spell: SpellLanding): string {
|
|
if (spell.attackRoll) return 'ATTACK';
|
|
return spell.saveAbility ? `${spell.saveAbility}:${spell.halfOnSave ? 'HALF' : 'NONE'}` : '';
|
|
}
|
|
|
|
export function landingFrom(value: string): SpellLanding {
|
|
if (value === 'ATTACK') return { attackRoll: true, saveAbility: null, halfOnSave: false };
|
|
if (!value) return { attackRoll: false, saveAbility: null, halfOnSave: false };
|
|
const [ability, half] = value.split(':');
|
|
return { attackRoll: false, saveAbility: ability as Ability, halfOnSave: half === 'HALF' };
|
|
}
|