diff --git a/src/Augmentation/AugmentationHelpers.tsx b/src/Augmentation/AugmentationHelpers.tsx
index c388356f6..bdfebe870 100644
--- a/src/Augmentation/AugmentationHelpers.tsx
+++ b/src/Augmentation/AugmentationHelpers.tsx
@@ -1,6 +1,6 @@
import { Augmentation } from "./Augmentation";
import { StaticAugmentations } from "./StaticAugmentations";
-import { PlayerOwnedAugmentation, IPlayerOwnedAugmentation } from "./PlayerOwnedAugmentation";
+import { PlayerOwnedAugmentation } from "./PlayerOwnedAugmentation";
import { AugmentationNames } from "./data/AugmentationNames";
import { CONSTANTS } from "../Constants";
@@ -71,7 +71,7 @@ function resetAugmentation(aug: Augmentation): void {
AddToStaticAugmentations(aug);
}
-function applyAugmentation(aug: IPlayerOwnedAugmentation, reapply = false): void {
+function applyAugmentation(aug: PlayerOwnedAugmentation, reapply = false): void {
const staticAugmentation = StaticAugmentations[aug.name];
// Apply multipliers
@@ -146,8 +146,8 @@ function augmentationExists(name: string): boolean {
return StaticAugmentations.hasOwnProperty(name);
}
-export function isRepeatableAug(aug: Augmentation): boolean {
- const augName = aug instanceof Augmentation ? aug.name : aug;
+export function isRepeatableAug(aug: Augmentation | string): boolean {
+ const augName = typeof aug === "string" ? aug : aug.name;
return augName === AugmentationNames.NeuroFluxGovernor;
}
diff --git a/src/Augmentation/PlayerOwnedAugmentation.ts b/src/Augmentation/PlayerOwnedAugmentation.ts
index e8807b894..b762b2e41 100644
--- a/src/Augmentation/PlayerOwnedAugmentation.ts
+++ b/src/Augmentation/PlayerOwnedAugmentation.ts
@@ -6,8 +6,3 @@ export class PlayerOwnedAugmentation {
this.name = name;
}
}
-
-export interface IPlayerOwnedAugmentation {
- level: number;
- name: string;
-}
diff --git a/src/Augmentation/ui/PurchaseAugmentationModal.tsx b/src/Augmentation/ui/PurchaseAugmentationModal.tsx
index 20990efb7..c719efee6 100644
--- a/src/Augmentation/ui/PurchaseAugmentationModal.tsx
+++ b/src/Augmentation/ui/PurchaseAugmentationModal.tsx
@@ -18,12 +18,12 @@ interface IProps {
}
export function PurchaseAugmentationModal(props: IProps): React.ReactElement {
- if (typeof props.aug === "undefined" || typeof props.faction === "undefined") {
+ if (!props.aug || !props.faction) {
return <>>;
}
function buy(): void {
- if (!isRepeatableAug(props.aug as Augmentation) && Player.hasAugmentation(props.aug as Augmentation)) {
+ if (!props.aug || (!isRepeatableAug(props.aug) && Player.hasAugmentation(props.aug.name))) {
return;
}
diff --git a/src/Bladeburner/Bladeburner.tsx b/src/Bladeburner/Bladeburner.tsx
index 1c88a4678..00cef4634 100644
--- a/src/Bladeburner/Bladeburner.tsx
+++ b/src/Bladeburner/Bladeburner.tsx
@@ -23,7 +23,6 @@ import { BladeburnerConstants } from "./data/Constants";
import { numeralWrapper } from "../ui/numeralFormat";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { addOffset } from "../utils/helpers/addOffset";
-import { Faction } from "../Faction/Faction";
import { Factions, factionExists } from "../Faction/Factions";
import { calculateHospitalizationCost } from "../Hospital/Hospital";
import { dialogBoxCreate } from "../ui/React/DialogBox";
@@ -113,9 +112,7 @@ export class Bladeburner {
getCurrentCity(): City {
const city = this.cities[this.city];
- if (!(city instanceof City)) {
- throw new Error("Bladeburner.getCurrentCity() did not properly return a City object");
- }
+ if (!city) throw new Error("Invalid city in Bladeburner.getCurrentCity()");
return city;
}
@@ -541,7 +538,7 @@ export class Bladeburner {
case 3: {
const skillName = args[2];
const skill = Skills[skillName];
- if (skill == null || !(skill instanceof Skill)) {
+ if (!skill) {
this.postToConsole("Invalid skill name (Note that it is case-sensitive): " + skillName);
break;
}
@@ -683,10 +680,7 @@ export class Bladeburner {
".",
);
} else if (flag.toLowerCase().includes("en")) {
- if (
- !(this.automateActionLow instanceof ActionIdentifier) ||
- !(this.automateActionHigh instanceof ActionIdentifier)
- ) {
+ if (!this.automateActionLow || !this.automateActionHigh) {
return this.log("Failed to enable automation. Actions were not set");
}
this.automateEnabled = true;
@@ -897,9 +891,7 @@ export class Bladeburner {
// Choose random source/destination city for events
const sourceCityName = BladeburnerConstants.CityNames[getRandomInt(0, 5)];
const sourceCity = this.cities[sourceCityName];
- if (!(sourceCity instanceof City)) {
- throw new Error("sourceCity was not a City object in Bladeburner.randomEvent()");
- }
+ if (!sourceCity) throw new Error("Invalid sourceCity in Bladeburner.randomEvent()");
let destCityName = BladeburnerConstants.CityNames[getRandomInt(0, 5)];
while (destCityName === sourceCityName) {
@@ -907,9 +899,7 @@ export class Bladeburner {
}
const destCity = this.cities[destCityName];
- if (!(sourceCity instanceof City) || !(destCity instanceof City)) {
- throw new Error("sourceCity/destCity was not a City object in Bladeburner.randomEvent()");
- }
+ if (!sourceCity || !destCity) throw new Error("Invalid sourceCity or destCity in Bladeburner.randomEvent()");
if (chance <= 0.05) {
// New Synthoid Community, 5%
@@ -1621,7 +1611,7 @@ export class Bladeburner {
const bladeburnersFactionName = FactionNames.Bladeburners;
if (factionExists(bladeburnersFactionName)) {
const bladeburnerFac = Factions[bladeburnersFactionName];
- if (!(bladeburnerFac instanceof Faction)) {
+ if (!bladeburnerFac) {
throw new Error(
`Could not properly get ${FactionNames.Bladeburners} Faction object in ${FactionNames.Bladeburners} UI Overview Faction button`,
);
@@ -1650,7 +1640,7 @@ export class Bladeburner {
if (this.actionTimeToComplete <= 0) {
throw new Error(`Invalid actionTimeToComplete value: ${this.actionTimeToComplete}, type; ${this.action.type}`);
}
- if (!(this.action instanceof ActionIdentifier)) {
+ if (!this.action) {
throw new Error("Bladeburner.action is not an ActionIdentifier Object");
}
@@ -2018,9 +2008,7 @@ export class Bladeburner {
// Chaos goes down very slowly
for (const cityName of BladeburnerConstants.CityNames) {
const city = this.cities[cityName];
- if (!(city instanceof City)) {
- throw new Error("Invalid City object when processing passive chaos reduction in Bladeburner.process");
- }
+ if (!city) throw new Error("Invalid city when processing passive chaos reduction in Bladeburner.process");
city.chaos -= 0.0001 * seconds;
city.chaos = Math.max(0, city.chaos);
}
diff --git a/src/Company/Companies.ts b/src/Company/Companies.ts
index 0847795eb..7ad6d9d39 100644
--- a/src/Company/Companies.ts
+++ b/src/Company/Companies.ts
@@ -29,7 +29,7 @@ export function initCompanies(): void {
for (const companyName of Object.keys(Companies)) {
const company = Companies[companyName];
const oldCompany = oldCompanies[companyName];
- if (!(oldCompany instanceof Company)) {
+ if (!oldCompany) {
// New game, so no OldCompanies data
company.favor = 0;
} else {
diff --git a/src/Company/Company.ts b/src/Company/Company.ts
index 49473c6d4..492ed4ad3 100644
--- a/src/Company/Company.ts
+++ b/src/Company/Company.ts
@@ -88,11 +88,7 @@ export class Company {
}
hasPosition(pos: CompanyPosition | string): boolean {
- if (pos instanceof CompanyPosition) {
- return this.companyPositions[pos.name] != null;
- } else {
- return this.companyPositions[pos] != null;
- }
+ return this.companyPositions[typeof pos === "string" ? pos : pos.name] != null;
}
hasAgentPositions(): boolean {
diff --git a/src/Corporation/Actions.ts b/src/Corporation/Actions.ts
index 820017692..3b65654a7 100644
--- a/src/Corporation/Actions.ts
+++ b/src/Corporation/Actions.ts
@@ -361,7 +361,7 @@ export function ThrowParty(corp: Corporation, office: OfficeSpace, costPerEmploy
export function PurchaseWarehouse(corp: Corporation, division: Industry, city: string): void {
if (corp.funds < CorporationConstants.WarehouseInitialCost) return;
- if (division.warehouses[city] instanceof Warehouse) return;
+ if (division.warehouses[city]) return;
division.warehouses[city] = new Warehouse({
corp: corp,
industry: division,
@@ -439,7 +439,7 @@ export function MakeProduct(
designCost: designInvest,
advCost: marketingInvest,
});
- if (products[product.name] instanceof Product) {
+ if (products[product.name]) {
throw new Error(`You already have a product with this name!`);
}
@@ -470,10 +470,10 @@ export function Research(division: Industry, researchName: string): void {
for (let i = 0; i < CorporationConstants.Cities.length; ++i) {
const city = CorporationConstants.Cities[i];
const warehouse = division.warehouses[city];
- if (!(warehouse instanceof Warehouse)) {
+ if (!warehouse) {
continue;
}
- if (Player.corporation instanceof Corporation) {
+ if (Player.corporation) {
// Stores cycles in a "buffer". Processed separately using Engine Counters
warehouse.updateSize(Player.corporation, division);
}
diff --git a/src/Corporation/Corporation.tsx b/src/Corporation/Corporation.tsx
index edb3314e0..dacb5ea24 100644
--- a/src/Corporation/Corporation.tsx
+++ b/src/Corporation/Corporation.tsx
@@ -1,7 +1,6 @@
import { CorporationState } from "./CorporationState";
import { CorporationUnlockUpgrade, CorporationUnlockUpgrades } from "./data/CorporationUnlockUpgrades";
import { CorporationUpgrade, CorporationUpgrades } from "./data/CorporationUpgrades";
-import { Warehouse } from "./Warehouse";
import { CorporationConstants } from "./data/Constants";
import { Industry } from "./Industry";
@@ -331,7 +330,7 @@ export class Corporation {
for (const city of Object.keys(industry.warehouses)) {
const warehouse = industry.warehouses[city];
if (warehouse === 0) continue;
- if (industry.warehouses.hasOwnProperty(city) && warehouse instanceof Warehouse) {
+ if (industry.warehouses.hasOwnProperty(city) && warehouse) {
warehouse.updateSize(this, industry);
}
}
diff --git a/src/Corporation/Industry.ts b/src/Corporation/Industry.ts
index 74426c857..fe1a6d8a8 100644
--- a/src/Corporation/Industry.ts
+++ b/src/Corporation/Industry.ts
@@ -355,9 +355,7 @@ export class Industry {
for (let i = 0; i < CorporationConstants.Cities.length; ++i) {
const city = CorporationConstants.Cities[i];
const warehouse = this.warehouses[city];
- if (!(warehouse instanceof Warehouse)) {
- continue;
- }
+ if (!warehouse) continue;
const materials = warehouse.materials;
@@ -413,10 +411,7 @@ export class Industry {
let employeeSalary = 0;
for (const officeLoc of Object.keys(this.offices)) {
const office = this.offices[officeLoc];
- if (office === 0) continue;
- if (office instanceof OfficeSpace) {
- employeeSalary += office.process(marketCycles, corporation, this);
- }
+ if (office) employeeSalary += office.process(marketCycles, corporation, this);
}
this.thisCycleExpenses = this.thisCycleExpenses + employeeSalary;
@@ -467,7 +462,7 @@ export class Industry {
for (let i = 0; i < CorporationConstants.Cities.length; ++i) {
//If this industry has a warehouse in this city, process the market
//for every material this industry requires or produces
- if (this.warehouses[CorporationConstants.Cities[i]] instanceof Warehouse) {
+ if (this.warehouses[CorporationConstants.Cities[i]]) {
const wh = this.warehouses[CorporationConstants.Cities[i]];
if (wh === 0) continue;
for (const name of Object.keys(reqMats)) {
@@ -527,7 +522,7 @@ export class Industry {
const office = this.offices[city];
if (office === 0) continue;
- if (this.warehouses[city] instanceof Warehouse) {
+ if (this.warehouses[city]) {
const warehouse = this.warehouses[city];
if (warehouse === 0) continue;
@@ -893,7 +888,7 @@ export class Industry {
if (corporation.divisions[foo].name === exp.ind) {
const expIndustry = corporation.divisions[foo];
const expWarehouse = expIndustry.warehouses[exp.city];
- if (!(expWarehouse instanceof Warehouse)) {
+ if (!expWarehouse) {
console.error(`Invalid export! ${expIndustry.name} ${exp.city}`);
break;
}
@@ -936,7 +931,7 @@ export class Industry {
//Produce Scientific Research based on R&D employees
//Scientific Research can be produced without a warehouse
- if (office instanceof OfficeSpace) {
+ if (office) {
this.sciResearch.qty +=
0.004 *
Math.pow(office.employeeProd[EmployeePositions.RandD], 0.5) *
@@ -975,7 +970,7 @@ export class Industry {
for (const prodName of Object.keys(this.products)) {
if (this.products.hasOwnProperty(prodName)) {
const prod = this.products[prodName];
- if (prod instanceof Product && prod.fin) {
+ if (prod && prod.fin) {
revenue += this.processProduct(marketCycles, prod, corporation);
}
}
@@ -991,7 +986,7 @@ export class Industry {
const office = this.offices[city];
if (office === 0) continue;
const warehouse = this.warehouses[city];
- if (warehouse instanceof Warehouse) {
+ if (warehouse) {
switch (this.state) {
case "PRODUCTION": {
//Calculate the maximum production of this material based
@@ -1195,7 +1190,7 @@ export class Industry {
if (state === "EXPORT") {
for (let i = 0; i < CorporationConstants.Cities.length; ++i) {
const city = CorporationConstants.Cities[i];
- if (!(this.warehouses[city] instanceof Warehouse)) {
+ if (!this.warehouses[city]) {
continue;
}
const warehouse = this.warehouses[city];
diff --git a/src/Corporation/ui/IndustryWarehouse.tsx b/src/Corporation/ui/IndustryWarehouse.tsx
index c60998cec..f6bfbf1f3 100644
--- a/src/Corporation/ui/IndustryWarehouse.tsx
+++ b/src/Corporation/ui/IndustryWarehouse.tsx
@@ -3,8 +3,6 @@
import React, { useState } from "react";
import { CorporationConstants } from "../data/Constants";
-import { Material } from "../Material";
-import { Product } from "../Product";
import { Warehouse } from "../Warehouse";
import { SmartSupplyModal } from "./modals/SmartSupplyModal";
import { ProductElem } from "./ProductElem";
@@ -92,7 +90,7 @@ function WarehouseRoot(props: IProps): React.ReactElement {
// Create React components for materials
const mats = [];
for (const matName of Object.keys(props.warehouse.materials)) {
- if (!(props.warehouse.materials[matName] instanceof Material)) continue;
+ if (!props.warehouse.materials[matName]) continue;
// Only create UI for materials that are relevant for the industry or in stock
const isInStock = props.warehouse.materials[matName].qty > 0;
const isRelevant = isRelevantMaterial(matName, division);
@@ -113,7 +111,7 @@ function WarehouseRoot(props: IProps): React.ReactElement {
if (division.makesProducts && Object.keys(division.products).length > 0) {
for (const productName of Object.keys(division.products)) {
const product = division.products[productName];
- if (!(product instanceof Product)) continue;
+ if (!product) continue;
products.push(
,
);
@@ -217,7 +215,7 @@ function WarehouseRoot(props: IProps): React.ReactElement {
}
export function IndustryWarehouse(props: IProps): React.ReactElement {
- if (props.warehouse instanceof Warehouse) {
+ if (props.warehouse) {
return ;
} else {
return ;
diff --git a/src/Corporation/ui/MaterialElem.tsx b/src/Corporation/ui/MaterialElem.tsx
index 4f37eba1f..1e16af134 100644
--- a/src/Corporation/ui/MaterialElem.tsx
+++ b/src/Corporation/ui/MaterialElem.tsx
@@ -2,7 +2,6 @@
// (right-side panel in the Industry UI)
import React, { useState } from "react";
-import { OfficeSpace } from "../OfficeSpace";
import { Material } from "../Material";
import { Warehouse } from "../Warehouse";
import { ExportModal } from "./modals/ExportModal";
@@ -45,7 +44,7 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement {
const mat = props.mat;
const markupLimit = mat.getMarkupLimit();
const office = division.offices[city];
- if (!(office instanceof OfficeSpace)) {
+ if (!office) {
throw new Error(`Could not get OfficeSpace object for this city (${city})`);
}
diff --git a/src/Corporation/ui/modals/SmartSupplyModal.tsx b/src/Corporation/ui/modals/SmartSupplyModal.tsx
index a4fd540d6..4533119e5 100644
--- a/src/Corporation/ui/modals/SmartSupplyModal.tsx
+++ b/src/Corporation/ui/modals/SmartSupplyModal.tsx
@@ -2,7 +2,6 @@ import React, { useState } from "react";
import { Warehouse } from "../../Warehouse";
import { SetSmartSupply, SetSmartSupplyUseLeftovers } from "../../Actions";
-import { Material } from "../../Material";
import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { Modal } from "../../../ui/React/Modal";
import { useDivision } from "../Context";
@@ -62,7 +61,7 @@ export function SmartSupplyModal(props: IProps): React.ReactElement {
// Create React components for materials
const mats = [];
for (const matName of Object.keys(props.warehouse.materials)) {
- if (!(props.warehouse.materials[matName] instanceof Material)) continue;
+ if (!props.warehouse.materials[matName]) continue;
if (!Object.keys(division.reqMats).includes(matName)) continue;
mats.push();
}
diff --git a/src/DevMenu.tsx b/src/DevMenu.tsx
index b590fc6df..c291c2fda 100644
--- a/src/DevMenu.tsx
+++ b/src/DevMenu.tsx
@@ -1,5 +1,4 @@
import { Player } from "./Player";
-import { Bladeburner } from "./Bladeburner/Bladeburner";
import { AugmentationNames } from "./Augmentation/data/AugmentationNames";
import React, { useEffect } from "react";
@@ -42,11 +41,11 @@ export function DevMenuRoot(): React.ReactElement {
- {Player.bladeburner instanceof Bladeburner && }
+ {Player.bladeburner && }
- {Player.inGang() && }
+ {Player.gang && }
- {Player.hasCorporation() && }
+ {Player.corporation && }
diff --git a/src/Faction/FactionHelpers.tsx b/src/Faction/FactionHelpers.tsx
index c5cea74ae..de6cf4166 100644
--- a/src/Faction/FactionHelpers.tsx
+++ b/src/Faction/FactionHelpers.tsx
@@ -38,9 +38,7 @@ export function joinFaction(faction: Faction): void {
//Determine what factions you are banned from now that you have joined this faction
for (const enemy of factionInfo.enemies) {
- if (Factions[enemy] instanceof Faction) {
- Factions[enemy].isBanned = true;
- }
+ if (Factions[enemy]) Factions[enemy].isBanned = true;
}
for (let i = 0; i < Player.factionInvitations.length; ++i) {
if (Player.factionInvitations[i] == faction.name || Factions[Player.factionInvitations[i]].isBanned) {
diff --git a/src/Faction/Factions.ts b/src/Faction/Factions.ts
index e06795a88..7469dee72 100644
--- a/src/Faction/Factions.ts
+++ b/src/Faction/Factions.ts
@@ -43,9 +43,6 @@ export function initFactions(): void {
//Faction object and deletes the old Faction Object from "Factions". Then
//reinserts the new Faction object
function resetFaction(newFactionObject: Faction): void {
- if (!(newFactionObject instanceof Faction)) {
- throw new Error("Invalid argument 'newFactionObject' passed into resetFaction()");
- }
const factionName: string = newFactionObject.name;
if (factionExists(factionName)) {
newFactionObject.favor = Factions[factionName].favor;
diff --git a/src/Faction/ui/FactionRoot.tsx b/src/Faction/ui/FactionRoot.tsx
index 7e633b2d9..f23e15240 100644
--- a/src/Faction/ui/FactionRoot.tsx
+++ b/src/Faction/ui/FactionRoot.tsx
@@ -102,7 +102,7 @@ function MainPage({ faction, rerender, onAugmentations }: IMainProps): React.Rea
// We have a special flag for whether the player this faction is the player's
// gang faction because if the player has a gang, they cannot do any other action
- const isPlayersGang = Player.inGang() && Player.getGangName() === faction.name;
+ const isPlayersGang = Player.gang && Player.getGangName() === faction.name;
// Flags for whether special options (gang, sleeve purchases, donate, etc.)
// should be shown
diff --git a/src/Faction/ui/GangButton.tsx b/src/Faction/ui/GangButton.tsx
index f88f09028..a8c05b151 100644
--- a/src/Faction/ui/GangButton.tsx
+++ b/src/Faction/ui/GangButton.tsx
@@ -16,7 +16,7 @@ export function GangButton({ faction }: IProps): React.ReactElement {
if (
!GangConstants.Names.includes(faction.name) || // not even a gang
!Player.isAwareOfGang() || // doesn't know about gang
- (Player.inGang() && Player.getGangName() !== faction.name) // already in another gang
+ (Player.gang && Player.getGangName() !== faction.name) // already in another gang
) {
return <>>;
}
@@ -28,7 +28,7 @@ export function GangButton({ faction }: IProps): React.ReactElement {
description: "",
};
- if (Player.inGang()) {
+ if (Player.gang) {
data = {
enabled: true,
title: "Manage Gang",
diff --git a/src/Gang/Gang.ts b/src/Gang/Gang.ts
index 3f7449d02..32fe4f60c 100644
--- a/src/Gang/Gang.ts
+++ b/src/Gang/Gang.ts
@@ -4,7 +4,6 @@
* balance point to keep them from running out of control
*/
-import { Faction } from "../Faction/Faction";
import { Factions } from "../Faction/Factions";
import { dialogBoxCreate } from "../ui/React/DialogBox";
@@ -123,7 +122,7 @@ export class Gang {
this.respect += gain;
// Faction reputation gains is respect gain divided by some constant
const fac = Factions[this.facName];
- if (!(fac instanceof Faction)) {
+ if (!fac) {
dialogBoxCreate(
"ERROR: Could not get Faction associates with your gang. This is a bug, please report to game dev",
);
diff --git a/src/Hacknet/ui/HashUpgradeModal.tsx b/src/Hacknet/ui/HashUpgradeModal.tsx
index e62d10e9f..83c4d68c2 100644
--- a/src/Hacknet/ui/HashUpgradeModal.tsx
+++ b/src/Hacknet/ui/HashUpgradeModal.tsx
@@ -3,7 +3,6 @@
*/
import React, { useState, useEffect } from "react";
-import { HashManager } from "../HashManager";
import { HashUpgrades } from "../HashUpgrades";
import { Hashes } from "../../ui/React/Hashes";
@@ -29,7 +28,7 @@ export function HashUpgradeModal(props: IProps): React.ReactElement {
}, []);
const hashManager = Player.hashManager;
- if (!(hashManager instanceof HashManager)) {
+ if (!hashManager) {
throw new Error(`Player does not have a HashManager)`);
}
diff --git a/src/Locations/Locations.ts b/src/Locations/Locations.ts
index def929474..33da0eade 100644
--- a/src/Locations/Locations.ts
+++ b/src/Locations/Locations.ts
@@ -21,7 +21,7 @@ function constructLocation(p: IConstructorParams): Location {
throw new Error(`Invalid constructor parameters for Location. No 'name' property`);
}
- if (Locations[p.name] instanceof Location) {
+ if (Locations[p.name]) {
console.warn(`Property with name ${p.name} already exists and is being overwritten`);
}
diff --git a/src/Locations/ui/CompanyLocation.tsx b/src/Locations/ui/CompanyLocation.tsx
index 105c661af..13a125df8 100644
--- a/src/Locations/ui/CompanyLocation.tsx
+++ b/src/Locations/ui/CompanyLocation.tsx
@@ -15,7 +15,6 @@ import { Locations } from "../Locations";
import { LocationName } from "../data/LocationNames";
import { Companies } from "../../Company/Companies";
-import { CompanyPosition } from "../../Company/CompanyPosition";
import { CompanyPositions } from "../../Company/CompanyPositions";
import * as posNames from "../../Company/data/companypositionnames";
@@ -174,7 +173,7 @@ export function CompanyLocation(props: IProps): React.ReactElement {
}
const pos = companyPosition;
- if (pos instanceof CompanyPosition) {
+ if (pos) {
Player.startWork(
new CompanyWork({
singularity: false,
diff --git a/src/NetscriptFunctions/Bladeburner.ts b/src/NetscriptFunctions/Bladeburner.ts
index 0b0c3e8ea..701cb7ae1 100644
--- a/src/NetscriptFunctions/Bladeburner.ts
+++ b/src/NetscriptFunctions/Bladeburner.ts
@@ -350,7 +350,7 @@ export function NetscriptBladeburner(): InternalAPI {
if (BitNodeMultipliers.BladeburnerRank === 0) {
return false; // Disabled in this bitnode
}
- if (Player.bladeburner instanceof Bladeburner) {
+ if (Player.bladeburner) {
return true; // Already member
} else if (
Player.skills.strength >= 100 &&
diff --git a/src/NetscriptFunctions/Gang.ts b/src/NetscriptFunctions/Gang.ts
index d880d6801..c08fb12f6 100644
--- a/src/NetscriptFunctions/Gang.ts
+++ b/src/NetscriptFunctions/Gang.ts
@@ -1,6 +1,6 @@
import { FactionNames } from "../Faction/data/FactionNames";
import { GangConstants } from "../Gang/data/Constants";
-import { Player as player } from "../Player";
+import { Player } from "../Player";
import { Gang } from "../Gang/Gang";
import { AllGangs } from "../Gang/AllGangs";
import { GangMemberTasks } from "../Gang/GangMemberTasks";
@@ -22,18 +22,14 @@ import {
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
export function NetscriptGang(): InternalAPI {
- const checkGangApiAccess = function (ctx: NetscriptContext): void {
- const gang = player.gang;
- if (gang === null) throw new Error("Must have joined gang");
- const hasAccess = gang instanceof Gang;
- if (!hasAccess) {
- throw helpers.makeRuntimeErrorMsg(ctx, `You do not currently have a Gang`);
- }
+ /** Functions as an API check and also returns the gang object */
+ const getGang = function (ctx: NetscriptContext): Gang {
+ if (!Player.gang) throw helpers.makeRuntimeErrorMsg(ctx, "Must have joined gang", "API ACCESS");
+ return Player.gang;
};
const getGangMember = function (ctx: NetscriptContext, name: string): GangMember {
- const gang = player.gang;
- if (gang === null) throw new Error("Must have joined gang");
+ const gang = getGang(ctx);
for (const member of gang.members) if (member.name === name) return member;
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid gang member: '${name}'`);
};
@@ -54,27 +50,23 @@ export function NetscriptGang(): InternalAPI {
const faction = helpers.string(ctx, "faction", _faction);
// this list is copied from Faction/ui/Root.tsx
- if (!player.canAccessGang() || !GangConstants.Names.includes(faction)) return false;
- if (player.inGang()) return false;
- if (!player.factions.includes(faction)) return false;
+ if (!Player.canAccessGang() || !GangConstants.Names.includes(faction)) return false;
+ if (Player.gang) return false;
+ if (!Player.factions.includes(faction)) return false;
const isHacking = faction === FactionNames.NiteSec || faction === FactionNames.TheBlackHand;
- player.startGang(faction, isHacking);
+ Player.startGang(faction, isHacking);
return true;
},
inGang: () => (): boolean => {
- return player.inGang();
+ return Player.gang ? true : false;
},
getMemberNames: (ctx: NetscriptContext) => (): string[] => {
- checkGangApiAccess(ctx);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
+ const gang = getGang(ctx);
return gang.members.map((member) => member.name);
},
getGangInformation: (ctx: NetscriptContext) => (): GangGenInfo => {
- checkGangApiAccess(ctx);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
+ const gang = getGang(ctx);
return {
faction: gang.facName,
isHacking: gang.isHackingGang,
@@ -91,7 +83,7 @@ export function NetscriptGang(): InternalAPI {
};
},
getOtherGangInformation: (ctx: NetscriptContext) => (): GangOtherInfo => {
- checkGangApiAccess(ctx);
+ getGang(ctx);
const cpy: Record = {};
for (const gang of Object.keys(AllGangs)) {
cpy[gang] = Object.assign({}, AllGangs[gang]);
@@ -103,9 +95,7 @@ export function NetscriptGang(): InternalAPI {
(ctx: NetscriptContext) =>
(_memberName: unknown): GangMemberInfo => {
const memberName = helpers.string(ctx, "memberName", _memberName);
- checkGangApiAccess(ctx);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
+ const gang = getGang(ctx);
const member = getGangMember(ctx, memberName);
return {
name: member.name,
@@ -155,18 +145,14 @@ export function NetscriptGang(): InternalAPI {
};
},
canRecruitMember: (ctx: NetscriptContext) => (): boolean => {
- checkGangApiAccess(ctx);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
+ const gang = getGang(ctx);
return gang.canRecruitMember();
},
recruitMember:
(ctx: NetscriptContext) =>
(_memberName: unknown): boolean => {
const memberName = helpers.string(ctx, "memberName", _memberName);
- checkGangApiAccess(ctx);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
+ const gang = getGang(ctx);
const recruited = gang.recruitMember(memberName);
if (recruited) {
ctx.workerScript.log("gang.recruitMember", () => `Successfully recruited Gang Member '${memberName}'`);
@@ -177,9 +163,7 @@ export function NetscriptGang(): InternalAPI {
return recruited;
},
getTaskNames: (ctx: NetscriptContext) => (): string[] => {
- checkGangApiAccess(ctx);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
+ const gang = getGang(ctx);
const tasks = gang.getAllTaskNames();
tasks.unshift("Unassigned");
return tasks;
@@ -189,10 +173,8 @@ export function NetscriptGang(): InternalAPI {
(_memberName: unknown, _taskName: unknown): boolean => {
const memberName = helpers.string(ctx, "memberName", _memberName);
const taskName = helpers.string(ctx, "taskName", _taskName);
- checkGangApiAccess(ctx);
+ const gang = getGang(ctx);
const member = getGangMember(ctx, memberName);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
if (!gang.getAllTaskNames().includes(taskName)) {
ctx.workerScript.log(
"gang.setMemberTask",
@@ -221,23 +203,21 @@ export function NetscriptGang(): InternalAPI {
(ctx: NetscriptContext) =>
(_taskName: unknown): GangTaskStats => {
const taskName = helpers.string(ctx, "taskName", _taskName);
- checkGangApiAccess(ctx);
+ getGang(ctx);
const task = getGangTask(ctx, taskName);
const copy = Object.assign({}, task);
copy.territory = Object.assign({}, task.territory);
return copy;
},
getEquipmentNames: (ctx: NetscriptContext) => (): string[] => {
- checkGangApiAccess(ctx);
+ getGang(ctx);
return Object.keys(GangMemberUpgrades);
},
getEquipmentCost:
(ctx: NetscriptContext) =>
(_equipName: unknown): number => {
const equipName = helpers.string(ctx, "equipName", _equipName);
- checkGangApiAccess(ctx);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
+ const gang = getGang(ctx);
const upg = GangMemberUpgrades[equipName];
if (upg === null) return Infinity;
return gang.getUpgradeCost(upg);
@@ -246,7 +226,7 @@ export function NetscriptGang(): InternalAPI {
(ctx: NetscriptContext) =>
(_equipName: unknown): string => {
const equipName = helpers.string(ctx, "equipName", _equipName);
- checkGangApiAccess(ctx);
+ getGang(ctx);
const upg = GangMemberUpgrades[equipName];
if (upg == null) return "";
return upg.getType();
@@ -255,7 +235,7 @@ export function NetscriptGang(): InternalAPI {
(ctx: NetscriptContext) =>
(_equipName: unknown): EquipmentStats => {
const equipName = helpers.string(ctx, "equipName", _equipName);
- checkGangApiAccess(ctx);
+ getGang(ctx);
const equipment = GangMemberUpgrades[equipName];
if (!equipment) {
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid equipment: ${equipName}`);
@@ -268,9 +248,7 @@ export function NetscriptGang(): InternalAPI {
(_memberName: unknown, _equipName: unknown): boolean => {
const memberName = helpers.string(ctx, "memberName", _memberName);
const equipName = helpers.string(ctx, "equipName", _equipName);
- checkGangApiAccess(ctx);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
+ getGang(ctx);
const member = getGangMember(ctx, memberName);
const equipment = GangMemberUpgrades[equipName];
if (!equipment) return false;
@@ -293,9 +271,7 @@ export function NetscriptGang(): InternalAPI {
(ctx: NetscriptContext) =>
(_memberName: unknown): GangMemberAscension | undefined => {
const memberName = helpers.string(ctx, "memberName", _memberName);
- checkGangApiAccess(ctx);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
+ const gang = getGang(ctx);
const member = getGangMember(ctx, memberName);
if (!member.canAscend()) return;
return gang.ascendMember(member, ctx.workerScript);
@@ -304,9 +280,7 @@ export function NetscriptGang(): InternalAPI {
(ctx: NetscriptContext) =>
(_memberName: unknown): GangMemberAscension | undefined => {
const memberName = helpers.string(ctx, "memberName", _memberName);
- checkGangApiAccess(ctx);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
+ getGang(ctx);
const member = getGangMember(ctx, memberName);
if (!member.canAscend()) return;
return {
@@ -318,9 +292,7 @@ export function NetscriptGang(): InternalAPI {
(ctx: NetscriptContext) =>
(_engage: unknown): void => {
const engage = !!_engage;
- checkGangApiAccess(ctx);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
+ const gang = getGang(ctx);
if (engage) {
gang.territoryWarfareEngaged = true;
ctx.workerScript.log("gang.setTerritoryWarfare", () => "Engaging in Gang Territory Warfare");
@@ -333,9 +305,7 @@ export function NetscriptGang(): InternalAPI {
(ctx: NetscriptContext) =>
(_otherGang: unknown): number => {
const otherGang = helpers.string(ctx, "otherGang", _otherGang);
- checkGangApiAccess(ctx);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
+ const gang = getGang(ctx);
if (AllGangs[otherGang] == null) {
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid gang: ${otherGang}`);
}
@@ -346,9 +316,7 @@ export function NetscriptGang(): InternalAPI {
return playerPower / (otherPower + playerPower);
},
getBonusTime: (ctx: NetscriptContext) => (): number => {
- checkGangApiAccess(ctx);
- const gang = player.gang;
- if (gang === null) throw new Error("Should not be called without Gang");
+ const gang = getGang(ctx);
return Math.round(gang.storedCycles / 5) * 1000;
},
};
diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts
index e4d6217cd..7ac5483cc 100644
--- a/src/NetscriptFunctions/Singularity.ts
+++ b/src/NetscriptFunctions/Singularity.ts
@@ -19,7 +19,6 @@ import {
} from "../ScriptEditor/NetscriptDefinitions";
import { findCrime } from "../Crime/CrimeHelpers";
-import { CompanyPosition } from "../Company/CompanyPosition";
import { CompanyPositions } from "../Company/CompanyPositions";
import { DarkWebItems } from "../DarkWeb/DarkWebItems";
import { CityName } from "../Locations/data/CityNames";
@@ -76,9 +75,7 @@ export function NetscriptSingularity(): InternalAPI {
const getCompany = function (ctx: NetscriptContext, name: string): Company {
const company = Companies[name];
- if (company == null || !(company instanceof Company)) {
- throw helpers.makeRuntimeErrorMsg(ctx, `Invalid company name: '${name}'`);
- }
+ if (!company) throw helpers.makeRuntimeErrorMsg(ctx, `Invalid company name: '${name}'`);
return company;
};
@@ -784,7 +781,7 @@ export function NetscriptSingularity(): InternalAPI {
const focus = !!_focus;
// Make sure its a valid company
- if (companyName == null || companyName === "" || !(Companies[companyName] instanceof Company)) {
+ if (companyName == null || companyName === "" || !Companies[companyName]) {
helpers.log(ctx, () => `Invalid company: '${companyName}'`);
return false;
}
@@ -798,7 +795,7 @@ export function NetscriptSingularity(): InternalAPI {
// Check to make sure company position data is valid
const companyPositionName = Player.jobs[companyName];
const companyPosition = CompanyPositions[companyPositionName];
- if (companyPositionName === "" || !(companyPosition instanceof CompanyPosition)) {
+ if (companyPositionName === "" || !companyPosition) {
helpers.log(ctx, () => "You do not have a job");
return false;
}
@@ -953,7 +950,7 @@ export function NetscriptSingularity(): InternalAPI {
const faction = getFaction(ctx, facName);
// if the player is in a gang and the target faction is any of the gang faction, fail
- if (Player.inGang() && faction.name === Player.getGangFaction().name) {
+ if (Player.gang && faction.name === Player.getGangFaction().name) {
helpers.log(ctx, () => `You can't work for '${facName}' because youre managing a gang for it`);
return false;
}
@@ -1071,7 +1068,7 @@ export function NetscriptSingularity(): InternalAPI {
helpers.log(ctx, () => `You can't donate to '${facName}' because you aren't a member`);
return false;
}
- if (Player.inGang() && faction.name === Player.getGangFaction().name) {
+ if (Player.gang && faction.name === Player.getGangFaction().name) {
helpers.log(ctx, () => `You can't donate to '${facName}' because youre managing a gang for it`);
return false;
}
diff --git a/src/PersonObjects/Person.ts b/src/PersonObjects/Person.ts
index e1e8c3243..787c57cb1 100644
--- a/src/PersonObjects/Person.ts
+++ b/src/PersonObjects/Person.ts
@@ -1,5 +1,5 @@
import * as personMethods from "./PersonMethods";
-import { IPlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation";
+import { PlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation";
import { CityName } from "../Locations/data/CityNames";
import { calculateSkill } from "./formulas/skill";
import { calculateIntelligenceBonus } from "./formulas/intelligence";
@@ -33,8 +33,8 @@ export abstract class Person {
mults = defaultMultipliers();
/** Augmentations */
- augmentations: IPlayerOwnedAugmentation[] = [];
- queuedAugmentations: IPlayerOwnedAugmentation[] = [];
+ augmentations: PlayerOwnedAugmentation[] = [];
+ queuedAugmentations: PlayerOwnedAugmentation[] = [];
/** City that the person is in */
city: CityName = CityName.Sector12;
diff --git a/src/PersonObjects/PersonMethods.ts b/src/PersonObjects/PersonMethods.ts
index 9c4d4bbb8..8ed01d5ef 100644
--- a/src/PersonObjects/PersonMethods.ts
+++ b/src/PersonObjects/PersonMethods.ts
@@ -198,6 +198,6 @@ export function updateSkillLevels(this: Person): void {
this.hp.current = Math.round(this.hp.max * ratio);
}
-export function hasAugmentation(this: Person, augName: string, ignoreQueued: boolean = false) {
+export function hasAugmentation(this: Person, augName: string, ignoreQueued = false) {
return this.augmentations.some((a) => a.name === augName && (ignoreQueued || !this.queuedAugmentations.includes(a)));
}
diff --git a/src/PersonObjects/Player/PlayerObject.ts b/src/PersonObjects/Player/PlayerObject.ts
index 7a08ca5d7..6d5e31182 100644
--- a/src/PersonObjects/Player/PlayerObject.ts
+++ b/src/PersonObjects/Player/PlayerObject.ts
@@ -12,7 +12,6 @@ import { PlayerOwnedSourceFile } from "../../SourceFile/PlayerOwnedSourceFile";
import { Exploit } from "../../Exploits/Exploit";
import { LocationName } from "../../Locations/data/LocationNames";
-import { IPlayerOwnedAugmentation } from "../../Augmentation/PlayerOwnedAugmentation";
import { Corporation } from "../../Corporation/Corporation";
import { Gang } from "../../Gang/Gang";
import { Bladeburner } from "../../Bladeburner/Bladeburner";
diff --git a/src/PersonObjects/Player/PlayerObjectBladeburnerMethods.ts b/src/PersonObjects/Player/PlayerObjectBladeburnerMethods.ts
index b8e9e31ad..3febedfdf 100644
--- a/src/PersonObjects/Player/PlayerObjectBladeburnerMethods.ts
+++ b/src/PersonObjects/Player/PlayerObjectBladeburnerMethods.ts
@@ -6,10 +6,7 @@ export function canAccessBladeburner(this: PlayerObject): boolean {
}
export function inBladeburner(this: PlayerObject): boolean {
- if (this.bladeburner == null) {
- return false;
- }
- return this.bladeburner instanceof Bladeburner;
+ return Boolean(this.bladeburner);
}
export function startBladeburner(this: PlayerObject): void {
diff --git a/src/PersonObjects/Player/PlayerObjectCorporationMethods.ts b/src/PersonObjects/Player/PlayerObjectCorporationMethods.ts
index 95acac366..1014c112a 100644
--- a/src/PersonObjects/Player/PlayerObjectCorporationMethods.ts
+++ b/src/PersonObjects/Player/PlayerObjectCorporationMethods.ts
@@ -10,10 +10,7 @@ export function canAccessCorporation(this: PlayerObject): boolean {
}
export function hasCorporation(this: PlayerObject): boolean {
- if (this.corporation == null) {
- return false;
- }
- return this.corporation instanceof Corporation;
+ return Boolean(this.corporation);
}
export function startCorporation(this: PlayerObject, corpName: string, additionalShares = 0): void {
diff --git a/src/PersonObjects/Player/PlayerObjectGangMethods.ts b/src/PersonObjects/Player/PlayerObjectGangMethods.ts
index fbe765a74..9911349cd 100644
--- a/src/PersonObjects/Player/PlayerObjectGangMethods.ts
+++ b/src/PersonObjects/Player/PlayerObjectGangMethods.ts
@@ -21,41 +21,22 @@ export function isAwareOfGang(this: PlayerObject): boolean {
export function getGangFaction(this: PlayerObject): Faction {
const gang = this.gang;
- if (gang === null) {
- throw new Error("Cannot get gang faction because player is not in a gang.");
- }
+ if (gang === null) throw new Error("Cannot get gang faction because player is not in a gang.");
+
const fac = Factions[gang.facName];
- if (fac == null) {
- throw new Error(`Gang has invalid faction name: ${gang.facName}`);
- }
+ if (fac == null) throw new Error(`Gang has invalid faction name: ${gang.facName}`);
return fac;
}
export function getGangName(this: PlayerObject): string {
- if (!this.inGang()) return "";
const gang = this.gang;
- if (gang === null) {
- throw new Error("Cannot get gang faction because player is not in a gang.");
- }
- return gang.facName;
+ return gang ? gang.facName : "";
}
export function hasGangWith(this: PlayerObject, facName: string): boolean {
- if (!this.inGang()) return false;
const gang = this.gang;
- if (gang === null) {
- throw new Error("Cannot get gang faction because player is not in a gang.");
- }
- return gang.facName === facName;
-}
-
-export function inGang(this: PlayerObject): boolean {
- if (this.gang == null || this.gang == undefined) {
- return false;
- }
-
- return this.gang instanceof Gang;
+ return gang ? gang.facName === facName : false;
}
export function startGang(this: PlayerObject, factionName: string, hacking: boolean): void {
@@ -67,3 +48,7 @@ export function startGang(this: PlayerObject, factionName: string, hacking: bool
}
fac.playerReputation = 0;
}
+
+export function inGang(this: PlayerObject) {
+ return Boolean(this.gang);
+}
diff --git a/src/PersonObjects/Player/PlayerObjectGeneralMethods.ts b/src/PersonObjects/Player/PlayerObjectGeneralMethods.ts
index 490d92739..21dde3745 100644
--- a/src/PersonObjects/Player/PlayerObjectGeneralMethods.ts
+++ b/src/PersonObjects/Player/PlayerObjectGeneralMethods.ts
@@ -105,15 +105,7 @@ export function prestigeAugmentation(this: PlayerObject): void {
this.sleeves.push(new Sleeve());
}
- for (let i = 0; i < this.sleeves.length; ++i) {
- if (this.sleeves[i] instanceof Sleeve) {
- if (this.sleeves[i].shock >= 100) {
- this.sleeves[i].synchronize();
- } else {
- this.sleeves[i].shockRecovery();
- }
- }
- }
+ this.sleeves.forEach((sleeve) => (sleeve.shock >= 100 ? sleeve.synchronize() : sleeve.shockRecovery()));
this.lastUpdate = new Date().getTime();
@@ -137,13 +129,7 @@ export function prestigeSourceFile(this: PlayerObject): void {
this.prestigeAugmentation();
this.karma = 0;
// Duplicate sleeves are reset to level 1 every Bit Node (but the number of sleeves you have persists)
- for (let i = 0; i < this.sleeves.length; ++i) {
- if (this.sleeves[i] instanceof Sleeve) {
- this.sleeves[i].prestige();
- } else {
- this.sleeves[i] = new Sleeve();
- }
- }
+ this.sleeves.forEach((sleeve) => sleeve.prestige());
if (this.bitNodeN === 10) {
for (let i = 0; i < this.sleeves.length; i++) {
@@ -284,7 +270,7 @@ export function hospitalize(this: PlayerObject): number {
//the applyToCompany() Netscript Singularity function
export function applyForJob(this: PlayerObject, entryPosType: CompanyPosition, sing = false): boolean {
const company = Companies[this.location]; //Company being applied to
- if (!(company instanceof Company)) {
+ if (!company) {
console.error(`Could not find company that matches the location: ${this.location}. Player.applyToCompany() failed`);
return false;
}
@@ -1131,7 +1117,7 @@ export function gainCodingContractReward(this: PlayerObject, reward: ICodingCont
/* eslint-disable no-case-declarations */
switch (reward.type) {
case CodingContractRewardType.FactionReputation:
- if (reward.name == null || !(Factions[reward.name] instanceof Faction)) {
+ if (reward.name == null || !Factions[reward.name]) {
// If no/invalid faction was designated, just give rewards to all factions
reward.type = CodingContractRewardType.FactionReputationAll;
return this.gainCodingContractReward(reward);
@@ -1156,14 +1142,12 @@ export function gainCodingContractReward(this: PlayerObject, reward: ICodingCont
const gainPerFaction = Math.floor(totalGain / factions.length);
for (const facName of factions) {
- if (!(Factions[facName] instanceof Faction)) {
- continue;
- }
+ if (!Factions[facName]) continue;
Factions[facName].playerReputation += gainPerFaction;
}
return `Gained ${gainPerFaction} reputation for each of the following factions: ${factions.toString()}`;
case CodingContractRewardType.CompanyReputation: {
- if (reward.name == null || !(Companies[reward.name] instanceof Company)) {
+ if (reward.name == null || !Companies[reward.name]) {
//If no/invalid company was designated, just give rewards to all factions
reward.type = CodingContractRewardType.FactionReputationAll;
return this.gainCodingContractReward(reward);
diff --git a/src/PersonObjects/Sleeve/Sleeve.ts b/src/PersonObjects/Sleeve/Sleeve.ts
index 2b0d5c4a5..96a078ba2 100644
--- a/src/PersonObjects/Sleeve/Sleeve.ts
+++ b/src/PersonObjects/Sleeve/Sleeve.ts
@@ -24,7 +24,6 @@ import { Contracts } from "../../Bladeburner/data/Contracts";
import { CONSTANTS } from "../../Constants";
-import { Faction } from "../../Faction/Faction";
import { Factions } from "../../Faction/Factions";
import { CityName } from "../../Locations/data/CityNames";
@@ -307,7 +306,7 @@ export class Sleeve extends Person {
* Returns boolean indicating success
*/
workForCompany(companyName: string): boolean {
- if (!(Companies[companyName] instanceof Company) || Player.jobs[companyName] == null) {
+ if (!Companies[companyName] || Player.jobs[companyName] == null) {
return false;
}
@@ -327,7 +326,7 @@ export class Sleeve extends Person {
*/
workForFaction(factionName: string, workType: string): boolean {
const faction = Factions[factionName];
- if (factionName === "" || !faction || !(faction instanceof Faction) || !Player.factions.includes(factionName)) {
+ if (factionName === "" || !faction || !Player.factions.includes(factionName)) {
return false;
}
diff --git a/src/PersonObjects/Sleeve/SleeveMethods.ts b/src/PersonObjects/Sleeve/SleeveMethods.ts
index 0607ea85f..2009da2f7 100644
--- a/src/PersonObjects/Sleeve/SleeveMethods.ts
+++ b/src/PersonObjects/Sleeve/SleeveMethods.ts
@@ -61,7 +61,7 @@ export function findPurchasableAugs(this: Sleeve): Augmentation[] {
// If player is in a gang, then we return all augs that the player
// has enough reputation for (since that gang offers all augs)
- if (Player.inGang()) {
+ if (Player.gang) {
const fac = Player.getGangFaction();
const gangAugs = getFactionAugmentationsFiltered(fac);
diff --git a/src/Prestige.ts b/src/Prestige.ts
index 1ebbf1789..e3ec486ce 100755
--- a/src/Prestige.ts
+++ b/src/Prestige.ts
@@ -4,11 +4,9 @@ import { StaticAugmentations } from "./Augmentation/StaticAugmentations";
import { augmentationExists, initAugmentations } from "./Augmentation/AugmentationHelpers";
import { AugmentationNames } from "./Augmentation/data/AugmentationNames";
import { initBitNodeMultipliers } from "./BitNode/BitNode";
-import { Bladeburner } from "./Bladeburner/Bladeburner";
import { Companies, initCompanies } from "./Company/Companies";
import { resetIndustryResearchTrees } from "./Corporation/IndustryData";
import { Programs } from "./Programs/Programs";
-import { Faction } from "./Faction/Faction";
import { Factions, initFactions } from "./Faction/Factions";
import { joinFaction } from "./Faction/FactionHelpers";
import { updateHashManagerCapacity } from "./Hacknet/HacknetHelpers";
@@ -108,11 +106,9 @@ export function prestigeAugmentation(): void {
// Gang
const gang = Player.gang;
- if (Player.inGang() && gang !== null) {
+ if (gang) {
const faction = Factions[gang.facName];
- if (faction instanceof Faction) {
- joinFaction(faction);
- }
+ if (faction) joinFaction(faction);
const penalty = 0.95;
for (const m of gang.members) {
m.hack_asc_points *= penalty;
@@ -130,7 +126,7 @@ export function prestigeAugmentation(): void {
}
// Cancel Bladeburner action
- if (Player.bladeburner instanceof Bladeburner) {
+ if (Player.bladeburner) {
Player.bladeburner.prestige();
}
diff --git a/src/SaveObject.tsx b/src/SaveObject.tsx
index 451198ec1..8262f1faf 100755
--- a/src/SaveObject.tsx
+++ b/src/SaveObject.tsx
@@ -97,9 +97,8 @@ class BitburnerSaveObject {
this.LastExportBonus = JSON.stringify(ExportBonus.LastExportBonus);
this.StaneksGiftSave = JSON.stringify(staneksGift);
- if (Player.inGang()) {
- this.AllGangsSave = JSON.stringify(AllGangs);
- }
+ if (Player.gang) this.AllGangsSave = JSON.stringify(AllGangs);
+
const saveString = btoa(unescape(encodeURIComponent(JSON.stringify(this))));
return saveString;
@@ -724,7 +723,7 @@ function loadGame(saveString: string): boolean {
console.error("ERROR: Failed to parse last export bonus Settings " + err);
}
}
- if (Player.inGang() && saveObj.hasOwnProperty("AllGangsSave")) {
+ if (Player.gang && saveObj.hasOwnProperty("AllGangsSave")) {
try {
loadAllGangs(saveObj.AllGangsSave);
} catch (e) {
diff --git a/src/Server/BaseServer.ts b/src/Server/BaseServer.ts
index 6e00e71fd..6ba4b96c8 100644
--- a/src/Server/BaseServer.ts
+++ b/src/Server/BaseServer.ts
@@ -164,15 +164,8 @@ export class BaseServer {
}
removeContract(contract: CodingContract | string): void {
- if (contract instanceof CodingContract) {
- this.contracts = this.contracts.filter((c) => {
- return c.fn !== contract.fn;
- });
- } else {
- this.contracts = this.contracts.filter((c) => {
- return c.fn !== contract;
- });
- }
+ const index = this.contracts.findIndex((c) => c.fn === (typeof contract === "string" ? contract : contract.fn));
+ if (index > -1) this.contracts.splice(index, 1);
}
/**
diff --git a/src/engine.tsx b/src/engine.tsx
index 3c66e2c89..0611e4669 100644
--- a/src/engine.tsx
+++ b/src/engine.tsx
@@ -6,10 +6,8 @@ import { initAugmentations } from "./Augmentation/AugmentationHelpers";
import { AugmentationNames } from "./Augmentation/data/AugmentationNames";
import { initBitNodeMultipliers } from "./BitNode/BitNode";
import { initDarkWebItems } from "./DarkWeb/DarkWebItems";
-import { Bladeburner } from "./Bladeburner/Bladeburner";
import { generateRandomContract } from "./CodingContractGenerator";
import { initCompanies } from "./Company/Companies";
-import { Corporation } from "./Corporation/Corporation";
import { CONSTANTS } from "./Constants";
import { Factions, initFactions } from "./Faction/Factions";
import { staneksGift } from "./CotMG/Helper";
@@ -101,28 +99,20 @@ const Engine: {
processStockPrices(numCycles);
}
- // Gang, if applicable
- if (Player.inGang() && Player.gang !== null) {
- Player.gang.process(numCycles);
- }
+ // Gang
+ if (Player.gang) Player.gang.process(numCycles);
// Staneks gift
staneksGift.process(numCycles);
// Corporation
- if (Player.corporation instanceof Corporation) {
- // Stores cycles in a "buffer". Processed separately using Engine Counters
- Player.corporation.storeCycles(numCycles);
- }
+ if (Player.corporation) Player.corporation.storeCycles(numCycles);
- if (Player.bladeburner instanceof Bladeburner) {
- Player.bladeburner.storeCycles(numCycles);
- }
+ // Bladeburner
+ if (Player.bladeburner) Player.bladeburner.storeCycles(numCycles);
// Sleeves
- for (let i = 0; i < Player.sleeves.length; ++i) {
- Player.sleeves[i].process(numCycles);
- }
+ Player.sleeves.forEach((sleeve) => sleeve.process(numCycles));
// Counters
Engine.decrementAllCounters(numCycles);
@@ -205,11 +195,11 @@ const Engine: {
Engine.Counters.messages = 150;
}
}
- if (Player.corporation instanceof Corporation) {
+ if (Player.corporation) {
Player.corporation.process();
}
if (Engine.Counters.mechanicProcess <= 0) {
- if (Player.bladeburner instanceof Bladeburner) {
+ if (Player.bladeburner) {
try {
Player.bladeburner.process();
} catch (e) {
@@ -328,39 +318,25 @@ const Engine: {
}
// Gang progress for BitNode 2
- const gang = Player.gang;
- if (Player.inGang() && gang !== null) {
- gang.process(numCyclesOffline);
- }
+ if (Player.gang) Player.gang.process(numCyclesOffline);
// Corporation offline progress
- if (Player.corporation instanceof Corporation) {
- Player.corporation.storeCycles(numCyclesOffline);
- }
+ if (Player.corporation) Player.corporation.storeCycles(numCyclesOffline);
// Bladeburner offline progress
- if (Player.bladeburner instanceof Bladeburner) {
- Player.bladeburner.storeCycles(numCyclesOffline);
- }
+ if (Player.bladeburner) Player.bladeburner.storeCycles(numCyclesOffline);
staneksGift.process(numCyclesOffline);
// Sleeves offline progress
- for (let i = 0; i < Player.sleeves.length; ++i) {
- Player.sleeves[i].process(numCyclesOffline);
- }
+ Player.sleeves.forEach((sleeve) => sleeve.process(numCyclesOffline));
// Update total playtime
const time = numCyclesOffline * CONSTANTS._idleSpeed;
- if (Player.totalPlaytime == null) {
- Player.totalPlaytime = 0;
- }
- if (Player.playtimeSinceLastAug == null) {
- Player.playtimeSinceLastAug = 0;
- }
- if (Player.playtimeSinceLastBitnode == null) {
- Player.playtimeSinceLastBitnode = 0;
- }
+ Player.totalPlaytime ??= 0;
+ Player.playtimeSinceLastAug ??= 0;
+ Player.playtimeSinceLastBitnode ??= 0;
+
Player.totalPlaytime += time;
Player.playtimeSinceLastAug += time;
Player.playtimeSinceLastBitnode += time;
diff --git a/src/ui/WorkInProgressRoot.tsx b/src/ui/WorkInProgressRoot.tsx
index d07fc6f40..f4f30fbdb 100644
--- a/src/ui/WorkInProgressRoot.tsx
+++ b/src/ui/WorkInProgressRoot.tsx
@@ -4,7 +4,6 @@ import Typography from "@mui/material/Typography";
import { uniqueId } from "lodash";
import React, { useEffect, useState } from "react";
import { Companies } from "../Company/Companies";
-import { Company } from "../Company/Company";
import { CONSTANTS } from "../Constants";
import { LocationName } from "../Locations/data/LocationNames";
import { Locations } from "../Locations/Locations";
@@ -430,7 +429,7 @@ export function WorkInProgressRoot(): React.ReactElement {
if (isCompanyWork(Player.currentWork)) {
const comp = Companies[Player.currentWork.companyName];
- if (comp == null || !(comp instanceof Company)) {
+ if (comp) {
workInfo = {
buttons: {
cancel: () => Router.toTerminal(),