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
73
src/components/AI.ts
Normal file
73
src/components/AI.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import { Component } from '../core/Component.ts';
|
||||
import { ComponentType } from '../core/Constants.ts';
|
||||
|
||||
/**
|
||||
* Component for AI behavior and state.
|
||||
*/
|
||||
export class AI extends Component {
|
||||
behaviorType: string;
|
||||
state: string;
|
||||
target: number | null;
|
||||
awareness: number;
|
||||
alertRadius: number;
|
||||
chaseRadius: number;
|
||||
fleeRadius: number;
|
||||
wanderSpeed: number;
|
||||
wanderDirection: number;
|
||||
wanderChangeTime: number;
|
||||
wanderChangeInterval: number;
|
||||
|
||||
/**
|
||||
* @param behaviorType - The initial behavior type
|
||||
*/
|
||||
constructor(behaviorType = 'wander') {
|
||||
super(ComponentType.AI);
|
||||
this.behaviorType = behaviorType;
|
||||
this.state = 'idle';
|
||||
this.target = null;
|
||||
this.awareness = 0;
|
||||
this.alertRadius = 60;
|
||||
this.chaseRadius = 120;
|
||||
this.fleeRadius = 40;
|
||||
|
||||
this.wanderSpeed = 20;
|
||||
this.wanderDirection = Math.random() * Math.PI * 2;
|
||||
this.wanderChangeTime = 0;
|
||||
this.wanderChangeInterval = 2.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior type for this AI.
|
||||
* @param type - The new behavior type (e.g., 'wander', 'patrol', 'chase')
|
||||
*/
|
||||
setBehavior(type: string): void {
|
||||
this.behaviorType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a target entity for the AI to interact with.
|
||||
* @param entityId - The ID of the target entity
|
||||
*/
|
||||
setTarget(entityId: number): void {
|
||||
this.target = entityId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the current target.
|
||||
*/
|
||||
clearTarget(): void {
|
||||
this.target = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the AI's awareness level.
|
||||
* @param delta - The amount to change awareness by
|
||||
* @param maxAwareness - The maximum awareness level
|
||||
*/
|
||||
updateAwareness(delta: number, maxAwareness = 1.0): void {
|
||||
this.awareness = Math.min(maxAwareness, this.awareness + delta);
|
||||
if (this.awareness <= 0) {
|
||||
this.awareness = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue