slight change on how wrapping work based on discussion in #development

This commit is contained in:
TheMas3212
2022-04-08 09:57:16 +10:00
parent f0cfc8700a
commit 9b53896732
2 changed files with 46 additions and 47 deletions
+31 -33
View File
@@ -26,88 +26,86 @@ export function NetscriptStanek(
}
return {
giftWidth: function (): number {
giftWidth: (_ctx: NetscriptContext) => function (): number {
checkStanekAPIAccess("giftWidth");
return staneksGift.width();
},
giftHeight: function (): number {
giftHeight: (_ctx: NetscriptContext) => function (): number {
checkStanekAPIAccess("giftHeight");
return staneksGift.height();
},
chargeFragment: function (ctx: NetscriptContext, _rootX: unknown, _rootY: unknown): Promise<void> {
const rootX = ctx.helper.number("rootX", _rootX);
const rootY = ctx.helper.number("rootY", _rootY);
chargeFragment: (_ctx: NetscriptContext) => function (_rootX: unknown, _rootY: unknown): Promise<void> {
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}).`);
if (!fragment) throw _ctx.makeRuntimeErrorMsg(`No fragment with root (${rootX}, ${rootY}).`);
const time = staneksGift.inBonus() ? 200 : 1000;
return netscriptDelay(time, workerScript).then(function () {
const charge = staneksGift.charge(player, fragment, workerScript.scriptRef.threads);
ctx.log(() => `Charged fragment for ${charge} charge.`);
_ctx.log(() => `Charged fragment for ${charge} charge.`);
return Promise.resolve();
});
},
fragmentDefinitions: function (ctx: NetscriptContext): IFragment[] {
fragmentDefinitions: (_ctx: NetscriptContext) => function (): IFragment[] {
checkStanekAPIAccess("fragmentDefinitions");
ctx.log(() => `Returned ${Fragments.length} fragments`);
_ctx.log(() => `Returned ${Fragments.length} fragments`);
return Fragments.map((f) => f.copy());
},
activeFragments: function (ctx: NetscriptContext): IActiveFragment[] {
activeFragments: (_ctx: NetscriptContext) => function (): IActiveFragment[] {
checkStanekAPIAccess("activeFragments");
ctx.log(() => `Returned ${staneksGift.fragments.length} fragments`);
_ctx.log(() => `Returned ${staneksGift.fragments.length} fragments`);
return staneksGift.fragments.map((af) => {
return { ...af.copy(), ...af.fragment().copy() };
});
},
clearGift: function (ctx: NetscriptContext): void {
clearGift: (_ctx: NetscriptContext) => function (): void {
checkStanekAPIAccess("clearGift");
ctx.log(() => `Cleared Stanek's Gift.`);
_ctx.log(() => `Cleared Stanek's Gift.`);
staneksGift.clear();
},
canPlaceFragment: function (
ctx: NetscriptContext,
canPlaceFragment: (_ctx: NetscriptContext) => function (
_rootX: unknown,
_rootY: unknown,
_rotation: unknown,
_fragmentId: unknown,
): boolean {
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);
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}`);
if (!fragment) throw _ctx.makeRuntimeErrorMsg(`Invalid fragment id: ${fragmentId}`);
const can = staneksGift.canPlace(rootX, rootY, rotation, fragment);
return can;
},
placeFragment: function (
ctx: NetscriptContext,
placeFragment: (_ctx: NetscriptContext) => function (
_rootX: unknown,
_rootY: unknown,
_rotation: unknown,
_fragmentId: unknown,
): boolean {
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);
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}`);
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 {
const rootX = ctx.helper.number("rootX", _rootX);
const rootY = ctx.helper.number("rootY", _rootY);
getFragment: (_ctx: NetscriptContext) => function (_rootX: unknown, _rootY: unknown): IActiveFragment | undefined {
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 {
const rootX = ctx.helper.number("rootX", _rootX);
const rootY = ctx.helper.number("rootY", _rootY);
removeFragment: (_ctx: NetscriptContext) => function (_rootX: unknown, _rootY: unknown): boolean {
const rootX = _ctx.helper.number("rootX", _rootX);
const rootY = _ctx.helper.number("rootY", _rootY);
checkStanekAPIAccess("removeFragment");
return staneksGift.delete(rootX, rootY);
},