mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-27 19:37:07 +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:
+6
-49
@@ -9,51 +9,7 @@ import { CrimeType } from "../utils/WorkType";
|
||||
import { Work, WorkType } from "./Work";
|
||||
import { scaleWorkStats, WorkStats } from "./WorkStats";
|
||||
import { calculateCrimeWorkStats } from "./formulas/Crime";
|
||||
|
||||
enum newCrimeType {
|
||||
SHOPLIFT = "SHOPLIFT",
|
||||
ROBSTORE = "ROBSTORE",
|
||||
MUG = "MUG",
|
||||
LARCENY = "LARCENY",
|
||||
DRUGS = "DRUGS",
|
||||
BONDFORGERY = "BONDFORGERY",
|
||||
TRAFFICKARMS = "TRAFFICKARMS",
|
||||
HOMICIDE = "HOMICIDE",
|
||||
GRANDTHEFTAUTO = "GRANDTHEFTAUTO",
|
||||
KIDNAP = "KIDNAP",
|
||||
ASSASSINATION = "ASSASSINATION",
|
||||
HEIST = "HEIST",
|
||||
}
|
||||
|
||||
const convertCrimeType = (crimeType: CrimeType): newCrimeType => {
|
||||
switch (crimeType) {
|
||||
case CrimeType.SHOPLIFT:
|
||||
return newCrimeType.SHOPLIFT;
|
||||
case CrimeType.ROB_STORE:
|
||||
return newCrimeType.ROBSTORE;
|
||||
case CrimeType.MUG:
|
||||
return newCrimeType.MUG;
|
||||
case CrimeType.LARCENY:
|
||||
return newCrimeType.LARCENY;
|
||||
case CrimeType.DRUGS:
|
||||
return newCrimeType.DRUGS;
|
||||
case CrimeType.BOND_FORGERY:
|
||||
return newCrimeType.BONDFORGERY;
|
||||
case CrimeType.TRAFFIC_ARMS:
|
||||
return newCrimeType.TRAFFICKARMS;
|
||||
case CrimeType.HOMICIDE:
|
||||
return newCrimeType.HOMICIDE;
|
||||
case CrimeType.GRAND_THEFT_AUTO:
|
||||
return newCrimeType.GRANDTHEFTAUTO;
|
||||
case CrimeType.KIDNAP:
|
||||
return newCrimeType.KIDNAP;
|
||||
case CrimeType.ASSASSINATION:
|
||||
return newCrimeType.ASSASSINATION;
|
||||
case CrimeType.HEIST:
|
||||
return newCrimeType.HEIST;
|
||||
}
|
||||
return newCrimeType.SHOPLIFT;
|
||||
};
|
||||
import { checkEnum } from "../utils/helpers/checkEnum";
|
||||
|
||||
interface CrimeWorkParams {
|
||||
crimeType: CrimeType;
|
||||
@@ -73,9 +29,10 @@ export class CrimeWork extends Work {
|
||||
}
|
||||
|
||||
getCrime(): Crime {
|
||||
const crime = Object.values(Crimes).find((c) => c.type === this.crimeType);
|
||||
if (!crime) throw new Error("CrimeWork object constructed with invalid crime type");
|
||||
return crime;
|
||||
if (!checkEnum(CrimeType, this.crimeType)) {
|
||||
throw new Error("CrimeWork object constructed with invalid crime type");
|
||||
}
|
||||
return Crimes[this.crimeType];
|
||||
}
|
||||
|
||||
process(cycles = 1): boolean {
|
||||
@@ -132,7 +89,7 @@ export class CrimeWork extends Work {
|
||||
return {
|
||||
type: this.type,
|
||||
cyclesWorked: this.cyclesWorked,
|
||||
crimeType: convertCrimeType(this.crimeType),
|
||||
crimeType: checkEnum(CrimeType, this.crimeType) ? this.crimeType : CrimeType.SHOPLIFT,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user