@lands.io/mod-sdk / BaseAction
Class: BaseAction\<T>¶
Abstract base class for creating custom actions. Extend this class to create new action types.
Example
class MyCustomAction extends BaseAction {
readonly id = 'my-action';
readonly label = 'My Action';
canActivate(context: ActionContext): boolean {
return context.player.troops() > 1000;
}
chooseTarget(context: ActionContext): ActionTarget | null {
// AI targeting logic
return null;
}
createExecution(context: ActionContext, target: ActionTarget): Execution {
// Create and return an execution
}
}
Type parameters¶
| Name | Type |
|---|---|
T |
extends ActionTarget = ActionTarget |
Implements¶
Action\<T>
Table of contents¶
Constructors¶
Properties¶
Methods¶
Constructors¶
constructor¶
• new BaseAction\<T>(): BaseAction\<T>
Type parameters¶
| Name | Type |
|---|---|
T |
extends ActionTarget = ActionTarget |
Returns¶
BaseAction\<T>
Properties¶
id¶
• Readonly Abstract id: string
Implementation of¶
label¶
• Readonly Abstract label: string
Implementation of¶
Methods¶
canActivate¶
▸ canActivate(context): boolean
Parameters¶
| Name | Type |
|---|---|
context |
ActionContext |
Returns¶
boolean
Implementation of¶
chooseTarget¶
▸ chooseTarget(context): null | T
Parameters¶
| Name | Type |
|---|---|
context |
ActionContext |
Returns¶
null | T
Implementation of¶
createExecution¶
▸ createExecution(context, target): Execution
Parameters¶
| Name | Type |
|---|---|
context |
ActionContext |
target |
T |
Returns¶
Implementation of¶
getCost¶
▸ getCost(context): number
Parameters¶
| Name | Type |
|---|---|
context |
ActionContext |
Returns¶
number
Implementation of¶
Source Code¶
View full implementation
/**
* Abstract base class for creating custom actions.
* Extend this class to create new action types.
*
* @example
* ```typescript
* class MyCustomAction extends BaseAction {
* readonly id = 'my-action';
* readonly label = 'My Action';
*
* canActivate(context: ActionContext): boolean {
* return context.player.troops() > 1000;
* }
*
* chooseTarget(context: ActionContext): ActionTarget | null {
* // AI targeting logic
* return null;
* }
*
* createExecution(context: ActionContext, target: ActionTarget): Execution {
* // Create and return an execution
* }
* }
* ```
*/
export abstract class BaseAction<T extends ActionTarget = ActionTarget>
implements Action<T>
{
abstract readonly id: string;
abstract readonly label: string;
abstract canActivate(context: ActionContext): boolean;
abstract chooseTarget(context: ActionContext): T | null;
abstract createExecution(context: ActionContext, target: T): Execution;
getCost?(context: ActionContext): number;
}