feat(engine): add instant action execution

Implements executeInstant, which applies an instant action's costs and
yields immediately with no queue slot and no duration requirement.
This commit is contained in:
ginnoir
2026-06-11 20:29:28 -05:00
parent b54805637c
commit b3940774c4
2 changed files with 52 additions and 0 deletions
+17
View File
@@ -156,6 +156,23 @@ export function clearQueue(state: GameState): void {
state.actionQueue.length = 0;
}
/**
* Execute an instant action immediately, deducting costs and granting yields
* without occupying a queue slot or requiring a duration.
* Throws if the action is not of kind 'instant' or is unavailable.
*/
export function executeInstant(state: GameState, content: Content, actionId: string): void {
const action = content.actionsById[actionId];
if (!action || action.kind !== 'instant') {
throw new Error(`Action "${actionId}" is not instant`);
}
if (!isActionAvailable(state, content, actionId)) {
throw new Error(`Cannot perform instant action "${actionId}"`);
}
deductCosts(state, content, actionId);
grantYields(state, content, actionId);
}
/**
* Advance the active action by `tickMs`. On completion, grants yields and
* advances the queue — actions do not auto-repeat when the queue is empty.