mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-08 00:27:47 +02:00
TYPESAFETY: FactionName (#644)
This commit is contained in:
@@ -292,38 +292,31 @@ export class Sleeve extends Person implements SleevePerson {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start work for one of the player's factions
|
||||
* Returns boolean indicating success
|
||||
*/
|
||||
workForFaction(factionName: string, workType: string): boolean {
|
||||
/** TODO 2.4: Make this take in type correct data */
|
||||
workForFaction(_factionName: string, _workType: string): boolean {
|
||||
const factionName = getEnumHelper("FactionName").fuzzyGetMember(_factionName);
|
||||
if (!factionName) return false;
|
||||
const faction = Factions[factionName];
|
||||
if (factionName === "" || !faction || !Player.factions.includes(factionName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const workType = getEnumHelper("FactionWorkType").fuzzyGetMember(_workType);
|
||||
if (!workType) return false;
|
||||
const factionInfo = faction.getInfo();
|
||||
|
||||
// Set type of work (hacking/field/security), and the experience gains
|
||||
const sanitizedWorkType = workType.toLowerCase();
|
||||
let factionWorkType: FactionWorkType;
|
||||
if (sanitizedWorkType.includes("hack")) {
|
||||
if (!factionInfo.offerHackingWork) return false;
|
||||
factionWorkType = FactionWorkType.hacking;
|
||||
} else if (sanitizedWorkType.includes("field")) {
|
||||
if (!factionInfo.offerFieldWork) return false;
|
||||
factionWorkType = FactionWorkType.field;
|
||||
} else if (sanitizedWorkType.includes("security")) {
|
||||
if (!factionInfo.offerSecurityWork) return false;
|
||||
factionWorkType = FactionWorkType.security;
|
||||
} else {
|
||||
return false;
|
||||
switch (workType) {
|
||||
case FactionWorkType.field:
|
||||
if (!factionInfo.offerFieldWork) return false;
|
||||
break;
|
||||
case FactionWorkType.hacking:
|
||||
if (!factionInfo.offerHackingWork) return false;
|
||||
break;
|
||||
case FactionWorkType.security:
|
||||
if (!factionInfo.offerSecurityWork) return false;
|
||||
break;
|
||||
}
|
||||
|
||||
this.startWork(
|
||||
new SleeveFactionWork({
|
||||
factionWorkType: factionWorkType,
|
||||
factionName: faction.name,
|
||||
factionWorkType: workType,
|
||||
factionName: factionName,
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -7,11 +7,11 @@ import { Factions } from "../../../Faction/Factions";
|
||||
import { calculateFactionExp, calculateFactionRep } from "../../../Work/Formulas";
|
||||
import { Faction } from "../../../Faction/Faction";
|
||||
import { scaleWorkStats, WorkStats } from "../../../Work/WorkStats";
|
||||
import { findEnumMember } from "../../../utils/helpers/enum";
|
||||
import { getEnumHelper } from "../../../utils/EnumHelper";
|
||||
|
||||
interface SleeveFactionWorkParams {
|
||||
factionWorkType: FactionWorkType;
|
||||
factionName: string;
|
||||
factionName: FactionName;
|
||||
}
|
||||
|
||||
export const isSleeveFactionWork = (w: SleeveWorkClass | null): w is SleeveFactionWork =>
|
||||
@@ -20,7 +20,7 @@ export const isSleeveFactionWork = (w: SleeveWorkClass | null): w is SleeveFacti
|
||||
export class SleeveFactionWork extends SleeveWorkClass {
|
||||
type: SleeveWorkType.FACTION = SleeveWorkType.FACTION;
|
||||
factionWorkType: FactionWorkType;
|
||||
factionName: string;
|
||||
factionName: FactionName;
|
||||
|
||||
constructor(params?: SleeveFactionWorkParams) {
|
||||
super();
|
||||
@@ -67,8 +67,8 @@ export class SleeveFactionWork extends SleeveWorkClass {
|
||||
/** Initializes a FactionWork object from a JSON save state. */
|
||||
static fromJSON(value: IReviverValue): SleeveFactionWork {
|
||||
const factionWork = Generic_fromJSON(SleeveFactionWork, value.data);
|
||||
factionWork.factionWorkType =
|
||||
findEnumMember(FactionWorkType, factionWork.factionWorkType) ?? FactionWorkType.hacking;
|
||||
factionWork.factionWorkType = getEnumHelper("FactionWorkType").fuzzyGetMember(factionWork.factionWorkType, true);
|
||||
factionWork.factionName = getEnumHelper("FactionName").fuzzyGetMember(factionWork.factionName, true);
|
||||
return factionWork;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,10 +137,9 @@ const tasks: {
|
||||
|
||||
return {
|
||||
first: factions,
|
||||
second: (s1: string) => {
|
||||
second: (s1) => {
|
||||
if (!getEnumHelper("FactionName").isMember(s1)) return ["------"];
|
||||
const faction = Factions[s1];
|
||||
if (!faction) return ["------"];
|
||||
|
||||
const facInfo = faction.getInfo();
|
||||
const options: string[] = [];
|
||||
if (facInfo.offerHackingWork) {
|
||||
|
||||
Reference in New Issue
Block a user