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 { staneksGift } from "../CotMG/Helper";
|
|
|
|
import { Fragments, FragmentById } from "../CotMG/Fragment";
|
|
|
|
|
2021-11-14 05:45:26 +01:00
|
|
|
import {
|
|
|
|
Fragment as IFragment,
|
|
|
|
ActiveFragment as IActiveFragment,
|
2022-03-30 01:11:13 +02:00
|
|
|
Stanek as IStanek
|
2021-11-14 05:45:26 +01:00
|
|
|
} from "../ScriptEditor/NetscriptDefinitions";
|
|
|
|
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
|
2022-03-30 01:11:13 +02:00
|
|
|
import { NetscriptContext, InternalAPI } from "src/Netscript/APIWrapper";
|
2021-11-14 05:45:26 +01:00
|
|
|
|
2022-03-30 01:11:13 +02:00
|
|
|
export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, helper: INetscriptHelper): InternalAPI<IStanek> {
|
2021-11-14 05:45:26 +01:00
|
|
|
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 {
|
2022-03-29 23:57:17 +02:00
|
|
|
giftWidth: function (): number {
|
2022-03-29 20:20:40 +02:00
|
|
|
checkStanekAPIAccess("giftWidth");
|
2021-10-18 00:59:37 +02:00
|
|
|
return staneksGift.width();
|
|
|
|
},
|
2022-03-29 23:57:17 +02:00
|
|
|
giftHeight: function (): number {
|
2022-03-29 20:20:40 +02:00
|
|
|
checkStanekAPIAccess("giftHeight");
|
2021-10-18 00:59:37 +02:00
|
|
|
return staneksGift.height();
|
|
|
|
},
|
2022-03-20 09:32:29 +01:00
|
|
|
chargeFragment: function (ctx: NetscriptContext, _rootX: unknown, _rootY: unknown): Promise<void> {
|
2022-03-29 23:57:17 +02:00
|
|
|
const rootX = ctx.helper.number("rootX", _rootX);
|
|
|
|
const rootY = ctx.helper.number("rootY", _rootY);
|
2022-03-29 20:20:40 +02:00
|
|
|
checkStanekAPIAccess("chargeFragment");
|
2021-10-18 00:59:37 +02:00
|
|
|
const fragment = staneksGift.findFragment(rootX, rootY);
|
2022-03-20 09:32:29 +01:00
|
|
|
if (!fragment) throw ctx.makeRuntimeErrorMsg(`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);
|
2022-03-20 09:32:29 +01:00
|
|
|
ctx.log(() => `Charged fragment for ${charge} charge.`);
|
2021-11-14 05:45:26 +01:00
|
|
|
return Promise.resolve();
|
2021-10-05 04:31:07 +02:00
|
|
|
});
|
|
|
|
},
|
2022-03-20 09:32:29 +01:00
|
|
|
fragmentDefinitions: function (ctx: NetscriptContext): IFragment[] {
|
2021-11-14 05:45:26 +01:00
|
|
|
checkStanekAPIAccess("fragmentDefinitions");
|
2022-03-20 09:32:29 +01:00
|
|
|
ctx.log(() => `Returned ${Fragments.length} fragments`);
|
2021-10-05 04:31:07 +02:00
|
|
|
return Fragments.map((f) => f.copy());
|
|
|
|
},
|
2022-03-20 09:32:29 +01:00
|
|
|
activeFragments: function (ctx: NetscriptContext): IActiveFragment[] {
|
2021-11-14 05:45:26 +01:00
|
|
|
checkStanekAPIAccess("activeFragments");
|
2022-03-20 09:32:29 +01:00
|
|
|
ctx.log(() => `Returned ${staneksGift.fragments.length} fragments`);
|
2021-10-05 04:31:07 +02:00
|
|
|
return staneksGift.fragments.map((af) => {
|
|
|
|
return { ...af.copy(), ...af.fragment().copy() };
|
|
|
|
});
|
|
|
|
},
|
2022-03-20 09:32:29 +01:00
|
|
|
clearGift: function (ctx: NetscriptContext): void {
|
2022-03-29 20:20:40 +02:00
|
|
|
checkStanekAPIAccess("clearGift");
|
2022-03-20 09:32:29 +01:00
|
|
|
ctx.log(() => `Cleared Stanek's Gift.`);
|
2021-10-05 04:31:07 +02:00
|
|
|
staneksGift.clear();
|
|
|
|
},
|
2022-03-20 09:32:29 +01:00
|
|
|
canPlaceFragment: function (ctx: NetscriptContext, _rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean {
|
2022-03-29 23:57:17 +02:00
|
|
|
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);
|
2022-03-29 20:20:40 +02:00
|
|
|
checkStanekAPIAccess("canPlaceFragment");
|
2021-10-05 04:31:07 +02:00
|
|
|
const fragment = FragmentById(fragmentId);
|
2022-03-20 09:32:29 +01:00
|
|
|
if (!fragment) throw ctx.makeRuntimeErrorMsg(`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-03-20 09:32:29 +01:00
|
|
|
placeFragment: function (ctx: NetscriptContext, _rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean {
|
2022-03-29 23:57:17 +02:00
|
|
|
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);
|
2022-03-29 20:20:40 +02:00
|
|
|
checkStanekAPIAccess("placeFragment");
|
2021-10-05 04:31:07 +02:00
|
|
|
const fragment = FragmentById(fragmentId);
|
2022-03-20 09:32:29 +01:00
|
|
|
if (!fragment) throw ctx.makeRuntimeErrorMsg(`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-03-20 09:32:29 +01:00
|
|
|
getFragment: function (ctx: NetscriptContext, _rootX: unknown, _rootY: unknown): IActiveFragment | undefined {
|
2022-03-29 23:57:17 +02:00
|
|
|
const rootX = ctx.helper.number("rootX", _rootX);
|
|
|
|
const rootY = ctx.helper.number("rootY", _rootY);
|
2022-03-29 20:20:40 +02:00
|
|
|
checkStanekAPIAccess("getFragment");
|
2021-10-18 00:59:37 +02:00
|
|
|
const fragment = staneksGift.findFragment(rootX, rootY);
|
|
|
|
if (fragment !== undefined) return fragment.copy();
|
|
|
|
return undefined;
|
|
|
|
},
|
2022-03-20 09:32:29 +01:00
|
|
|
removeFragment: function (ctx: NetscriptContext, _rootX: unknown, _rootY: unknown): boolean {
|
2022-03-29 23:57:17 +02:00
|
|
|
const rootX = ctx.helper.number("rootX", _rootX);
|
|
|
|
const rootY = ctx.helper.number("rootY", _rootY);
|
2022-03-29 20:20:40 +02:00
|
|
|
checkStanekAPIAccess("removeFragment");
|
2021-11-14 05:45:26 +01:00
|
|
|
return staneksGift.delete(rootX, rootY);
|
2021-10-05 04:31:07 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|