From 612f149cf996ea3d5655a5e0428b60de5ce3b1be Mon Sep 17 00:00:00 2001 From: Mari Date: Sat, 4 Sep 2021 17:01:49 -0400 Subject: [PATCH] Add interfaces for Action and related objects. Progress on #3, #4, #5. --- src/battlers/Action.ts | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/battlers/Action.ts diff --git a/src/battlers/Action.ts b/src/battlers/Action.ts new file mode 100644 index 0000000..0d10fd6 --- /dev/null +++ b/src/battlers/Action.ts @@ -0,0 +1,76 @@ +/** The interface for actions that can be selected during battle. This is also used automatically for the Defend and Flee options. */ +export interface ActionData { + /** The name that will be displayed in the action list - a Handlebars template. */ + readonly nameTemplate: string + /** The help message that will be displayed when this action is selected - a Handlebars template. */ + readonly helpMessageTemplate: string + /** The cost of the action - a script expression. The cost of the action is automatically deducted, and need not be deducted by the effect as well. */ + readonly costExpression: string + /** Whether the action can currently be used, and if so, how much of the turn it takes up - a script expression. */ + readonly speedExpression: string + /** The effect of the action - a sequence of script statements separated by newlines. */ + readonly actionEffect: string +} + +/** The state of an action, determining its display in the action menu. */ +export enum ActionSpeed { + /** + * Fast actions only cost half the user's turn. + * If a Fast action is used at the start of the user's turn, they can use a single Fast or Normal action afterward. + */ + FAST="Fast", + /** + * Normal actions only cost half (or maybe two thirds) of the user's turn. + * If these actions are used on the user's turn, it ends, but they can be used after a Fast action. + */ + NORMAL="Normal", + /** + * Slow actions cost a user's entire turn. + * They can't be used after Fast actions, and the user's turn ends after using them. + */ + SLOW="Slow", + /** + * Disabled actions are shown in the action list, but cannot be used. + */ + DISABLED="Disabled", + /** + * Hidden actions are not shown in the action list and cannot be used. + */ + HIDDEN="Hidden", +} + +/** The counters that actions' costs and damage/healing can deduct from. */ +export enum Counter { + CONFIDENCE="Confidence", + HEALTH="Health", + STAMINA="Stamina", + ENERGY="Energy", +} + +/** The interface for an action's cost. */ +export interface ActionCost { + /** The counter that the cost will be deducted from. */ + readonly affects: Counter + /** + * The cost, which the counter must be greater than or equal to for the skill to be used, and + * which will be deducted from the counter when it is used. + */ + readonly cost: number +} + +/** + * The interface for an evaluated action. This saves time recalculating actions on every repaint and avoids cases + * where the cost a user sees before choosing the action is not the same as the cost a user sees when using it. + */ +export interface Action { + /** The data this action originated from. */ + readonly data: ActionData + /** The name, with any template variables substituted in. */ + readonly name: string + /** The help message, with any template variables substituted in. */ + readonly helpMessage: string + /** The cost, which has been evaluated into an optimized set of ActionCost with at most one ActionCost per Counter. */ + readonly cost: readonly ActionCost[] + /** The speed of the action, determining when it can be used and what other actions can be used with it. */ + readonly speed: ActionSpeed +} \ No newline at end of file