48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import type { Entity } from '../core/Entity.ts';
|
|
import type { Engine } from '../core/Engine.ts';
|
|
import { ComponentType } from '../core/Constants.ts';
|
|
import type { Skills } from '../components/Skills.ts';
|
|
|
|
/**
|
|
* Base class for all skills in the game.
|
|
*/
|
|
export class Skill {
|
|
id: string;
|
|
name: string;
|
|
cooldown: number;
|
|
description: string;
|
|
|
|
/**
|
|
* @param id - Unique identifier for the skill
|
|
* @param name - Display name of the skill
|
|
* @param cooldown - Cooldown duration in seconds
|
|
*/
|
|
constructor(id: string, name: string, cooldown = 2.0) {
|
|
this.id = id;
|
|
this.name = name;
|
|
this.cooldown = cooldown;
|
|
this.description = '';
|
|
}
|
|
|
|
/**
|
|
* Activate the skill's effects.
|
|
* @param _caster - Entity using the skill
|
|
* @param _engine - Game engine
|
|
* @returns Whether skill was successfully activated
|
|
*/
|
|
activate(_caster: Entity, _engine: Engine): boolean {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Check if the skill can be used by the caster.
|
|
* @param caster - The caster entity
|
|
* @param _engine - Game engine
|
|
* @returns True if the skill is not on cooldown
|
|
*/
|
|
canUse(caster: Entity, _engine: Engine): boolean {
|
|
const skills = caster.getComponent<Skills>(ComponentType.SKILLS);
|
|
if (!skills) return false;
|
|
return !skills.isOnCooldown(this.id);
|
|
}
|
|
}
|