mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-11-10 16:26:15 +00:00
Upgrader, LevelUpSkill
This commit is contained in:
39
assets/Scripts/Game/Upgrades/Upgrader.ts
Normal file
39
assets/Scripts/Game/Upgrades/Upgrader.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Player } from "../Player/Player";
|
||||
import { UpgradeType } from "./UpgradeType";
|
||||
|
||||
export class Upgrader {
|
||||
private player: Player;
|
||||
private typeToAction: Map<UpgradeType, () => void> = new Map<UpgradeType, () => void>();
|
||||
private typeToLevel: Map<UpgradeType, number> = new Map<UpgradeType, number>();
|
||||
|
||||
public constructor(player: Player) {
|
||||
this.player = player;
|
||||
|
||||
this.typeToAction.set(UpgradeType.MaxHP, this.upgradeMaxHp);
|
||||
this.typeToAction.set(UpgradeType.WeaponLength, this.upgradeWeaponLength);
|
||||
this.typeToAction.set(UpgradeType.WeaponDamage, this.upgradeWeaponDamage);
|
||||
|
||||
this.typeToLevel.set(UpgradeType.MaxHP, 0);
|
||||
this.typeToLevel.set(UpgradeType.WeaponLength, 0);
|
||||
}
|
||||
|
||||
public upgradeSkill(type: UpgradeType): void {
|
||||
if (!this.typeToAction.has(type)) throw new Error("Upgrade does not have " + type);
|
||||
this.typeToAction.get(type)();
|
||||
}
|
||||
|
||||
private upgradeMaxHp(): void {
|
||||
const healthIncrease = 5;
|
||||
const currentMax: number = this.player.Health.MaxHealthPoints;
|
||||
this.player.Health.setMaxHealth(currentMax + healthIncrease);
|
||||
this.player.Health.heal(healthIncrease);
|
||||
}
|
||||
|
||||
private upgradeWeaponLength(): void {
|
||||
this.player.Weapon.upgradeWeaponLength();
|
||||
}
|
||||
|
||||
private upgradeWeaponDamage(): void {
|
||||
this.player.Weapon.upgradeWeaponDamage();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user