bitburner-src/src/NetscriptFunctions/Stanek.ts

111 lines
5.5 KiB
TypeScript
Raw Normal View History

2021-10-05 04:31:07 +02:00
import { INetscriptHelper } from "./INetscriptHelper";
import { IPlayer } from "../PersonObjects/IPlayer";
import { WorkerScript } from "../Netscript/WorkerScript";
import { netscriptDelay } from "../NetscriptEvaluator";
import { getRamCost } from "../Netscript/RamCostGenerator";
import { staneksGift } from "../CotMG/Helper";
import { Fragments, FragmentById } from "../CotMG/Fragment";
2021-11-14 05:45:26 +01:00
import {
Stanek as IStanek,
Fragment as IFragment,
ActiveFragment as IActiveFragment,
} from "../ScriptEditor/NetscriptDefinitions";
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, helper: INetscriptHelper): IStanek {
function checkStanekAPIAccess(func: string): void {
if (!player.hasAugmentation(AugmentationNames.StaneksGift1, true)) {
helper.makeRuntimeErrorMsg(func, "Requires Stanek's Gift installed.");
}
}
2021-10-05 04:31:07 +02:00
return {
2021-10-18 00:59:37 +02:00
width: function (): number {
helper.updateDynamicRam("width", getRamCost(player, "stanek", "width"));
checkStanekAPIAccess("width");
2021-10-18 00:59:37 +02:00
return staneksGift.width();
},
height: function (): number {
helper.updateDynamicRam("height", getRamCost(player, "stanek", "height"));
checkStanekAPIAccess("height");
2021-10-18 00:59:37 +02:00
return staneksGift.height();
},
2022-01-28 02:48:37 +01:00
charge: function (arootX: unknown, arootY: unknown): Promise<void> {
2021-11-14 05:45:26 +01:00
const rootX = helper.number("stanek.charge", "rootX", arootX);
const rootY = helper.number("stanek.charge", "rootY", arootY);
2022-01-05 01:09:34 +01:00
helper.updateDynamicRam("charge", getRamCost(player, "stanek", "charge"));
2021-11-14 05:45:26 +01:00
checkStanekAPIAccess("charge");
2021-10-18 00:59:37 +02:00
const fragment = staneksGift.findFragment(rootX, rootY);
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.charge", `No fragment with root (${rootX}, ${rootY}).`);
2021-10-08 09:16:51 +02:00
const time = staneksGift.inBonus() ? 200 : 1000;
return netscriptDelay(time, workerScript).then(function () {
2021-11-17 16:59:15 +01:00
const charge = staneksGift.charge(player, fragment, workerScript.scriptRef.threads);
2021-12-03 21:35:45 +01:00
workerScript.log("stanek.charge", () => `Charged fragment for ${charge} charge.`);
2021-11-14 05:45:26 +01:00
return Promise.resolve();
2021-10-05 04:31:07 +02:00
});
},
2021-11-14 05:45:26 +01:00
fragmentDefinitions: function (): IFragment[] {
2022-01-05 01:09:34 +01:00
helper.updateDynamicRam("fragmentDefinitions", getRamCost(player, "stanek", "fragmentDefinitions"));
2021-11-14 05:45:26 +01:00
checkStanekAPIAccess("fragmentDefinitions");
2021-12-03 21:35:45 +01:00
workerScript.log("stanek.fragmentDefinitions", () => `Returned ${Fragments.length} fragments`);
2021-10-05 04:31:07 +02:00
return Fragments.map((f) => f.copy());
},
2021-11-14 05:45:26 +01:00
activeFragments: function (): IActiveFragment[] {
2022-01-05 01:09:34 +01:00
helper.updateDynamicRam("activeFragments", getRamCost(player, "stanek", "activeFragments"));
2021-11-14 05:45:26 +01:00
checkStanekAPIAccess("activeFragments");
2021-12-03 21:35:45 +01:00
workerScript.log("stanek.activeFragments", () => `Returned ${staneksGift.fragments.length} fragments`);
2021-10-05 04:31:07 +02:00
return staneksGift.fragments.map((af) => {
return { ...af.copy(), ...af.fragment().copy() };
});
},
2021-11-14 05:45:26 +01:00
clear: function (): void {
2022-01-05 01:09:34 +01:00
helper.updateDynamicRam("clear", getRamCost(player, "stanek", "clear"));
2021-11-14 05:45:26 +01:00
checkStanekAPIAccess("clear");
2021-12-03 21:35:45 +01:00
workerScript.log("stanek.clear", () => `Cleared Stanek's Gift.`);
2021-10-05 04:31:07 +02:00
staneksGift.clear();
},
2022-01-28 02:48:37 +01:00
canPlace: function (arootX: unknown, arootY: unknown, arotation: unknown, afragmentId: unknown): boolean {
2021-11-14 05:45:26 +01:00
const rootX = helper.number("stanek.canPlace", "rootX", arootX);
const rootY = helper.number("stanek.canPlace", "rootY", arootY);
const rotation = helper.number("stanek.canPlace", "rotation", arotation);
const fragmentId = helper.number("stanek.canPlace", "fragmentId", afragmentId);
2022-01-05 01:09:34 +01:00
helper.updateDynamicRam("canPlace", getRamCost(player, "stanek", "canPlace"));
2021-11-14 05:45:26 +01:00
checkStanekAPIAccess("canPlace");
2021-10-05 04:31:07 +02:00
const fragment = FragmentById(fragmentId);
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.canPlace", `Invalid fragment id: ${fragmentId}`);
2021-11-14 05:45:26 +01:00
const can = staneksGift.canPlace(rootX, rootY, rotation, fragment);
2021-10-18 00:59:37 +02:00
return can;
2021-10-05 04:31:07 +02:00
},
2022-01-28 02:48:37 +01:00
place: function (arootX: unknown, arootY: unknown, arotation: unknown, afragmentId: unknown): boolean {
2021-11-14 05:45:26 +01:00
const rootX = helper.number("stanek.place", "rootX", arootX);
const rootY = helper.number("stanek.place", "rootY", arootY);
const rotation = helper.number("stanek.place", "rotation", arotation);
const fragmentId = helper.number("stanek.place", "fragmentId", afragmentId);
2022-01-05 01:09:34 +01:00
helper.updateDynamicRam("place", getRamCost(player, "stanek", "place"));
2021-11-14 05:45:26 +01:00
checkStanekAPIAccess("place");
2021-10-05 04:31:07 +02:00
const fragment = FragmentById(fragmentId);
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.place", `Invalid fragment id: ${fragmentId}`);
2021-11-14 05:45:26 +01:00
return staneksGift.place(rootX, rootY, rotation, fragment);
2021-10-05 04:31:07 +02:00
},
2022-01-28 02:48:37 +01:00
get: function (arootX: unknown, arootY: unknown): IActiveFragment | undefined {
2021-11-14 05:45:26 +01:00
const rootX = helper.number("stanek.get", "rootX", arootX);
const rootY = helper.number("stanek.get", "rootY", arootY);
2022-01-05 01:09:34 +01:00
helper.updateDynamicRam("get", getRamCost(player, "stanek", "get"));
2021-11-14 05:45:26 +01:00
checkStanekAPIAccess("get");
2021-10-18 00:59:37 +02:00
const fragment = staneksGift.findFragment(rootX, rootY);
if (fragment !== undefined) return fragment.copy();
return undefined;
},
2022-01-28 02:48:37 +01:00
remove: function (arootX: unknown, arootY: unknown): boolean {
2021-11-14 05:45:26 +01:00
const rootX = helper.number("stanek.remove", "rootX", arootX);
const rootY = helper.number("stanek.remove", "rootY", arootY);
2022-01-05 01:09:34 +01:00
helper.updateDynamicRam("remove", getRamCost(player, "stanek", "remove"));
2021-11-14 05:45:26 +01:00
checkStanekAPIAccess("remove");
return staneksGift.delete(rootX, rootY);
2021-10-05 04:31:07 +02:00
},
};
}