mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-08 08:37:48 +02:00
3d7d2d7734
* REFACTOR: Move Result to the public API This refactors Result<T> to be part of the public NetscriptDefinitions. It is not used by anything in this PR, but it is planned to be used in the autoinfil APIs, or lacking that, future APIs, so this should not be exposing anything prematurely. * Add @public as api-extractor suggested and generate docs * Use import type --------- Co-authored-by: CatLover <152669316+catloversg@users.noreply.github.com>
75 lines
2.1 KiB
TypeScript
75 lines
2.1 KiB
TypeScript
import { Player } from "@player";
|
|
import { AugmentationName } from "@enums";
|
|
import { dialogBoxCreate } from "../ui/React/DialogBox";
|
|
import { Reviver } from "../utils/GenericReviver";
|
|
import { BaseGift } from "./BaseGift";
|
|
|
|
import { StaneksGift } from "./StaneksGift";
|
|
import type { Result } from "@nsdefs";
|
|
import { isStanekGiftImplemented } from "../utils/ErrorHelper";
|
|
|
|
export let staneksGift = new StaneksGift();
|
|
|
|
export function loadStaneksGift(saveString: string, versionSave?: string): void {
|
|
let staneksGiftData: unknown;
|
|
try {
|
|
staneksGiftData = JSON.parse(saveString, Reviver);
|
|
if (!(staneksGiftData instanceof StaneksGift)) {
|
|
throw new Error(`Data of Stanek's Gift is not an instance of "StaneksGift"`);
|
|
}
|
|
} catch (error) {
|
|
console.error(error);
|
|
console.error("Invalid StaneksGiftSave:", saveString);
|
|
staneksGift = new StaneksGift();
|
|
if (isStanekGiftImplemented(versionSave)) {
|
|
setTimeout(() => {
|
|
dialogBoxCreate(`Cannot load data of Stanek's Gift. Stanek's Gift is reset. Error: ${error}.`);
|
|
}, 1000);
|
|
}
|
|
return;
|
|
}
|
|
staneksGift = staneksGiftData;
|
|
}
|
|
|
|
export function zeros(width: number, height: number): number[][] {
|
|
const array = [];
|
|
|
|
for (let i = 0; i < width; ++i) {
|
|
array.push(Array<number>(height).fill(0));
|
|
}
|
|
|
|
return array;
|
|
}
|
|
|
|
export function calculateGrid(gift: BaseGift): number[][] {
|
|
const newGrid = zeros(gift.width(), gift.height());
|
|
for (let i = 0; i < gift.width(); i++) {
|
|
for (let j = 0; j < gift.height(); j++) {
|
|
const fragment = gift.fragmentAt(i, j);
|
|
if (!fragment) {
|
|
continue;
|
|
}
|
|
newGrid[i][j] = 1;
|
|
}
|
|
}
|
|
|
|
return newGrid;
|
|
}
|
|
|
|
export function canAcceptStaneksGift(): Result {
|
|
if (!Player.canAccessCotMG()) {
|
|
return { success: false, message: "You do not have Source-File 13." };
|
|
}
|
|
if (
|
|
[...Player.augmentations, ...Player.queuedAugmentations].filter(
|
|
(a) => a.name !== AugmentationName.NeuroFluxGovernor,
|
|
).length !== 0
|
|
) {
|
|
return {
|
|
success: false,
|
|
message: `You already purchased or installed augmentations that are not ${AugmentationName.NeuroFluxGovernor}.`,
|
|
};
|
|
}
|
|
return { success: true };
|
|
}
|