2022-08-09 21:41:47 +02:00
|
|
|
import { Player as player } from "../Player";
|
2021-10-05 04:31:07 +02:00
|
|
|
|
|
|
|
import { staneksGift } from "../CotMG/Helper";
|
|
|
|
import { Fragments, FragmentById } from "../CotMG/Fragment";
|
2022-05-09 21:29:42 +02:00
|
|
|
import { FragmentType } from "../CotMG/FragmentType";
|
2021-10-05 04:31:07 +02:00
|
|
|
|
2021-11-14 05:45:26 +01:00
|
|
|
import {
|
|
|
|
Fragment as IFragment,
|
|
|
|
ActiveFragment as IActiveFragment,
|
2022-04-07 02:00:54 +02:00
|
|
|
Stanek as IStanek,
|
2021-11-14 05:45:26 +01:00
|
|
|
} from "../ScriptEditor/NetscriptDefinitions";
|
|
|
|
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
|
2022-04-11 20:17:27 +02:00
|
|
|
import { NetscriptContext, InternalAPI } from "../Netscript/APIWrapper";
|
2022-04-19 19:00:24 +02:00
|
|
|
import { applyAugmentation } from "../Augmentation/AugmentationHelpers";
|
|
|
|
import { FactionNames } from "../Faction/data/FactionNames";
|
|
|
|
import { joinFaction } from "../Faction/FactionHelpers";
|
|
|
|
import { Factions } from "../Faction/Factions";
|
2022-08-08 19:43:41 +02:00
|
|
|
import { helpers } from "../Netscript/NetscriptHelpers";
|
2021-11-14 05:45:26 +01:00
|
|
|
|
2022-08-09 21:41:47 +02:00
|
|
|
export function NetscriptStanek(): InternalAPI<IStanek> {
|
2022-08-08 19:43:41 +02:00
|
|
|
function checkStanekAPIAccess(ctx: NetscriptContext): void {
|
2021-11-14 05:45:26 +01:00
|
|
|
if (!player.hasAugmentation(AugmentationNames.StaneksGift1, true)) {
|
2022-08-08 19:43:41 +02:00
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, "Stanek's Gift is not installed");
|
2021-11-14 05:45:26 +01:00
|
|
|
}
|
|
|
|
}
|
2021-10-05 04:31:07 +02:00
|
|
|
|
|
|
|
return {
|
2022-08-08 19:43:41 +02:00
|
|
|
giftWidth: (ctx: NetscriptContext) =>
|
2022-04-08 02:02:59 +02:00
|
|
|
function (): number {
|
2022-08-08 19:43:41 +02:00
|
|
|
checkStanekAPIAccess(ctx);
|
2022-04-08 02:02:59 +02:00
|
|
|
return staneksGift.width();
|
|
|
|
},
|
2022-08-08 19:43:41 +02:00
|
|
|
giftHeight: (ctx: NetscriptContext) =>
|
2022-04-08 02:02:59 +02:00
|
|
|
function (): number {
|
2022-08-08 19:43:41 +02:00
|
|
|
checkStanekAPIAccess(ctx);
|
2022-04-08 02:02:59 +02:00
|
|
|
return staneksGift.height();
|
|
|
|
},
|
2022-08-08 19:43:41 +02:00
|
|
|
chargeFragment: (ctx: NetscriptContext) =>
|
2022-04-08 02:02:59 +02:00
|
|
|
function (_rootX: unknown, _rootY: unknown): Promise<void> {
|
2022-05-09 21:29:42 +02:00
|
|
|
//Get the fragment object using the given coordinates
|
2022-08-08 19:43:41 +02:00
|
|
|
const rootX = helpers.number(ctx, "rootX", _rootX);
|
|
|
|
const rootY = helpers.number(ctx, "rootY", _rootY);
|
|
|
|
checkStanekAPIAccess(ctx);
|
2022-04-08 02:02:59 +02:00
|
|
|
const fragment = staneksGift.findFragment(rootX, rootY);
|
2022-05-09 21:29:42 +02:00
|
|
|
//Check whether the selected fragment can ge charged
|
2022-08-08 19:43:41 +02:00
|
|
|
if (!fragment) throw helpers.makeRuntimeErrorMsg(ctx, `No fragment with root (${rootX}, ${rootY}).`);
|
2022-05-09 21:29:42 +02:00
|
|
|
if (fragment.fragment().type == FragmentType.Booster) {
|
2022-08-08 19:43:41 +02:00
|
|
|
throw helpers.makeRuntimeErrorMsg(
|
|
|
|
ctx,
|
2022-05-09 21:29:42 +02:00
|
|
|
`The fragment with root (${rootX}, ${rootY}) is a Booster Fragment and thus cannot be charged.`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
//Charge the fragment
|
2022-04-08 02:02:59 +02:00
|
|
|
const time = staneksGift.inBonus() ? 200 : 1000;
|
2022-08-08 19:43:41 +02:00
|
|
|
return helpers.netscriptDelay(ctx, time).then(function () {
|
2022-09-18 03:09:15 +02:00
|
|
|
staneksGift.charge(fragment, ctx.workerScript.scriptRef.threads);
|
2022-08-08 21:51:50 +02:00
|
|
|
helpers.log(ctx, () => `Charged fragment with ${ctx.workerScript.scriptRef.threads} threads.`);
|
2022-04-08 02:02:59 +02:00
|
|
|
return Promise.resolve();
|
|
|
|
});
|
|
|
|
},
|
2022-08-08 19:43:41 +02:00
|
|
|
fragmentDefinitions: (ctx: NetscriptContext) =>
|
2022-04-08 02:02:59 +02:00
|
|
|
function (): IFragment[] {
|
2022-08-08 19:43:41 +02:00
|
|
|
checkStanekAPIAccess(ctx);
|
2022-08-08 21:51:50 +02:00
|
|
|
helpers.log(ctx, () => `Returned ${Fragments.length} fragments`);
|
2022-04-08 02:02:59 +02:00
|
|
|
return Fragments.map((f) => f.copy());
|
|
|
|
},
|
2022-08-08 19:43:41 +02:00
|
|
|
activeFragments: (ctx: NetscriptContext) =>
|
2022-04-08 02:02:59 +02:00
|
|
|
function (): IActiveFragment[] {
|
2022-08-08 19:43:41 +02:00
|
|
|
checkStanekAPIAccess(ctx);
|
2022-08-08 21:51:50 +02:00
|
|
|
helpers.log(ctx, () => `Returned ${staneksGift.fragments.length} fragments`);
|
2022-04-08 02:02:59 +02:00
|
|
|
return staneksGift.fragments.map((af) => {
|
|
|
|
return { ...af.copy(), ...af.fragment().copy() };
|
|
|
|
});
|
|
|
|
},
|
2022-08-08 19:43:41 +02:00
|
|
|
clearGift: (ctx: NetscriptContext) =>
|
2022-04-08 02:02:59 +02:00
|
|
|
function (): void {
|
2022-08-08 19:43:41 +02:00
|
|
|
checkStanekAPIAccess(ctx);
|
2022-08-08 21:51:50 +02:00
|
|
|
helpers.log(ctx, () => `Cleared Stanek's Gift.`);
|
2022-04-08 02:02:59 +02:00
|
|
|
staneksGift.clear();
|
|
|
|
},
|
2022-08-08 19:43:41 +02:00
|
|
|
canPlaceFragment: (ctx: NetscriptContext) =>
|
2022-04-08 02:02:59 +02:00
|
|
|
function (_rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean {
|
2022-08-08 19:43:41 +02:00
|
|
|
const rootX = helpers.number(ctx, "rootX", _rootX);
|
|
|
|
const rootY = helpers.number(ctx, "rootY", _rootY);
|
|
|
|
const rotation = helpers.number(ctx, "rotation", _rotation);
|
|
|
|
const fragmentId = helpers.number(ctx, "fragmentId", _fragmentId);
|
|
|
|
checkStanekAPIAccess(ctx);
|
2022-04-08 02:02:59 +02:00
|
|
|
const fragment = FragmentById(fragmentId);
|
2022-08-08 19:43:41 +02:00
|
|
|
if (!fragment) throw helpers.makeRuntimeErrorMsg(ctx, `Invalid fragment id: ${fragmentId}`);
|
2022-04-08 02:02:59 +02:00
|
|
|
const can = staneksGift.canPlace(rootX, rootY, rotation, fragment);
|
|
|
|
return can;
|
|
|
|
},
|
2022-08-08 19:43:41 +02:00
|
|
|
placeFragment: (ctx: NetscriptContext) =>
|
2022-04-08 02:02:59 +02:00
|
|
|
function (_rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean {
|
2022-08-08 19:43:41 +02:00
|
|
|
const rootX = helpers.number(ctx, "rootX", _rootX);
|
|
|
|
const rootY = helpers.number(ctx, "rootY", _rootY);
|
|
|
|
const rotation = helpers.number(ctx, "rotation", _rotation);
|
|
|
|
const fragmentId = helpers.number(ctx, "fragmentId", _fragmentId);
|
|
|
|
checkStanekAPIAccess(ctx);
|
2022-04-08 02:02:59 +02:00
|
|
|
const fragment = FragmentById(fragmentId);
|
2022-08-08 19:43:41 +02:00
|
|
|
if (!fragment) throw helpers.makeRuntimeErrorMsg(ctx, `Invalid fragment id: ${fragmentId}`);
|
2022-04-08 02:02:59 +02:00
|
|
|
return staneksGift.place(rootX, rootY, rotation, fragment);
|
|
|
|
},
|
2022-08-08 19:43:41 +02:00
|
|
|
getFragment: (ctx: NetscriptContext) =>
|
2022-04-08 02:02:59 +02:00
|
|
|
function (_rootX: unknown, _rootY: unknown): IActiveFragment | undefined {
|
2022-08-08 19:43:41 +02:00
|
|
|
const rootX = helpers.number(ctx, "rootX", _rootX);
|
|
|
|
const rootY = helpers.number(ctx, "rootY", _rootY);
|
|
|
|
checkStanekAPIAccess(ctx);
|
2022-04-08 02:02:59 +02:00
|
|
|
const fragment = staneksGift.findFragment(rootX, rootY);
|
|
|
|
if (fragment !== undefined) return fragment.copy();
|
|
|
|
return undefined;
|
|
|
|
},
|
2022-08-08 19:43:41 +02:00
|
|
|
removeFragment: (ctx: NetscriptContext) =>
|
2022-04-08 02:02:59 +02:00
|
|
|
function (_rootX: unknown, _rootY: unknown): boolean {
|
2022-08-08 19:43:41 +02:00
|
|
|
const rootX = helpers.number(ctx, "rootX", _rootX);
|
|
|
|
const rootY = helpers.number(ctx, "rootY", _rootY);
|
|
|
|
checkStanekAPIAccess(ctx);
|
2022-04-08 02:02:59 +02:00
|
|
|
return staneksGift.delete(rootX, rootY);
|
|
|
|
},
|
2022-08-08 19:43:41 +02:00
|
|
|
acceptGift: (ctx: NetscriptContext) =>
|
2022-04-19 19:00:24 +02:00
|
|
|
function (): boolean {
|
2022-04-19 20:33:07 +02:00
|
|
|
//Check if the player is eligible to join the church
|
|
|
|
if (
|
|
|
|
player.canAccessCotMG() &&
|
|
|
|
player.augmentations.filter((a) => a.name !== AugmentationNames.NeuroFluxGovernor).length == 0 &&
|
|
|
|
player.queuedAugmentations.filter((a) => a.name !== AugmentationNames.NeuroFluxGovernor).length == 0
|
|
|
|
) {
|
2022-04-19 19:00:24 +02:00
|
|
|
//Attempt to join CotMG
|
2022-04-19 20:39:56 +02:00
|
|
|
joinFaction(Factions[FactionNames.ChurchOfTheMachineGod]);
|
2022-04-19 19:00:24 +02:00
|
|
|
//Attempt to install the first Stanek aug
|
|
|
|
if (
|
|
|
|
!player.hasAugmentation(AugmentationNames.StaneksGift1) &&
|
|
|
|
!player.queuedAugmentations.some((a) => a.name === AugmentationNames.StaneksGift1)
|
|
|
|
) {
|
|
|
|
applyAugmentation({ name: AugmentationNames.StaneksGift1, level: 1 });
|
2022-08-08 21:51:50 +02:00
|
|
|
helpers.log(
|
|
|
|
ctx,
|
2022-07-19 18:19:32 +02:00
|
|
|
() => `'${FactionNames.ChurchOfTheMachineGod}' joined and '${AugmentationNames.StaneksGift1}' installed.`,
|
|
|
|
);
|
2022-04-19 19:00:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//Return true iff the player is in CotMG and has the first Stanek aug installed
|
|
|
|
return (
|
2022-04-19 20:33:07 +02:00
|
|
|
Factions[FactionNames.ChurchOfTheMachineGod].isMember &&
|
2022-09-14 20:02:12 +02:00
|
|
|
player.hasAugmentation(AugmentationNames.StaneksGift1, true)
|
2022-04-19 19:00:24 +02:00
|
|
|
);
|
|
|
|
},
|
2021-10-05 04:31:07 +02:00
|
|
|
};
|
|
|
|
}
|