You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.7 KiB
97 lines
2.7 KiB
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<string|typeof Target|typeof Source>;
|
|
export function OperandItems<T extends string|typeof Target|typeof Source>(...items: readonly T[]): Set<T> {
|
|
return new Set<T>(items)
|
|
}
|
|
export function OperandSets<T extends string|typeof Target|typeof Source>(children: readonly Set<T>[]): Set<T> {
|
|
return new Set<T>([...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<string> {
|
|
const result = new Set<string>()
|
|
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<string, IdentifierLookupResult> {
|
|
const set = evaluateOperands(operands, ctx)
|
|
const result = new Map<string, IdentifierLookupResult>()
|
|
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
|
|
} |