diff --git a/src/NetscriptFunctions/Sleeve.ts b/src/NetscriptFunctions/Sleeve.ts index 1f7ec0f02..c7c713cc1 100644 --- a/src/NetscriptFunctions/Sleeve.ts +++ b/src/NetscriptFunctions/Sleeve.ts @@ -12,6 +12,7 @@ import { isSleeveCompanyWork } from "../PersonObjects/Sleeve/Work/SleeveCompanyW import { helpers } from "../Netscript/NetscriptHelpers"; import { cloneDeep } from "lodash"; import { getAugCost } from "../Augmentation/AugmentationHelpers"; +import { Factions } from "../Faction/Factions"; export function NetscriptSleeve(): InternalAPI { const checkSleeveAPIAccess = function (ctx: NetscriptContext) { @@ -102,11 +103,15 @@ export function NetscriptSleeve(): InternalAPI { }, setToFactionWork: (ctx) => (_sleeveNumber, _factionName, _workType) => { const sleeveNumber = helpers.number(ctx, "sleeveNumber", _sleeveNumber); - const factionName = helpers.string(ctx, "factionName", _factionName); + const factionName = getEnumHelper("FactionName").nsGetMember(ctx, _factionName); const workType = helpers.string(ctx, "workType", _workType); checkSleeveAPIAccess(ctx); checkSleeveNumber(ctx, sleeveNumber); + if (!Factions[factionName].isMember) { + throw helpers.makeRuntimeErrorMsg(ctx, `Cannot work for faction ${factionName} without being a member.`); + } + // Cannot work at the same faction that another sleeve is working at for (let i = 0; i < Player.sleeves.length; ++i) { if (i === sleeveNumber) { diff --git a/src/PersonObjects/Sleeve/Sleeve.ts b/src/PersonObjects/Sleeve/Sleeve.ts index cbfbdcd81..06f17c9c3 100644 --- a/src/PersonObjects/Sleeve/Sleeve.ts +++ b/src/PersonObjects/Sleeve/Sleeve.ts @@ -25,6 +25,7 @@ import { LocationName, UniversityClassType, CompanyName, + FactionName, } from "@enums"; import { Factions } from "../../Faction/Factions"; @@ -291,15 +292,13 @@ export class Sleeve extends Person implements SleevePerson { } /** TODO 2.4: Make this take in type correct data */ - workForFaction(_factionName: string, _workType: string): boolean { + workForFaction(factionName: FactionName, _workType: string): boolean { const workTypeConversion: Record = { "Hacking Contracts": "hacking", "Field Work": "field", "Security Work": "security", }; if (workTypeConversion[_workType]) _workType = workTypeConversion[_workType]; - const factionName = getEnumHelper("FactionName").fuzzyGetMember(_factionName); - if (!factionName) return false; const faction = Factions[factionName]; const workType = getEnumHelper("FactionWorkType").fuzzyGetMember(_workType); if (!workType) return false; diff --git a/src/PersonObjects/Sleeve/ui/SleeveElem.tsx b/src/PersonObjects/Sleeve/ui/SleeveElem.tsx index b12d7e985..298176018 100644 --- a/src/PersonObjects/Sleeve/ui/SleeveElem.tsx +++ b/src/PersonObjects/Sleeve/ui/SleeveElem.tsx @@ -80,7 +80,8 @@ export function SleeveElem(props: SleeveElemProps): React.ReactElement { else console.error(`Invalid company name in setSleeveTask: ${abc[1]}`); break; case "Work for Faction": - props.sleeve.workForFaction(abc[1], abc[2]); + if (getEnumHelper("FactionName").isMember(abc[1])) props.sleeve.workForFaction(abc[1], abc[2]); + else console.error(`Invalid faction name in setSleeveTask: ${abc[1]}`); break; case "Commit Crime": props.sleeve.commitCrime(findCrime(abc[1])?.type ?? CrimeType.shoplift);