mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-21 16:52:55 +02:00
add wrapped helpers to ctx
add ramcheck into wrapper
This commit is contained in:
@@ -21,20 +21,17 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel
|
||||
}
|
||||
|
||||
return {
|
||||
giftWidth: function (ctx: NetscriptContext): number {
|
||||
ctx.updateDynamicRam();
|
||||
giftWidth: function (): number {
|
||||
checkStanekAPIAccess("giftWidth");
|
||||
return staneksGift.width();
|
||||
},
|
||||
giftHeight: function (ctx: NetscriptContext): number {
|
||||
ctx.updateDynamicRam();
|
||||
giftHeight: function (): number {
|
||||
checkStanekAPIAccess("giftHeight");
|
||||
return staneksGift.height();
|
||||
},
|
||||
chargeFragment: function (ctx: NetscriptContext, _rootX: unknown, _rootY: unknown): Promise<void> {
|
||||
ctx.updateDynamicRam();
|
||||
const rootX = helper.number("stanek.chargeFragment", "rootX", _rootX);
|
||||
const rootY = helper.number("stanek.chargeFragment", "rootY", _rootY);
|
||||
const rootX = ctx.helper.number("rootX", _rootX);
|
||||
const rootY = ctx.helper.number("rootY", _rootY);
|
||||
checkStanekAPIAccess("chargeFragment");
|
||||
const fragment = staneksGift.findFragment(rootX, rootY);
|
||||
if (!fragment) throw ctx.makeRuntimeErrorMsg(`No fragment with root (${rootX}, ${rootY}).`);
|
||||
@@ -46,13 +43,11 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel
|
||||
});
|
||||
},
|
||||
fragmentDefinitions: function (ctx: NetscriptContext): IFragment[] {
|
||||
ctx.updateDynamicRam();
|
||||
checkStanekAPIAccess("fragmentDefinitions");
|
||||
ctx.log(() => `Returned ${Fragments.length} fragments`);
|
||||
return Fragments.map((f) => f.copy());
|
||||
},
|
||||
activeFragments: function (ctx: NetscriptContext): IActiveFragment[] {
|
||||
ctx.updateDynamicRam();
|
||||
checkStanekAPIAccess("activeFragments");
|
||||
ctx.log(() => `Returned ${staneksGift.fragments.length} fragments`);
|
||||
return staneksGift.fragments.map((af) => {
|
||||
@@ -60,17 +55,15 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel
|
||||
});
|
||||
},
|
||||
clearGift: function (ctx: NetscriptContext): void {
|
||||
ctx.updateDynamicRam();
|
||||
checkStanekAPIAccess("clearGift");
|
||||
ctx.log(() => `Cleared Stanek's Gift.`);
|
||||
staneksGift.clear();
|
||||
},
|
||||
canPlaceFragment: function (ctx: NetscriptContext, _rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean {
|
||||
ctx.updateDynamicRam();
|
||||
const rootX = helper.number("stanek.canPlaceFragment", "rootX", _rootX);
|
||||
const rootY = helper.number("stanek.canPlaceFragment", "rootY", _rootY);
|
||||
const rotation = helper.number("stanek.canPlaceFragment", "rotation", _rotation);
|
||||
const fragmentId = helper.number("stanek.canPlaceFragment", "fragmentId", _fragmentId);
|
||||
const rootX = ctx.helper.number("rootX", _rootX);
|
||||
const rootY = ctx.helper.number("rootY", _rootY);
|
||||
const rotation = ctx.helper.number("rotation", _rotation);
|
||||
const fragmentId = ctx.helper.number("fragmentId", _fragmentId);
|
||||
checkStanekAPIAccess("canPlaceFragment");
|
||||
const fragment = FragmentById(fragmentId);
|
||||
if (!fragment) throw ctx.makeRuntimeErrorMsg(`Invalid fragment id: ${fragmentId}`);
|
||||
@@ -78,29 +71,26 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel
|
||||
return can;
|
||||
},
|
||||
placeFragment: function (ctx: NetscriptContext, _rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean {
|
||||
ctx.updateDynamicRam();
|
||||
const rootX = helper.number("stanek.placeFragment", "rootX", _rootX);
|
||||
const rootY = helper.number("stanek.placeFragment", "rootY", _rootY);
|
||||
const rotation = helper.number("stanek.placeFragment", "rotation", _rotation);
|
||||
const fragmentId = helper.number("stanek.placeFragment", "fragmentId", _fragmentId);
|
||||
const rootX = ctx.helper.number("rootX", _rootX);
|
||||
const rootY = ctx.helper.number("rootY", _rootY);
|
||||
const rotation = ctx.helper.number("rotation", _rotation);
|
||||
const fragmentId = ctx.helper.number("fragmentId", _fragmentId);
|
||||
checkStanekAPIAccess("placeFragment");
|
||||
const fragment = FragmentById(fragmentId);
|
||||
if (!fragment) throw ctx.makeRuntimeErrorMsg(`Invalid fragment id: ${fragmentId}`);
|
||||
return staneksGift.place(rootX, rootY, rotation, fragment);
|
||||
},
|
||||
getFragment: function (ctx: NetscriptContext, _rootX: unknown, _rootY: unknown): IActiveFragment | undefined {
|
||||
ctx.updateDynamicRam();
|
||||
const rootX = helper.number("stanek.getFragment", "rootX", _rootX);
|
||||
const rootY = helper.number("stanek.getFragment", "rootY", _rootY);
|
||||
const rootX = ctx.helper.number("rootX", _rootX);
|
||||
const rootY = ctx.helper.number("rootY", _rootY);
|
||||
checkStanekAPIAccess("getFragment");
|
||||
const fragment = staneksGift.findFragment(rootX, rootY);
|
||||
if (fragment !== undefined) return fragment.copy();
|
||||
return undefined;
|
||||
},
|
||||
removeFragment: function (ctx: NetscriptContext, _rootX: unknown, _rootY: unknown): boolean {
|
||||
ctx.updateDynamicRam();
|
||||
const rootX = helper.number("stanek.removeFragment", "rootX", _rootX);
|
||||
const rootY = helper.number("stanek.removeFragment", "rootY", _rootY);
|
||||
const rootX = ctx.helper.number("rootX", _rootX);
|
||||
const rootY = ctx.helper.number("rootY", _rootY);
|
||||
checkStanekAPIAccess("removeFragment");
|
||||
return staneksGift.delete(rootX, rootY);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user