mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2026-02-14 12:22:42 +00:00
Folder structure
This commit is contained in:
42
assets/Scripts/Game/Unit/UnitHealth.ts
Normal file
42
assets/Scripts/Game/Unit/UnitHealth.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user