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
60
src/systems/SkillSystem.ts
Normal file
60
src/systems/SkillSystem.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { System } from '../core/System.ts';
|
||||
import { SkillRegistry } from '../skills/SkillRegistry.ts';
|
||||
import { SystemName, ComponentType } from '../core/Constants.ts';
|
||||
import type { Entity } from '../core/Entity.ts';
|
||||
import type { Skills } from '../components/Skills.ts';
|
||||
import type { Intent } from '../components/Intent.ts';
|
||||
|
||||
/**
|
||||
* System responsible for managing skill cooldowns and activating skills based on entity intent.
|
||||
*/
|
||||
export class SkillSystem extends System {
|
||||
constructor() {
|
||||
super(SystemName.SKILL);
|
||||
this.requiredComponents = [ComponentType.SKILLS];
|
||||
this.priority = 30;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process all entities with skills, updating cooldowns and activating skills if intended.
|
||||
* @param deltaTime - Time elapsed since last frame in seconds
|
||||
* @param entities - Entities matching system requirements
|
||||
*/
|
||||
process(deltaTime: number, entities: Entity[]): void {
|
||||
entities.forEach((entity) => {
|
||||
const skills = entity.getComponent<Skills>(ComponentType.SKILLS);
|
||||
const intent = entity.getComponent<Intent>(ComponentType.INTENT);
|
||||
if (!skills) return;
|
||||
|
||||
skills.updateCooldowns(deltaTime);
|
||||
|
||||
if (intent && intent.action === 'skill_use') {
|
||||
const skillId = intent.data.skillId;
|
||||
if (skillId && !skills.isOnCooldown(skillId)) {
|
||||
this.activateSkill(entity, skillId);
|
||||
}
|
||||
intent.clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate a specific skill for an entity.
|
||||
* @param entity - The entity performing the skill
|
||||
* @param skillId - The ID of the skill to activate
|
||||
*/
|
||||
activateSkill(entity: Entity, skillId: string): void {
|
||||
const skill = SkillRegistry.get(skillId);
|
||||
if (!skill) {
|
||||
console.warn(`Skill not found: ${skillId}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (skill.activate(entity, this.engine)) {
|
||||
const skills = entity.getComponent<Skills>(ComponentType.SKILLS);
|
||||
if (skills) {
|
||||
skills.setCooldown(skillId, skill.cooldown);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue