mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-08 00:27:47 +02:00
MISC: A bunch of enums stuff. (#212)
* Some game enums moved to utils/enums. Others can eventually be moved there as well. * findEnumMember function for performing fuzzy matching of player input with enum members, without needing separate fuzzy functions for every enum. * Also used findEnumMember for safely loading save games (allows case changes in enum values) * Changed capitalization on some enums. * BREAKING: removed classGains work formulas function * Split ClassType enum into UniversityClassType and GymType. * Added universityGains and gymGains work formulas functions * Provided the new split enums to the player on ns.enums.
This commit is contained in:
@@ -18,7 +18,7 @@ import { CompanyPosition } from "../../Company/CompanyPosition";
|
||||
import { CompanyPositions } from "../../Company/CompanyPositions";
|
||||
import { Contracts } from "../../Bladeburner/data/Contracts";
|
||||
import { CONSTANTS } from "../../Constants";
|
||||
import { CrimeType } from "../../utils/WorkType";
|
||||
import { CrimeType, GymType, UniversityClassType } from "../../utils/enums";
|
||||
import { CityName } from "../../Locations/data/CityNames";
|
||||
|
||||
import { Factions } from "../../Faction/Factions";
|
||||
@@ -27,7 +27,7 @@ import { LocationName } from "../../Locations/data/LocationNames";
|
||||
|
||||
import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../../utils/JSONReviver";
|
||||
import { numeralWrapper } from "../../ui/numeralFormat";
|
||||
import { FactionWorkType } from "../../Work/data/FactionWorkType";
|
||||
import { FactionWorkType } from "../../utils/enums";
|
||||
import { Work } from "./Work/Work";
|
||||
import { SleeveClassWork } from "./Work/SleeveClassWork";
|
||||
import { ClassType } from "../../Work/ClassWork";
|
||||
@@ -221,22 +221,22 @@ export class Sleeve extends Person implements ISleeve {
|
||||
let classType: ClassType | undefined;
|
||||
switch (className.toLowerCase()) {
|
||||
case "study computer science":
|
||||
classType = ClassType.StudyComputerScience;
|
||||
classType = UniversityClassType.computerScience;
|
||||
break;
|
||||
case "data structures":
|
||||
classType = ClassType.DataStructures;
|
||||
classType = UniversityClassType.dataStructures;
|
||||
break;
|
||||
case "networks":
|
||||
classType = ClassType.Networks;
|
||||
classType = UniversityClassType.networks;
|
||||
break;
|
||||
case "algorithms":
|
||||
classType = ClassType.Algorithms;
|
||||
classType = UniversityClassType.algorithms;
|
||||
break;
|
||||
case "management":
|
||||
classType = ClassType.Management;
|
||||
classType = UniversityClassType.management;
|
||||
break;
|
||||
case "leadership":
|
||||
classType = ClassType.Leadership;
|
||||
classType = UniversityClassType.leadership;
|
||||
break;
|
||||
}
|
||||
if (!classType) return false;
|
||||
@@ -311,13 +311,13 @@ export class Sleeve extends Person implements ISleeve {
|
||||
let factionWorkType: FactionWorkType;
|
||||
if (sanitizedWorkType.includes("hack")) {
|
||||
if (!factionInfo.offerHackingWork) return false;
|
||||
factionWorkType = FactionWorkType.HACKING;
|
||||
factionWorkType = FactionWorkType.hacking;
|
||||
} else if (sanitizedWorkType.includes("field")) {
|
||||
if (!factionInfo.offerFieldWork) return false;
|
||||
factionWorkType = FactionWorkType.FIELD;
|
||||
factionWorkType = FactionWorkType.field;
|
||||
} else if (sanitizedWorkType.includes("security")) {
|
||||
if (!factionInfo.offerSecurityWork) return false;
|
||||
factionWorkType = FactionWorkType.SECURITY;
|
||||
factionWorkType = FactionWorkType.security;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -372,16 +372,16 @@ export class Sleeve extends Person implements ISleeve {
|
||||
// set stat to a default value.
|
||||
let classType: ClassType | undefined;
|
||||
if (sanitizedStat.includes("str")) {
|
||||
classType = ClassType.GymStrength;
|
||||
classType = GymType.strength;
|
||||
}
|
||||
if (sanitizedStat.includes("def")) {
|
||||
classType = ClassType.GymDefense;
|
||||
classType = GymType.defense;
|
||||
}
|
||||
if (sanitizedStat.includes("dex")) {
|
||||
classType = ClassType.GymDexterity;
|
||||
classType = GymType.dexterity;
|
||||
}
|
||||
if (sanitizedStat.includes("agi")) {
|
||||
classType = ClassType.GymAgility;
|
||||
classType = GymType.agility;
|
||||
}
|
||||
// if stat is still equals its default value, then validation has failed.
|
||||
if (!classType) return false;
|
||||
|
||||
@@ -5,6 +5,8 @@ import { LocationName } from "../../../Locations/data/LocationNames";
|
||||
import { calculateClassEarnings } from "../../../Work/Formulas";
|
||||
import { Sleeve } from "../Sleeve";
|
||||
import { scaleWorkStats, WorkStats } from "../../../Work/WorkStats";
|
||||
import { GymType, UniversityClassType } from "../../../utils/enums";
|
||||
import { checkEnum } from "../../../utils/helpers/enum";
|
||||
|
||||
export const isSleeveClassWork = (w: Work | null): w is SleeveClassWork => w !== null && w.type === WorkType.CLASS;
|
||||
|
||||
@@ -19,7 +21,7 @@ export class SleeveClassWork extends Work {
|
||||
|
||||
constructor(params?: ClassWorkParams) {
|
||||
super(WorkType.CLASS);
|
||||
this.classType = params?.classType ?? ClassType.StudyComputerScience;
|
||||
this.classType = params?.classType ?? UniversityClassType.computerScience;
|
||||
this.location = params?.location ?? LocationName.Sector12RothmanUniversity;
|
||||
}
|
||||
|
||||
@@ -28,9 +30,7 @@ export class SleeveClassWork extends Work {
|
||||
}
|
||||
|
||||
isGym(): boolean {
|
||||
return [ClassType.GymAgility, ClassType.GymDefense, ClassType.GymDexterity, ClassType.GymStrength].includes(
|
||||
this.classType,
|
||||
);
|
||||
return checkEnum(GymType, this.classType);
|
||||
}
|
||||
|
||||
process(sleeve: Sleeve, cycles: number) {
|
||||
|
||||
@@ -2,13 +2,14 @@ import { Player } from "@player";
|
||||
import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../../../utils/JSONReviver";
|
||||
import { Sleeve } from "../Sleeve";
|
||||
import { applySleeveGains, Work, WorkType } from "./Work";
|
||||
import { CrimeType } from "../../../utils/WorkType";
|
||||
import { CrimeType } from "../../../utils/enums";
|
||||
import { Crimes } from "../../../Crime/Crimes";
|
||||
import { Crime } from "../../../Crime/Crime";
|
||||
import { scaleWorkStats, WorkStats } from "../../../Work/WorkStats";
|
||||
import { CONSTANTS } from "../../../Constants";
|
||||
import { checkEnum } from "../../../utils/helpers/checkEnum";
|
||||
import { checkEnum } from "../../../utils/helpers/enum";
|
||||
import { calculateCrimeWorkStats } from "../../../Work/Formulas";
|
||||
import { findCrime } from "../../../Crime/CrimeHelpers";
|
||||
|
||||
export const isSleeveCrimeWork = (w: Work | null): w is SleeveCrimeWork => w !== null && w.type === WorkType.CRIME;
|
||||
|
||||
@@ -17,7 +18,7 @@ export class SleeveCrimeWork extends Work {
|
||||
cyclesWorked = 0;
|
||||
constructor(crimeType?: CrimeType) {
|
||||
super(WorkType.CRIME);
|
||||
this.crimeType = crimeType ?? CrimeType.SHOPLIFT;
|
||||
this.crimeType = crimeType ?? CrimeType.shoplift;
|
||||
}
|
||||
|
||||
getCrime(): Crime {
|
||||
@@ -60,7 +61,9 @@ export class SleeveCrimeWork extends Work {
|
||||
|
||||
/** Initializes a RecoveryWork object from a JSON save state. */
|
||||
static fromJSON(value: IReviverValue): SleeveCrimeWork {
|
||||
return Generic_fromJSON(SleeveCrimeWork, value.data);
|
||||
const crimeWork = Generic_fromJSON(SleeveCrimeWork, value.data);
|
||||
crimeWork.crimeType = findCrime(crimeWork.crimeType)?.type ?? CrimeType.shoplift;
|
||||
return crimeWork;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Player } from "@player";
|
||||
import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../../../utils/JSONReviver";
|
||||
import { Sleeve } from "../Sleeve";
|
||||
import { applySleeveGains, Work, WorkType } from "./Work";
|
||||
import { FactionWorkType } from "../../../Work/data/FactionWorkType";
|
||||
import { FactionWorkType } from "../../../utils/enums";
|
||||
import { FactionNames } from "../../../Faction/data/FactionNames";
|
||||
import { Factions } from "../../../Faction/Factions";
|
||||
import { calculateFactionExp, calculateFactionRep } from "../../../Work/Formulas";
|
||||
@@ -23,7 +23,7 @@ export class SleeveFactionWork extends Work {
|
||||
|
||||
constructor(params?: SleeveFactionWorkParams) {
|
||||
super(WorkType.FACTION);
|
||||
this.factionWorkType = params?.factionWorkType ?? FactionWorkType.HACKING;
|
||||
this.factionWorkType = params?.factionWorkType ?? FactionWorkType.hacking;
|
||||
this.factionName = params?.factionName ?? FactionNames.Sector12;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Box, Button, Paper, Tooltip, Typography } from "@mui/material";
|
||||
import React, { useState } from "react";
|
||||
import { FactionWorkType } from "../../../Work/data/FactionWorkType";
|
||||
import { FactionWorkType } from "../../../utils/enums";
|
||||
import { CONSTANTS } from "../../../Constants";
|
||||
import { Player } from "@player";
|
||||
import { numeralWrapper } from "../../../ui/numeralFormat";
|
||||
@@ -21,7 +21,7 @@ import { isSleeveSupportWork } from "../Work/SleeveSupportWork";
|
||||
import { isSleeveBladeburnerWork } from "../Work/SleeveBladeburnerWork";
|
||||
import { isSleeveCrimeWork } from "../Work/SleeveCrimeWork";
|
||||
import { findCrime } from "../../../Crime/CrimeHelpers";
|
||||
import { CrimeType } from "../../../utils/WorkType";
|
||||
import { CrimeType } from "../../../utils/enums";
|
||||
|
||||
interface IProps {
|
||||
sleeve: Sleeve;
|
||||
@@ -46,7 +46,7 @@ export function SleeveElem(props: IProps): React.ReactElement {
|
||||
props.sleeve.workForFaction(abc[1], abc[2]);
|
||||
break;
|
||||
case "Commit Crime":
|
||||
props.sleeve.commitCrime(findCrime(abc[1])?.type ?? CrimeType.SHOPLIFT);
|
||||
props.sleeve.commitCrime(findCrime(abc[1])?.type ?? CrimeType.shoplift);
|
||||
break;
|
||||
case "Take University Course":
|
||||
props.sleeve.takeUniversityCourse(abc[2], abc[1]);
|
||||
@@ -106,13 +106,13 @@ export function SleeveElem(props: IProps): React.ReactElement {
|
||||
if (isSleeveFactionWork(props.sleeve.currentWork)) {
|
||||
let doing = "nothing";
|
||||
switch (props.sleeve.currentWork.factionWorkType) {
|
||||
case FactionWorkType.FIELD:
|
||||
case FactionWorkType.field:
|
||||
doing = "Field work";
|
||||
break;
|
||||
case FactionWorkType.HACKING:
|
||||
case FactionWorkType.hacking:
|
||||
doing = "Hacking contracts";
|
||||
break;
|
||||
case FactionWorkType.SECURITY:
|
||||
case FactionWorkType.security:
|
||||
doing = "Security work";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -16,11 +16,9 @@ import { isSleeveSynchroWork } from "../Work/SleeveSynchroWork";
|
||||
import { isSleeveClassWork } from "../Work/SleeveClassWork";
|
||||
import { isSleeveInfiltrateWork } from "../Work/SleeveInfiltrateWork";
|
||||
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";
|
||||
import { CrimeType, FactionWorkType, GymType, UniversityClassType } from "../../../utils/enums";
|
||||
import { checkEnum } from "../../../utils/helpers/enum";
|
||||
|
||||
const universitySelectorOptions: string[] = [
|
||||
"Study Computer Science",
|
||||
@@ -167,7 +165,7 @@ const tasks: {
|
||||
};
|
||||
},
|
||||
"Commit Crime": (): ITaskDetails => {
|
||||
return { first: Object.values(Crimes).map((crime) => crime.name), second: () => ["------"] };
|
||||
return { first: Object.keys(Crimes), second: () => ["------"] };
|
||||
},
|
||||
"Take University Course": (sleeve: Sleeve): ITaskDetails => {
|
||||
let universities: string[] = [];
|
||||
@@ -263,13 +261,13 @@ function getABC(sleeve: Sleeve): [string, string, string] {
|
||||
if (isSleeveFactionWork(w)) {
|
||||
let workType = "";
|
||||
switch (w.factionWorkType) {
|
||||
case FactionWorkType.HACKING:
|
||||
case FactionWorkType.hacking:
|
||||
workType = "Hacking Contracts";
|
||||
break;
|
||||
case FactionWorkType.FIELD:
|
||||
case FactionWorkType.field:
|
||||
workType = "Field Work";
|
||||
break;
|
||||
case FactionWorkType.SECURITY:
|
||||
case FactionWorkType.security:
|
||||
workType = "Security Work";
|
||||
break;
|
||||
}
|
||||
@@ -293,30 +291,30 @@ function getABC(sleeve: Sleeve): [string, string, string] {
|
||||
|
||||
if (isSleeveClassWork(w)) {
|
||||
switch (w.classType) {
|
||||
case ClassType.StudyComputerScience:
|
||||
case UniversityClassType.computerScience:
|
||||
return ["Take University Course", "Study Computer Science", w.location];
|
||||
case ClassType.DataStructures:
|
||||
case UniversityClassType.dataStructures:
|
||||
return ["Take University Course", "Data Structures", w.location];
|
||||
case ClassType.Networks:
|
||||
case UniversityClassType.networks:
|
||||
return ["Take University Course", "Networks", w.location];
|
||||
case ClassType.Algorithms:
|
||||
case UniversityClassType.algorithms:
|
||||
return ["Take University Course", "Algorithms", w.location];
|
||||
case ClassType.Management:
|
||||
case UniversityClassType.management:
|
||||
return ["Take University Course", "Management", w.location];
|
||||
case ClassType.Leadership:
|
||||
case UniversityClassType.leadership:
|
||||
return ["Take University Course", "Leadership", w.location];
|
||||
case ClassType.GymStrength:
|
||||
case GymType.strength:
|
||||
return ["Workout at Gym", "Train Strength", w.location];
|
||||
case ClassType.GymDefense:
|
||||
case GymType.defense:
|
||||
return ["Workout at Gym", "Train Defense", w.location];
|
||||
case ClassType.GymDexterity:
|
||||
case GymType.dexterity:
|
||||
return ["Workout at Gym", "Train Dexterity", w.location];
|
||||
case ClassType.GymAgility:
|
||||
case GymType.agility:
|
||||
return ["Workout at Gym", "Train Agility", w.location];
|
||||
}
|
||||
}
|
||||
if (isSleeveCrimeWork(w)) {
|
||||
return ["Commit Crime", checkEnum(CrimeType, w.crimeType) ? Crimes[w.crimeType].name : "Shoplift", "------"];
|
||||
return ["Commit Crime", checkEnum(CrimeType, w.crimeType) ? w.crimeType : "Shoplift", "------"];
|
||||
}
|
||||
if (isSleeveSupportWork(w)) {
|
||||
return ["Perform Bladeburner Actions", "Support main sleeve", "------"];
|
||||
|
||||
Reference in New Issue
Block a user