Skip to content

Instantly share code, notes, and snippets.

@AllGistsEqual
Created March 9, 2021 13:03
Show Gist options
  • Save AllGistsEqual/f9509ca9667bb18a4dc2cd2685e50f87 to your computer and use it in GitHub Desktop.
Save AllGistsEqual/f9509ca9667bb18a4dc2cd2685e50f87 to your computer and use it in GitHub Desktop.
// We need units to compare and some stats and status to check.
// I will skill the imported 'Effect' and 'RaceName' types here
type UnitBase = {
hp: {
current: number;
max: number;
};
status: Effect[];
};
export type Unit = UnitBase & {
name: string;
id: string;
race: RaceName;
};
// possible selections for targeets and derived types
const targets = [
"self",
"currentAlly",
"currentEnemy",
"leader",
"leaderCurrentEnemy",
"leaderCurrentAlly"
] as const
type Target = typeof targets[number];
const conditionTargets = [
...targets,
"ally",
"enemy",
] as const
type ConditionTarget = typeof conditionTargets[number];
/*
* skipped a few more types here including a selection of
* valid absolute numbers and percentage values as well as
* our previously used Effect type
*/
// comparison operators for numerical values like hitpoints
const comparisonOperators = ["lt", "lte", "eq", "gte", "gt"] as const
type ComparisonOperator = typeof comparisonOperators[number];
type PercentageComparison = [ComparisonOperator, Percentage];
type AbsoluteComparison = [ComparisonOperator, AbsoluteValue];
type StatusComparison = [boolean, Effect];
// last thing to do here is a simple mapping of valid combinations
type TargetComparison =
| ["hp", AbsoluteComparison]
| ["hp%", PercentageComparison]
| ["mp", AbsoluteComparison]
| ["mp%", PercentageComparison]
| ["status", StatusComparison]
type TriggerCondition = [ConditionTarget, TargetComparison];
type Gambit = {
target: ConditionTarget;
comparison: TargetComparison;
action: Spell | Skill | Item;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment