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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user