bitburner-src/src/PersonObjects/Resleeving/Resleeve.ts

64 lines
1.8 KiB
TypeScript
Raw Normal View History

/**
* Implements the Resleeve class, which defines a new body
* that the player can "re-sleeve" into.
*/
import { Person } from "../Person";
import { Augmentation } from "../../Augmentation/Augmentation";
import { Augmentations } from "../../Augmentation/Augmentations";
2021-09-09 05:47:34 +02:00
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../../utils/JSONReviver";
export class Resleeve extends Person {
2021-09-05 01:09:30 +02:00
constructor() {
super();
}
2021-09-05 01:09:30 +02:00
getCost(): number {
// Each experience point adds this to the cost
const CostPerExp = 25e3;
2021-09-05 01:09:30 +02:00
// Final cost is multiplied by this constant ^ # Augs
const NumAugsExponent = 1.2;
2021-09-05 01:09:30 +02:00
// Get total exp in this re-sleeve
const totalExp: number =
this.hacking_exp +
this.strength_exp +
this.defense_exp +
this.dexterity_exp +
this.agility_exp +
this.charisma_exp;
2021-05-01 09:17:31 +02:00
2021-09-05 01:09:30 +02:00
// Get total base Augmentation cost for this re-sleeve
let totalAugmentationCost = 0;
for (let i = 0; i < this.augmentations.length; ++i) {
2021-09-09 05:47:34 +02:00
const aug: Augmentation | null = Augmentations[this.augmentations[i].name];
2021-09-05 01:09:30 +02:00
if (aug == null) {
2021-09-09 05:47:34 +02:00
console.error(`Could not find Augmentation ${this.augmentations[i].name}`);
2021-09-05 01:09:30 +02:00
continue;
}
totalAugmentationCost += aug.startingCost;
2021-05-01 09:17:31 +02:00
}
2021-09-05 01:09:30 +02:00
2021-09-09 05:47:34 +02:00
return totalExp * CostPerExp + totalAugmentationCost * Math.pow(NumAugsExponent, this.augmentations.length);
2021-09-05 01:09:30 +02:00
}
/**
* Serialize the current object to a JSON save state.
*/
toJSON(): any {
return Generic_toJSON("Resleeve", this);
}
/**
* Initiatizes a Resleeve object from a JSON save state.
*/
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
static fromJSON(value: any): Resleeve {
return Generic_fromJSON(Resleeve, value.data);
}
}
Reviver.constructors.Resleeve = Resleeve;