import {GameState, IdentifierLookupResult, lookupIdentifier} from "./GameState"; export enum ElementalType { Fire = "fire", Water = "water", Lightning = "lightning", Ice = "ice", Earth = "earth", Wind = "wind", Light = "light", Dark = "dark", Physical = "physical", Nonelemental = "non-elemental", Healing = "healing", } export enum Affinity { Absorbs = "absorbs", Immune = "immune", Resistant = "resistant", Normal = "normal", Vulnerable = "vulnerable", } export const AffinityDisplay = { [Affinity.Absorbs]: "??", [Affinity.Immune]: ".", [Affinity.Resistant]: "...", [Affinity.Normal]: "", [Affinity.Vulnerable]: "!!", } as const satisfies {[affinity in Affinity]: string} export enum NumberSign { Positive = "+", Negative = "-", } export enum FailReason { Avoid = "avoid", Dodge = "dodge", Miss = "miss", Resist = "resist", Fail = "fail", Block = "block", Parry = "parry", } export const Target: unique symbol = Symbol("target"); export const Source: unique symbol = Symbol("source"); export type Operands = Set; export function OperandItems(...items: readonly T[]): Set { return new Set(items) } export function OperandSets(children: readonly Set[]): Set { return new Set([...children.flatMap((child) => [...child.values()])]) } export interface EvaluationContext { readonly timestamp: number readonly source: readonly string[] readonly target: readonly string[] readonly game: GameState } export function evaluateOperands(operands: Operands, ctx: EvaluationContext): Set { const result = new Set() for (const operand of operands) { if (operand === Source) { for (const sourceItem of ctx.source) { result.add(sourceItem) } } else if (operand === Target) { for (const targetItem of ctx.target) { result.add(targetItem) } } else { result.add(operand) } } return result } export function lookupOperands(operands: Operands, ctx: EvaluationContext): Map { const set = evaluateOperands(operands, ctx) const result = new Map() for (const operand of set) { result.set(operand, lookupIdentifier(ctx.game, operand)) } return result } export interface MarkdownContext extends EvaluationContext {} export interface MarkdownOutput extends MarkdownContext { readonly output: string|null }