2019-02-22 03:26:28 +01:00
|
|
|
/**
|
|
|
|
* This is an object that is used to keep track of where all of the player's
|
2019-05-14 10:35:37 +02:00
|
|
|
* money is coming from (or going to)
|
2019-02-22 03:26:28 +01:00
|
|
|
*/
|
2021-09-25 20:42:57 +02:00
|
|
|
import { Generic_fromJSON, Generic_toJSON, Reviver } from "./JSONReviver";
|
2019-02-22 03:26:28 +01:00
|
|
|
|
|
|
|
export class MoneySourceTracker {
|
2021-09-05 01:09:30 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
|
|
[key: string]: number | Function;
|
2019-02-22 03:26:28 +01:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
bladeburner = 0;
|
|
|
|
casino = 0;
|
|
|
|
class = 0;
|
|
|
|
codingcontract = 0;
|
|
|
|
corporation = 0;
|
|
|
|
crime = 0;
|
|
|
|
gang = 0;
|
|
|
|
hacking = 0;
|
2021-10-27 20:18:33 +02:00
|
|
|
hacknet = 0;
|
2021-11-06 02:01:23 +01:00
|
|
|
hacknet_expenses = 0;
|
2021-09-05 01:09:30 +02:00
|
|
|
hospitalization = 0;
|
|
|
|
infiltration = 0;
|
|
|
|
sleeves = 0;
|
|
|
|
stock = 0;
|
|
|
|
total = 0;
|
|
|
|
work = 0;
|
2021-10-27 20:18:33 +02:00
|
|
|
servers = 0;
|
|
|
|
other = 0;
|
|
|
|
augmentations = 0;
|
2019-02-22 03:26:28 +01:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// Record money earned
|
|
|
|
record(amt: number, source: string): void {
|
|
|
|
const sanitizedSource = source.toLowerCase();
|
|
|
|
if (typeof this[sanitizedSource] !== "number") {
|
2021-09-09 05:47:34 +02:00
|
|
|
console.warn(`MoneySourceTracker.record() called with invalid source: ${source}`);
|
2021-09-05 01:09:30 +02:00
|
|
|
return;
|
2019-02-22 03:26:28 +01:00
|
|
|
}
|
2021-04-29 02:07:26 +02:00
|
|
|
|
2021-09-05 01:57:49 +02:00
|
|
|
(this[sanitizedSource] as number) += amt;
|
2021-09-05 01:09:30 +02:00
|
|
|
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;
|
|
|
|
}
|
2021-04-29 02:07:26 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
2019-02-22 03:26:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Reviver.constructors.MoneySourceTracker = MoneySourceTracker;
|