2023-06-12 06:34:20 +02:00
|
|
|
import { Player } from "@player";
|
|
|
|
import { AugmentationName, FactionName } from "@enums";
|
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
|
|
|
|
2022-12-30 02:28:53 +01:00
|
|
|
import { Stanek as IStanek } from "@nsdefs";
|
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 { 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 {
|
2023-06-12 06:34:20 +02:00
|
|
|
if (!Player.hasAugmentation(AugmentationName.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-10-12 14:49:27 +02:00
|
|
|
giftWidth: (ctx) => () => {
|
|
|
|
checkStanekAPIAccess(ctx);
|
|
|
|
return staneksGift.width();
|
|
|
|
},
|
|
|
|
giftHeight: (ctx) => () => {
|
|
|
|
checkStanekAPIAccess(ctx);
|
|
|
|
return staneksGift.height();
|
|
|
|
},
|
|
|
|
chargeFragment: (ctx) => (_rootX, _rootY) => {
|
|
|
|
//Get the fragment object using the given coordinates
|
|
|
|
const rootX = helpers.number(ctx, "rootX", _rootX);
|
|
|
|
const rootY = helpers.number(ctx, "rootY", _rootY);
|
|
|
|
checkStanekAPIAccess(ctx);
|
|
|
|
const fragment = staneksGift.findFragment(rootX, rootY);
|
|
|
|
//Check whether the selected fragment can ge charged
|
|
|
|
if (!fragment) throw helpers.makeRuntimeErrorMsg(ctx, `No fragment with root (${rootX}, ${rootY}).`);
|
|
|
|
if (fragment.fragment().type == FragmentType.Booster) {
|
|
|
|
throw helpers.makeRuntimeErrorMsg(
|
|
|
|
ctx,
|
|
|
|
`The fragment with root (${rootX}, ${rootY}) is a Booster Fragment and thus cannot be charged.`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
//Charge the fragment
|
2023-03-07 20:45:22 +01:00
|
|
|
const inBonus = staneksGift.inBonus();
|
|
|
|
const time = inBonus ? 200 : 1000;
|
|
|
|
if (inBonus) staneksGift.isBonusCharging = true;
|
2022-10-12 14:49:27 +02:00
|
|
|
return helpers.netscriptDelay(ctx, time).then(function () {
|
|
|
|
staneksGift.charge(fragment, ctx.workerScript.scriptRef.threads);
|
|
|
|
helpers.log(ctx, () => `Charged fragment with ${ctx.workerScript.scriptRef.threads} threads.`);
|
|
|
|
return Promise.resolve();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fragmentDefinitions: (ctx) => () => {
|
|
|
|
checkStanekAPIAccess(ctx);
|
|
|
|
helpers.log(ctx, () => `Returned ${Fragments.length} fragments`);
|
|
|
|
return Fragments.map((f) => f.copy());
|
|
|
|
},
|
|
|
|
activeFragments: (ctx) => () => {
|
|
|
|
checkStanekAPIAccess(ctx);
|
|
|
|
helpers.log(ctx, () => `Returned ${staneksGift.fragments.length} fragments`);
|
|
|
|
return staneksGift.fragments.map((af) => {
|
|
|
|
return { ...af.copy(), ...af.fragment().copy() };
|
|
|
|
});
|
|
|
|
},
|
|
|
|
clearGift: (ctx) => () => {
|
|
|
|
checkStanekAPIAccess(ctx);
|
|
|
|
helpers.log(ctx, () => `Cleared Stanek's Gift.`);
|
|
|
|
staneksGift.clear();
|
|
|
|
},
|
|
|
|
canPlaceFragment: (ctx) => (_rootX, _rootY, _rotation, _fragmentId) => {
|
|
|
|
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);
|
|
|
|
const fragment = FragmentById(fragmentId);
|
|
|
|
if (!fragment) throw helpers.makeRuntimeErrorMsg(ctx, `Invalid fragment id: ${fragmentId}`);
|
|
|
|
const can = staneksGift.canPlace(rootX, rootY, rotation, fragment);
|
|
|
|
return can;
|
|
|
|
},
|
|
|
|
placeFragment: (ctx) => (_rootX, _rootY, _rotation, _fragmentId) => {
|
|
|
|
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);
|
|
|
|
const fragment = FragmentById(fragmentId);
|
|
|
|
if (!fragment) throw helpers.makeRuntimeErrorMsg(ctx, `Invalid fragment id: ${fragmentId}`);
|
|
|
|
return staneksGift.place(rootX, rootY, rotation, fragment);
|
|
|
|
},
|
|
|
|
getFragment: (ctx) => (_rootX, _rootY) => {
|
|
|
|
const rootX = helpers.number(ctx, "rootX", _rootX);
|
|
|
|
const rootY = helpers.number(ctx, "rootY", _rootY);
|
|
|
|
checkStanekAPIAccess(ctx);
|
|
|
|
const fragment = staneksGift.findFragment(rootX, rootY);
|
|
|
|
if (fragment !== undefined) return fragment.copy();
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
removeFragment: (ctx) => (_rootX, _rootY) => {
|
|
|
|
const rootX = helpers.number(ctx, "rootX", _rootX);
|
|
|
|
const rootY = helpers.number(ctx, "rootY", _rootY);
|
|
|
|
checkStanekAPIAccess(ctx);
|
|
|
|
return staneksGift.delete(rootX, rootY);
|
|
|
|
},
|
|
|
|
acceptGift: (ctx) => () => {
|
|
|
|
//Check if the player is eligible to join the church
|
|
|
|
if (
|
2023-06-12 06:34:20 +02:00
|
|
|
Player.canAccessCotMG() &&
|
|
|
|
Player.augmentations.filter((a) => a.name !== AugmentationName.NeuroFluxGovernor).length == 0 &&
|
|
|
|
Player.queuedAugmentations.filter((a) => a.name !== AugmentationName.NeuroFluxGovernor).length == 0
|
2022-10-12 14:49:27 +02:00
|
|
|
) {
|
|
|
|
//Attempt to join CotMG
|
2023-06-12 06:34:20 +02:00
|
|
|
joinFaction(Factions[FactionName.ChurchOfTheMachineGod]);
|
2022-10-12 14:49:27 +02:00
|
|
|
//Attempt to install the first Stanek aug
|
2022-04-19 20:33:07 +02:00
|
|
|
if (
|
2023-06-12 06:34:20 +02:00
|
|
|
!Player.hasAugmentation(AugmentationName.StaneksGift1) &&
|
|
|
|
!Player.queuedAugmentations.some((a) => a.name === AugmentationName.StaneksGift1)
|
2022-04-19 20:33:07 +02:00
|
|
|
) {
|
2023-06-12 06:34:20 +02:00
|
|
|
applyAugmentation({ name: AugmentationName.StaneksGift1, level: 1 });
|
2022-10-12 14:49:27 +02:00
|
|
|
helpers.log(
|
|
|
|
ctx,
|
2023-06-12 06:34:20 +02:00
|
|
|
() => `'${FactionName.ChurchOfTheMachineGod}' joined and '${AugmentationName.StaneksGift1}' installed.`,
|
2022-10-12 14:49:27 +02:00
|
|
|
);
|
2022-04-19 19:00:24 +02:00
|
|
|
}
|
2022-10-12 14:49:27 +02:00
|
|
|
}
|
|
|
|
//Return true iff the player is in CotMG and has the first Stanek aug installed
|
|
|
|
return (
|
2023-06-12 06:34:20 +02:00
|
|
|
Factions[FactionName.ChurchOfTheMachineGod].isMember &&
|
|
|
|
Player.hasAugmentation(AugmentationName.StaneksGift1, true)
|
2022-10-12 14:49:27 +02:00
|
|
|
);
|
|
|
|
},
|
2021-10-05 04:31:07 +02:00
|
|
|
};
|
|
|
|
}
|