2022-05-08 01:08:07 +02:00
|
|
|
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
2022-04-14 19:19:51 +02:00
|
|
|
import { StaticAugmentations } from "../Augmentation/StaticAugmentations";
|
2022-03-29 23:09:36 +02:00
|
|
|
import { hasAugmentationPrereqs } from "../Faction/FactionHelpers";
|
2022-12-30 02:28:53 +01:00
|
|
|
import { CityName } from "../Enums";
|
2022-03-29 20:09:17 +02:00
|
|
|
import { GraftableAugmentation } from "../PersonObjects/Grafting/GraftableAugmentation";
|
2022-04-22 04:48:18 +02:00
|
|
|
import { getGraftingAvailableAugs, calculateGraftingTimeWithBonus } from "../PersonObjects/Grafting/GraftingHelpers";
|
2022-08-09 21:41:47 +02:00
|
|
|
import { Player as player } from "../Player";
|
2022-12-30 02:28:53 +01:00
|
|
|
import { Grafting as IGrafting } from "@nsdefs";
|
2022-03-23 18:35:15 +01:00
|
|
|
import { Router } from "../ui/GameRoot";
|
2022-12-04 09:14:06 +01:00
|
|
|
import { Page } from "../ui/Router";
|
2022-07-10 07:37:36 +02:00
|
|
|
import { GraftingWork } from "../Work/GraftingWork";
|
2022-08-08 19:43:41 +02:00
|
|
|
import { helpers } from "../Netscript/NetscriptHelpers";
|
2022-03-23 18:35:15 +01:00
|
|
|
|
2022-08-09 21:41:47 +02:00
|
|
|
export function NetscriptGrafting(): InternalAPI<IGrafting> {
|
2022-05-08 01:08:07 +02:00
|
|
|
const checkGraftingAPIAccess = (ctx: NetscriptContext): void => {
|
2022-03-23 21:48:39 +01:00
|
|
|
if (!player.canAccessGrafting()) {
|
2022-08-08 19:43:41 +02:00
|
|
|
throw helpers.makeRuntimeErrorMsg(
|
|
|
|
ctx,
|
2022-03-23 18:35:15 +01:00
|
|
|
"You do not currently have access to the Grafting API. This is either because you are not in BitNode 10 or because you do not have Source-File 10",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
2022-10-12 14:49:27 +02:00
|
|
|
getAugmentationGraftPrice: (ctx) => (_augName) => {
|
|
|
|
const augName = helpers.string(ctx, "augName", _augName);
|
|
|
|
checkGraftingAPIAccess(ctx);
|
|
|
|
if (!getGraftingAvailableAugs().includes(augName) || !StaticAugmentations.hasOwnProperty(augName)) {
|
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid aug: ${augName}`);
|
|
|
|
}
|
|
|
|
const graftableAug = new GraftableAugmentation(StaticAugmentations[augName]);
|
|
|
|
return graftableAug.cost;
|
|
|
|
},
|
2022-03-23 18:35:15 +01:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
getAugmentationGraftTime: (ctx) => (_augName) => {
|
|
|
|
const augName = helpers.string(ctx, "augName", _augName);
|
|
|
|
checkGraftingAPIAccess(ctx);
|
|
|
|
if (!getGraftingAvailableAugs().includes(augName) || !StaticAugmentations.hasOwnProperty(augName)) {
|
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid aug: ${augName}`);
|
|
|
|
}
|
|
|
|
const graftableAug = new GraftableAugmentation(StaticAugmentations[augName]);
|
|
|
|
return calculateGraftingTimeWithBonus(graftableAug);
|
|
|
|
},
|
2022-03-23 18:35:15 +01:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
getGraftableAugmentations: (ctx) => () => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkGraftingAPIAccess(ctx);
|
2022-09-06 15:07:12 +02:00
|
|
|
const graftableAugs = getGraftingAvailableAugs();
|
2022-04-13 16:43:27 +02:00
|
|
|
return graftableAugs;
|
|
|
|
},
|
|
|
|
|
2022-05-08 01:08:07 +02:00
|
|
|
graftAugmentation:
|
2022-10-12 14:49:27 +02:00
|
|
|
(ctx) =>
|
|
|
|
(_augName, _focus = true) => {
|
2022-08-08 19:43:41 +02:00
|
|
|
const augName = helpers.string(ctx, "augName", _augName);
|
|
|
|
const focus = !!_focus;
|
2022-05-08 01:08:07 +02:00
|
|
|
checkGraftingAPIAccess(ctx);
|
|
|
|
if (player.city !== CityName.NewTokyo) {
|
2022-08-08 19:43:41 +02:00
|
|
|
throw helpers.makeRuntimeErrorMsg(ctx, "You must be in New Tokyo to begin grafting an Augmentation.");
|
2022-05-08 01:08:07 +02:00
|
|
|
}
|
2022-09-06 15:07:12 +02:00
|
|
|
if (!getGraftingAvailableAugs().includes(augName) || !StaticAugmentations.hasOwnProperty(augName)) {
|
2022-08-08 21:51:50 +02:00
|
|
|
helpers.log(ctx, () => `Invalid aug: ${augName}`);
|
2022-05-08 01:08:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
2022-03-23 18:35:15 +01:00
|
|
|
|
2022-05-08 01:08:07 +02:00
|
|
|
const wasFocusing = player.focus;
|
2022-03-23 18:35:15 +01:00
|
|
|
|
2022-05-08 01:08:07 +02:00
|
|
|
const craftableAug = new GraftableAugmentation(StaticAugmentations[augName]);
|
|
|
|
if (player.money < craftableAug.cost) {
|
2022-08-08 21:51:50 +02:00
|
|
|
helpers.log(ctx, () => `You don't have enough money to craft ${augName}`);
|
2022-05-08 01:08:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
2022-03-23 18:35:15 +01:00
|
|
|
|
2022-05-08 01:08:07 +02:00
|
|
|
if (!hasAugmentationPrereqs(craftableAug.augmentation)) {
|
2022-08-08 21:51:50 +02:00
|
|
|
helpers.log(ctx, () => `You don't have the pre-requisites for ${augName}`);
|
2022-05-08 01:08:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
2022-03-29 23:09:36 +02:00
|
|
|
|
2022-07-14 23:43:08 +02:00
|
|
|
player.startWork(
|
2022-07-10 07:37:36 +02:00
|
|
|
new GraftingWork({
|
|
|
|
singularity: true,
|
|
|
|
augmentation: augName,
|
|
|
|
}),
|
|
|
|
);
|
2022-03-23 18:35:15 +01:00
|
|
|
|
2022-05-08 01:08:07 +02:00
|
|
|
if (focus) {
|
|
|
|
player.startFocusing();
|
2022-12-04 09:14:06 +01:00
|
|
|
Router.toPage(Page.Work);
|
2022-05-08 01:08:07 +02:00
|
|
|
} else if (wasFocusing) {
|
|
|
|
player.stopFocusing();
|
2022-12-04 09:14:06 +01:00
|
|
|
Router.toPage(Page.Terminal);
|
2022-05-08 01:08:07 +02:00
|
|
|
}
|
2022-03-23 18:35:15 +01:00
|
|
|
|
2022-08-08 21:51:50 +02:00
|
|
|
helpers.log(ctx, () => `Began grafting Augmentation ${augName}.`);
|
2022-05-08 01:08:07 +02:00
|
|
|
return true;
|
|
|
|
},
|
2022-03-23 18:35:15 +01:00
|
|
|
};
|
|
|
|
}
|