Slash-The-Hordes/assets/Scripts/Game/Unit/Player/PlayerRegeneration.ts
2022-11-28 14:34:34 +01:00

29 lines
920 B
TypeScript

import { GameTimer } from "../../../Services/GameTimer";
import { UnitHealth } from "../UnitHealth";
export class PlayerRegeneration {
private currentRegenerationAmount = 0;
private regenerationDelay: number;
private regenerationTimer: GameTimer = new GameTimer(0);
private health: UnitHealth;
public constructor(health: UnitHealth, regenerationDelay: number) {
this.health = health;
this.regenerationDelay = regenerationDelay;
}
public upgrade(): void {
this.currentRegenerationAmount++;
this.regenerationTimer = new GameTimer(this.regenerationDelay / this.currentRegenerationAmount);
}
public gameTick(deltaTime: number): void {
if (this.currentRegenerationAmount <= 0) return;
this.regenerationTimer.gameTick(deltaTime);
if (this.regenerationTimer.tryFinishPeriod()) {
this.health.heal(1);
}
}
}