mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-11 18:23:54 +01:00
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
/**
|
|
* This is an object that is used to keep track of where all of the player's
|
|
* money is coming from (or going to)
|
|
*/
|
|
import { Generic_fromJSON, Generic_toJSON, Reviver } from "./JSONReviver";
|
|
|
|
export class MoneySourceTracker {
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
[key: string]: number | Function;
|
|
|
|
bladeburner = 0;
|
|
casino = 0;
|
|
class = 0;
|
|
codingcontract = 0;
|
|
corporation = 0;
|
|
crime = 0;
|
|
gang = 0;
|
|
hacking = 0;
|
|
hacknetnode = 0;
|
|
hospitalization = 0;
|
|
infiltration = 0;
|
|
sleeves = 0;
|
|
stock = 0;
|
|
total = 0;
|
|
work = 0;
|
|
|
|
// Record money earned
|
|
record(amt: number, source: string): void {
|
|
const sanitizedSource = source.toLowerCase();
|
|
if (typeof this[sanitizedSource] !== "number") {
|
|
console.warn(`MoneySourceTracker.record() called with invalid source: ${source}`);
|
|
return;
|
|
}
|
|
|
|
(this[sanitizedSource] as number) += amt;
|
|
this.total += amt;
|
|
}
|
|
|
|
// Reset the money tracker by setting all stats to 0
|
|
reset(): void {
|
|
for (const prop in this) {
|
|
if (typeof this[prop] === "number") {
|
|
(this[prop] as number) = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Serialize the current object to a JSON save state.
|
|
toJSON(): any {
|
|
return Generic_toJSON("MoneySourceTracker", this);
|
|
}
|
|
|
|
// Initiatizes a MoneySourceTracker object from a JSON save state.
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
static fromJSON(value: any): MoneySourceTracker {
|
|
return Generic_fromJSON(MoneySourceTracker, value.data);
|
|
}
|
|
}
|
|
|
|
Reviver.constructors.MoneySourceTracker = MoneySourceTracker;
|