2023-06-16 23:52:42 +02:00
|
|
|
import type { Augmentation } from "../Augmentation/Augmentation";
|
2023-06-12 06:34:20 +02:00
|
|
|
import type { Sleeve as NetscriptSleeve } from "@nsdefs";
|
2024-03-29 02:52:37 +01:00
|
|
|
import type { ActionIdentifier } from "../Bladeburner/Types";
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2023-06-16 23:52:42 +02:00
|
|
|
import { Player } from "@player";
|
2024-06-04 15:49:23 +02:00
|
|
|
import { BladeActionType, type BladeContractName } from "@enums";
|
2023-06-16 23:52:42 +02:00
|
|
|
import { Augmentations } from "../Augmentation/Augmentations";
|
|
|
|
import { findCrime } from "../Crime/CrimeHelpers";
|
2023-06-12 06:34:20 +02:00
|
|
|
import { getEnumHelper } from "../utils/EnumHelper";
|
2023-08-07 08:38:38 +02:00
|
|
|
import { InternalAPI, NetscriptContext, setRemovedFunctions } from "../Netscript/APIWrapper";
|
2024-03-29 02:52:37 +01:00
|
|
|
import { SleeveBladeburnerWork } from "../PersonObjects/Sleeve/Work/SleeveBladeburnerWork";
|
2022-07-28 09:08:39 +02:00
|
|
|
import { isSleeveFactionWork } from "../PersonObjects/Sleeve/Work/SleeveFactionWork";
|
|
|
|
import { isSleeveCompanyWork } from "../PersonObjects/Sleeve/Work/SleeveCompanyWork";
|
2022-08-08 19:43:41 +02:00
|
|
|
import { helpers } from "../Netscript/NetscriptHelpers";
|
2023-06-16 23:52:42 +02:00
|
|
|
import { getAugCost } from "../Augmentation/AugmentationHelpers";
|
2023-07-31 16:36:24 +02:00
|
|
|
import { Factions } from "../Faction/Factions";
|
2024-03-29 02:52:37 +01:00
|
|
|
import { SleeveWorkType } from "../PersonObjects/Sleeve/Work/Work";
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2023-06-12 06:34:20 +02:00
|
|
|
export function NetscriptSleeve(): InternalAPI<NetscriptSleeve> {
|
2022-10-12 14:49:27 +02:00
|
|
|
const checkSleeveAPIAccess = function (ctx: NetscriptContext) {
|
2022-09-06 15:07:12 +02:00
|
|
|
if (Player.bitNodeN !== 10 && !Player.sourceFileLvl(10)) {
|
2024-02-26 14:05:10 +01:00
|
|
|
throw helpers.errorMessage(
|
2022-08-08 19:43:41 +02:00
|
|
|
ctx,
|
2021-10-05 04:25:21 +02:00
|
|
|
"You do not currently have access to the Sleeve API. This is either because you are not in BitNode-10 or because you do not have Source-File 10",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
const checkSleeveNumber = function (ctx: NetscriptContext, sleeveNumber: number) {
|
2022-09-06 15:07:12 +02:00
|
|
|
if (sleeveNumber >= Player.sleeves.length || sleeveNumber < 0) {
|
2021-10-05 04:25:21 +02:00
|
|
|
const msg = `Invalid sleeve number: ${sleeveNumber}`;
|
2022-08-08 21:51:50 +02:00
|
|
|
helpers.log(ctx, () => msg);
|
2024-02-26 14:05:10 +01:00
|
|
|
throw helpers.errorMessage(ctx, msg);
|
2021-10-05 04:25:21 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-06-12 06:34:20 +02:00
|
|
|
const sleeveFunctions: InternalAPI<NetscriptSleeve> = {
|
2022-10-12 14:49:27 +02:00
|
|
|
getNumSleeves: (ctx) => () => {
|
2022-05-08 01:08:07 +02:00
|
|
|
checkSleeveAPIAccess(ctx);
|
2022-09-06 15:07:12 +02:00
|
|
|
return Player.sleeves.length;
|
2023-02-19 06:13:23 +01:00
|
|
|
},
|
|
|
|
setToIdle: (ctx) => (_sleeveNumber) => {
|
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
|
|
|
Player.sleeves[sleeveNumber].stopWork();
|
2021-10-05 04:25:21 +02:00
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
setToShockRecovery: (ctx) => (_sleeveNumber) => {
|
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
|
|
|
return Player.sleeves[sleeveNumber].shockRecovery();
|
|
|
|
},
|
|
|
|
setToSynchronize: (ctx) => (_sleeveNumber) => {
|
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
|
|
|
return Player.sleeves[sleeveNumber].synchronize();
|
|
|
|
},
|
2022-10-21 17:57:37 +02:00
|
|
|
setToCommitCrime: (ctx) => (_sleeveNumber, _crimeType) => {
|
2022-10-12 14:49:27 +02:00
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
2022-10-21 17:57:37 +02:00
|
|
|
const crimeType = helpers.string(ctx, "crimeType", _crimeType);
|
2022-10-12 14:49:27 +02:00
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
2022-11-10 17:05:42 +01:00
|
|
|
const crime = findCrime(crimeType);
|
2022-10-21 17:57:37 +02:00
|
|
|
if (crime == null) return false;
|
2022-11-03 13:39:34 +01:00
|
|
|
return Player.sleeves[sleeveNumber].commitCrime(crime.type);
|
2022-10-12 14:49:27 +02:00
|
|
|
},
|
|
|
|
setToUniversityCourse: (ctx) => (_sleeveNumber, _universityName, _className) => {
|
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
|
|
|
const universityName = helpers.string(ctx, "universityName", _universityName);
|
|
|
|
const className = helpers.string(ctx, "className", _className);
|
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
|
|
|
return Player.sleeves[sleeveNumber].takeUniversityCourse(universityName, className);
|
|
|
|
},
|
|
|
|
travel: (ctx) => (_sleeveNumber, _cityName) => {
|
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
2023-06-12 06:34:20 +02:00
|
|
|
const cityName = getEnumHelper("CityName").nsGetMember(ctx, _cityName);
|
2022-10-12 14:49:27 +02:00
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
2023-06-12 06:34:20 +02:00
|
|
|
return Player.sleeves[sleeveNumber].travel(cityName);
|
2022-10-12 14:49:27 +02:00
|
|
|
},
|
2023-07-11 15:23:17 +02:00
|
|
|
setToCompanyWork: (ctx) => (_sleeveNumber, _companyName) => {
|
2022-10-12 14:49:27 +02:00
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
2023-07-11 15:23:17 +02:00
|
|
|
const companyName = getEnumHelper("CompanyName").nsGetMember(ctx, _companyName);
|
2022-10-12 14:49:27 +02:00
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
// Cannot work at the same company that another sleeve is working at
|
|
|
|
for (let i = 0; i < Player.sleeves.length; ++i) {
|
|
|
|
if (i === sleeveNumber) {
|
|
|
|
continue;
|
2022-05-08 01:08:07 +02:00
|
|
|
}
|
2022-10-12 14:49:27 +02:00
|
|
|
const other = Player.sleeves[i];
|
|
|
|
if (isSleeveCompanyWork(other.currentWork) && other.currentWork.companyName === companyName) {
|
2024-02-26 14:05:10 +01:00
|
|
|
throw helpers.errorMessage(
|
2022-10-12 14:49:27 +02:00
|
|
|
ctx,
|
|
|
|
`Sleeve ${sleeveNumber} cannot work for company ${companyName} because Sleeve ${i} is already working for them.`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
return Player.sleeves[sleeveNumber].workForCompany(companyName);
|
|
|
|
},
|
|
|
|
setToFactionWork: (ctx) => (_sleeveNumber, _factionName, _workType) => {
|
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
2023-07-31 16:36:24 +02:00
|
|
|
const factionName = getEnumHelper("FactionName").nsGetMember(ctx, _factionName);
|
2022-10-12 14:49:27 +02:00
|
|
|
const workType = helpers.string(ctx, "workType", _workType);
|
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2023-07-31 16:36:24 +02:00
|
|
|
if (!Factions[factionName].isMember) {
|
2024-02-26 14:05:10 +01:00
|
|
|
throw helpers.errorMessage(ctx, `Cannot work for faction ${factionName} without being a member.`);
|
2023-07-31 16:36:24 +02:00
|
|
|
}
|
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
// Cannot work at the same faction that another sleeve is working at
|
|
|
|
for (let i = 0; i < Player.sleeves.length; ++i) {
|
|
|
|
if (i === sleeveNumber) {
|
|
|
|
continue;
|
2021-10-05 04:25:21 +02:00
|
|
|
}
|
2022-10-12 14:49:27 +02:00
|
|
|
const other = Player.sleeves[i];
|
|
|
|
if (isSleeveFactionWork(other.currentWork) && other.currentWork.factionName === factionName) {
|
2024-02-26 14:05:10 +01:00
|
|
|
throw helpers.errorMessage(
|
2022-08-08 19:43:41 +02:00
|
|
|
ctx,
|
2022-10-12 14:49:27 +02:00
|
|
|
`Sleeve ${sleeveNumber} cannot work for faction ${factionName} because Sleeve ${i} is already working for them.`,
|
2021-10-05 04:25:21 +02:00
|
|
|
);
|
|
|
|
}
|
2022-10-12 14:49:27 +02:00
|
|
|
}
|
2022-04-04 12:10:21 +02:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
if (Player.gang && Player.gang.facName == factionName) {
|
2024-02-26 14:05:10 +01:00
|
|
|
throw helpers.errorMessage(
|
2022-10-12 14:49:27 +02:00
|
|
|
ctx,
|
|
|
|
`Sleeve ${sleeveNumber} cannot work for faction ${factionName} because you have started a gang with them.`,
|
|
|
|
);
|
|
|
|
}
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
return Player.sleeves[sleeveNumber].workForFaction(factionName, workType);
|
|
|
|
},
|
|
|
|
setToGymWorkout: (ctx) => (_sleeveNumber, _gymName, _stat) => {
|
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
|
|
|
const gymName = helpers.string(ctx, "gymName", _gymName);
|
|
|
|
const stat = helpers.string(ctx, "stat", _stat);
|
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
return Player.sleeves[sleeveNumber].workoutAtGym(gymName, stat);
|
|
|
|
},
|
|
|
|
getTask: (ctx) => (_sleeveNumber) => {
|
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
const sl = Player.sleeves[sleeveNumber];
|
|
|
|
if (sl.currentWork === null) return null;
|
2023-03-07 11:30:15 +01:00
|
|
|
return sl.currentWork.APICopy(sl);
|
2022-10-12 14:49:27 +02:00
|
|
|
},
|
2022-11-09 13:26:26 +01:00
|
|
|
getSleeve: (ctx) => (_sleeveNumber) => {
|
2022-10-12 14:49:27 +02:00
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
const sl = Player.sleeves[sleeveNumber];
|
2022-11-09 13:26:26 +01:00
|
|
|
|
|
|
|
const data = {
|
2024-02-10 10:10:19 +01:00
|
|
|
hp: structuredClone(sl.hp),
|
|
|
|
skills: structuredClone(sl.skills),
|
|
|
|
exp: structuredClone(sl.exp),
|
|
|
|
mults: structuredClone(sl.mults),
|
2022-11-09 13:26:26 +01:00
|
|
|
city: sl.city,
|
|
|
|
shock: sl.shock,
|
|
|
|
sync: sl.sync,
|
|
|
|
memory: sl.memory,
|
2023-01-02 15:45:51 +01:00
|
|
|
storedCycles: sl.storedCycles,
|
2022-10-12 14:49:27 +02:00
|
|
|
};
|
2022-11-09 13:26:26 +01:00
|
|
|
|
|
|
|
return data;
|
2022-10-12 14:49:27 +02:00
|
|
|
},
|
|
|
|
getSleeveAugmentations: (ctx) => (_sleeveNumber) => {
|
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
const augs = [];
|
|
|
|
for (let i = 0; i < Player.sleeves[sleeveNumber].augmentations.length; i++) {
|
|
|
|
augs.push(Player.sleeves[sleeveNumber].augmentations[i].name);
|
|
|
|
}
|
|
|
|
return augs;
|
|
|
|
},
|
|
|
|
getSleevePurchasableAugs: (ctx) => (_sleeveNumber) => {
|
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
const purchasableAugs = Player.sleeves[sleeveNumber].findPurchasableAugs();
|
|
|
|
const augs = [];
|
|
|
|
for (let i = 0; i < purchasableAugs.length; i++) {
|
|
|
|
const aug = purchasableAugs[i];
|
|
|
|
augs.push({
|
|
|
|
name: aug.name,
|
|
|
|
cost: aug.baseCost,
|
|
|
|
});
|
|
|
|
}
|
2022-03-19 04:37:59 +01:00
|
|
|
|
2022-10-12 14:49:27 +02:00
|
|
|
return augs;
|
|
|
|
},
|
|
|
|
purchaseSleeveAug: (ctx) => (_sleeveNumber, _augName) => {
|
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
2023-06-16 23:52:42 +02:00
|
|
|
const augName = getEnumHelper("AugmentationName").nsGetMember(ctx, _augName);
|
2022-10-12 14:49:27 +02:00
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
2022-03-19 04:37:59 +01:00
|
|
|
|
2022-11-09 13:26:26 +01:00
|
|
|
if (Player.sleeves[sleeveNumber].shock > 0) {
|
2024-02-26 14:05:10 +01:00
|
|
|
throw helpers.errorMessage(ctx, `Sleeve shock too high: Sleeve ${sleeveNumber}`);
|
2022-10-12 14:49:27 +02:00
|
|
|
}
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2023-06-16 23:52:42 +02:00
|
|
|
const aug = Augmentations[augName];
|
2022-10-12 14:49:27 +02:00
|
|
|
if (!aug) {
|
2024-02-26 14:05:10 +01:00
|
|
|
throw helpers.errorMessage(ctx, `Invalid aug: ${augName}`);
|
2022-10-12 14:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Player.sleeves[sleeveNumber].tryBuyAugmentation(aug);
|
|
|
|
},
|
|
|
|
getSleeveAugmentationPrice: (ctx) => (_augName) => {
|
|
|
|
checkSleeveAPIAccess(ctx);
|
2023-06-16 23:52:42 +02:00
|
|
|
const augName = getEnumHelper("AugmentationName").nsGetMember(ctx, _augName);
|
|
|
|
const aug: Augmentation = Augmentations[augName];
|
2022-10-12 14:49:27 +02:00
|
|
|
return aug.baseCost;
|
|
|
|
},
|
|
|
|
getSleeveAugmentationRepReq: (ctx) => (_augName) => {
|
|
|
|
checkSleeveAPIAccess(ctx);
|
2023-06-16 23:52:42 +02:00
|
|
|
const augName = getEnumHelper("AugmentationName").nsGetMember(ctx, _augName);
|
|
|
|
const aug: Augmentation = Augmentations[augName];
|
|
|
|
return getAugCost(aug).repCost;
|
2022-10-12 14:49:27 +02:00
|
|
|
},
|
|
|
|
setToBladeburnerAction: (ctx) => (_sleeveNumber, _action, _contract?) => {
|
|
|
|
const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber);
|
|
|
|
const action = helpers.string(ctx, "action", _action);
|
|
|
|
checkSleeveAPIAccess(ctx);
|
|
|
|
checkSleeveNumber(ctx, sleeveNumber);
|
2024-06-04 15:49:23 +02:00
|
|
|
let contract: BladeContractName | undefined = undefined;
|
2022-10-12 14:49:27 +02:00
|
|
|
if (action === "Take on contracts") {
|
2024-06-04 15:49:23 +02:00
|
|
|
contract = getEnumHelper("BladeContractName").nsGetMember(ctx, _contract);
|
2022-10-12 14:49:27 +02:00
|
|
|
for (let i = 0; i < Player.sleeves.length; ++i) {
|
2024-03-29 02:52:37 +01:00
|
|
|
if (i === sleeveNumber) continue;
|
|
|
|
const otherWork = Player.sleeves[i].currentWork;
|
2024-06-04 15:49:23 +02:00
|
|
|
if (otherWork?.type === SleeveWorkType.BLADEBURNER && otherWork.actionId.name === contract) {
|
2024-02-26 14:05:10 +01:00
|
|
|
throw helpers.errorMessage(
|
2022-10-12 14:49:27 +02:00
|
|
|
ctx,
|
|
|
|
`Sleeve ${sleeveNumber} cannot take on contracts because Sleeve ${i} is already performing that action.`,
|
|
|
|
);
|
2022-04-30 21:25:36 +02:00
|
|
|
}
|
|
|
|
}
|
2024-06-04 15:49:23 +02:00
|
|
|
const actionId: ActionIdentifier = { type: BladeActionType.contract, name: contract };
|
2024-03-29 02:52:37 +01:00
|
|
|
Player.sleeves[sleeveNumber].startWork(new SleeveBladeburnerWork({ actionId }));
|
2022-10-12 14:49:27 +02:00
|
|
|
}
|
2024-06-04 15:49:23 +02:00
|
|
|
return Player.sleeves[sleeveNumber].bladeburner(action, contract);
|
2022-10-12 14:49:27 +02:00
|
|
|
},
|
2021-10-05 04:25:21 +02:00
|
|
|
};
|
2023-08-07 08:38:38 +02:00
|
|
|
|
|
|
|
// Removed functions
|
|
|
|
setRemovedFunctions(sleeveFunctions, {
|
|
|
|
getSleeveStats: { version: "2.2.0", replacement: "sleeve.getSleeve" },
|
|
|
|
getInformation: { version: "2.2.0", replacement: "sleeve.getSleeve" },
|
2022-12-30 02:28:53 +01:00
|
|
|
});
|
|
|
|
return sleeveFunctions;
|
2021-10-05 04:25:21 +02:00
|
|
|
}
|