mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-01-10 13:03:15 +00:00
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
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>();
|
|
private typeToMaxLevel: Map<UpgradeType, number> = new Map<UpgradeType, number>();
|
|
|
|
public constructor(player: Player) {
|
|
this.player = player;
|
|
|
|
this.setTypeMaps(UpgradeType.WeaponLength, this.upgradeWeaponLength, 5);
|
|
this.setTypeMaps(UpgradeType.WeaponDamage, this.upgradeWeaponDamage, 5);
|
|
}
|
|
|
|
public upgradeSkill(type: UpgradeType): void {
|
|
if (!this.typeToAction.has(type)) throw new Error("Upgrade does not have " + type);
|
|
this.typeToAction.get(type)();
|
|
}
|
|
|
|
private setTypeMaps(upgradeType: UpgradeType, action: () => void, maxLevel: number): void {
|
|
this.typeToAction.set(upgradeType, action);
|
|
this.typeToLevel.set(upgradeType, 0);
|
|
this.typeToMaxLevel.set(upgradeType, maxLevel);
|
|
}
|
|
|
|
private upgradeWeaponLength(): void {
|
|
this.player.Weapon.upgradeWeaponLength();
|
|
}
|
|
|
|
private upgradeWeaponDamage(): void {
|
|
this.player.Weapon.upgradeWeaponDamage();
|
|
}
|
|
}
|