mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-08 00:27:47 +02:00
WIP: Crimes streamlining. (#138)
* streamline crimes * Crimes object is now indexed by CrimeType enum instead of an entirely new set of keys that aren't used for anything else. This eliminated a lot of instances of iterating to find the right crime for a given CrimeType. * Removed unused `None` CrimeType which allowed typing Crimes as a Record<CrimeType, Crime>. * Added slums tooltip text as a crime property, to allow streamlining slums. * Refactor slums location - removed repetitive code, rerenders 1/sec to update chances * Fix bugged descriptive text when sleeve is committing a crime (was "is attempting to DRUGS", now uses correct text e.g. "to deal drugs"). * Remove unused and now unneeded NewCrimeType enum. Values were identical to existing CrimeType values after removing unused None. * Add CrimeType enum in NetscriptDefinition.d.ts * Also update broken ToastVariant type. Better support for enums in player scripts. * Still todo is modifying some NS functions to expect CrimeType as input (rough crime names will continue to work to avoid breaking scripts) * Expect enum use for crime functions Affected functions: * ns.singularity.commitCrime * ns.singularity.getCrimeChance * ns.singularity.getCrimeStats * ns.sleeve.setToCommitCrime * formulas.work.crimeGains (param type only) - Affected functions still will fall back to rough names, except formulas.work.crimeGains which already only accepted the enum members. - Some documentation changes: * examples updated to use uppercase expected form. * Note on sleeve.setToCommitCrime that it only accepts exact matches removed. It already, and still does, accept any rough crime name (but the enum is expected input). * note about needing to use isBusy to schedule crimes remove - crimes autoloop now. * Since expected string inputs are documented directly on the type, removed list of crimes from sleeve.setToCommitCrimes
This commit is contained in:
@@ -12,21 +12,18 @@ import { Person } from "../Person";
|
||||
|
||||
import { Augmentation } from "../../Augmentation/Augmentation";
|
||||
|
||||
import { Crime } from "../../Crime/Crime";
|
||||
import { Crimes } from "../../Crime/Crimes";
|
||||
|
||||
import { Companies } from "../../Company/Companies";
|
||||
import { Company } from "../../Company/Company";
|
||||
import { CompanyPosition } from "../../Company/CompanyPosition";
|
||||
import { CompanyPositions } from "../../Company/CompanyPositions";
|
||||
|
||||
import { Contracts } from "../../Bladeburner/data/Contracts";
|
||||
|
||||
import { CONSTANTS } from "../../Constants";
|
||||
import { checkEnum } from "../../utils/helpers/checkEnum";
|
||||
import { CrimeType } from "../../utils/WorkType";
|
||||
import { CityName } from "../../Locations/data/CityNames";
|
||||
|
||||
import { Factions } from "../../Faction/Factions";
|
||||
|
||||
import { CityName } from "../../Locations/data/CityNames";
|
||||
import { LocationName } from "../../Locations/data/LocationNames";
|
||||
|
||||
import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../../utils/JSONReviver";
|
||||
@@ -97,13 +94,9 @@ export class Sleeve extends Person {
|
||||
}
|
||||
|
||||
/** Commit crimes */
|
||||
commitCrime(crimeKey: string): boolean {
|
||||
const crime: Crime | null = Crimes[crimeKey] || Object.values(Crimes).find((crime) => crime.name === crimeKey);
|
||||
if (!crime) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.startWork(new SleeveCrimeWork(crime.type));
|
||||
commitCrime(type: string): boolean {
|
||||
if (!checkEnum(CrimeType, type)) return false;
|
||||
this.startWork(new SleeveCrimeWork(type));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Crime } from "../../../Crime/Crime";
|
||||
import { newWorkStats, scaleWorkStats, WorkStats } from "../../../Work/WorkStats";
|
||||
import { CONSTANTS } from "../../../Constants";
|
||||
import { BitNodeMultipliers } from "../../../BitNode/BitNodeMultipliers";
|
||||
import { checkEnum } from "../../../utils/helpers/checkEnum";
|
||||
|
||||
export const isSleeveCrimeWork = (w: Work | null): w is SleeveCrimeWork => w !== null && w.type === WorkType.CRIME;
|
||||
|
||||
@@ -20,9 +21,8 @@ export class SleeveCrimeWork extends Work {
|
||||
}
|
||||
|
||||
getCrime(): Crime {
|
||||
const crime = Object.values(Crimes).find((crime) => crime.type === this.crimeType);
|
||||
if (!crime) throw new Error("crime should not be undefined");
|
||||
return crime;
|
||||
if (!checkEnum(CrimeType, this.crimeType)) throw new Error("crime should not be undefined");
|
||||
return Crimes[this.crimeType];
|
||||
}
|
||||
|
||||
getExp(sleeve: Sleeve): WorkStats {
|
||||
|
||||
@@ -74,7 +74,7 @@ export function SleeveElem(props: IProps): React.ReactElement {
|
||||
const crime = w.getCrime();
|
||||
desc = (
|
||||
<>
|
||||
This sleeve is currently attempting to {crime.type} (Success Rate:{" "}
|
||||
This sleeve is currently attempting {crime.workName} (Success Rate:{" "}
|
||||
{numeralWrapper.formatPercentage(crime.successRate(props.sleeve))}).
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -19,6 +19,8 @@ import { isSleeveSupportWork } from "../Work/SleeveSupportWork";
|
||||
import { ClassType } from "../../../Work/ClassWork";
|
||||
import { isSleeveCrimeWork } from "../Work/SleeveCrimeWork";
|
||||
import { FactionWorkType } from "../../../Work/data/FactionWorkType";
|
||||
import { checkEnum } from "../../../utils/helpers/checkEnum";
|
||||
import { CrimeType } from "../../../utils/WorkType";
|
||||
|
||||
const universitySelectorOptions: string[] = [
|
||||
"Study Computer Science",
|
||||
@@ -314,11 +316,7 @@ function getABC(sleeve: Sleeve): [string, string, string] {
|
||||
}
|
||||
}
|
||||
if (isSleeveCrimeWork(w)) {
|
||||
return [
|
||||
"Commit Crime",
|
||||
Object.values(Crimes).find((crime) => crime.type === w.crimeType)?.name ?? "Shoplift",
|
||||
"------",
|
||||
];
|
||||
return ["Commit Crime", checkEnum(CrimeType, w.crimeType) ? Crimes[w.crimeType].name : "Shoplift", "------"];
|
||||
}
|
||||
if (isSleeveSupportWork(w)) {
|
||||
return ["Perform Bladeburner Actions", "Support main sleeve", "------"];
|
||||
|
||||
Reference in New Issue
Block a user