bitburner-src/src/Gang/GangMemberUpgrade.ts

68 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-06-17 23:37:05 +02:00
import { IMults, UpgradeType } from "./data/upgrades";
import { formatPercent, FormatsHaveChanged } from "../ui/formatNumber";
2021-06-14 21:42:38 +02:00
export class GangMemberUpgrade {
2021-09-05 01:09:30 +02:00
name: string;
cost: number;
type: UpgradeType;
desc: string;
mults: IMults;
2021-06-14 21:42:38 +02:00
2021-09-09 05:47:34 +02:00
constructor(name = "", cost = 0, type: UpgradeType = UpgradeType.Weapon, mults: IMults = {}) {
2021-09-05 01:09:30 +02:00
this.name = name;
this.cost = cost;
this.type = type;
this.mults = mults;
// No initialization because it depend on number formatter config
this.desc = "";
FormatsHaveChanged.subscribe(() => (this.desc = this.createDescription()));
2021-09-05 01:09:30 +02:00
}
2021-06-14 21:42:38 +02:00
2021-09-05 01:09:30 +02:00
createDescription(): string {
const lines = ["Effects:"];
if (this.mults.str != null) {
lines.push(`+${formatPercent(this.mults.str - 1, 0)} strength skill`);
lines.push(`+${formatPercent((this.mults.str - 1) / 4, 2)} strength exp`);
2021-09-05 01:09:30 +02:00
}
if (this.mults.def != null) {
lines.push(`+${formatPercent(this.mults.def - 1, 0)} defense skill`);
lines.push(`+${formatPercent((this.mults.def - 1) / 4, 2)} defense exp`);
2021-09-05 01:09:30 +02:00
}
if (this.mults.dex != null) {
lines.push(`+${formatPercent(this.mults.dex - 1, 0)} dexterity skill`);
lines.push(`+${formatPercent((this.mults.dex - 1) / 4, 2)} dexterity exp`);
2021-09-05 01:09:30 +02:00
}
if (this.mults.agi != null) {
lines.push(`+${formatPercent(this.mults.agi - 1, 0)} agility skill`);
lines.push(`+${formatPercent((this.mults.agi - 1) / 4, 2)} agility exp`);
2021-09-05 01:09:30 +02:00
}
if (this.mults.cha != null) {
lines.push(`+${formatPercent(this.mults.cha - 1, 0)} charisma skill`);
lines.push(`+${formatPercent((this.mults.cha - 1) / 4, 2)} charisma exp`);
2021-09-05 01:09:30 +02:00
}
if (this.mults.hack != null) {
lines.push(`+${formatPercent(this.mults.hack - 1, 0)} hacking skill`);
lines.push(`+${formatPercent((this.mults.hack - 1) / 4, 2)} hacking exp`);
2021-06-14 21:42:38 +02:00
}
2021-09-05 01:09:30 +02:00
return lines.join("<br>");
}
2021-06-14 21:42:38 +02:00
2021-09-05 01:09:30 +02:00
// User friendly version of type.
getType(): string {
switch (this.type) {
case UpgradeType.Weapon:
return "Weapon";
case UpgradeType.Armor:
return "Armor";
case UpgradeType.Vehicle:
return "Vehicle";
case UpgradeType.Rootkit:
return "Rootkit";
case UpgradeType.Augmentation:
return "Augmentation";
default:
return "";
2021-06-16 08:26:10 +02:00
}
2021-09-05 01:09:30 +02:00
}
}