mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 22:38:34 +02:00
85 lines
3.6 KiB
TypeScript
85 lines
3.6 KiB
TypeScript
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";
|
|
|
|
export interface INetscriptStanek {
|
|
charge(worldX: any, worldY: any): any;
|
|
fragmentDefinitions(): any;
|
|
placedFragments(): any;
|
|
clear(): any;
|
|
canPlace(worldX: any, worldY: any, fragmentId: any): any;
|
|
place(worldX: any, worldY: any, fragmentId: any): any;
|
|
fragmentAt(worldX: any, worldY: any): any;
|
|
deleteAt(worldX: any, worldY: any): any;
|
|
}
|
|
|
|
export function NetscriptStanek(
|
|
player: IPlayer,
|
|
workerScript: WorkerScript,
|
|
helper: INetscriptHelper,
|
|
): INetscriptStanek {
|
|
return {
|
|
charge: function (worldX: any, worldY: any): any {
|
|
helper.updateDynamicRam("charge", getRamCost("stanek", "charge"));
|
|
//checkStanekAPIAccess("charge");
|
|
const fragment = staneksGift.fragmentAt(worldX, worldY);
|
|
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.charge", `No fragment at (${worldX}, ${worldY})`);
|
|
return netscriptDelay(1000, workerScript).then(function () {
|
|
if (workerScript.env.stopFlag) {
|
|
return Promise.reject(workerScript);
|
|
}
|
|
const ram = workerScript.scriptRef.ramUsage * workerScript.scriptRef.threads;
|
|
return Promise.resolve(staneksGift.charge(worldX, worldY, ram));
|
|
});
|
|
},
|
|
fragmentDefinitions: function () {
|
|
helper.updateDynamicRam("fragmentDefinitions", getRamCost("stanek", "fragmentDefinitions"));
|
|
//checkStanekAPIAccess("fragmentDefinitions");
|
|
return Fragments.map((f) => f.copy());
|
|
},
|
|
placedFragments: function () {
|
|
helper.updateDynamicRam("placedFragments", getRamCost("stanek", "placedFragments"));
|
|
//checkStanekAPIAccess("placedFragments");
|
|
return staneksGift.fragments.map((af) => {
|
|
return { ...af.copy(), ...af.fragment().copy() };
|
|
});
|
|
},
|
|
clear: function () {
|
|
helper.updateDynamicRam("clear", getRamCost("stanek", "clear"));
|
|
//checkStanekAPIAccess("clear");
|
|
staneksGift.clear();
|
|
},
|
|
canPlace: function (worldX: any, worldY: any, fragmentId: any): any {
|
|
helper.updateDynamicRam("canPlace", getRamCost("stanek", "canPlace"));
|
|
//checkStanekAPIAccess("canPlace");
|
|
const fragment = FragmentById(fragmentId);
|
|
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.canPlace", `Invalid fragment id: ${fragmentId}`);
|
|
return staneksGift.canPlace(worldX, worldY, fragment);
|
|
},
|
|
place: function (worldX: any, worldY: any, fragmentId: any): any {
|
|
helper.updateDynamicRam("place", getRamCost("stanek", "place"));
|
|
//checkStanekAPIAccess("place");
|
|
const fragment = FragmentById(fragmentId);
|
|
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.place", `Invalid fragment id: ${fragmentId}`);
|
|
return staneksGift.place(worldX, worldY, fragment);
|
|
},
|
|
fragmentAt: function (worldX: any, worldY: any): any {
|
|
helper.updateDynamicRam("fragmentAt", getRamCost("stanek", "fragmentAt"));
|
|
//checkStanekAPIAccess("fragmentAt");
|
|
const fragment = staneksGift.fragmentAt(worldX, worldY);
|
|
if (fragment !== null) return fragment.copy();
|
|
return null;
|
|
},
|
|
deleteAt: function (worldX: any, worldY: any): any {
|
|
helper.updateDynamicRam("deleteAt", getRamCost("stanek", "deleteAt"));
|
|
//checkStanekAPIAccess("deleteAt");
|
|
return staneksGift.deleteAt(worldX, worldY);
|
|
},
|
|
};
|
|
}
|