feat: migrate JavaScript files to TypeScript, enhancing type safety and maintainability across the codebase
This commit is contained in:
parent
3db2bb9160
commit
c582f2004e
107 changed files with 5876 additions and 3588 deletions
48
src/skills/Skill.ts
Normal file
48
src/skills/Skill.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue