mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-29 04:58:06 +00:00
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { ISignal } from "../../Services/EventSystem/ISignal";
|
|
import { Signal } from "../../Services/EventSystem/Signal";
|
|
|
|
export class UnitHealth {
|
|
private healthPoints: number;
|
|
private maxHealthPoints: number;
|
|
private healthPointsChangeEvent: Signal<number> = new Signal<number>();
|
|
|
|
public constructor(maxHealth: number) {
|
|
this.maxHealthPoints = maxHealth;
|
|
this.healthPoints = maxHealth;
|
|
}
|
|
|
|
public get IsAlive(): boolean {
|
|
return 0 < this.healthPoints;
|
|
}
|
|
|
|
public get HealthPoints(): number {
|
|
return this.healthPoints;
|
|
}
|
|
public get MaxHealthPoints(): number {
|
|
return this.maxHealthPoints;
|
|
}
|
|
|
|
public get HealthPointsChangeEvent(): ISignal<number> {
|
|
return this.healthPointsChangeEvent;
|
|
}
|
|
|
|
public heal(points: number): void {
|
|
this.healthPoints = Math.min(this.maxHealthPoints, this.healthPoints + points);
|
|
this.healthPointsChangeEvent.trigger(this.healthPoints);
|
|
}
|
|
|
|
public damage(points: number): void {
|
|
this.healthPoints -= points;
|
|
this.healthPointsChangeEvent.trigger(this.healthPoints);
|
|
}
|
|
|
|
public setMaxHealth(maxHealth: number): void {
|
|
this.maxHealthPoints = maxHealth;
|
|
}
|
|
}
|