Init work types with new None member

This commit is contained in:
nickofolas 2022-05-04 15:03:02 -05:00
parent 59982370cb
commit 7d75093989
6 changed files with 39 additions and 37 deletions

@ -391,12 +391,10 @@ export const achievements: IMap<Achievement> = {
WORKOUT: { WORKOUT: {
...achievementData["WORKOUT"], ...achievementData["WORKOUT"],
Icon: "WORKOUT", Icon: "WORKOUT",
Condition: () => { Condition: () =>
if (Player.className === null) return false; [ClassType.GymStrength, ClassType.GymDefense, ClassType.GymDexterity, ClassType.GymAgility].includes(
return [ClassType.GymStrength, ClassType.GymDefense, ClassType.GymDexterity, ClassType.GymAgility].includes(
Player.className, Player.className,
); ),
},
}, },
TOR: { TOR: {
...achievementData["TOR"], ...achievementData["TOR"],

@ -2460,7 +2460,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
crime_money_mult: Player.crime_money_mult, crime_money_mult: Player.crime_money_mult,
crime_success_mult: Player.crime_success_mult, crime_success_mult: Player.crime_success_mult,
isWorking: Player.isWorking, isWorking: Player.isWorking,
workType: Player.workType ?? "", // Avoids breaking scripts that for some reason rely on this workType: Player.workType,
currentWorkFactionName: Player.currentWorkFactionName, currentWorkFactionName: Player.currentWorkFactionName,
currentWorkFactionDescription: Player.currentWorkFactionDescription, currentWorkFactionDescription: Player.currentWorkFactionDescription,
workHackExpGainRate: Player.workHackExpGainRate, workHackExpGainRate: Player.workHackExpGainRate,
@ -2482,8 +2482,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
workMoneyGained: Player.workMoneyGained, workMoneyGained: Player.workMoneyGained,
createProgramName: Player.createProgramName, createProgramName: Player.createProgramName,
createProgramReqLvl: Player.createProgramReqLvl, createProgramReqLvl: Player.createProgramReqLvl,
className: Player.className ?? "", // ditto className: Player.className,
crimeType: Player.crimeType ?? "", // ditto (*2) crimeType: Player.crimeType,
work_money_mult: Player.work_money_mult, work_money_mult: Player.work_money_mult,
hacknet_node_money_mult: Player.hacknet_node_money_mult, hacknet_node_money_mult: Player.hacknet_node_money_mult,
hacknet_node_purchase_cost_mult: Player.hacknet_node_purchase_cost_mult, hacknet_node_purchase_cost_mult: Player.hacknet_node_purchase_cost_mult,

@ -131,14 +131,14 @@ export interface IPlayer {
timeWorkedCreateProgram: number; timeWorkedCreateProgram: number;
graftAugmentationName: string; graftAugmentationName: string;
timeWorkedGraftAugmentation: number; timeWorkedGraftAugmentation: number;
crimeType: CrimeType | null; crimeType: CrimeType;
committingCrimeThruSingFn: boolean; committingCrimeThruSingFn: boolean;
singFnCrimeWorkerScript: WorkerScript | null; singFnCrimeWorkerScript: WorkerScript | null;
timeNeededToCompleteWork: number; timeNeededToCompleteWork: number;
focus: boolean; focus: boolean;
className: ClassType | null; className: ClassType;
currentWorkFactionName: string; currentWorkFactionName: string;
workType: WorkType | null; workType: WorkType;
workCostMult: number; workCostMult: number;
workExpMult: number; workExpMult: number;
currentWorkFactionDescription: string; currentWorkFactionDescription: string;

@ -38,7 +38,7 @@ import { PlayerAchievement } from "../../Achievements/Achievements";
import { cyrb53 } from "../../utils/StringHelperFunctions"; import { cyrb53 } from "../../utils/StringHelperFunctions";
import { getRandomInt } from "../../utils/helpers/getRandomInt"; import { getRandomInt } from "../../utils/helpers/getRandomInt";
import { CONSTANTS } from "../../Constants"; import { CONSTANTS } from "../../Constants";
import { WorkType, ClassType, CrimeType } from "../../utils/WorkType"; import { WorkType, ClassType, CrimeType, PlayerFactionWorkType } from "../../utils/WorkType";
export class PlayerObject implements IPlayer { export class PlayerObject implements IPlayer {
// Class members // Class members
@ -136,19 +136,19 @@ export class PlayerObject implements IPlayer {
bladeburner_success_chance_mult: number; bladeburner_success_chance_mult: number;
createProgramReqLvl: number; createProgramReqLvl: number;
factionWorkType: string; factionWorkType: PlayerFactionWorkType;
createProgramName: string; createProgramName: string;
timeWorkedCreateProgram: number; timeWorkedCreateProgram: number;
graftAugmentationName: string; graftAugmentationName: string;
timeWorkedGraftAugmentation: number; timeWorkedGraftAugmentation: number;
crimeType: CrimeType | null; crimeType: CrimeType;
committingCrimeThruSingFn: boolean; committingCrimeThruSingFn: boolean;
singFnCrimeWorkerScript: WorkerScript | null; singFnCrimeWorkerScript: WorkerScript | null;
timeNeededToCompleteWork: number; timeNeededToCompleteWork: number;
focus: boolean; focus: boolean;
className: ClassType | null; className: ClassType;
currentWorkFactionName: string; currentWorkFactionName: string;
workType: WorkType | null; workType: WorkType;
workCostMult: number; workCostMult: number;
workExpMult: number; workExpMult: number;
currentWorkFactionDescription: string; currentWorkFactionDescription: string;
@ -399,7 +399,7 @@ export class PlayerObject implements IPlayer {
//Flags/variables for working (Company, Faction, Creating Program, Taking Class) //Flags/variables for working (Company, Faction, Creating Program, Taking Class)
this.isWorking = false; this.isWorking = false;
this.focus = false; this.focus = false;
this.workType = null; this.workType = WorkType.None;
this.workCostMult = 1; this.workCostMult = 1;
this.workExpMult = 1; this.workExpMult = 1;
@ -431,9 +431,9 @@ export class PlayerObject implements IPlayer {
this.graftAugmentationName = ""; this.graftAugmentationName = "";
this.timeWorkedGraftAugmentation = 0; this.timeWorkedGraftAugmentation = 0;
this.className = null; this.className = ClassType.None;
this.crimeType = null; this.crimeType = CrimeType.None;
this.timeWorked = 0; //in m; this.timeWorked = 0; //in m;
this.timeWorkedCreateProgram = 0; this.timeWorkedCreateProgram = 0;
@ -619,7 +619,7 @@ export class PlayerObject implements IPlayer {
this.getUpgradeHomeRamCost = serverMethods.getUpgradeHomeRamCost; this.getUpgradeHomeRamCost = serverMethods.getUpgradeHomeRamCost;
this.getUpgradeHomeCoresCost = serverMethods.getUpgradeHomeCoresCost; this.getUpgradeHomeCoresCost = serverMethods.getUpgradeHomeCoresCost;
this.createHacknetServer = serverMethods.createHacknetServer; this.createHacknetServer = serverMethods.createHacknetServer;
this.factionWorkType = ""; this.factionWorkType = PlayerFactionWorkType.None;
this.committingCrimeThruSingFn = false; this.committingCrimeThruSingFn = false;
this.singFnCrimeWorkerScript = null; this.singFnCrimeWorkerScript = null;

@ -66,7 +66,7 @@ import { achievements } from "../../Achievements/Achievements";
import { FactionNames } from "../../Faction/data/FactionNames"; import { FactionNames } from "../../Faction/data/FactionNames";
import { graftingIntBonus } from "../Grafting/GraftingHelpers"; import { graftingIntBonus } from "../Grafting/GraftingHelpers";
import { WorkType, FactionWorkType, ClassType, CrimeType } from "../../utils/WorkType"; import { WorkType, PlayerFactionWorkType, ClassType, CrimeType } from "../../utils/WorkType";
export function init(this: IPlayer): void { export function init(this: IPlayer): void {
/* Initialize Player's home computer */ /* Initialize Player's home computer */
@ -142,8 +142,8 @@ export function prestigeAugmentation(this: PlayerObject): void {
this.currentWorkFactionName = ""; this.currentWorkFactionName = "";
this.currentWorkFactionDescription = ""; this.currentWorkFactionDescription = "";
this.createProgramName = ""; this.createProgramName = "";
this.className = null; this.className = ClassType.None;
this.crimeType = null; this.crimeType = CrimeType.None;
this.workHackExpGainRate = 0; this.workHackExpGainRate = 0;
this.workStrExpGainRate = 0; this.workStrExpGainRate = 0;
@ -534,8 +534,8 @@ export function resetWorkStatus(this: IPlayer, generalType?: WorkType, group?: s
this.currentWorkFactionDescription = ""; this.currentWorkFactionDescription = "";
this.createProgramName = ""; this.createProgramName = "";
this.graftAugmentationName = ""; this.graftAugmentationName = "";
this.className = null; this.className = ClassType.None;
this.workType = null; this.workType = WorkType.None;
} }
export function processWorkEarnings(this: IPlayer, numCycles = 1): void { export function processWorkEarnings(this: IPlayer, numCycles = 1): void {
@ -889,19 +889,19 @@ export function startFactionWork(this: IPlayer, faction: Faction): void {
} }
export function startFactionHackWork(this: IPlayer, faction: Faction): void { export function startFactionHackWork(this: IPlayer, faction: Faction): void {
this.resetWorkStatus(WorkType.Faction, faction.name, FactionWorkType.Hacking); this.resetWorkStatus(WorkType.Faction, faction.name, PlayerFactionWorkType.Hacking);
this.workHackExpGainRate = 0.15 * this.hacking_exp_mult * BitNodeMultipliers.FactionWorkExpGain; this.workHackExpGainRate = 0.15 * this.hacking_exp_mult * BitNodeMultipliers.FactionWorkExpGain;
this.workRepGainRate = getHackingWorkRepGain(this, faction); this.workRepGainRate = getHackingWorkRepGain(this, faction);
this.factionWorkType = FactionWorkType.Hacking; this.factionWorkType = PlayerFactionWorkType.Hacking;
this.currentWorkFactionDescription = "carrying out hacking contracts"; this.currentWorkFactionDescription = "carrying out hacking contracts";
this.startFactionWork(faction); this.startFactionWork(faction);
} }
export function startFactionFieldWork(this: IPlayer, faction: Faction): void { export function startFactionFieldWork(this: IPlayer, faction: Faction): void {
this.resetWorkStatus(WorkType.Faction, faction.name, FactionWorkType.Field); this.resetWorkStatus(WorkType.Faction, faction.name, PlayerFactionWorkType.Field);
this.workHackExpGainRate = 0.1 * this.hacking_exp_mult * BitNodeMultipliers.FactionWorkExpGain; this.workHackExpGainRate = 0.1 * this.hacking_exp_mult * BitNodeMultipliers.FactionWorkExpGain;
this.workStrExpGainRate = 0.1 * this.strength_exp_mult * BitNodeMultipliers.FactionWorkExpGain; this.workStrExpGainRate = 0.1 * this.strength_exp_mult * BitNodeMultipliers.FactionWorkExpGain;
@ -911,14 +911,14 @@ export function startFactionFieldWork(this: IPlayer, faction: Faction): void {
this.workChaExpGainRate = 0.1 * this.charisma_exp_mult * BitNodeMultipliers.FactionWorkExpGain; this.workChaExpGainRate = 0.1 * this.charisma_exp_mult * BitNodeMultipliers.FactionWorkExpGain;
this.workRepGainRate = getFactionFieldWorkRepGain(this, faction); this.workRepGainRate = getFactionFieldWorkRepGain(this, faction);
this.factionWorkType = FactionWorkType.Field; this.factionWorkType = PlayerFactionWorkType.Field;
this.currentWorkFactionDescription = "carrying out field missions"; this.currentWorkFactionDescription = "carrying out field missions";
this.startFactionWork(faction); this.startFactionWork(faction);
} }
export function startFactionSecurityWork(this: IPlayer, faction: Faction): void { export function startFactionSecurityWork(this: IPlayer, faction: Faction): void {
this.resetWorkStatus(WorkType.Faction, faction.name, FactionWorkType.Security); this.resetWorkStatus(WorkType.Faction, faction.name, PlayerFactionWorkType.Security);
this.workHackExpGainRate = 0.05 * this.hacking_exp_mult * BitNodeMultipliers.FactionWorkExpGain; this.workHackExpGainRate = 0.05 * this.hacking_exp_mult * BitNodeMultipliers.FactionWorkExpGain;
this.workStrExpGainRate = 0.15 * this.strength_exp_mult * BitNodeMultipliers.FactionWorkExpGain; this.workStrExpGainRate = 0.15 * this.strength_exp_mult * BitNodeMultipliers.FactionWorkExpGain;
@ -928,7 +928,7 @@ export function startFactionSecurityWork(this: IPlayer, faction: Faction): void
this.workChaExpGainRate = 0.0 * this.charisma_exp_mult * BitNodeMultipliers.FactionWorkExpGain; this.workChaExpGainRate = 0.0 * this.charisma_exp_mult * BitNodeMultipliers.FactionWorkExpGain;
this.workRepGainRate = getFactionSecurityWorkRepGain(this, faction); this.workRepGainRate = getFactionSecurityWorkRepGain(this, faction);
this.factionWorkType = FactionWorkType.Security; this.factionWorkType = PlayerFactionWorkType.Security;
this.currentWorkFactionDescription = "performing security detail"; this.currentWorkFactionDescription = "performing security detail";
this.startFactionWork(faction); this.startFactionWork(faction);
@ -943,13 +943,13 @@ export function workForFaction(this: IPlayer, numCycles: number): boolean {
//Constantly update the rep gain rate //Constantly update the rep gain rate
switch (this.factionWorkType) { switch (this.factionWorkType) {
case FactionWorkType.Hacking: case PlayerFactionWorkType.Hacking:
this.workRepGainRate = getHackingWorkRepGain(this, faction); this.workRepGainRate = getHackingWorkRepGain(this, faction);
break; break;
case FactionWorkType.Field: case PlayerFactionWorkType.Field:
this.workRepGainRate = getFactionFieldWorkRepGain(this, faction); this.workRepGainRate = getFactionFieldWorkRepGain(this, faction);
break; break;
case FactionWorkType.Security: case PlayerFactionWorkType.Security:
this.workRepGainRate = getFactionSecurityWorkRepGain(this, faction); this.workRepGainRate = getFactionSecurityWorkRepGain(this, faction);
break; break;
default: default:
@ -1536,7 +1536,7 @@ export function commitCrime(this: IPlayer, numCycles: number): boolean {
export function finishCrime(this: IPlayer, cancelled: boolean): string { export function finishCrime(this: IPlayer, cancelled: boolean): string {
//Determine crime success/failure //Determine crime success/failure
if (!cancelled) { if (!cancelled) {
if (determineCrimeSuccess(this, this.crimeType ?? "")) { if (determineCrimeSuccess(this, this.crimeType)) {
//Handle Karma and crime statistics //Handle Karma and crime statistics
let crime = null; let crime = null;
for (const i of Object.keys(Crimes)) { for (const i of Object.keys(Crimes)) {
@ -1669,7 +1669,7 @@ export function finishCrime(this: IPlayer, cancelled: boolean): string {
this.committingCrimeThruSingFn = false; this.committingCrimeThruSingFn = false;
this.singFnCrimeWorkerScript = null; this.singFnCrimeWorkerScript = null;
this.isWorking = false; this.isWorking = false;
this.crimeType = null; this.crimeType = CrimeType.None;
this.resetWorkStatus(); this.resetWorkStatus();
return ""; return "";
} }

@ -1,4 +1,5 @@
export enum WorkType { export enum WorkType {
None = "",
Company = "Working for Company", Company = "Working for Company",
CompanyPartTime = "Working for Company part-time", CompanyPartTime = "Working for Company part-time",
Faction = "Working for Faction", Faction = "Working for Faction",
@ -8,13 +9,15 @@ export enum WorkType {
GraftAugmentation = "Grafting an Augmentation", GraftAugmentation = "Grafting an Augmentation",
} }
export enum FactionWorkType { export enum PlayerFactionWorkType {
None = "",
Hacking = "Faction Hacking Work", Hacking = "Faction Hacking Work",
Field = "Faction Field Work", Field = "Faction Field Work",
Security = "Faction Security Work", Security = "Faction Security Work",
} }
export enum ClassType { export enum ClassType {
None = "",
StudyComputerScience = "studying Computer Science", StudyComputerScience = "studying Computer Science",
DataStructures = "taking a Data Structures course", DataStructures = "taking a Data Structures course",
Networks = "taking a Networks course", Networks = "taking a Networks course",
@ -30,6 +33,7 @@ export enum ClassType {
} }
export enum CrimeType { export enum CrimeType {
None = "",
Shoplift = "shoplift", Shoplift = "shoplift",
RobStore = "rob a store", RobStore = "rob a store",
Mug = "mug someone", Mug = "mug someone",