mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-22 17:23:00 +02:00
CODEBASE: Add Jsonable Map and Set types, move player.sourceFiles to a map (#473)
This commit is contained in:
@@ -8,7 +8,6 @@ import * as workMethods from "./PlayerObjectWorkMethods";
|
||||
|
||||
import { setPlayer } from "../../Player";
|
||||
import { Sleeve } from "../Sleeve/Sleeve";
|
||||
import { PlayerOwnedSourceFile } from "../../SourceFile/PlayerOwnedSourceFile";
|
||||
import { Exploit } from "../../Exploits/Exploit";
|
||||
|
||||
import { LocationName } from "../../Enums";
|
||||
@@ -21,6 +20,7 @@ import { HashManager } from "../../Hacknet/HashManager";
|
||||
|
||||
import { MoneySourceTracker } from "../../utils/MoneySourceTracker";
|
||||
import { constructorsForReviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../../utils/JSONReviver";
|
||||
import { JSONMap } from "../../Types/Jsonable";
|
||||
import { PlayerAchievement } from "../../Achievements/Achievements";
|
||||
import { cyrb53 } from "../../utils/StringHelperFunctions";
|
||||
import { getRandomInt } from "../../utils/helpers/getRandomInt";
|
||||
@@ -59,7 +59,7 @@ export class PlayerObject extends Person implements IPlayer {
|
||||
scriptProdSinceLastAug = 0;
|
||||
sleeves: Sleeve[] = [];
|
||||
sleevesFromCovenant = 0;
|
||||
sourceFiles: PlayerOwnedSourceFile[] = [];
|
||||
sourceFiles: JSONMap<number, number> = new JSONMap();
|
||||
exploits: Exploit[] = [];
|
||||
achievements: PlayerAchievement[] = [];
|
||||
terminalCommandHistory: string[] = [];
|
||||
@@ -168,9 +168,15 @@ export class PlayerObject extends Person implements IPlayer {
|
||||
|
||||
/** Initializes a PlayerObject object from a JSON save state. */
|
||||
static fromJSON(value: IReviverValue): PlayerObject {
|
||||
if (!value.data.hp?.current || !value.data.hp?.max) value.data.hp = { current: 10, max: 10 };
|
||||
const player = Generic_fromJSON(PlayerObject, value.data);
|
||||
if (player.money === null) player.money = 0;
|
||||
player.hp = { current: player.hp?.current ?? 10, max: player.hp?.max ?? 10 };
|
||||
player.money ??= 0;
|
||||
player.updateSkillLevels();
|
||||
if (Array.isArray(player.sourceFiles)) {
|
||||
// Expect pre-2.3 sourcefile format here.
|
||||
type OldSourceFiles = { n: number; lvl: number }[];
|
||||
player.sourceFiles = new JSONMap((player.sourceFiles as OldSourceFiles).map(({ n, lvl }) => [n, lvl]));
|
||||
}
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,14 +586,14 @@ export function reapplyAllSourceFiles(this: PlayerObject): void {
|
||||
//Will always be called after reapplyAllAugmentations() so multipliers do not have to be reset
|
||||
//this.resetMultipliers();
|
||||
|
||||
for (let i = 0; i < this.sourceFiles.length; ++i) {
|
||||
const srcFileKey = "SourceFile" + this.sourceFiles[i].n;
|
||||
for (const [bn, lvl] of this.sourceFiles) {
|
||||
const srcFileKey = "SourceFile" + bn;
|
||||
const sourceFileObject = SourceFiles[srcFileKey];
|
||||
if (sourceFileObject == null) {
|
||||
console.error(`Invalid source file number: ${this.sourceFiles[i].n}`);
|
||||
if (!sourceFileObject) {
|
||||
console.error(`Invalid source file number: ${bn}`);
|
||||
continue;
|
||||
}
|
||||
applySourceFile(this.sourceFiles[i]);
|
||||
applySourceFile(bn, lvl);
|
||||
}
|
||||
applyExploit();
|
||||
this.updateSkillLevels();
|
||||
@@ -1222,9 +1222,7 @@ export function canAccessCotMG(this: PlayerObject): boolean {
|
||||
}
|
||||
|
||||
export function sourceFileLvl(this: PlayerObject, n: number): number {
|
||||
const sf = this.sourceFiles.find((sf) => sf.n === n);
|
||||
if (!sf) return 0;
|
||||
return sf.lvl;
|
||||
return this.sourceFiles.get(n) ?? 0;
|
||||
}
|
||||
|
||||
export function focusPenalty(this: PlayerObject): number {
|
||||
|
||||
Reference in New Issue
Block a user