From ebae35b1fb118b0fb0a399d40750a166f06bc854 Mon Sep 17 00:00:00 2001 From: Snarling <84951833+Snarling@users.noreply.github.com> Date: Fri, 5 May 2023 03:55:59 -0400 Subject: [PATCH] CODEBASE: Expand lint rules, and Aliases are stored as maps (#501) --- .eslintrc.js | 5 +- src/Achievements/Achievements.ts | 150 ++++++++-------- src/Alias.ts | 84 +++------ src/Augmentation/Augmentation.tsx | 12 +- src/Augmentation/AugmentationHelpers.tsx | 11 +- .../ui/PurchaseAugmentationModal.tsx | 33 ++-- src/BitNode/BitNode.tsx | 26 +-- src/BitNode/BitNodeMultipliers.ts | 1 - .../ui/BitnodeMultipliersDescription.tsx | 9 +- src/Bladeburner/Action.tsx | 6 +- src/Bladeburner/Bladeburner.tsx | 168 +++++++++--------- src/Bladeburner/GeneralActions.tsx | 2 +- src/Bladeburner/data/BlackOperations.tsx | 4 +- src/Bladeburner/data/Contracts.tsx | 4 +- src/Bladeburner/data/GeneralActions.tsx | 4 +- src/Bladeburner/data/Operations.tsx | 4 +- src/Bladeburner/ui/BlackOpElem.tsx | 3 +- src/Bladeburner/ui/BlackOpList.tsx | 2 +- src/Bladeburner/ui/ContractElem.tsx | 2 +- src/Bladeburner/ui/GeneralActionList.tsx | 2 +- src/Bladeburner/ui/OperationElem.tsx | 2 +- src/Bladeburner/ui/SkillPage.tsx | 46 ++--- src/Bladeburner/ui/TravelModal.tsx | 2 +- src/Casino/Blackjack.tsx | 22 +-- src/Casino/CardDeck/Deck.ts | 8 +- src/Casino/CardDeck/ReactCard.tsx | 4 +- src/Casino/Roulette.tsx | 4 +- src/Casino/utils.ts | 4 +- src/CodingContracts.ts | 4 - src/Company/CompanyPosition.ts | 2 - src/Corporation/Corporation.tsx | 2 +- src/Corporation/Industry.ts | 43 +++-- src/Corporation/OfficeSpace.ts | 2 +- src/Corporation/Product.ts | 4 +- src/Corporation/ui/ExpandIndustryTab.tsx | 2 +- src/Corporation/ui/ExpandNewCity.tsx | 2 +- src/Corporation/ui/IndustryOverview.tsx | 2 +- src/Corporation/ui/IndustryWarehouse.tsx | 2 +- src/Corporation/ui/MaterialElem.tsx | 4 +- .../ui/modals/BribeFactionModal.tsx | 2 +- src/Corporation/ui/modals/ExportModal.tsx | 4 +- .../ui/modals/MakeProductModal.tsx | 2 +- .../ui/modals/SellDivisionModal.tsx | 9 +- src/CotMG/ui/ActiveFragmentSummary.tsx | 4 +- src/CotMG/ui/Cell.tsx | 4 +- src/CotMG/ui/FragmentInspector.tsx | 4 +- src/CotMG/ui/FragmentPreview.tsx | 4 +- src/CotMG/ui/FragmentSelector.tsx | 8 +- src/CotMG/ui/StaneksGiftRoot.tsx | 4 +- src/DevMenu/ui/Augmentations.tsx | 2 +- src/DevMenu/ui/Bladeburner.tsx | 12 +- src/DevMenu/ui/CodingContracts.tsx | 2 +- src/DevMenu/ui/Companies.tsx | 2 +- src/DevMenu/ui/Factions.tsx | 2 +- src/DevMenu/ui/General.tsx | 2 +- src/DevMenu/ui/Programs.tsx | 2 +- src/DevMenu/ui/Servers.tsx | 2 +- src/DevMenu/ui/StockMarket.tsx | 2 +- src/Electron.tsx | 2 +- src/Exploits/Exploit.ts | 4 +- src/Faction/FactionHelpers.tsx | 2 +- src/Faction/FactionInfo.tsx | 1 - src/Faction/Factions.ts | 2 +- src/Faction/ui/AugmentationsPage.tsx | 4 +- src/Faction/ui/DonateOption.tsx | 4 +- src/Faction/ui/FactionRoot.tsx | 4 +- src/Faction/ui/FactionsRoot.tsx | 6 +- src/Faction/ui/GangButton.tsx | 4 +- src/Faction/ui/Info.tsx | 4 +- src/Faction/ui/Option.tsx | 4 +- src/GameOptions/ui/NumericDisplayOptions.tsx | 2 +- src/GameOptions/ui/OptionsSlider.tsx | 4 +- src/GameOptions/ui/RemoteAPIPage.tsx | 2 +- src/GameOptions/ui/SystemPage.tsx | 30 +--- src/Gang/AllGangs.ts | 4 +- src/Gang/Gang.ts | 20 +-- src/Gang/GangMember.ts | 8 +- src/Gang/GangMemberTasks.ts | 4 +- src/Gang/GangMemberUpgrades.ts | 4 +- src/Gang/data/power.ts | 4 +- src/Gang/data/tasks.ts | 1 - src/Gang/ui/EquipmentsSubpage.tsx | 4 +- src/Gang/ui/TaskDescription.tsx | 2 +- src/Gang/ui/TaskSelector.tsx | 2 +- src/Hacking.ts | 1 - src/Hacking/netscriptCanHack.ts | 2 +- src/Hacknet/HacknetServer.ts | 3 +- src/Hacknet/ui/HacknetServerElem.tsx | 3 - src/Hacknet/ui/HacknetUpgradeElem.tsx | 8 +- src/Infiltration/ui/Difficulty.ts | 4 +- src/Infiltration/ui/Victory.tsx | 2 +- src/Literature/Literature.ts | 6 +- src/Locations/ui/ApplyToJobButton.tsx | 4 +- src/Locations/ui/City.tsx | 8 +- src/Locations/ui/CompanyLocation.tsx | 4 +- src/Locations/ui/CoresButton.tsx | 4 +- src/Locations/ui/GenericLocation.tsx | 4 +- src/Locations/ui/GymLocation.tsx | 4 +- src/Locations/ui/RamButton.tsx | 4 +- src/Locations/ui/SpecialLocation.tsx | 4 +- src/Locations/ui/TorButton.tsx | 4 +- src/Locations/ui/UniversityLocation.tsx | 4 +- src/Milestones/Milestone.ts | 4 +- src/Milestones/Milestones.ts | 4 +- src/Netscript/APIWrapper.ts | 4 +- src/Netscript/NetscriptHelpers.ts | 50 ++---- src/Netscript/WorkerScripts.ts | 2 +- src/NetscriptFunctions.ts | 8 +- src/NetscriptFunctions/Corporation.ts | 2 +- src/NetscriptFunctions/Extra.ts | 12 +- src/NetscriptFunctions/Flags.ts | 8 +- src/NetscriptFunctions/Grafting.ts | 7 +- src/NetscriptFunctions/Infiltration.ts | 18 +- src/NetscriptFunctions/Singularity.ts | 2 +- src/NetscriptFunctions/StockMarket.ts | 2 +- src/NetscriptFunctions/UserInterface.ts | 2 +- src/NetscriptFunctions/toNative.ts | 10 +- src/NetscriptJSEvaluator.ts | 6 +- src/NetscriptPort.ts | 4 +- src/NetscriptWorker.ts | 8 +- src/Paths/Directory.ts | 2 +- src/Paths/FilePath.ts | 2 +- src/PersonObjects/Player/PlayerObject.ts | 2 +- .../Player/PlayerObjectGeneralMethods.ts | 10 +- src/PersonObjects/Sleeve/ui/SleeveElem.tsx | 6 +- src/PersonObjects/Sleeve/ui/TaskSelector.tsx | 12 +- src/Prestige.ts | 38 +--- src/Programs/Program.ts | 4 +- src/Programs/ui/ProgramsRoot.tsx | 4 +- src/RemoteFileAPI/MessageDefinitions.ts | 2 +- src/SaveObject.tsx | 53 +++--- src/Script/RamCalculations.ts | 82 ++++----- src/Script/RunningScript.ts | 10 +- src/Script/Script.ts | 4 +- src/Script/ScriptHelpers.ts | 4 +- src/ScriptEditor/ui/Editor.tsx | 4 +- src/ScriptEditor/ui/Options.ts | 4 +- src/ScriptEditor/ui/ScriptEditorRoot.tsx | 14 +- src/ScriptEditor/ui/themes.ts | 4 +- src/Server/AllServers.ts | 2 +- src/Server/BaseServer.ts | 6 +- src/Server/Server.ts | 4 +- src/Server/ServerPurchases.ts | 5 +- src/Server/data/servers.ts | 1 - src/SourceFile/SourceFiles.tsx | 26 +-- src/StockMarket/IOrderBook.ts | 4 +- src/StockMarket/IStockMarket.ts | 4 +- src/StockMarket/OrderProcessing.tsx | 6 +- src/StockMarket/StockMarket.tsx | 18 +- src/StockMarket/ui/InfoAndPurchases.tsx | 4 +- src/StockMarket/ui/StockMarketRoot.tsx | 4 +- src/StockMarket/ui/StockTicker.tsx | 8 +- src/StockMarket/ui/StockTickerHeaderText.tsx | 4 +- src/StockMarket/ui/StockTickerOrder.tsx | 4 +- src/StockMarket/ui/StockTickerOrderList.tsx | 4 +- .../ui/StockTickerPositionText.tsx | 4 +- src/StockMarket/ui/StockTickerTxButton.tsx | 4 +- src/StockMarket/ui/StockTickers.tsx | 4 +- src/StockMarket/ui/StockTickersConfig.tsx | 4 +- src/Terminal/HelpText.ts | 2 - src/Terminal/Terminal.ts | 19 +- src/Terminal/commands/common/editor.ts | 2 +- src/Terminal/commands/mem.ts | 2 +- src/Terminal/commands/runScript.ts | 2 +- src/Terminal/commands/scan.ts | 3 +- src/Terminal/getTabCompletionPossibilities.ts | 16 +- src/Themes/ui/ThemeEditorModal.tsx | 148 +++++++-------- src/Types/strings.ts | 2 +- src/data/codingcontracttypes.ts | 34 ++-- src/engine.tsx | 2 +- src/hash/hash.ts | 9 +- src/index.tsx | 4 +- .../ActiveScripts/RecentScriptAccordion.tsx | 2 +- src/ui/ActiveScripts/ServerAccordion.tsx | 4 +- src/ui/ActiveScripts/ServerAccordions.tsx | 8 +- .../ActiveScripts/WorkerScriptAccordion.tsx | 6 +- src/ui/CharacterStats.tsx | 2 +- src/ui/GameRoot.tsx | 33 ++-- .../InteractiveTutorialRoot.tsx | 2 +- src/ui/React/AugmentationAccordion.tsx | 4 +- src/ui/React/CharacterOverview.tsx | 10 +- src/ui/React/CompanyDropdown.tsx | 2 +- src/ui/React/CopyableText.tsx | 4 +- src/ui/React/LogBoxManager.tsx | 4 +- src/ui/React/Overview.tsx | 2 +- src/ui/React/PromptManager.tsx | 14 +- src/ui/React/ServerDropdown.tsx | 2 +- src/ui/React/SourceFileAccordion.tsx | 4 +- src/ui/WorkInProgressRoot.tsx | 104 +++++------ src/utils/ErrorHelper.ts | 4 +- src/utils/EventEmitter.ts | 2 +- src/utils/HammingCodeTools.ts | 10 +- src/utils/IPAddress.ts | 5 +- .../{arrayToString.ts => ArrayHelpers.ts} | 6 + src/utils/helpers/addOffset.ts | 1 - src/utils/helpers/clearObject.ts | 16 -- src/utils/helpers/createProgressBarText.ts | 1 - src/utils/helpers/exceptionAlert.ts | 2 +- src/utils/helpers/isPowerOfTwo.ts | 1 - src/utils/helpers/scriptKey.ts | 2 +- src/utils/helpers/typeAssertion.ts | 6 +- tsconfig.json | 2 +- 202 files changed, 905 insertions(+), 1110 deletions(-) rename src/utils/helpers/{arrayToString.ts => ArrayHelpers.ts} (79%) delete mode 100644 src/utils/helpers/clearObject.ts diff --git a/.eslintrc.js b/.eslintrc.js index cb9f464aa..5139c8b31 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -7,8 +7,8 @@ module.exports = { extends: [ "eslint:recommended", "plugin:@typescript-eslint/recommended", - "plugin:@typescript-eslint/recommended-requiring-type-checking", - "plugin:@typescript-eslint/strict", + //"plugin:@typescript-eslint/recommended-requiring-type-checking", + //"plugin:@typescript-eslint/strict", ], parser: "@typescript-eslint/parser", parserOptions: { @@ -20,7 +20,6 @@ module.exports = { project: ["./tsconfig.json", "./test/tsconfig.json", "./tools/tsconfig.json"], }, plugins: ["@typescript-eslint"], - extends: ["plugin:@typescript-eslint/recommended"], rules: { "@typescript-eslint/no-unused-vars": [ "error", diff --git a/src/Achievements/Achievements.ts b/src/Achievements/Achievements.ts index 945fda837..a114467b9 100644 --- a/src/Achievements/Achievements.ts +++ b/src/Achievements/Achievements.ts @@ -61,9 +61,7 @@ function bitNodeFinishedState(): boolean { const wd = GetServer(SpecialServers.WorldDaemon); if (!(wd instanceof Server)) return false; if (wd.backdoorInstalled) return true; - return ( - Player.bladeburner !== null && Player.bladeburner.blackops.hasOwnProperty(BlackOperationNames.OperationDaedalus) - ); + return Player.bladeburner !== null && BlackOperationNames.OperationDaedalus in Player.bladeburner.blackops; } function hasAccessToSF(player: PlayerObject, bn: number): boolean { @@ -100,7 +98,7 @@ export const achievements: Record = { Condition: () => Player.factions.includes(FactionNames.NiteSec), }, THE_BLACK_HAND: { - ...achievementData["THE_BLACK_HAND"], + ...achievementData.THE_BLACK_HAND, Icon: "TBH", Condition: () => Player.factions.includes(FactionNames.TheBlackHand), }, @@ -115,7 +113,7 @@ export const achievements: Record = { Condition: () => Player.factions.includes(FactionNames.Daedalus), }, THE_COVENANT: { - ...achievementData["THE_COVENANT"], + ...achievementData.THE_COVENANT, Icon: FactionNames.TheCovenant.toLowerCase().replace(/ /g, ""), Condition: () => Player.factions.includes(FactionNames.TheCovenant), }, @@ -228,38 +226,38 @@ export const achievements: Record = { Condition: () => Player.sourceFileLvl(12) >= 1, }, MONEY_1Q: { - ...achievementData["MONEY_1Q"], + ...achievementData.MONEY_1Q, Icon: "$1Q", Condition: () => Player.money >= 1e18, }, MONEY_M1B: { - ...achievementData["MONEY_M1B"], + ...achievementData.MONEY_M1B, Icon: "-1b", Secret: true, Condition: () => Player.money <= -1e9, }, INSTALL_1: { - ...achievementData["INSTALL_1"], + ...achievementData.INSTALL_1, Icon: "install", Condition: () => Player.augmentations.length >= 1, }, INSTALL_100: { - ...achievementData["INSTALL_100"], + ...achievementData.INSTALL_100, Icon: "install_100", Condition: () => Player.augmentations.length >= 100, }, QUEUE_40: { - ...achievementData["QUEUE_40"], + ...achievementData.QUEUE_40, Icon: "queue40", Condition: () => Player.queuedAugmentations.length >= 40, }, HACKING_100000: { - ...achievementData["HACKING_100000"], + ...achievementData.HACKING_100000, Icon: "hack100000", Condition: () => Player.skills.hacking >= 100000, }, COMBAT_3000: { - ...achievementData["COMBAT_3000"], + ...achievementData.COMBAT_3000, Icon: "combat3000", Condition: () => Player.skills.strength >= 3000 && @@ -268,27 +266,27 @@ export const achievements: Record = { Player.skills.agility >= 3000, }, NEUROFLUX_255: { - ...achievementData["NEUROFLUX_255"], + ...achievementData.NEUROFLUX_255, Icon: "nf255", Condition: () => Player.augmentations.some((a) => a.name === AugmentationNames.NeuroFluxGovernor && a.level >= 255), }, NS2: { - ...achievementData["NS2"], + ...achievementData.NS2, Icon: "ns2", Condition: () => [...Player.getHomeComputer().scripts.values()].some((s) => s.filename.endsWith(".js")), }, FROZE: { - ...achievementData["FROZE"], + ...achievementData.FROZE, Icon: "forze", Condition: () => location.href.includes("noScripts"), }, RUNNING_SCRIPTS_1000: { - ...achievementData["RUNNING_SCRIPTS_1000"], + ...achievementData.RUNNING_SCRIPTS_1000, Icon: "run1000", Condition: (): boolean => workerScripts.size >= 1000, }, DRAIN_SERVER: { - ...achievementData["DRAIN_SERVER"], + ...achievementData.DRAIN_SERVER, Icon: "drain", Condition: (): boolean => { for (const s of GetAllServers()) { @@ -300,33 +298,33 @@ export const achievements: Record = { }, }, MAX_RAM: { - ...achievementData["MAX_RAM"], + ...achievementData.MAX_RAM, Icon: "maxram", Condition: () => Player.getHomeComputer().maxRam === CONSTANTS.HomeComputerMaxRam, }, MAX_CORES: { - ...achievementData["MAX_CORES"], + ...achievementData.MAX_CORES, Icon: "maxcores", Condition: () => Player.getHomeComputer().cpuCores === 8, }, SCRIPTS_30: { - ...achievementData["SCRIPTS_30"], + ...achievementData.SCRIPTS_30, Icon: "folders", Condition: () => Player.getHomeComputer().scripts.size >= 30, }, KARMA_1000000: { - ...achievementData["KARMA_1000000"], + ...achievementData.KARMA_1000000, Icon: "karma", Secret: true, Condition: () => Player.karma <= -1e6, }, STOCK_1q: { - ...achievementData["STOCK_1q"], + ...achievementData.STOCK_1q, Icon: "$1Q", Condition: () => Player.moneySourceB.stock >= 1e15, }, DISCOUNT: { - ...achievementData["DISCOUNT"], + ...achievementData.DISCOUNT, Icon: "discount", Condition: (): boolean => { const p = GetServer("powerhouse-fitness"); @@ -335,12 +333,12 @@ export const achievements: Record = { }, }, SCRIPT_32GB: { - ...achievementData["SCRIPT_32GB"], + ...achievementData.SCRIPT_32GB, Icon: "bigcost", Condition: () => [...Player.getHomeComputer().scripts.values()].some((s) => (s.ramUsage ?? 0) >= 32), }, FIRST_HACKNET_NODE: { - ...achievementData["FIRST_HACKNET_NODE"], + ...achievementData.FIRST_HACKNET_NODE, Icon: "node", Condition: () => !hasHacknetServers() && Player.hacknetNodes.length > 0, }, @@ -350,7 +348,7 @@ export const achievements: Record = { Condition: () => !hasHacknetServers() && Player.hacknetNodes.length >= 30, }, MAX_HACKNET_NODE: { - ...achievementData["MAX_HACKNET_NODE"], + ...achievementData.MAX_HACKNET_NODE, Icon: "hacknet-max", Condition: (): boolean => { if (hasHacknetServers()) return false; @@ -367,17 +365,17 @@ export const achievements: Record = { }, }, HACKNET_NODE_10M: { - ...achievementData["HACKNET_NODE_10M"], + ...achievementData.HACKNET_NODE_10M, Icon: "hacknet-10m", Condition: () => !hasHacknetServers() && Player.moneySourceB.hacknet >= 10e6, }, REPUTATION_10M: { - ...achievementData["REPUTATION_10M"], + ...achievementData.REPUTATION_10M, Icon: "reputation", Condition: () => Object.values(Factions).some((f) => f.playerReputation >= 10e6), }, DONATION: { - ...achievementData["DONATION"], + ...achievementData.DONATION, Icon: "donation", Condition: () => Object.values(Factions).some( @@ -385,45 +383,45 @@ export const achievements: Record = { ), }, TRAVEL: { - ...achievementData["TRAVEL"], + ...achievementData.TRAVEL, Icon: "TRAVEL", Condition: () => Player.city !== CityName.Sector12, }, WORKOUT: { - ...achievementData["WORKOUT"], + ...achievementData.WORKOUT, Icon: "WORKOUT", Condition: () => isClassWork(Player.currentWork), }, TOR: { - ...achievementData["TOR"], + ...achievementData.TOR, Icon: "TOR", Condition: () => Player.hasTorRouter(), }, HOSPITALIZED: { - ...achievementData["HOSPITALIZED"], + ...achievementData.HOSPITALIZED, Icon: "OUCH", Condition: () => Player.moneySourceB.hospitalization !== 0, }, GANG: { - ...achievementData["GANG"], + ...achievementData.GANG, Icon: "GANG", Visible: () => hasAccessToSF(Player, 2), Condition: () => Player.gang !== null, }, FULL_GANG: { - ...achievementData["FULL_GANG"], + ...achievementData.FULL_GANG, Icon: "GANGMAX", Visible: () => hasAccessToSF(Player, 2), Condition: () => Player.gang !== null && Player.gang.members.length === GangConstants.MaximumGangMembers, }, GANG_TERRITORY: { - ...achievementData["GANG_TERRITORY"], + ...achievementData.GANG_TERRITORY, Icon: "GANG100%", Visible: () => hasAccessToSF(Player, 2), Condition: () => Player.gang !== null && AllGangs[Player.gang.facName].territory >= 0.999, }, GANG_MEMBER_POWER: { - ...achievementData["GANG_MEMBER_POWER"], + ...achievementData.GANG_MEMBER_POWER, Icon: "GANG10000", Visible: () => hasAccessToSF(Player, 2), Condition: () => @@ -434,25 +432,25 @@ export const achievements: Record = { ), }, CORPORATION: { - ...achievementData["CORPORATION"], + ...achievementData.CORPORATION, Icon: "CORP", Visible: () => hasAccessToSF(Player, 3), Condition: () => Player.corporation !== null, }, CORPORATION_BRIBE: { - ...achievementData["CORPORATION_BRIBE"], + ...achievementData.CORPORATION_BRIBE, Icon: "CORPLOBBY", Visible: () => hasAccessToSF(Player, 3), Condition: () => Player.corporation !== null && Player.corporation.unlockUpgrades[6] === 1, }, CORPORATION_PROD_1000: { - ...achievementData["CORPORATION_PROD_1000"], + ...achievementData.CORPORATION_PROD_1000, Icon: "CORP1000", Visible: () => hasAccessToSF(Player, 3), Condition: () => Player.corporation !== null && Player.corporation.divisions.some((d) => d.prodMult >= 1000), }, CORPORATION_EMPLOYEE_3000: { - ...achievementData["CORPORATION_EMPLOYEE_3000"], + ...achievementData.CORPORATION_EMPLOYEE_3000, Icon: "CORPCITY", Visible: () => hasAccessToSF(Player, 3), Condition: (): boolean => { @@ -466,7 +464,7 @@ export const achievements: Record = { }, }, CORPORATION_REAL_ESTATE: { - ...achievementData["CORPORATION_REAL_ESTATE"], + ...achievementData.CORPORATION_REAL_ESTATE, Icon: "CORPRE", Name: "Own the land", Description: "Expand to the Real Estate division.", @@ -475,19 +473,19 @@ export const achievements: Record = { Player.corporation !== null && Player.corporation.divisions.some((d) => d.type === IndustryType.RealEstate), }, INTELLIGENCE_255: { - ...achievementData["INTELLIGENCE_255"], + ...achievementData.INTELLIGENCE_255, Icon: "INT255", Visible: () => hasAccessToSF(Player, 5), Condition: () => Player.skills.intelligence >= 255, }, BLADEBURNER_DIVISION: { - ...achievementData["BLADEBURNER_DIVISION"], + ...achievementData.BLADEBURNER_DIVISION, Icon: "BLADE", Visible: () => hasAccessToSF(Player, 6), Condition: () => Player.bladeburner !== null, }, BLADEBURNER_OVERCLOCK: { - ...achievementData["BLADEBURNER_OVERCLOCK"], + ...achievementData.BLADEBURNER_OVERCLOCK, Icon: "BLADEOVERCLOCK", Visible: () => hasAccessToSF(Player, 6), Condition: () => @@ -495,7 +493,7 @@ export const achievements: Record = { Player.bladeburner.skills[SkillNames.Overclock] === Skills[SkillNames.Overclock].maxLvl, }, BLADEBURNER_UNSPENT_100000: { - ...achievementData["BLADEBURNER_UNSPENT_100000"], + ...achievementData.BLADEBURNER_UNSPENT_100000, Icon: "BLADE100K", Visible: () => hasAccessToSF(Player, 6), Condition: () => Player.bladeburner !== null && Player.bladeburner.skillPoints >= 100000, @@ -506,21 +504,21 @@ export const achievements: Record = { Condition: () => Player.has4SData, }, FIRST_HACKNET_SERVER: { - ...achievementData["FIRST_HACKNET_SERVER"], + ...achievementData.FIRST_HACKNET_SERVER, Icon: "HASHNET", Visible: () => hasAccessToSF(Player, 9), Condition: () => hasHacknetServers() && Player.hacknetNodes.length > 0, AdditionalUnlock: [achievementData.FIRST_HACKNET_NODE.ID], }, ALL_HACKNET_SERVER: { - ...achievementData["ALL_HACKNET_SERVER"], + ...achievementData.ALL_HACKNET_SERVER, Icon: "HASHNETALL", Visible: () => hasAccessToSF(Player, 9), Condition: () => hasHacknetServers() && Player.hacknetNodes.length === HacknetServerConstants.MaxServers, AdditionalUnlock: [achievementData["30_HACKNET_NODE"].ID], }, MAX_HACKNET_SERVER: { - ...achievementData["MAX_HACKNET_SERVER"], + ...achievementData.MAX_HACKNET_SERVER, Icon: "HASHNETALL", Visible: () => hasAccessToSF(Player, 9), Condition: (): boolean => { @@ -542,14 +540,14 @@ export const achievements: Record = { AdditionalUnlock: [achievementData.MAX_HACKNET_NODE.ID], }, HACKNET_SERVER_1B: { - ...achievementData["HACKNET_SERVER_1B"], + ...achievementData.HACKNET_SERVER_1B, Icon: "HASHNETMONEY", Visible: () => hasAccessToSF(Player, 9), Condition: () => hasHacknetServers() && Player.moneySourceB.hacknet >= 1e9, AdditionalUnlock: [achievementData.HACKNET_NODE_10M.ID], }, MAX_CACHE: { - ...achievementData["MAX_CACHE"], + ...achievementData.MAX_CACHE, Icon: "HASHNETCAP", Visible: () => hasAccessToSF(Player, 9), Condition: () => @@ -558,13 +556,13 @@ export const achievements: Record = { Player.hashManager.capacity > 0, }, SLEEVE_8: { - ...achievementData["SLEEVE_8"], + ...achievementData.SLEEVE_8, Icon: "SLEEVE8", Visible: () => hasAccessToSF(Player, 10), Condition: () => Player.sleeves.length === 8 && Player.sourceFileLvl(10) === 3, }, INDECISIVE: { - ...achievementData["INDECISIVE"], + ...achievementData.INDECISIVE, Icon: "1H", Visible: () => knowsAboutBitverse(Player), Condition: (function () { @@ -580,13 +578,13 @@ export const achievements: Record = { })(), }, FAST_BN: { - ...achievementData["FAST_BN"], + ...achievementData.FAST_BN, Icon: "2DAYS", Visible: () => knowsAboutBitverse(Player), Condition: () => bitNodeFinishedState() && Player.playtimeSinceLastBitnode < 1000 * 60 * 60 * 24 * 2, }, CHALLENGE_BN1: { - ...achievementData["CHALLENGE_BN1"], + ...achievementData.CHALLENGE_BN1, Icon: "BN1+", Visible: () => knowsAboutBitverse(Player), Condition: () => @@ -596,37 +594,37 @@ export const achievements: Record = { Player.getHomeComputer().cpuCores === 1, }, CHALLENGE_BN2: { - ...achievementData["CHALLENGE_BN2"], + ...achievementData.CHALLENGE_BN2, Icon: "BN2+", Visible: () => hasAccessToSF(Player, 2), Condition: () => Player.bitNodeN === 2 && bitNodeFinishedState() && Player.gang === null, }, CHALLENGE_BN3: { - ...achievementData["CHALLENGE_BN3"], + ...achievementData.CHALLENGE_BN3, Icon: "BN3+", Visible: () => hasAccessToSF(Player, 3), Condition: () => Player.bitNodeN === 3 && bitNodeFinishedState() && Player.corporation === null, }, CHALLENGE_BN6: { - ...achievementData["CHALLENGE_BN6"], + ...achievementData.CHALLENGE_BN6, Icon: "BN6+", Visible: () => hasAccessToSF(Player, 6), Condition: () => Player.bitNodeN === 6 && bitNodeFinishedState() && Player.bladeburner === null, }, CHALLENGE_BN7: { - ...achievementData["CHALLENGE_BN7"], + ...achievementData.CHALLENGE_BN7, Icon: "BN7+", Visible: () => hasAccessToSF(Player, 7), Condition: () => Player.bitNodeN === 7 && bitNodeFinishedState() && Player.bladeburner === null, }, CHALLENGE_BN8: { - ...achievementData["CHALLENGE_BN8"], + ...achievementData.CHALLENGE_BN8, Icon: "BN8+", Visible: () => hasAccessToSF(Player, 8), Condition: () => Player.bitNodeN === 8 && bitNodeFinishedState() && !Player.has4SData && !Player.has4SDataTixApi, }, CHALLENGE_BN9: { - ...achievementData["CHALLENGE_BN9"], + ...achievementData.CHALLENGE_BN9, Icon: "BN9+", Visible: () => hasAccessToSF(Player, 9), Condition: () => @@ -636,7 +634,7 @@ export const achievements: Record = { Player.moneySourceB.hacknet_expenses === 0, }, CHALLENGE_BN10: { - ...achievementData["CHALLENGE_BN10"], + ...achievementData.CHALLENGE_BN10, Icon: "BN10+", Visible: () => hasAccessToSF(Player, 10), Condition: () => @@ -654,68 +652,68 @@ export const achievements: Record = { ), }, CHALLENGE_BN12: { - ...achievementData["CHALLENGE_BN12"], + ...achievementData.CHALLENGE_BN12, Icon: "BN12+", Visible: () => hasAccessToSF(Player, 12), Condition: () => Player.sourceFileLvl(12) >= 50, }, BYPASS: { - ...achievementData["BYPASS"], + ...achievementData.BYPASS, Icon: "SF-1", Secret: true, Condition: () => Player.exploits.includes(Exploit.Bypass), }, PROTOTYPETAMPERING: { - ...achievementData["PROTOTYPETAMPERING"], + ...achievementData.PROTOTYPETAMPERING, Icon: "SF-1", Secret: true, Condition: () => Player.exploits.includes(Exploit.PrototypeTampering), }, UNCLICKABLE: { - ...achievementData["UNCLICKABLE"], + ...achievementData.UNCLICKABLE, Icon: "SF-1", Secret: true, Condition: () => Player.exploits.includes(Exploit.Unclickable), }, UNDOCUMENTEDFUNCTIONCALL: { - ...achievementData["UNDOCUMENTEDFUNCTIONCALL"], + ...achievementData.UNDOCUMENTEDFUNCTIONCALL, Icon: "SF-1", Secret: true, Condition: () => Player.exploits.includes(Exploit.UndocumentedFunctionCall), }, TIMECOMPRESSION: { - ...achievementData["TIMECOMPRESSION"], + ...achievementData.TIMECOMPRESSION, Icon: "SF-1", Secret: true, Condition: () => Player.exploits.includes(Exploit.TimeCompression), }, REALITYALTERATION: { - ...achievementData["REALITYALTERATION"], + ...achievementData.REALITYALTERATION, Icon: "SF-1", Secret: true, Condition: () => Player.exploits.includes(Exploit.RealityAlteration), }, N00DLES: { - ...achievementData["N00DLES"], + ...achievementData.N00DLES, Icon: "SF-1", Secret: true, Condition: () => Player.exploits.includes(Exploit.N00dles), }, EDITSAVEFILE: { - ...achievementData["EDITSAVEFILE"], + ...achievementData.EDITSAVEFILE, Icon: "SF-1", Secret: true, Condition: () => Player.exploits.includes(Exploit.EditSaveFile), }, UNACHIEVABLE: { - ...achievementData["UNACHIEVABLE"], + ...achievementData.UNACHIEVABLE, Icon: "SF-1", Secret: true, // Hey Players! Yes, you're supposed to modify this to get the achievement! Condition: () => false, }, CHALLENGE_BN13: { - ...achievementData["CHALLENGE_BN13"], + ...achievementData.CHALLENGE_BN13, Icon: "BN13+", Visible: () => hasAccessToSF(Player, 13), Condition: () => @@ -724,19 +722,19 @@ export const achievements: Record = { !Player.augmentations.some((a) => a.name === AugmentationNames.StaneksGift1), }, DEVMENU: { - ...achievementData["DEVMENU"], + ...achievementData.DEVMENU, Icon: "SF-1", Secret: true, Condition: () => Player.exploits.includes(Exploit.YoureNotMeantToAccessThis), }, RAINBOW: { - ...achievementData["RAINBOW"], + ...achievementData.RAINBOW, Icon: "SF-1", Secret: true, Condition: () => Player.exploits.includes(Exploit.INeedARainbow), }, TRUE_RECURSION: { - ...achievementData["TRUE_RECURSION"], + ...achievementData.TRUE_RECURSION, Icon: "SF-1", Secret: true, Condition: () => Player.exploits.includes(Exploit.TrueRecursion), diff --git a/src/Alias.ts b/src/Alias.ts index 585315c86..0586ea6e4 100644 --- a/src/Alias.ts +++ b/src/Alias.ts @@ -1,36 +1,30 @@ import { Terminal } from "./Terminal"; -export let Aliases: Record = {}; -export let GlobalAliases: Record = {}; +export const Aliases = new Map(); +export const GlobalAliases = new Map(); export function loadAliases(saveString: string): void { - if (saveString === "") { - Aliases = {}; - } else { - Aliases = JSON.parse(saveString); + Aliases.clear(); + const parsedAliases: unknown = JSON.parse(saveString); + if (!parsedAliases || typeof parsedAliases !== "object") return; + for (const [name, alias] of Object.entries(parsedAliases)) { + if (typeof name === "string" && typeof alias === "string") Aliases.set(name, alias); } } export function loadGlobalAliases(saveString: string): void { - if (saveString === "") { - GlobalAliases = {}; - } else { - GlobalAliases = JSON.parse(saveString); + GlobalAliases.clear(); + const parsedAliases: unknown = JSON.parse(saveString); + if (!parsedAliases || typeof parsedAliases !== "object") return; + for (const [name, alias] of Object.entries(parsedAliases)) { + if (typeof name === "string" && typeof alias === "string") GlobalAliases.set(name, alias); } } // Prints all aliases to terminal export function printAliases(): void { - for (const name of Object.keys(Aliases)) { - if (Aliases.hasOwnProperty(name)) { - Terminal.print("alias " + name + "=" + Aliases[name]); - } - } - for (const name of Object.keys(GlobalAliases)) { - if (GlobalAliases.hasOwnProperty(name)) { - Terminal.print("global alias " + name + "=" + GlobalAliases[name]); - } - } + for (const [name, alias] of Aliases) Terminal.print("alias " + name + "=" + alias); + for (const [name, alias] of GlobalAliases) Terminal.print("global alias " + name + "=" + alias); } // Returns true if successful, false otherwise @@ -50,46 +44,20 @@ export function parseAliasDeclaration(dec: string, global = false): boolean { } function addAlias(name: string, value: string): void { - if (name in GlobalAliases) { - delete GlobalAliases[name]; - } - Aliases[name] = value.trim(); + GlobalAliases.delete(name); + Aliases.set(name, value.trim()); } function addGlobalAlias(name: string, value: string): void { - if (name in Aliases) { - delete Aliases[name]; - } - GlobalAliases[name] = value.trim(); -} - -function getAlias(name: string): string | null { - if (Aliases.hasOwnProperty(name)) { - return Aliases[name]; - } - - return null; -} - -function getGlobalAlias(name: string): string | null { - if (GlobalAliases.hasOwnProperty(name)) { - return GlobalAliases[name]; - } - return null; + Aliases.delete(name); + GlobalAliases.set(name, value.trim()); } export function removeAlias(name: string): boolean { - if (Aliases.hasOwnProperty(name)) { - delete Aliases[name]; - return true; - } - - if (GlobalAliases.hasOwnProperty(name)) { - delete GlobalAliases[name]; - return true; - } - - return false; + const hadAlias = Aliases.has(name) || GlobalAliases.has(name); + Aliases.delete(name); + GlobalAliases.delete(name); + return hadAlias; } /** @@ -110,15 +78,15 @@ export function substituteAliases(origCommand: string): string { while (somethingSubstituted && depth < 10) { depth++; somethingSubstituted = false; - const alias = getAlias(commandArray[0])?.split(" "); - if (alias != null) { + const alias = Aliases.get(commandArray[0])?.split(" "); + if (alias !== undefined) { somethingSubstituted = true; commandArray.splice(0, 1, ...alias); //commandArray[0] = alias; } for (let i = 0; i < commandArray.length; ++i) { - const alias = getGlobalAlias(commandArray[i])?.split(" "); - if (alias != null) { + const alias = GlobalAliases.get(commandArray[i])?.split(" "); + if (alias !== undefined) { somethingSubstituted = true; commandArray.splice(i, 1, ...alias); i += alias.length - 1; diff --git a/src/Augmentation/Augmentation.tsx b/src/Augmentation/Augmentation.tsx index f1d601861..a961c6b8d 100644 --- a/src/Augmentation/Augmentation.tsx +++ b/src/Augmentation/Augmentation.tsx @@ -584,16 +584,8 @@ export class Augmentation { // Adds this Augmentation to all Factions addToAllFactions(): void { - for (const fac of Object.keys(Factions)) { - if (Factions.hasOwnProperty(fac)) { - const facObj: Faction | null = Factions[fac]; - if (facObj == null) { - console.warn(`Invalid Faction object in addToAllFactions(). Key value: ${fac}`); - continue; - } - if (facObj.getInfo().special) continue; - facObj.augmentations.push(this.name); - } + for (const faction of Object.values(Factions)) { + if (!faction.getInfo().special) faction.augmentations.push(this.name); } } diff --git a/src/Augmentation/AugmentationHelpers.tsx b/src/Augmentation/AugmentationHelpers.tsx index 96648f5f9..13d007fd1 100644 --- a/src/Augmentation/AugmentationHelpers.tsx +++ b/src/Augmentation/AugmentationHelpers.tsx @@ -9,7 +9,6 @@ import { Player } from "@player"; import { prestigeAugmentation } from "../Prestige"; import { dialogBoxCreate } from "../ui/React/DialogBox"; -import { clearObject } from "../utils/helpers/clearObject"; import { FactionNames } from "../Faction/data/FactionNames"; import { @@ -41,16 +40,12 @@ function createAugmentations(): void { } function resetFactionAugmentations(): void { - for (const name of Object.keys(Factions)) { - if (Factions.hasOwnProperty(name)) { - Factions[name].augmentations = []; - } - } + for (const faction of Object.values(Factions)) faction.augmentations = []; } function initAugmentations(): void { resetFactionAugmentations(); - clearObject(StaticAugmentations); + for (const augName of Object.getOwnPropertyNames(StaticAugmentations)) delete StaticAugmentations[augName]; createAugmentations(); Player.reapplyAllAugmentations(); } @@ -144,7 +139,7 @@ function installAugmentations(force?: boolean): boolean { } function augmentationExists(name: string): boolean { - return StaticAugmentations.hasOwnProperty(name); + return Object.hasOwn(StaticAugmentations, name); } export function isRepeatableAug(aug: Augmentation | string): boolean { diff --git a/src/Augmentation/ui/PurchaseAugmentationModal.tsx b/src/Augmentation/ui/PurchaseAugmentationModal.tsx index 11b930be5..2656fe629 100644 --- a/src/Augmentation/ui/PurchaseAugmentationModal.tsx +++ b/src/Augmentation/ui/PurchaseAugmentationModal.tsx @@ -17,36 +17,33 @@ interface IProps { aug?: Augmentation; } -export function PurchaseAugmentationModal(props: IProps): React.ReactElement { - if (!props.aug || !props.faction) { +export function PurchaseAugmentationModal({ aug, faction, onClose, open }: IProps): React.ReactElement { + if (!aug || !faction || (!isRepeatableAug(aug) && Player.hasAugmentation(aug.name))) { return <>; } - function buy(): void { - if (!props.aug || (!isRepeatableAug(props.aug) && Player.hasAugmentation(props.aug.name))) { - return; - } - - purchaseAugmentation(props.aug as Augmentation, props.faction as Faction); - props.onClose(); - } - return ( - - {props.aug.name} + + {aug.name} - {props.aug.info} + {aug.info}

- {props.aug.stats} + {aug.stats}

- Would you like to purchase the {props.aug.name} Augmentation for  - ? + Would you like to purchase the {aug.name} Augmentation for  + ?

-
diff --git a/src/BitNode/BitNode.tsx b/src/BitNode/BitNode.tsx index 757d6c61a..dfa1ebe66 100644 --- a/src/BitNode/BitNode.tsx +++ b/src/BitNode/BitNode.tsx @@ -30,7 +30,7 @@ class BitNode { export const BitNodes: Record = {}; export function initBitNodes() { - BitNodes["BitNode1"] = new BitNode( + BitNodes.BitNode1 = new BitNode( 1, 0, "Source Genesis", @@ -57,7 +57,7 @@ export function initBitNodes() { ), ); - BitNodes["BitNode2"] = new BitNode( + BitNodes.BitNode2 = new BitNode( 2, 0, "Rise of the Underworld", @@ -95,7 +95,7 @@ export function initBitNodes() { ), ); - BitNodes["BitNode3"] = new BitNode( + BitNodes.BitNode3 = new BitNode( 3, 0, "Corporatocracy", @@ -127,7 +127,7 @@ export function initBitNodes() { ), ); - BitNodes["BitNode4"] = new BitNode( + BitNodes.BitNode4 = new BitNode( 4, 1, "The Singularity", @@ -155,7 +155,7 @@ export function initBitNodes() { ), ); - BitNodes["BitNode5"] = new BitNode( + BitNodes.BitNode5 = new BitNode( 5, 1, "Artificial Intelligence", @@ -185,7 +185,7 @@ export function initBitNodes() { ), ); - BitNodes["BitNode6"] = new BitNode( + BitNodes.BitNode6 = new BitNode( 6, 1, FactionNames.Bladeburners, @@ -217,7 +217,7 @@ export function initBitNodes() { ), ); - BitNodes["BitNode7"] = new BitNode( + BitNodes.BitNode7 = new BitNode( 7, 2, `${FactionNames.Bladeburners} 2079`, @@ -249,7 +249,7 @@ export function initBitNodes() { ), ); - BitNodes["BitNode8"] = new BitNode( + BitNodes.BitNode8 = new BitNode( 8, 2, "Ghost of Wall Street", @@ -290,7 +290,7 @@ export function initBitNodes() { ), ); - BitNodes["BitNode9"] = new BitNode( + BitNodes.BitNode9 = new BitNode( 9, 2, "Hacktocracy", @@ -332,7 +332,7 @@ export function initBitNodes() { ), ); - BitNodes["BitNode10"] = new BitNode( + BitNodes.BitNode10 = new BitNode( 10, 2, "Digital Carbon", @@ -363,7 +363,7 @@ export function initBitNodes() { ), ); - BitNodes["BitNode11"] = new BitNode( + BitNodes.BitNode11 = new BitNode( 11, 1, "The Big Crash", @@ -406,7 +406,7 @@ export function initBitNodes() { ), ); - BitNodes["BitNode12"] = new BitNode( + BitNodes.BitNode12 = new BitNode( 12, 0, "The Recursion", @@ -423,7 +423,7 @@ export function initBitNodes() { ), ); - BitNodes["BitNode13"] = new BitNode( + BitNodes.BitNode13 = new BitNode( 13, 2, "They're lunatics", diff --git a/src/BitNode/BitNodeMultipliers.ts b/src/BitNode/BitNodeMultipliers.ts index 3d51bc540..bb10c6fc2 100644 --- a/src/BitNode/BitNodeMultipliers.ts +++ b/src/BitNode/BitNodeMultipliers.ts @@ -165,5 +165,4 @@ export interface IBitNodeMultipliers { } /** The multipliers that are influenced by current Bitnode progression. */ -// tslint:disable-next-line:variable-name export const BitNodeMultipliers = Object.assign({}, defaultMultipliers); diff --git a/src/BitNode/ui/BitnodeMultipliersDescription.tsx b/src/BitNode/ui/BitnodeMultipliersDescription.tsx index 4336ceda3..90767678e 100644 --- a/src/BitNode/ui/BitnodeMultipliersDescription.tsx +++ b/src/BitNode/ui/BitnodeMultipliersDescription.tsx @@ -60,13 +60,14 @@ export const BitNodeMultipliersDisplay = ({ n, level }: IProps): React.ReactElem ); }; -interface IBNMultRows { - [mult: string]: { +type IBNMultRows = Record< + string, + { name: string; content?: string; color?: string; - }; -} + } +>; interface IBNMultTableProps { sectionName: string; diff --git a/src/Bladeburner/Action.tsx b/src/Bladeburner/Action.tsx index f74ae4820..767b2c441 100644 --- a/src/Bladeburner/Action.tsx +++ b/src/Bladeburner/Action.tsx @@ -122,7 +122,7 @@ export class Action { // Check to make sure weights are summed properly let sum = 0; for (const weight of Object.keys(this.weights)) { - if (this.weights.hasOwnProperty(weight)) { + if (Object.hasOwn(this.weights, weight)) { sum += this.weights[weight]; } } @@ -136,7 +136,7 @@ export class Action { } for (const decay of Object.keys(this.decays)) { - if (this.decays.hasOwnProperty(decay)) { + if (Object.hasOwn(this.decays, decay)) { if (this.decays[decay] > 1) { throw new Error(`Invalid decays when constructing Action ${this.name}. Decay value cannot be greater than 1`); } @@ -243,7 +243,7 @@ export class Action { let difficulty = this.getDifficulty(); let competence = 0; for (const stat of Object.keys(this.weights)) { - if (this.weights.hasOwnProperty(stat)) { + if (Object.hasOwn(this.weights, stat)) { const playerStatLvl = person.queryStatFromString(stat); const key = "eff" + stat.charAt(0).toUpperCase() + stat.slice(1); let effMultiplier = inst.skillMultipliers[key]; diff --git a/src/Bladeburner/Bladeburner.tsx b/src/Bladeburner/Bladeburner.tsx index 82dd1633b..b2cacafa0 100644 --- a/src/Bladeburner/Bladeburner.tsx +++ b/src/Bladeburner/Bladeburner.tsx @@ -67,7 +67,7 @@ export class Bladeburner { actionTimeOverflow = 0; action: ActionIdentifier = new ActionIdentifier({ - type: ActionTypes["Idle"], + type: ActionTypes.Idle, }); cities: Record; @@ -90,11 +90,11 @@ export class Bladeburner { }; automateEnabled = false; automateActionHigh: ActionIdentifier = new ActionIdentifier({ - type: ActionTypes["Idle"], + type: ActionTypes.Idle, }); automateThreshHigh = 0; automateActionLow: ActionIdentifier = new ActionIdentifier({ - type: ActionTypes["Idle"], + type: ActionTypes.Idle, }); automateThreshLow = 0; consoleHistory: string[] = []; @@ -138,7 +138,7 @@ export class Bladeburner { // Can't start a BlackOp if you haven't done the one before it const blackops = []; for (const nm of Object.keys(BlackOperations)) { - if (BlackOperations.hasOwnProperty(nm)) { + if (Object.hasOwn(BlackOperations, nm)) { blackops.push(nm); } } @@ -165,10 +165,10 @@ export class Bladeburner { this.action = actionId; this.actionTimeCurrent = 0; switch (actionId.type) { - case ActionTypes["Idle"]: + case ActionTypes.Idle: this.actionTimeToComplete = 0; break; - case ActionTypes["Contract"]: + case ActionTypes.Contract: try { const action = this.getActionObject(actionId); if (action == null) { @@ -182,7 +182,7 @@ export class Bladeburner { exceptionAlert(e); } break; - case ActionTypes["Operation"]: { + case ActionTypes.Operation: { try { const action = this.getActionObject(actionId); if (action == null) { @@ -200,8 +200,8 @@ export class Bladeburner { } break; } - case ActionTypes["BlackOp"]: - case ActionTypes["BlackOperation"]: { + case ActionTypes.BlackOp: + case ActionTypes.BlackOperation: { try { const testBlackOp = this.canAttemptBlackOp(actionId); if (!testBlackOp.isAvailable) { @@ -218,15 +218,15 @@ export class Bladeburner { } break; } - case ActionTypes["Recruitment"]: + case ActionTypes.Recruitment: this.actionTimeToComplete = this.getRecruitmentTime(Player); break; - case ActionTypes["Training"]: - case ActionTypes["FieldAnalysis"]: + case ActionTypes.Training: + case ActionTypes.FieldAnalysis: case ActionTypes["Field Analysis"]: this.actionTimeToComplete = 30; break; - case ActionTypes["Diplomacy"]: + case ActionTypes.Diplomacy: case ActionTypes["Hyperbolic Regeneration Chamber"]: case ActionTypes["Incite Violence"]: this.actionTimeToComplete = 60; @@ -318,8 +318,8 @@ export class Bladeburner { case "contract": case "contracts": case "contr": - action.type = ActionTypes["Contract"]; - if (this.contracts.hasOwnProperty(name)) { + action.type = ActionTypes.Contract; + if (Object.hasOwn(this.contracts, name)) { action.name = name; return action; } @@ -328,8 +328,8 @@ export class Bladeburner { case "operations": case "op": case "ops": - action.type = ActionTypes["Operation"]; - if (this.operations.hasOwnProperty(name)) { + action.type = ActionTypes.Operation; + if (Object.hasOwn(this.operations, name)) { action.name = name; return action; } @@ -341,8 +341,8 @@ export class Bladeburner { case "black ops": case "blackop": case "blackops": - action.type = ActionTypes["BlackOp"]; - if (BlackOperations.hasOwnProperty(name)) { + action.type = ActionTypes.BlackOp; + if (Object.hasOwn(BlackOperations, name)) { action.name = name; return action; } @@ -358,12 +358,12 @@ export class Bladeburner { if (convertedType.startsWith("gen")) { switch (convertedName) { case "training": - action.type = ActionTypes["Training"]; + action.type = ActionTypes.Training; action.name = "Training"; break; case "recruitment": case "recruit": - action.type = ActionTypes["Recruitment"]; + action.type = ActionTypes.Recruitment; action.name = "Recruitment"; break; case "field analysis": @@ -372,7 +372,7 @@ export class Bladeburner { action.name = "Field Analysis"; break; case "diplomacy": - action.type = ActionTypes["Diplomacy"]; + action.type = ActionTypes.Diplomacy; action.name = "Diplomacy"; break; case "hyperbolic regeneration chamber": @@ -1063,7 +1063,7 @@ export class Bladeburner { updateSkillMultipliers(): void { this.resetSkillMultipliers(); for (const skillName of Object.keys(this.skills)) { - if (this.skills.hasOwnProperty(skillName)) { + if (Object.hasOwn(this.skills, skillName)) { const skill = Skills[skillName]; if (skill == null) { throw new Error("Could not find Skill Object for: " + skillName); @@ -1191,21 +1191,21 @@ export class Bladeburner { * GeneralAction, Contract, Operation, or BlackOperation object */ switch (actionId.type) { - case ActionTypes["Contract"]: + case ActionTypes.Contract: return this.contracts[actionId.name]; - case ActionTypes["Operation"]: + case ActionTypes.Operation: return this.operations[actionId.name]; - case ActionTypes["BlackOp"]: - case ActionTypes["BlackOperation"]: + case ActionTypes.BlackOp: + case ActionTypes.BlackOperation: return BlackOperations[actionId.name]; - case ActionTypes["Training"]: - return GeneralActions["Training"]; + case ActionTypes.Training: + return GeneralActions.Training; case ActionTypes["Field Analysis"]: return GeneralActions["Field Analysis"]; - case ActionTypes["Recruitment"]: - return GeneralActions["Recruitment"]; - case ActionTypes["Diplomacy"]: - return GeneralActions["Diplomacy"]; + case ActionTypes.Recruitment: + return GeneralActions.Recruitment; + case ActionTypes.Diplomacy: + return GeneralActions.Diplomacy; case ActionTypes["Hyperbolic Regeneration Chamber"]: return GeneralActions["Hyperbolic Regeneration Chamber"]; case ActionTypes["Incite Violence"]: @@ -1243,10 +1243,10 @@ export class Bladeburner { completeAction(person: Person, actionIdent: ActionIdentifier, isPlayer = true): WorkStats { let retValue = newWorkStats(); switch (actionIdent.type) { - case ActionTypes["Contract"]: - case ActionTypes["Operation"]: { + case ActionTypes.Contract: + case ActionTypes.Operation: { try { - const isOperation = actionIdent.type === ActionTypes["Operation"]; + const isOperation = actionIdent.type === ActionTypes.Operation; const action = this.getActionObject(actionIdent); if (action == null) { throw new Error("Failed to get Contract/Operation Object for: " + actionIdent.name); @@ -1340,8 +1340,8 @@ export class Bladeburner { } break; } - case ActionTypes["BlackOp"]: - case ActionTypes["BlackOperation"]: { + case ActionTypes.BlackOp: + case ActionTypes.BlackOperation: { try { const action = this.getActionObject(actionIdent); if (action == null || !(action instanceof BlackOperation)) { @@ -1441,7 +1441,7 @@ export class Bladeburner { } break; } - case ActionTypes["Training"]: { + case ActionTypes.Training: { this.stamina -= 0.5 * BladeburnerConstants.BaseStaminaLoss; const strExpGain = 30 * person.mults.strength_exp, defExpGain = 30 * person.mults.defense_exp, @@ -1471,7 +1471,7 @@ export class Bladeburner { } break; } - case ActionTypes["FieldAnalysis"]: + case ActionTypes.FieldAnalysis: case ActionTypes["Field Analysis"]: { // Does not use stamina. Effectiveness depends on hacking, int, and cha let eff = @@ -1500,7 +1500,7 @@ export class Bladeburner { } break; } - case ActionTypes["Recruitment"]: { + case ActionTypes.Recruitment: { const successChance = this.getRecruitmentSuccessChance(person); const recruitTime = this.getRecruitmentTime(person) * 1000; if (Math.random() < successChance) { @@ -1529,7 +1529,7 @@ export class Bladeburner { } break; } - case ActionTypes["Diplomacy"]: { + case ActionTypes.Diplomacy: { const eff = this.getDiplomacyEffectiveness(person); this.getCurrentCity().chaos *= eff; if (this.getCurrentCity().chaos < 0) { @@ -1638,7 +1638,7 @@ export class Bladeburner { } processAction(seconds: number): void { - if (this.action.type === ActionTypes["Idle"]) return; + if (this.action.type === ActionTypes.Idle) return; if (this.actionTimeToComplete <= 0) { throw new Error(`Invalid actionTimeToComplete value: ${this.actionTimeToComplete}, type; ${this.action.type}`); } @@ -1659,7 +1659,7 @@ export class Bladeburner { // Operation Daedalus if (action == null) { throw new Error("Failed to get BlackOperation Object for: " + this.action.name); - } else if (this.action.type != ActionTypes["BlackOperation"] && this.action.type != ActionTypes["BlackOp"]) { + } else if (this.action.type != ActionTypes.BlackOperation && this.action.type != ActionTypes.BlackOp) { this.startAction(this.action); // Repeat action } } @@ -1689,7 +1689,7 @@ export class Bladeburner { } create(): void { - this.contracts["Tracking"] = new Contract({ + this.contracts.Tracking = new Contract({ name: "Tracking", baseDifficulty: 125, difficultyFac: 1.02, @@ -1745,7 +1745,7 @@ export class Bladeburner { }, isKill: true, }); - this.contracts["Retirement"] = new Contract({ + this.contracts.Retirement = new Contract({ name: "Retirement", baseDifficulty: 200, difficultyFac: 1.03, @@ -1774,7 +1774,7 @@ export class Bladeburner { isKill: true, }); - this.operations["Investigation"] = new Operation({ + this.operations.Investigation = new Operation({ name: "Investigation", baseDifficulty: 400, difficultyFac: 1.03, @@ -1863,7 +1863,7 @@ export class Bladeburner { }, isStealth: true, }); - this.operations["Raid"] = new Operation({ + this.operations.Raid = new Operation({ name: "Raid", baseDifficulty: 800, difficultyFac: 1.045, @@ -1924,7 +1924,7 @@ export class Bladeburner { isStealth: true, isKill: true, }); - this.operations["Assassination"] = new Operation({ + this.operations.Assassination = new Operation({ name: "Assassination", baseDifficulty: 1500, difficultyFac: 1.06, @@ -1963,7 +1963,7 @@ export class Bladeburner { // If the Player starts doing some other actions, set action to idle and alert if (!Player.hasAugmentation(AugmentationNames.BladesSimulacrum, true) && Player.currentWork) { - if (this.action.type !== ActionTypes["Idle"]) { + if (this.action.type !== ActionTypes.Idle) { let msg = "Your Bladeburner action was cancelled because you started doing something else."; if (this.automateEnabled) { msg += `\n\nYour automation was disabled as well. You will have to re-enable it through the Bladeburner console`; @@ -2111,7 +2111,7 @@ export class Bladeburner { } // Special logic for Black Ops - if (actionId.type === ActionTypes["BlackOp"]) { + if (actionId.type === ActionTypes.BlackOp) { const canRunOp = this.canAttemptBlackOp(actionId); if (!canRunOp.isAvailable) { workerScript.log("bladeburner.startAction", () => canRunOp.error + ""); @@ -2145,18 +2145,18 @@ export class Bladeburner { return "bladeburner.getActionTime"; } switch (actionId.type) { - case ActionTypes["Contract"]: - case ActionTypes["Operation"]: - case ActionTypes["BlackOp"]: - case ActionTypes["BlackOperation"]: + case ActionTypes.Contract: + case ActionTypes.Operation: + case ActionTypes.BlackOp: + case ActionTypes.BlackOperation: return actionObj.getActionTime(this, person) * 1000; - case ActionTypes["Training"]: + case ActionTypes.Training: case ActionTypes["Field Analysis"]: - case ActionTypes["FieldAnalysis"]: + case ActionTypes.FieldAnalysis: return 30000; - case ActionTypes["Recruitment"]: + case ActionTypes.Recruitment: return this.getRecruitmentTime(person) * 1000; - case ActionTypes["Diplomacy"]: + case ActionTypes.Diplomacy: case ActionTypes["Hyperbolic Regeneration Chamber"]: case ActionTypes["Incite Violence"]: return 60000; @@ -2176,19 +2176,19 @@ export class Bladeburner { return "bladeburner.getActionEstimatedSuccessChance"; } switch (actionId.type) { - case ActionTypes["Contract"]: - case ActionTypes["Operation"]: - case ActionTypes["BlackOp"]: - case ActionTypes["BlackOperation"]: + case ActionTypes.Contract: + case ActionTypes.Operation: + case ActionTypes.BlackOp: + case ActionTypes.BlackOperation: return actionObj.getEstSuccessChance(this, person); - case ActionTypes["Training"]: + case ActionTypes.Training: case ActionTypes["Field Analysis"]: - case ActionTypes["FieldAnalysis"]: - case ActionTypes["Diplomacy"]: + case ActionTypes.FieldAnalysis: + case ActionTypes.Diplomacy: case ActionTypes["Hyperbolic Regeneration Chamber"]: case ActionTypes["Incite Violence"]: return [1, 1]; - case ActionTypes["Recruitment"]: { + case ActionTypes.Recruitment: { const recChance = this.getRecruitmentSuccessChance(person); return [recChance, recChance]; } @@ -2212,21 +2212,21 @@ export class Bladeburner { } switch (actionId.type) { - case ActionTypes["Contract"]: - case ActionTypes["Operation"]: + case ActionTypes.Contract: + case ActionTypes.Operation: return Math.floor(actionObj.count); - case ActionTypes["BlackOp"]: - case ActionTypes["BlackOperation"]: + case ActionTypes.BlackOp: + case ActionTypes.BlackOperation: if (this.blackops[name] != null) { return 0; } else { return 1; } - case ActionTypes["Training"]: - case ActionTypes["Recruitment"]: + case ActionTypes.Training: + case ActionTypes.Recruitment: case ActionTypes["Field Analysis"]: - case ActionTypes["FieldAnalysis"]: - case ActionTypes["Diplomacy"]: + case ActionTypes.FieldAnalysis: + case ActionTypes.Diplomacy: case ActionTypes["Hyperbolic Regeneration Chamber"]: case ActionTypes["Incite Violence"]: return Infinity; @@ -2237,7 +2237,7 @@ export class Bladeburner { } getSkillLevelNetscriptFn(skillName: string, workerScript: WorkerScript): number { - if (skillName === "" || !Skills.hasOwnProperty(skillName)) { + if (skillName === "" || !Object.hasOwn(Skills, skillName)) { workerScript.log("bladeburner.getSkillLevel", () => `Invalid skill: '${skillName}'`); return -1; } @@ -2250,7 +2250,7 @@ export class Bladeburner { } getSkillUpgradeCostNetscriptFn(skillName: string, count: number, workerScript: WorkerScript): number { - if (skillName === "" || !Skills.hasOwnProperty(skillName)) { + if (skillName === "" || !Object.hasOwn(Skills, skillName)) { workerScript.log("bladeburner.getSkillUpgradeCost", () => `Invalid skill: '${skillName}'`); return -1; } @@ -2265,7 +2265,7 @@ export class Bladeburner { upgradeSkillNetscriptFn(skillName: string, count: number, workerScript: WorkerScript): boolean { const errorLogText = `Invalid skill: '${skillName}'`; - if (!Skills.hasOwnProperty(skillName)) { + if (!Object.hasOwn(Skills, skillName)) { workerScript.log("bladeburner.upgradeSkill", () => errorLogText); return false; } @@ -2316,9 +2316,9 @@ export class Bladeburner { } if ( - actionId.type === ActionTypes["Operation"] || - actionId.type === ActionTypes["BlackOp"] || - actionId.type === ActionTypes["BlackOperation"] + actionId.type === ActionTypes.Operation || + actionId.type === ActionTypes.BlackOp || + actionId.type === ActionTypes.BlackOperation ) { return actionObj.teamCount; } else { @@ -2335,9 +2335,9 @@ export class Bladeburner { } if ( - actionId.type !== ActionTypes["Operation"] && - actionId.type !== ActionTypes["BlackOp"] && - actionId.type !== ActionTypes["BlackOperation"] + actionId.type !== ActionTypes.Operation && + actionId.type !== ActionTypes.BlackOp && + actionId.type !== ActionTypes.BlackOperation ) { workerScript.log("bladeburner.setTeamSize", () => "Only valid for 'Operations' and 'BlackOps'"); return -1; diff --git a/src/Bladeburner/GeneralActions.tsx b/src/Bladeburner/GeneralActions.tsx index d41973ed6..496ee57c8 100644 --- a/src/Bladeburner/GeneralActions.tsx +++ b/src/Bladeburner/GeneralActions.tsx @@ -2,7 +2,7 @@ import { Action } from "./Action"; export const GeneralActions: Record = {}; -const actionNames: Array = [ +const actionNames: string[] = [ "Training", "Field Analysis", "Recruitment", diff --git a/src/Bladeburner/data/BlackOperations.tsx b/src/Bladeburner/data/BlackOperations.tsx index b8a396def..c7fd4c642 100644 --- a/src/Bladeburner/data/BlackOperations.tsx +++ b/src/Bladeburner/data/BlackOperations.tsx @@ -7,9 +7,7 @@ interface IBlackOp { desc: JSX.Element; } -export const BlackOperations: { - [key: string]: IBlackOp | undefined; -} = { +export const BlackOperations: Record = { [BlackOperationNames.OperationTyphoon]: { desc: ( <> diff --git a/src/Bladeburner/data/Contracts.tsx b/src/Bladeburner/data/Contracts.tsx index 21f6513aa..afc00ea4a 100644 --- a/src/Bladeburner/data/Contracts.tsx +++ b/src/Bladeburner/data/Contracts.tsx @@ -4,9 +4,7 @@ interface IContract { desc: JSX.Element; } -export const Contracts: { - [key: string]: IContract | undefined; -} = { +export const Contracts: Record = { Tracking: { desc: ( <> diff --git a/src/Bladeburner/data/GeneralActions.tsx b/src/Bladeburner/data/GeneralActions.tsx index 1725b21cf..64c310a0c 100644 --- a/src/Bladeburner/data/GeneralActions.tsx +++ b/src/Bladeburner/data/GeneralActions.tsx @@ -6,9 +6,7 @@ interface IGeneral { exp: WorkStats; } -export const GeneralActions: { - [key: string]: IGeneral | undefined; -} = { +export const GeneralActions: Record = { Training: { desc: ( <> diff --git a/src/Bladeburner/data/Operations.tsx b/src/Bladeburner/data/Operations.tsx index 81df45afc..77682f982 100644 --- a/src/Bladeburner/data/Operations.tsx +++ b/src/Bladeburner/data/Operations.tsx @@ -4,9 +4,7 @@ interface IOperation { desc: JSX.Element; } -export const Operations: { - [key: string]: IOperation | undefined; -} = { +export const Operations: Record = { Investigation: { desc: ( <> diff --git a/src/Bladeburner/ui/BlackOpElem.tsx b/src/Bladeburner/ui/BlackOpElem.tsx index c2ba8f2dc..d674af83b 100644 --- a/src/Bladeburner/ui/BlackOpElem.tsx +++ b/src/Bladeburner/ui/BlackOpElem.tsx @@ -33,8 +33,7 @@ export function BlackOpElem(props: IProps): React.ReactElement { } const isActive = - props.bladeburner.action.type === ActionTypes["BlackOperation"] && - props.action.name === props.bladeburner.action.name; + props.bladeburner.action.type === ActionTypes.BlackOperation && props.action.name === props.bladeburner.action.name; const actionTime = props.action.getActionTime(props.bladeburner, Player); const hasReqdRank = props.bladeburner.rank >= props.action.reqdRank; const computedActionTimeCurrent = Math.min( diff --git a/src/Bladeburner/ui/BlackOpList.tsx b/src/Bladeburner/ui/BlackOpList.tsx index a5fa39302..cebee7909 100644 --- a/src/Bladeburner/ui/BlackOpList.tsx +++ b/src/Bladeburner/ui/BlackOpList.tsx @@ -11,7 +11,7 @@ interface IProps { export function BlackOpList(props: IProps): React.ReactElement { let blackops: BlackOperation[] = []; for (const blackopName of Object.keys(BlackOperations)) { - if (BlackOperations.hasOwnProperty(blackopName)) { + if (Object.hasOwn(BlackOperations, blackopName)) { blackops.push(BlackOperations[blackopName]); } } diff --git a/src/Bladeburner/ui/ContractElem.tsx b/src/Bladeburner/ui/ContractElem.tsx index 91ee0874a..613a5bffe 100644 --- a/src/Bladeburner/ui/ContractElem.tsx +++ b/src/Bladeburner/ui/ContractElem.tsx @@ -24,7 +24,7 @@ interface IProps { export function ContractElem(props: IProps): React.ReactElement { const rerender = useRerender(); const isActive = - props.bladeburner.action.type === ActionTypes["Contract"] && props.action.name === props.bladeburner.action.name; + props.bladeburner.action.type === ActionTypes.Contract && props.action.name === props.bladeburner.action.name; const computedActionTimeCurrent = Math.min( props.bladeburner.actionTimeCurrent + props.bladeburner.actionTimeOverflow, props.bladeburner.actionTimeToComplete, diff --git a/src/Bladeburner/ui/GeneralActionList.tsx b/src/Bladeburner/ui/GeneralActionList.tsx index 58a64d944..442a0cb05 100644 --- a/src/Bladeburner/ui/GeneralActionList.tsx +++ b/src/Bladeburner/ui/GeneralActionList.tsx @@ -11,7 +11,7 @@ interface IProps { export function GeneralActionList(props: IProps): React.ReactElement { const actions: Action[] = []; for (const name of Object.keys(GeneralActions)) { - if (GeneralActions.hasOwnProperty(name)) { + if (Object.hasOwn(GeneralActions, name)) { actions.push(GeneralActions[name]); } } diff --git a/src/Bladeburner/ui/OperationElem.tsx b/src/Bladeburner/ui/OperationElem.tsx index 9ad22b982..cc5e5251f 100644 --- a/src/Bladeburner/ui/OperationElem.tsx +++ b/src/Bladeburner/ui/OperationElem.tsx @@ -25,7 +25,7 @@ interface IProps { export function OperationElem(props: IProps): React.ReactElement { const rerender = useRerender(); const isActive = - props.bladeburner.action.type === ActionTypes["Operation"] && props.action.name === props.bladeburner.action.name; + props.bladeburner.action.type === ActionTypes.Operation && props.action.name === props.bladeburner.action.name; const computedActionTimeCurrent = Math.min( props.bladeburner.actionTimeCurrent + props.bladeburner.actionTimeOverflow, props.bladeburner.actionTimeToComplete, diff --git a/src/Bladeburner/ui/SkillPage.tsx b/src/Bladeburner/ui/SkillPage.tsx index e21633479..e88251ea8 100644 --- a/src/Bladeburner/ui/SkillPage.tsx +++ b/src/Bladeburner/ui/SkillPage.tsx @@ -27,35 +27,35 @@ export function SkillPage(props: IProps): React.ReactElement { Note that when upgrading a skill, the benefit for that skill is additive. However, the effects of different skills with each other is multiplicative. - {valid(mults["successChanceAll"]) && ( - Total Success Chance: x{formatBigNumber(mults["successChanceAll"])} + {valid(mults.successChanceAll) && ( + Total Success Chance: x{formatBigNumber(mults.successChanceAll)} )} - {valid(mults["successChanceStealth"]) && ( - Stealth Success Chance: x{formatBigNumber(mults["successChanceStealth"])} + {valid(mults.successChanceStealth) && ( + Stealth Success Chance: x{formatBigNumber(mults.successChanceStealth)} )} - {valid(mults["successChanceKill"]) && ( - Retirement Success Chance: x{formatBigNumber(mults["successChanceKill"])} + {valid(mults.successChanceKill) && ( + Retirement Success Chance: x{formatBigNumber(mults.successChanceKill)} )} - {valid(mults["successChanceContract"]) && ( - Contract Success Chance: x{formatBigNumber(mults["successChanceContract"])} + {valid(mults.successChanceContract) && ( + Contract Success Chance: x{formatBigNumber(mults.successChanceContract)} )} - {valid(mults["successChanceOperation"]) && ( - Operation Success Chance: x{formatBigNumber(mults["successChanceOperation"])} + {valid(mults.successChanceOperation) && ( + Operation Success Chance: x{formatBigNumber(mults.successChanceOperation)} )} - {valid(mults["successChanceEstimate"]) && ( - Synthoid Data Estimate: x{formatBigNumber(mults["successChanceEstimate"])} + {valid(mults.successChanceEstimate) && ( + Synthoid Data Estimate: x{formatBigNumber(mults.successChanceEstimate)} )} - {valid(mults["actionTime"]) && Action Time: x{formatBigNumber(mults["actionTime"])}} - {valid(mults["effHack"]) && Hacking Skill: x{formatBigNumber(mults["effHack"])}} - {valid(mults["effStr"]) && Strength: x{formatBigNumber(mults["effStr"])}} - {valid(mults["effDef"]) && Defense: x{formatBigNumber(mults["effDef"])}} - {valid(mults["effDex"]) && Dexterity: x{formatBigNumber(mults["effDex"])}} - {valid(mults["effAgi"]) && Agility: x{formatBigNumber(mults["effAgi"])}} - {valid(mults["effCha"]) && Charisma: x{formatBigNumber(mults["effCha"])}} - {valid(mults["effInt"]) && Intelligence: x{formatBigNumber(mults["effInt"])}} - {valid(mults["stamina"]) && Stamina: x{formatBigNumber(mults["stamina"])}} - {valid(mults["money"]) && Contract Money: x{formatBigNumber(mults["money"])}} - {valid(mults["expGain"]) && Exp Gain: x{formatBigNumber(mults["expGain"])}} + {valid(mults.actionTime) && Action Time: x{formatBigNumber(mults.actionTime)}} + {valid(mults.effHack) && Hacking Skill: x{formatBigNumber(mults.effHack)}} + {valid(mults.effStr) && Strength: x{formatBigNumber(mults.effStr)}} + {valid(mults.effDef) && Defense: x{formatBigNumber(mults.effDef)}} + {valid(mults.effDex) && Dexterity: x{formatBigNumber(mults.effDex)}} + {valid(mults.effAgi) && Agility: x{formatBigNumber(mults.effAgi)}} + {valid(mults.effCha) && Charisma: x{formatBigNumber(mults.effCha)}} + {valid(mults.effInt) && Intelligence: x{formatBigNumber(mults.effInt)}} + {valid(mults.stamina) && Stamina: x{formatBigNumber(mults.stamina)}} + {valid(mults.money) && Contract Money: x{formatBigNumber(mults.money)}} + {valid(mults.expGain) && Exp Gain: x{formatBigNumber(mults.expGain)}} setRerender((old) => !old)} /> ); diff --git a/src/Bladeburner/ui/TravelModal.tsx b/src/Bladeburner/ui/TravelModal.tsx index 675418b65..f5318fbd2 100644 --- a/src/Bladeburner/ui/TravelModal.tsx +++ b/src/Bladeburner/ui/TravelModal.tsx @@ -33,7 +33,7 @@ export function TravelModal(props: IProps): React.ReactElement { )) ) : ( - + )}
diff --git a/src/Casino/Blackjack.tsx b/src/Casino/Blackjack.tsx index 106e44dc9..ebac70f18 100644 --- a/src/Casino/Blackjack.tsx +++ b/src/Casino/Blackjack.tsx @@ -24,7 +24,7 @@ enum Result { Tie = "Push! (Tie)", } -type State = { +interface State { playerHand: Hand; dealerHand: Hand; bet: number; @@ -34,7 +34,7 @@ type State = { gains: number; // Track gains only for this session wagerInvalid: boolean; wagerInvalidHelperText: string; -}; +} export class Blackjack extends React.Component, State> { deck: Deck; @@ -164,23 +164,15 @@ export class Blackjack extends React.Component, State> { }; playerStay = (event: React.MouseEvent): void => { - if (!event.isTrusted) { - return; - } + if (!event.isTrusted) return; // Determine if Dealer needs to hit. A dealer must hit if they have 16 or lower. // If the dealer has a Soft 17 (Ace + 6), then they stay. let newDealerHand = this.state.dealerHand; - while (true) { - // The dealer's "true" hand value is the 2nd one if its 21 or less (the 2nd value is always guaranteed - // to be equal or larger). Otherwise its the 1st. - const dealerHandValue = this.getTrueHandValue(newDealerHand); - - if (dealerHandValue <= 16) { - newDealerHand = newDealerHand.addCards(this.deck.safeDrawCard()); - } else { - break; - } + let dealerHandValue = this.getTrueHandValue(newDealerHand); + while (dealerHandValue <= 16) { + newDealerHand = newDealerHand.addCards(this.deck.safeDrawCard()); + dealerHandValue = this.getTrueHandValue(newDealerHand); } this.setState({ diff --git a/src/Casino/CardDeck/Deck.ts b/src/Casino/CardDeck/Deck.ts index 3f9f45d21..ab179e9d2 100644 --- a/src/Casino/CardDeck/Deck.ts +++ b/src/Casino/CardDeck/Deck.ts @@ -14,11 +14,9 @@ export class Deck { } drawCard(): Card { - if (this.cards.length == 0) { - throw new Error("Tried to draw card from empty deck"); - } - - return this.cards.shift() as Card; // Guaranteed to return a Card since we throw an Error if array is empty + if (this.cards.length == 0) throw new Error("Tried to draw card from empty deck"); + // Guaranteed to return a Card since we throw an Error if array is empty + return this.cards.shift() as Card; } // Draws a card, resetting the deck beforehand if the Deck is empty diff --git a/src/Casino/CardDeck/ReactCard.tsx b/src/Casino/CardDeck/ReactCard.tsx index 213ca8a77..b308a4a64 100644 --- a/src/Casino/CardDeck/ReactCard.tsx +++ b/src/Casino/CardDeck/ReactCard.tsx @@ -5,10 +5,10 @@ import makeStyles from "@mui/styles/makeStyles"; import createStyles from "@mui/styles/createStyles"; import Paper from "@mui/material/Paper"; -type Props = { +interface Props { card: Card; hidden?: boolean; -}; +} const useStyles = makeStyles(() => createStyles({ diff --git a/src/Casino/Roulette.tsx b/src/Casino/Roulette.tsx index f45af1cb3..226e84744 100644 --- a/src/Casino/Roulette.tsx +++ b/src/Casino/Roulette.tsx @@ -15,10 +15,10 @@ function isRed(n: number): boolean { return [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36].includes(n); } -type Strategy = { +interface Strategy { match: (n: number) => boolean; payout: number; -}; +} const redNumbers: number[] = [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36]; diff --git a/src/Casino/utils.ts b/src/Casino/utils.ts index ef2656db1..44417292c 100644 --- a/src/Casino/utils.ts +++ b/src/Casino/utils.ts @@ -1,7 +1,7 @@ import * as React from "react"; -export function trusted(f: () => void): (event: React.MouseEvent) => void { - return function (event: React.MouseEvent): void { +export function trusted(f: () => void): (event: React.MouseEvent) => void { + return function (event: React.MouseEvent): void { if (!event.isTrusted) return; f(); }; diff --git a/src/CodingContracts.ts b/src/CodingContracts.ts index 45bb35462..446ac02b7 100644 --- a/src/CodingContracts.ts +++ b/src/CodingContracts.ts @@ -4,8 +4,6 @@ import { Generic_fromJSON, Generic_toJSON, IReviverValue, constructorsForReviver import { CodingContractEvent } from "./ui/React/CodingContractModal"; import { ContractFilePath, resolveContractFilePath } from "./Paths/ContractFilePath"; -/* tslint:disable:no-magic-numbers completed-docs max-classes-per-file no-console */ - /* Represents different types of problems that a Coding Contract can have */ class CodingContractType { /** Function that generates a description of the problem */ @@ -44,11 +42,9 @@ class CodingContractType { } /* Contract Types */ -// tslint:disable-next-line export const CodingContractTypes: Record = {}; for (const md of codingContractTypesMetadata) { - // tslint:disable-next-line CodingContractTypes[md.name] = new CodingContractType( md.name, md.desc, diff --git a/src/Company/CompanyPosition.ts b/src/Company/CompanyPosition.ts index ad4748293..16d4fe101 100644 --- a/src/Company/CompanyPosition.ts +++ b/src/Company/CompanyPosition.ts @@ -3,8 +3,6 @@ import { CONSTANTS } from "../Constants"; import * as names from "./data/JobTracks"; import { JobName } from "../Enums"; -/* tslint:disable:completed-docs */ - export interface IConstructorParams { name: JobName; nextPosition: JobName | null; diff --git a/src/Corporation/Corporation.tsx b/src/Corporation/Corporation.tsx index 19b407b98..7b955411f 100644 --- a/src/Corporation/Corporation.tsx +++ b/src/Corporation/Corporation.tsx @@ -340,7 +340,7 @@ export class Corporation { for (const city of Object.keys(industry.warehouses) as CityName[]) { const warehouse = industry.warehouses[city]; if (warehouse === 0) continue; - if (industry.warehouses.hasOwnProperty(city) && warehouse) { + if (Object.hasOwn(industry.warehouses, city) && warehouse) { warehouse.updateSize(this, industry); } } diff --git a/src/Corporation/Industry.ts b/src/Corporation/Industry.ts index d8497f329..b35a86fc3 100644 --- a/src/Corporation/Industry.ts +++ b/src/Corporation/Industry.ts @@ -156,7 +156,7 @@ export class Industry { warehouse.updateMaterialSizeUsed(); for (const prodName of Object.keys(this.products)) { - if (this.products.hasOwnProperty(prodName)) { + if (Object.hasOwn(this.products, prodName)) { const prod = this.products[prodName]; if (prod === undefined) continue; warehouse.sizeUsed += prod.data[warehouse.loc][0] * prod.siz; @@ -247,7 +247,7 @@ export class Industry { if (this.warehouses[city]) { const wh = this.warehouses[city] as Warehouse; // Warehouse type is known due to if check above for (const name of Object.keys(reqMats) as CorpMaterialName[]) { - if (reqMats.hasOwnProperty(name)) { + if (Object.hasOwn(reqMats, name)) { wh.materials[name].processMarket(); } } @@ -268,7 +268,7 @@ export class Industry { processProductMarket(marketCycles = 1): void { // Demand gradually decreases, and competition gradually increases for (const name of Object.keys(this.products)) { - if (this.products.hasOwnProperty(name)) { + if (Object.hasOwn(this.products, name)) { const product = this.products[name]; if (product === undefined) continue; let change = getRandomInt(0, 3) * 0.0004; @@ -308,7 +308,7 @@ export class Industry { case "PURCHASE": { /* Process purchase of materials */ for (const matName of Object.values(corpConstants.materialNames)) { - if (!warehouse.materials.hasOwnProperty(matName)) continue; + if (!Object.hasOwn(warehouse.materials, matName)) continue; const mat = warehouse.materials[matName]; let buyAmt = 0; let maxAmt = 0; @@ -331,7 +331,7 @@ export class Industry { // smart supply const smartBuy: Partial> = {}; for (const matName of Object.values(corpConstants.materialNames)) { - if (!warehouse.materials.hasOwnProperty(matName)) continue; + if (!Object.hasOwn(warehouse.materials, matName)) continue; if (!warehouse.smartSupplyEnabled || !Object.keys(this.reqMats).includes(matName)) continue; const mat = warehouse.materials[matName]; @@ -455,7 +455,7 @@ export class Industry { // Make sure we have enough resource to make our materials let producableFrac = 1; for (const reqMatName of Object.keys(this.reqMats) as CorpMaterialName[]) { - if (this.reqMats.hasOwnProperty(reqMatName)) { + if (Object.hasOwn(this.reqMats, reqMatName)) { const reqMat = this.reqMats[reqMatName]; if (reqMat === undefined) continue; const req = reqMat * prod; @@ -504,7 +504,7 @@ export class Industry { } } else { for (const reqMatName of Object.keys(this.reqMats) as CorpMaterialName[]) { - if (this.reqMats.hasOwnProperty(reqMatName)) { + if (Object.hasOwn(this.reqMats, reqMatName)) { warehouse.materials[reqMatName].prd = 0; } } @@ -528,9 +528,9 @@ export class Industry { case "SALE": /* Process sale of materials */ for (const matName of Object.values(corpConstants.materialNames)) { - if (warehouse.materials.hasOwnProperty(matName)) { + if (Object.hasOwn(warehouse.materials, matName)) { const mat = warehouse.materials[matName]; - if (mat.sCost < 0 || mat.sllman[0] === false) { + if ((typeof mat.sCost === "number" && mat.sCost < 0) || !mat.sllman[0]) { mat.sll = 0; continue; } @@ -547,7 +547,7 @@ export class Industry { const adjustedQty = mat.qty / (corpConstants.secondsPerMarketCycle * marketCycles); if (isString(mat.sllman[1])) { //Dynamically evaluated - let tmp = (mat.sllman[1] as string).replace(/MAX/g, (adjustedQty + "").toUpperCase()); + let tmp = mat.sllman[1].replace(/MAX/g, (adjustedQty + "").toUpperCase()); tmp = tmp.replace(/PROD/g, mat.prd + ""); try { sellAmt = eval(tmp); @@ -562,7 +562,7 @@ export class Industry { sellAmt = adjustedQty; } else { //Player's input value is just a number - sellAmt = mat.sllman[1] as number; + sellAmt = mat.sllman[1]; } // Determine the cost that the material will be sold at @@ -603,7 +603,7 @@ export class Industry { } else if (mat.marketTa1) { sCost = mat.bCost + markupLimit; } else if (isString(mat.sCost)) { - sCost = (mat.sCost as string).replace(/MP/g, mat.bCost + ""); + sCost = mat.sCost.replace(/MP/g, mat.bCost + ""); sCost = eval(sCost); } else { sCost = mat.sCost; @@ -635,7 +635,7 @@ export class Industry { this.getSalesMultiplier(); if (isString(mat.sllman[1])) { //Dynamically evaluated - let tmp = (mat.sllman[1] as string).replace(/MAX/g, (mat.maxsll + "").toUpperCase()); + let tmp = mat.sllman[1].replace(/MAX/g, (mat.maxsll + "").toUpperCase()); tmp = tmp.replace(/PROD/g, mat.prd + ""); try { @@ -653,7 +653,7 @@ export class Industry { sellAmt = mat.maxsll; } else { //Player's input value is just a number - sellAmt = Math.min(mat.maxsll, mat.sllman[1] as number); + sellAmt = Math.min(mat.maxsll, mat.sllman[1]); } sellAmt = Math.min(mat.maxsll, sellAmt); sellAmt = sellAmt * corpConstants.secondsPerMarketCycle * marketCycles; @@ -676,7 +676,7 @@ export class Industry { case "EXPORT": for (const matName of Object.values(corpConstants.materialNames)) { - if (warehouse.materials.hasOwnProperty(matName)) { + if (Object.hasOwn(warehouse.materials, matName)) { const mat = warehouse.materials[matName]; mat.totalExp = 0; //Reset export for (let expI = 0; expI < mat.exp.length; ++expI) { @@ -805,7 +805,7 @@ export class Industry { //Produce Products for (const prodName of Object.keys(this.products)) { - if (this.products.hasOwnProperty(prodName)) { + if (Object.hasOwn(this.products, prodName)) { const prod = this.products[prodName]; if (prod && prod.fin) { revenue += this.processProduct(marketCycles, prod, corporation); @@ -845,11 +845,8 @@ export class Industry { //Calculate net change in warehouse storage making the Products will cost let netStorageSize = product.siz; - for (const reqMatName of Object.keys(product.reqMats) as CorpMaterialName[]) { - if (product.reqMats.hasOwnProperty(reqMatName)) { - const normQty = product.reqMats[reqMatName] as number; - netStorageSize -= MaterialInfo[reqMatName].size * normQty; - } + for (const [reqMatName, reqQty] of Object.entries(product.reqMats) as [CorpMaterialName, number][]) { + netStorageSize -= MaterialInfo[reqMatName].size * reqQty; } //If there's not enough space in warehouse, limit the amount of Product @@ -1036,7 +1033,7 @@ export class Industry { const warehouse = this.warehouses[city]; if (warehouse === 0) continue; for (const matName of Object.values(corpConstants.materialNames)) { - if (warehouse.materials.hasOwnProperty(matName)) { + if (Object.hasOwn(warehouse.materials, matName)) { const mat = warehouse.materials[matName]; mat.imp = 0; } @@ -1047,7 +1044,7 @@ export class Industry { discontinueProduct(product: Product): void { for (const productName of Object.keys(this.products)) { - if (this.products.hasOwnProperty(productName)) { + if (Object.hasOwn(this.products, productName)) { if (product === this.products[productName]) { delete this.products[productName]; } diff --git a/src/Corporation/OfficeSpace.ts b/src/Corporation/OfficeSpace.ts index d1cd24c10..f2c256929 100644 --- a/src/Corporation/OfficeSpace.ts +++ b/src/Corporation/OfficeSpace.ts @@ -258,7 +258,7 @@ export class OfficeSpace { static fromJSON(value: IReviverValue): OfficeSpace { // Convert employees from the old version - if (value.data.hasOwnProperty("employees")) { + if (Object.hasOwn(value.data, "employees")) { const empCopy: [{ data: { mor: number; ene: number; exp: number } }] = value.data.employees; delete value.data.employees; const ret = Generic_fromJSON(OfficeSpace, value.data); diff --git a/src/Corporation/Product.ts b/src/Corporation/Product.ts index a9b9c4601..6124b518c 100644 --- a/src/Corporation/Product.ts +++ b/src/Corporation/Product.ts @@ -58,7 +58,7 @@ export class Product { advCost = 0; // How much money was invested into advertising this Product // The average employee productivity and scientific research across the creation of the Product - creationProd: { [key: string]: number } = { + creationProd: Record = { [EmployeePositions.Operations]: 0, [EmployeePositions.Engineer]: 0, [EmployeePositions.Business]: 0, @@ -233,7 +233,7 @@ export class Product { //Calculate the product's required materials //For now, just set it to be the same as the requirements to make materials for (const matName of Object.keys(industry.reqMats) as CorpMaterialName[]) { - if (industry.reqMats.hasOwnProperty(matName)) { + if (Object.hasOwn(industry.reqMats, matName)) { const reqMat = industry.reqMats[matName]; if (reqMat === undefined) continue; this.reqMats[matName] = reqMat; diff --git a/src/Corporation/ui/ExpandIndustryTab.tsx b/src/Corporation/ui/ExpandIndustryTab.tsx index 2e3669c16..3bf5a907a 100644 --- a/src/Corporation/ui/ExpandIndustryTab.tsx +++ b/src/Corporation/ui/ExpandIndustryTab.tsx @@ -50,7 +50,7 @@ export function ExpandIndustryTab(props: IProps): React.ReactElement { if (event.key === KEY.ENTER) newIndustry(); } - function onIndustryChange(event: SelectChangeEvent): void { + function onIndustryChange(event: SelectChangeEvent): void { setIndustry(event.target.value as IndustryType); } diff --git a/src/Corporation/ui/ExpandNewCity.tsx b/src/Corporation/ui/ExpandNewCity.tsx index 13b693065..aabe869dc 100644 --- a/src/Corporation/ui/ExpandNewCity.tsx +++ b/src/Corporation/ui/ExpandNewCity.tsx @@ -22,7 +22,7 @@ export function ExpandNewCity(props: IProps): React.ReactElement { const disabled = corp.funds < corpConstants.officeInitialCost; - function onCityChange(event: SelectChangeEvent): void { + function onCityChange(event: SelectChangeEvent): void { setCity(event.target.value as CityName); } diff --git a/src/Corporation/ui/IndustryOverview.tsx b/src/Corporation/ui/IndustryOverview.tsx index a17ad06a5..5ca437f56 100644 --- a/src/Corporation/ui/IndustryOverview.tsx +++ b/src/Corporation/ui/IndustryOverview.tsx @@ -132,7 +132,7 @@ export function IndustryOverview(props: IProps): React.ReactElement { ["Popularity:", formatBigNumber(division.popularity)], ]} /> - {advertisingInfo !== false && ( + {advertisingInfo && ( diff --git a/src/Corporation/ui/IndustryWarehouse.tsx b/src/Corporation/ui/IndustryWarehouse.tsx index a10dd64b5..faad93e32 100644 --- a/src/Corporation/ui/IndustryWarehouse.tsx +++ b/src/Corporation/ui/IndustryWarehouse.tsx @@ -122,7 +122,7 @@ function WarehouseRoot(props: IProps): React.ReactElement { const breakdownItems: JSX.Element[] = []; for (const matName of Object.values(corpConstants.materialNames)) { const mat = props.warehouse.materials[matName]; - if (!MaterialInfo.hasOwnProperty(matName)) continue; + if (!Object.hasOwn(MaterialInfo, matName)) continue; if (mat.qty === 0) continue; breakdownItems.push( <> diff --git a/src/Corporation/ui/MaterialElem.tsx b/src/Corporation/ui/MaterialElem.tsx index dc8d846f4..4a53976cf 100644 --- a/src/Corporation/ui/MaterialElem.tsx +++ b/src/Corporation/ui/MaterialElem.tsx @@ -72,7 +72,7 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement { } else { sellButtonText = ( <> - Sell ({formatBigNumber(mat.sll)}/{formatBigNumber(mat.sllman[1] as number)}) + Sell ({formatBigNumber(mat.sll)}/{formatBigNumber(mat.sllman[1])}) ); } @@ -91,7 +91,7 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement { ); } else if (mat.sCost) { if (isString(mat.sCost)) { - const sCost = (mat.sCost as string).replace(/MP/g, mat.bCost + ""); + const sCost = mat.sCost.replace(/MP/g, mat.bCost + ""); sellButtonText = ( <> {sellButtonText} @ diff --git a/src/Corporation/ui/modals/BribeFactionModal.tsx b/src/Corporation/ui/modals/BribeFactionModal.tsx index ec9a46951..1af4e993c 100644 --- a/src/Corporation/ui/modals/BribeFactionModal.tsx +++ b/src/Corporation/ui/modals/BribeFactionModal.tsx @@ -30,7 +30,7 @@ export function BribeFactionModal(props: IProps): React.ReactElement { const [selectedFaction, setSelectedFaction] = useState(factions.length > 0 ? factions[0] : ""); const disabled = money === 0 || isNaN(money) || money < 0 || corp.funds < money; - function changeFaction(event: SelectChangeEvent): void { + function changeFaction(event: SelectChangeEvent): void { setSelectedFaction(event.target.value); } diff --git a/src/Corporation/ui/modals/ExportModal.tsx b/src/Corporation/ui/modals/ExportModal.tsx index 4f02e1e41..1efd8539d 100644 --- a/src/Corporation/ui/modals/ExportModal.tsx +++ b/src/Corporation/ui/modals/ExportModal.tsx @@ -35,11 +35,11 @@ export function ExportModal(props: IProps): React.ReactElement { const [amt, setAmt] = useState(""); const rerender = useRerender(); - function onCityChange(event: SelectChangeEvent): void { + function onCityChange(event: SelectChangeEvent): void { setCity(event.target.value as CityName); } - function onIndustryChange(event: SelectChangeEvent): void { + function onIndustryChange(event: SelectChangeEvent): void { const div = event.target.value; setIndustry(div); setCity(Object.keys(corp.divisions[0].warehouses)[0] as CityName); diff --git a/src/Corporation/ui/modals/MakeProductModal.tsx b/src/Corporation/ui/modals/MakeProductModal.tsx index ae7f21dd2..b84f9b3bf 100644 --- a/src/Corporation/ui/modals/MakeProductModal.tsx +++ b/src/Corporation/ui/modals/MakeProductModal.tsx @@ -52,7 +52,7 @@ export function MakeProductModal(props: IProps): React.ReactElement { props.onClose(); } - function onCityChange(event: SelectChangeEvent): void { + function onCityChange(event: SelectChangeEvent): void { setCity(event.target.value as CityName); } diff --git a/src/Corporation/ui/modals/SellDivisionModal.tsx b/src/Corporation/ui/modals/SellDivisionModal.tsx index 22415682d..34955fda9 100644 --- a/src/Corporation/ui/modals/SellDivisionModal.tsx +++ b/src/Corporation/ui/modals/SellDivisionModal.tsx @@ -1,12 +1,13 @@ import React, { useState } from "react"; +import type { Industry } from "src/Corporation/Industry"; + import { Modal } from "../../../ui/React/Modal"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; import MenuItem from "@mui/material/MenuItem"; import Select, { SelectChangeEvent } from "@mui/material/Select"; import { useCorporation } from "../../ui/Context"; -import { Industry } from "src/Corporation/Industry"; import { CityName } from "@nsdefs"; import * as corpConstants from "../../data/Constants"; import { formatMoney, formatNumber } from "../../../ui/formatNumber"; @@ -36,7 +37,7 @@ export function SellDivisionModal(props: IProps): React.ReactElement { return price; } - function onIndustryChange(event: SelectChangeEvent): void { + function onIndustryChange(event: SelectChangeEvent): void { setIndustry(corp.divisions.find((div) => div.name === event.target.value) as Industry); } @@ -76,11 +77,11 @@ export function SellDivisionModal(props: IProps): React.ReactElement {

- Profit: ${formatNumber((industry.lastCycleRevenue - industry.lastCycleExpenses) / 10)} / sec

- Cities:{" "} {Object.keys(industry.offices) - .map((city) => (!!industry.offices[city as CityName] ? 1 : 0)) + .map((city) => (industry.offices[city as CityName] ? 1 : 0)) .reduce(sum, 0)}

- Warehouses:{" "} {Object.keys(industry.warehouses) - .map((city) => (!!industry.warehouses[city as CityName] ? 1 : 0)) + .map((city) => (industry.warehouses[city as CityName] ? 1 : 0)) .reduce(sum, 0)} {industry.makesProducts ?? ( diff --git a/src/CotMG/ui/ActiveFragmentSummary.tsx b/src/CotMG/ui/ActiveFragmentSummary.tsx index 1ec5e0f63..e6046c0d6 100644 --- a/src/CotMG/ui/ActiveFragmentSummary.tsx +++ b/src/CotMG/ui/ActiveFragmentSummary.tsx @@ -9,9 +9,9 @@ import Typography from "@mui/material/Typography"; import Table from "@mui/material/Table"; import { TableBody, TableCell, TableRow } from "@mui/material"; -type IProps = { +interface IProps { gift: StaneksGift; -}; +} function formatEffect(effect: number, type: FragmentType): string { if (Effect(type).includes("+x%")) { diff --git a/src/CotMG/ui/Cell.tsx b/src/CotMG/ui/Cell.tsx index 3acfa6971..f4b845d5c 100644 --- a/src/CotMG/ui/Cell.tsx +++ b/src/CotMG/ui/Cell.tsx @@ -23,11 +23,11 @@ export const TableCell: React.FC = (props: TableCellProps) => { ); }; -type IProps = { +interface IProps { onMouseEnter?: () => void; onClick?: () => void; color: string; -}; +} export function Cell(cellProps: IProps): React.ReactElement { return ( diff --git a/src/CotMG/ui/FragmentInspector.tsx b/src/CotMG/ui/FragmentInspector.tsx index 311dc68dc..b2ed43536 100644 --- a/src/CotMG/ui/FragmentInspector.tsx +++ b/src/CotMG/ui/FragmentInspector.tsx @@ -7,12 +7,12 @@ import { formatPercent, formatStaneksGiftCharge, formatStaneksGiftPower } from " import Paper from "@mui/material/Paper"; import Typography from "@mui/material/Typography"; -type IProps = { +interface IProps { gift: StaneksGift; fragment: ActiveFragment | undefined; x: number; y: number; -}; +} export function FragmentInspector(props: IProps): React.ReactElement { const [, setC] = useState(new Date()); diff --git a/src/CotMG/ui/FragmentPreview.tsx b/src/CotMG/ui/FragmentPreview.tsx index a3da482c7..3c83bbd24 100644 --- a/src/CotMG/ui/FragmentPreview.tsx +++ b/src/CotMG/ui/FragmentPreview.tsx @@ -6,11 +6,11 @@ import TableRow from "@mui/material/TableRow"; import TableBody from "@mui/material/TableBody"; import { Table } from "../../ui/React/Table"; -type IProps = { +interface IProps { width: number; height: number; colorAt: (x: number, y: number) => string; -}; +} export function FragmentPreview(props: IProps): React.ReactElement { // switch the width/length to make axis consistent. diff --git a/src/CotMG/ui/FragmentSelector.tsx b/src/CotMG/ui/FragmentSelector.tsx index c3215cfdf..481b0688f 100644 --- a/src/CotMG/ui/FragmentSelector.tsx +++ b/src/CotMG/ui/FragmentSelector.tsx @@ -10,11 +10,11 @@ import MenuItem from "@mui/material/MenuItem"; import Typography from "@mui/material/Typography"; import Box from "@mui/material/Box"; -type IOptionProps = { +interface IOptionProps { gift: StaneksGift; fragment: Fragment; selectFragment: (fragment: Fragment) => void; -}; +} function FragmentOption(props: IOptionProps): React.ReactElement { const left = props.fragment.limit - props.gift.count(props.fragment); @@ -45,10 +45,10 @@ function FragmentOption(props: IOptionProps): React.ReactElement { ); } -type IProps = { +interface IProps { gift: StaneksGift; selectFragment: (fragment: Fragment) => void; -}; +} export function FragmentSelector(props: IProps): React.ReactElement { const [value, setValue] = useState("None"); diff --git a/src/CotMG/ui/StaneksGiftRoot.tsx b/src/CotMG/ui/StaneksGiftRoot.tsx index bfda3fbbb..e7afb8839 100644 --- a/src/CotMG/ui/StaneksGiftRoot.tsx +++ b/src/CotMG/ui/StaneksGiftRoot.tsx @@ -13,9 +13,9 @@ import { DummyGrid } from "./DummyGrid"; import Container from "@mui/material/Container"; import { useRerender } from "../../ui/React/hooks"; -type IProps = { +interface IProps { staneksGift: StaneksGift; -}; +} export function StaneksGiftRoot({ staneksGift }: IProps): React.ReactElement { const rerender = useRerender(); diff --git a/src/DevMenu/ui/Augmentations.tsx b/src/DevMenu/ui/Augmentations.tsx index 803c0808c..49ad2d9d1 100644 --- a/src/DevMenu/ui/Augmentations.tsx +++ b/src/DevMenu/ui/Augmentations.tsx @@ -17,7 +17,7 @@ import { Player } from "@player"; export function Augmentations(): React.ReactElement { const [augmentation, setAugmentation] = useState("Augmented Targeting I"); - function setAugmentationDropdown(event: SelectChangeEvent): void { + function setAugmentationDropdown(event: SelectChangeEvent): void { setAugmentation(event.target.value); } function queueAug(): void { diff --git a/src/DevMenu/ui/Bladeburner.tsx b/src/DevMenu/ui/Bladeburner.tsx index 5e5d09efe..c421d0375 100644 --- a/src/DevMenu/ui/Bladeburner.tsx +++ b/src/DevMenu/ui/Bladeburner.tsx @@ -59,8 +59,8 @@ export function Bladeburner(): React.ReactElement { }; // Skill functions - const [skill, setSkill] = useState(SkillNames.BladesIntuition as string); - function setSkillDropdown(event: SelectChangeEvent): void { + const [skill, setSkill] = useState(SkillNames.BladesIntuition); + function setSkillDropdown(event: SelectChangeEvent): void { setSkill(event.target.value); } const modifySkill = (modifier: number) => (levelchange: number) => { @@ -82,8 +82,8 @@ export function Bladeburner(): React.ReactElement { // Contract functions const AllContracts = bladeburner.contracts; - const [contractTarget, setContract] = useState(AllContracts.Tracking.name as string); - function setContractDropdown(event: SelectChangeEvent): void { + const [contractTarget, setContract] = useState(AllContracts.Tracking.name); + function setContractDropdown(event: SelectChangeEvent): void { setContract(event.target.value); } const modifyContractLevel = (modifier: number) => (levelchange: number) => { @@ -117,8 +117,8 @@ export function Bladeburner(): React.ReactElement { // Operation functions const AllOperations = bladeburner.operations; - const [operationTarget, setOperation] = useState(AllOperations.Investigation.name as string); - function setOperationDropdown(event: SelectChangeEvent): void { + const [operationTarget, setOperation] = useState(AllOperations.Investigation.name); + function setOperationDropdown(event: SelectChangeEvent): void { setOperation(event.target.value); } const modifyOperationLevel = (modifier: number) => (levelchange: number) => { diff --git a/src/DevMenu/ui/CodingContracts.tsx b/src/DevMenu/ui/CodingContracts.tsx index 3bc166268..f3891d16f 100644 --- a/src/DevMenu/ui/CodingContracts.tsx +++ b/src/DevMenu/ui/CodingContracts.tsx @@ -14,7 +14,7 @@ import { CodingContractTypes } from "../../CodingContracts"; export function CodingContracts(): React.ReactElement { const [codingcontract, setCodingcontract] = useState("Find Largest Prime Factor"); - function setCodingcontractDropdown(event: SelectChangeEvent): void { + function setCodingcontractDropdown(event: SelectChangeEvent): void { setCodingcontract(event.target.value); } diff --git a/src/DevMenu/ui/Companies.tsx b/src/DevMenu/ui/Companies.tsx index d3d40042a..cf64bea52 100644 --- a/src/DevMenu/ui/Companies.tsx +++ b/src/DevMenu/ui/Companies.tsx @@ -17,7 +17,7 @@ const bigNumber = 1e12; export function Companies(): React.ReactElement { const [company, setCompany] = useState(FactionNames.ECorp as string); - function setCompanyDropdown(event: SelectChangeEvent): void { + function setCompanyDropdown(event: SelectChangeEvent): void { setCompany(event.target.value); } function resetCompanyRep(): void { diff --git a/src/DevMenu/ui/Factions.tsx b/src/DevMenu/ui/Factions.tsx index 48195a88a..68efd51e9 100644 --- a/src/DevMenu/ui/Factions.tsx +++ b/src/DevMenu/ui/Factions.tsx @@ -24,7 +24,7 @@ const bigNumber = 1e12; export function Factions(): React.ReactElement { const [faction, setFaction] = useState(FactionNames.Illuminati as string); - function setFactionDropdown(event: SelectChangeEvent): void { + function setFactionDropdown(event: SelectChangeEvent): void { setFaction(event.target.value); } diff --git a/src/DevMenu/ui/General.tsx b/src/DevMenu/ui/General.tsx index 5f812852d..d58bceedc 100644 --- a/src/DevMenu/ui/General.tsx +++ b/src/DevMenu/ui/General.tsx @@ -71,7 +71,7 @@ export function General(): React.ReactElement { // Rerender so the gang menu option will be removed immediately on the devmenu page selection ThemeEvents.emit(); }; - const setGangFactionDropdown = (event: SelectChangeEvent) => setGangFaction(event.target.value); + const setGangFactionDropdown = (event: SelectChangeEvent) => setGangFaction(event.target.value); // Misc functions const checkMessages = () => checkForMessagesToSend(); diff --git a/src/DevMenu/ui/Programs.tsx b/src/DevMenu/ui/Programs.tsx index 7eb5120ff..17beca121 100644 --- a/src/DevMenu/ui/Programs.tsx +++ b/src/DevMenu/ui/Programs.tsx @@ -14,7 +14,7 @@ import { CompletedProgramName } from "../../Programs/Programs"; export function Programs(): React.ReactElement { const [program, setProgram] = useState(CompletedProgramName.bruteSsh); - function setProgramDropdown(event: SelectChangeEvent): void { + function setProgramDropdown(event: SelectChangeEvent): void { setProgram(event.target.value as CompletedProgramName); } function addProgram(): void { diff --git a/src/DevMenu/ui/Servers.tsx b/src/DevMenu/ui/Servers.tsx index db1f0e53f..9865d84d4 100644 --- a/src/DevMenu/ui/Servers.tsx +++ b/src/DevMenu/ui/Servers.tsx @@ -14,7 +14,7 @@ import MenuItem from "@mui/material/MenuItem"; export function Servers(): React.ReactElement { const [server, setServer] = useState("home"); - function setServerDropdown(event: SelectChangeEvent): void { + function setServerDropdown(event: SelectChangeEvent): void { setServer(event.target.value); } function rootServer(): void { diff --git a/src/DevMenu/ui/StockMarket.tsx b/src/DevMenu/ui/StockMarket.tsx index 5eaa50a64..400e6ba7a 100644 --- a/src/DevMenu/ui/StockMarket.tsx +++ b/src/DevMenu/ui/StockMarket.tsx @@ -39,7 +39,7 @@ export function StockMarket(): React.ReactElement { } for (const name of Object.keys(SM)) { - if (SM.hasOwnProperty(name)) { + if (Object.hasOwn(SM, name)) { const stock = SM[name]; if (stock instanceof Stock && match(stock.symbol)) { sub(stock); diff --git a/src/Electron.tsx b/src/Electron.tsx index f22bba790..21ab46407 100644 --- a/src/Electron.tsx +++ b/src/Electron.tsx @@ -44,7 +44,7 @@ declare global { export function initElectron(): void { const userAgent = navigator.userAgent.toLowerCase(); - if (userAgent.indexOf(" electron/") > -1) { + if (userAgent.includes(" electron/")) { // Electron-specific code document.achievements = []; initWebserver(); diff --git a/src/Exploits/Exploit.ts b/src/Exploits/Exploit.ts index a6408c399..ce7ab2217 100644 --- a/src/Exploits/Exploit.ts +++ b/src/Exploits/Exploit.ts @@ -27,9 +27,7 @@ export enum Exploit { EditSaveFile = "EditSaveFile", } -const names: { - [key: string]: string; -} = { +const names: Record = { Bypass: "by circumventing the ram cost of document.", EditSaveFile: "by editing your save file.", PrototypeTampering: "by tampering with Numbers prototype.", diff --git a/src/Faction/FactionHelpers.tsx b/src/Faction/FactionHelpers.tsx index a45f87111..295c461aa 100644 --- a/src/Faction/FactionHelpers.tsx +++ b/src/Faction/FactionHelpers.tsx @@ -110,7 +110,7 @@ export function processPassiveFactionRepGain(numCycles: number): void { if (Player.bitNodeN === 2) return; for (const name of Object.keys(Factions)) { if (isFactionWork(Player.currentWork) && name === Player.currentWork.factionName) continue; - if (!Factions.hasOwnProperty(name)) continue; + if (!Object.hasOwn(Factions, name)) continue; const faction = Factions[name]; if (!faction.isMember) continue; // No passive rep for special factions diff --git a/src/Faction/FactionInfo.tsx b/src/Faction/FactionInfo.tsx index 2227e1250..f435a7dfb 100644 --- a/src/Faction/FactionInfo.tsx +++ b/src/Faction/FactionInfo.tsx @@ -60,7 +60,6 @@ export class FactionInfo { } /** A map of all factions and associated info to them. */ -// tslint:disable-next-line:variable-name export const FactionInfos: Record = { // Endgame [FactionNames.Illuminati]: new FactionInfo({ diff --git a/src/Faction/Factions.ts b/src/Faction/Factions.ts index f0dd88620..8e48ed1b1 100644 --- a/src/Faction/Factions.ts +++ b/src/Faction/Factions.ts @@ -28,7 +28,7 @@ function AddToFactions(faction: Faction): void { } export function factionExists(name: string): boolean { - return Factions.hasOwnProperty(name); + return Object.hasOwn(Factions, name); } export function initFactions(): void { diff --git a/src/Faction/ui/AugmentationsPage.tsx b/src/Faction/ui/AugmentationsPage.tsx index 11c530200..224093627 100644 --- a/src/Faction/ui/AugmentationsPage.tsx +++ b/src/Faction/ui/AugmentationsPage.tsx @@ -17,10 +17,10 @@ import { getFactionAugmentationsFiltered, hasAugmentationPrereqs, purchaseAugmen import { CONSTANTS } from "../../Constants"; import { useRerender } from "../../ui/React/hooks"; -type IProps = { +interface IProps { faction: Faction; routeToMainPage: () => void; -}; +} /** Root React Component for displaying a faction's "Purchase Augmentations" page */ export function AugmentationsPage(props: IProps): React.ReactElement { diff --git a/src/Faction/ui/DonateOption.tsx b/src/Faction/ui/DonateOption.tsx index cc93b2c13..cb6f43dc0 100644 --- a/src/Faction/ui/DonateOption.tsx +++ b/src/Faction/ui/DonateOption.tsx @@ -17,12 +17,12 @@ import Paper from "@mui/material/Paper"; import Button from "@mui/material/Button"; import { NumberInput } from "../../ui/React/NumberInput"; -type IProps = { +interface IProps { faction: Faction; disabled: boolean; favorToDonate: number; rerender: () => void; -}; +} /** React component for a donate option on the Faction UI */ export function DonateOption(props: IProps): React.ReactElement { diff --git a/src/Faction/ui/FactionRoot.tsx b/src/Faction/ui/FactionRoot.tsx index 68c446ec4..3ac41f8d4 100644 --- a/src/Faction/ui/FactionRoot.tsx +++ b/src/Faction/ui/FactionRoot.tsx @@ -27,10 +27,10 @@ import { FactionWork } from "../../Work/FactionWork"; import { FactionWorkType } from "../../Enums"; import { useRerender } from "../../ui/React/hooks"; -type IProps = { +interface IProps { faction: Faction; augPage: boolean; -}; +} // Info text for all options on the UI const hackingContractsInfo = diff --git a/src/Faction/ui/FactionsRoot.tsx b/src/Faction/ui/FactionsRoot.tsx index 4717d031d..67fbe4c23 100644 --- a/src/Faction/ui/FactionsRoot.tsx +++ b/src/Faction/ui/FactionsRoot.tsx @@ -59,7 +59,7 @@ const FactionElement = (props: FactionElementProps): React.ReactElement => { Router.toFaction(faction, true); } - function acceptInvitation(event: React.MouseEvent, faction: string): void { + function acceptInvitation(event: React.MouseEvent, faction: string): void { if (!event.isTrusted) return; joinFaction(Factions[faction]); props.rerender(); @@ -218,7 +218,7 @@ export function FactionsRoot(): React.ReactElement { {invitations.map((facName) => { - if (!Factions.hasOwnProperty(facName)) return null; + if (!Object.hasOwn(Factions, facName)) return null; return ; })} @@ -232,7 +232,7 @@ export function FactionsRoot(): React.ReactElement { {allJoinedFactions.length > 0 ? ( allJoinedFactions.map((facName) => { - if (!Factions.hasOwnProperty(facName)) return null; + if (!Object.hasOwn(Factions, facName)) return null; return ; }) ) : ( diff --git a/src/Faction/ui/GangButton.tsx b/src/Faction/ui/GangButton.tsx index 3316e9d81..bba7bf974 100644 --- a/src/Faction/ui/GangButton.tsx +++ b/src/Faction/ui/GangButton.tsx @@ -7,9 +7,9 @@ import { Player } from "@player"; import { Faction } from "../Faction"; import { CreateGangModal } from "./CreateGangModal"; -type IProps = { +interface IProps { faction: Faction; -}; +} export function GangButton({ faction }: IProps): React.ReactElement { const [gangOpen, setGangOpen] = useState(false); diff --git a/src/Faction/ui/Info.tsx b/src/Faction/ui/Info.tsx index 7f5958499..b32d0b6bb 100644 --- a/src/Faction/ui/Info.tsx +++ b/src/Faction/ui/Info.tsx @@ -18,10 +18,10 @@ import Tooltip from "@mui/material/Tooltip"; import Box from "@mui/material/Box"; import { useRerender } from "../../ui/React/hooks"; -type IProps = { +interface IProps { faction: Faction; factionInfo: FactionInfo; -}; +} const useStyles = makeStyles(() => createStyles({ diff --git a/src/Faction/ui/Option.tsx b/src/Faction/ui/Option.tsx index 9ec2af68b..895a5e3a8 100644 --- a/src/Faction/ui/Option.tsx +++ b/src/Faction/ui/Option.tsx @@ -10,11 +10,11 @@ import Button from "@mui/material/Button"; import Paper from "@mui/material/Paper"; import Box from "@mui/material/Box"; -type IProps = { +interface IProps { buttonText: string; infoText: string; onClick: (e: React.MouseEvent) => void; -}; +} export function Option(props: IProps): React.ReactElement { return ( diff --git a/src/GameOptions/ui/NumericDisplayOptions.tsx b/src/GameOptions/ui/NumericDisplayOptions.tsx index a46ec36ba..1bb0cbe06 100644 --- a/src/GameOptions/ui/NumericDisplayOptions.tsx +++ b/src/GameOptions/ui/NumericDisplayOptions.tsx @@ -8,7 +8,7 @@ import { FormatsNeedToChange } from "../../ui/formatNumber"; export const NumericDisplayPage = (): React.ReactElement => { const [locale, setLocale] = useState(Settings.Locale); - function handleLocaleChange(event: SelectChangeEvent): void { + function handleLocaleChange(event: SelectChangeEvent): void { setLocale(event.target.value); Settings.Locale = event.target.value; FormatsNeedToChange.emit(); diff --git a/src/GameOptions/ui/OptionsSlider.tsx b/src/GameOptions/ui/OptionsSlider.tsx index bd6c7955a..12a3ab3d6 100644 --- a/src/GameOptions/ui/OptionsSlider.tsx +++ b/src/GameOptions/ui/OptionsSlider.tsx @@ -3,7 +3,7 @@ import React, { useState } from "react"; interface IProps { initialValue: number; - callback: (event: Event | React.SyntheticEvent, newValue: number | number[]) => void; + callback: (event: Event | React.SyntheticEvent, newValue: number | number[]) => void; step: number; min: number; max: number; @@ -15,7 +15,7 @@ interface IProps { export const OptionsSlider = (props: IProps): React.ReactElement => { const [value, setValue] = useState(props.initialValue); - const onChange = (_evt: Event, newValue: number | Array): void => { + const onChange = (_evt: Event, newValue: number | number[]): void => { if (typeof newValue === "number") setValue(newValue); }; diff --git a/src/GameOptions/ui/RemoteAPIPage.tsx b/src/GameOptions/ui/RemoteAPIPage.tsx index 6dc91fa81..b870ef807 100644 --- a/src/GameOptions/ui/RemoteAPIPage.tsx +++ b/src/GameOptions/ui/RemoteAPIPage.tsx @@ -9,7 +9,7 @@ export const RemoteAPIPage = (): React.ReactElement => { const [remoteFileApiPort, setRemoteFileApiPort] = useState(Settings.RemoteFileApiPort); function handleRemoteFileApiPortChange(event: React.ChangeEvent): void { - setRemoteFileApiPort(Number(event.target.value) as number); + setRemoteFileApiPort(Number(event.target.value)); Settings.RemoteFileApiPort = Number(event.target.value); } diff --git a/src/GameOptions/ui/SystemPage.tsx b/src/GameOptions/ui/SystemPage.tsx index dd32d4476..7af32f8cd 100644 --- a/src/GameOptions/ui/SystemPage.tsx +++ b/src/GameOptions/ui/SystemPage.tsx @@ -12,50 +12,32 @@ export const SystemPage = (): React.ReactElement => { const [terminalSize, setTerminalSize] = useState(Settings.MaxTerminalCapacity); const [autosaveInterval, setAutosaveInterval] = useState(Settings.AutosaveInterval); - function handlePortSizeChange( - _event: Event | React.SyntheticEvent, - newValue: number | number[], - ): void { + function handlePortSizeChange(_event: Event | React.SyntheticEvent, newValue: number | number[]): void { setPortSize(newValue as number); Settings.MaxPortCapacity = newValue as number; } - function handleTerminalSizeChange( - _event: Event | React.SyntheticEvent, - newValue: number | number[], - ): void { + function handleTerminalSizeChange(_event: Event | React.SyntheticEvent, newValue: number | number[]): void { setTerminalSize(newValue as number); Settings.MaxTerminalCapacity = newValue as number; } - function handleExecTimeChange( - _event: Event | React.SyntheticEvent, - newValue: number | number[], - ): void { + function handleExecTimeChange(_event: Event | React.SyntheticEvent, newValue: number | number[]): void { setExecTime(newValue as number); Settings.CodeInstructionRunTime = newValue as number; } - function handleRecentScriptsSizeChange( - _event: Event | React.SyntheticEvent, - newValue: number | number[], - ): void { + function handleRecentScriptsSizeChange(_event: Event | React.SyntheticEvent, newValue: number | number[]): void { setRecentScriptsSize(newValue as number); Settings.MaxRecentScriptsCapacity = newValue as number; } - function handleLogSizeChange( - _event: Event | React.SyntheticEvent, - newValue: number | number[], - ): void { + function handleLogSizeChange(_event: Event | React.SyntheticEvent, newValue: number | number[]): void { setLogSize(newValue as number); Settings.MaxLogCapacity = newValue as number; } - function handleAutosaveIntervalChange( - _event: Event | React.SyntheticEvent, - newValue: number | number[], - ): void { + function handleAutosaveIntervalChange(_event: Event | React.SyntheticEvent, newValue: number | number[]): void { setAutosaveInterval(newValue as number); Settings.AutosaveInterval = newValue as number; } diff --git a/src/Gang/AllGangs.ts b/src/Gang/AllGangs.ts index f42b7eeda..d7838b340 100644 --- a/src/Gang/AllGangs.ts +++ b/src/Gang/AllGangs.ts @@ -6,9 +6,7 @@ interface GangTerritory { territory: number; } -export let AllGangs: { - [key: string]: GangTerritory; -} = { +export let AllGangs: Record = { [FactionNames.SlumSnakes]: { power: 1, territory: 1 / 7, diff --git a/src/Gang/Gang.ts b/src/Gang/Gang.ts index 50d867fd9..eba5a2efc 100644 --- a/src/Gang/Gang.ts +++ b/src/Gang/Gang.ts @@ -148,6 +148,12 @@ export class Gang { } processTerritoryAndPowerGains(numCycles = 1): void { + function calculateTerritoryGain(winGang: string, loseGang: string): number { + const powerBonus = Math.max(1, 1 + Math.log(AllGangs[winGang].power / AllGangs[loseGang].power) / Math.log(50)); + const gains = Math.min(AllGangs[loseGang].territory, powerBonus * 0.0001 * (Math.random() + 0.5)); + return gains; + } + this.storedTerritoryAndPowerCycles += numCycles; if (this.storedTerritoryAndPowerCycles < GangConstants.CyclesPerTerritoryAndPowerUpdate) return; this.storedTerritoryAndPowerCycles -= GangConstants.CyclesPerTerritoryAndPowerUpdate; @@ -155,7 +161,7 @@ export class Gang { // Process power first const gangName = this.facName; for (const name of Object.keys(AllGangs)) { - if (AllGangs.hasOwnProperty(name)) { + if (Object.hasOwn(AllGangs, name)) { if (name == gangName) { AllGangs[name].power += this.calculatePower(); } else { @@ -208,15 +214,6 @@ export class Gang { const otherPwr = AllGangs[otherGang].power; const thisChance = thisPwr / (thisPwr + otherPwr); - function calculateTerritoryGain(winGang: string, loseGang: string): number { - const powerBonus = Math.max( - 1, - 1 + Math.log(AllGangs[winGang].power / AllGangs[loseGang].power) / Math.log(50), - ); - const gains = Math.min(AllGangs[loseGang].territory, powerBonus * 0.0001 * (Math.random() + 0.5)); - return gains; - } - if (Math.random() < thisChance) { if (AllGangs[otherGang].territory <= 0) return; const territoryGain = calculateTerritoryGain(thisGang, otherGang); @@ -320,8 +317,7 @@ export class Gang { calculatePower(): number { let memberTotal = 0; for (let i = 0; i < this.members.length; ++i) { - if (!GangMemberTasks.hasOwnProperty(this.members[i].task) || this.members[i].task !== "Territory Warfare") - continue; + if (this.members[i].task !== "Territory Warfare") continue; memberTotal += this.members[i].calculatePower(); } return 0.015 * Math.max(0.002, this.getTerritory()) * memberTotal; diff --git a/src/Gang/GangMember.ts b/src/Gang/GangMember.ts index 99b58734b..f3fc64bb8 100644 --- a/src/Gang/GangMember.ts +++ b/src/Gang/GangMember.ts @@ -86,7 +86,7 @@ export class GangMember { } assignToTask(taskName: string): boolean { - if (!GangMemberTasks.hasOwnProperty(taskName)) { + if (!Object.hasOwn(GangMemberTasks, taskName)) { this.task = "Unassigned"; return false; } @@ -105,10 +105,10 @@ export class GangMember { this.task = (this.task as any).name; } - if (GangMemberTasks.hasOwnProperty(this.task)) { + if (Object.hasOwn(GangMemberTasks, this.task)) { return GangMemberTasks[this.task]; } - return GangMemberTasks["Unassigned"]; + return GangMemberTasks.Unassigned; } calculateRespectGain(gang: Gang): number { @@ -154,7 +154,7 @@ export class GangMember { gainExperience(numCycles = 1): void { const task = this.getTask(); - if (task === GangMemberTasks["Unassigned"]) return; + if (task === GangMemberTasks.Unassigned) return; const difficultyMult = Math.pow(task.difficulty, 0.9); const difficultyPerCycles = difficultyMult * numCycles; const weightDivisor = 1500; diff --git a/src/Gang/GangMemberTasks.ts b/src/Gang/GangMemberTasks.ts index 579a15566..8717506b0 100644 --- a/src/Gang/GangMemberTasks.ts +++ b/src/Gang/GangMemberTasks.ts @@ -1,9 +1,7 @@ import { gangMemberTasksMetadata } from "./data/tasks"; import { GangMemberTask } from "./GangMemberTask"; -export const GangMemberTasks: { - [key: string]: GangMemberTask; -} = {}; +export const GangMemberTasks: Record = {}; (function () { gangMemberTasksMetadata.forEach((e) => { diff --git a/src/Gang/GangMemberUpgrades.ts b/src/Gang/GangMemberUpgrades.ts index 65acf6c5c..cceb213cc 100644 --- a/src/Gang/GangMemberUpgrades.ts +++ b/src/Gang/GangMemberUpgrades.ts @@ -1,9 +1,7 @@ import { gangMemberUpgradesMetadata } from "./data/upgrades"; import { GangMemberUpgrade } from "./GangMemberUpgrade"; -export const GangMemberUpgrades: { - [key: string]: GangMemberUpgrade; -} = {}; +export const GangMemberUpgrades: Record = {}; (function () { gangMemberUpgradesMetadata.forEach((e) => { diff --git a/src/Gang/data/power.ts b/src/Gang/data/power.ts index 8b4d03831..ee981ae60 100644 --- a/src/Gang/data/power.ts +++ b/src/Gang/data/power.ts @@ -1,7 +1,5 @@ import { FactionNames } from "../../Faction/data/FactionNames"; -export const PowerMultiplier: { - [key: string]: number | undefined; -} = { +export const PowerMultiplier: Record = { [FactionNames.SlumSnakes]: 1, [FactionNames.Tetrads]: 2, [FactionNames.TheSyndicate]: 2, diff --git a/src/Gang/data/tasks.ts b/src/Gang/data/tasks.ts index 1944206d5..acdeeed2a 100644 --- a/src/Gang/data/tasks.ts +++ b/src/Gang/data/tasks.ts @@ -1,5 +1,4 @@ import { ITaskParams } from "../ITaskParams"; -/* tslint:disable:max-line-length */ /** * Defines the parameters that can be used to initialize and describe a GangMemberTask diff --git a/src/Gang/ui/EquipmentsSubpage.tsx b/src/Gang/ui/EquipmentsSubpage.tsx index 377ec5a3a..aa59b1773 100644 --- a/src/Gang/ui/EquipmentsSubpage.tsx +++ b/src/Gang/ui/EquipmentsSubpage.tsx @@ -102,7 +102,7 @@ function GangMemberUpgradePanel(props: IPanelProps): React.ReactElement { .map((upgName: string) => GangMemberUpgrades[upgName]); } - const onChange = (event: SelectChangeEvent): void => { + const onChange = (event: SelectChangeEvent): void => { setCurrentCategory(event.target.value); rerender(); }; @@ -113,7 +113,7 @@ function GangMemberUpgradePanel(props: IPanelProps): React.ReactElement { const rootkitUpgrades = filterUpgrades(props.member.upgrades, UpgradeType.Rootkit); const augUpgrades = filterUpgrades(props.member.augmentations, UpgradeType.Augmentation); - const categories: { [key: string]: (GangMemberUpgrade[] | UpgradeType)[] } = { + const categories: Record = { Weapons: [weaponUpgrades, UpgradeType.Weapon], Armor: [armorUpgrades, UpgradeType.Armor], Vehicles: [vehicleUpgrades, UpgradeType.Vehicle], diff --git a/src/Gang/ui/TaskDescription.tsx b/src/Gang/ui/TaskDescription.tsx index 1946bf23e..f6f958d36 100644 --- a/src/Gang/ui/TaskDescription.tsx +++ b/src/Gang/ui/TaskDescription.tsx @@ -13,7 +13,7 @@ interface IProps { export function TaskDescription(props: IProps): React.ReactElement { const task = GangMemberTasks[props.member.task]; - const desc = task ? task.desc : GangMemberTasks["Unassigned"].desc; + const desc = task ? task.desc : GangMemberTasks.Unassigned.desc; return ; } diff --git a/src/Gang/ui/TaskSelector.tsx b/src/Gang/ui/TaskSelector.tsx index 49dfe105c..7879f18ea 100644 --- a/src/Gang/ui/TaskSelector.tsx +++ b/src/Gang/ui/TaskSelector.tsx @@ -26,7 +26,7 @@ export function TaskSelector(props: IProps): React.ReactElement { setCurrentTask(contextMember.task); } - function onChange(event: SelectChangeEvent): void { + function onChange(event: SelectChangeEvent): void { const task = event.target.value; props.member.assignToTask(task); setCurrentTask(task); diff --git a/src/Hacking.ts b/src/Hacking.ts index 10ed92aff..eb5eb30b1 100644 --- a/src/Hacking.ts +++ b/src/Hacking.ts @@ -65,7 +65,6 @@ export function calculateHackingTime(server: IServer, person: IPerson): number { const baseSkill = 50; const diffFactor = 2.5; let skillFactor = diffFactor * difficultyMult + baseDiff; - // tslint:disable-next-line skillFactor /= person.skills.hacking + baseSkill; const hackTimeMultiplier = 5; diff --git a/src/Hacking/netscriptCanHack.ts b/src/Hacking/netscriptCanHack.ts index fed9ae613..0f409e060 100644 --- a/src/Hacking/netscriptCanHack.ts +++ b/src/Hacking/netscriptCanHack.ts @@ -19,7 +19,7 @@ function baseCheck(server: Server, fnName: string): IReturnStatus { }; } - if (server.hasAdminRights === false) { + if (!server.hasAdminRights) { return { res: false, msg: `Cannot ${fnName} ${hostname} server because you do not have root access`, diff --git a/src/Hacknet/HacknetServer.ts b/src/Hacknet/HacknetServer.ts index 95aff0e9b..41ec93dba 100644 --- a/src/Hacknet/HacknetServer.ts +++ b/src/Hacknet/HacknetServer.ts @@ -12,6 +12,7 @@ import { calculateCacheUpgradeCost, } from "./formulas/HacknetServers"; +import { IPAddress } from "../Types/strings"; import { createRandomIp } from "../utils/IPAddress"; import { IReviverValue, constructorsForReviver } from "../utils/JSONReviver"; @@ -20,7 +21,7 @@ import { Player } from "@player"; interface IConstructorParams { adminRights?: boolean; hostname: string; - ip?: string; + ip?: IPAddress; isConnectedTo?: boolean; maxRam?: number; organizationName?: string; diff --git a/src/Hacknet/ui/HacknetServerElem.tsx b/src/Hacknet/ui/HacknetServerElem.tsx index 6e608e95e..97242d233 100644 --- a/src/Hacknet/ui/HacknetServerElem.tsx +++ b/src/Hacknet/ui/HacknetServerElem.tsx @@ -232,9 +232,6 @@ export function HacknetServerElem(props: IProps): React.ReactElement {
); - if (Player.money < upgradeCacheCost) { - } else { - } } function upgradeCacheOnClick(): void { let numUpgrades = purchaseMult; diff --git a/src/Hacknet/ui/HacknetUpgradeElem.tsx b/src/Hacknet/ui/HacknetUpgradeElem.tsx index 65289a5bf..6b7233a37 100644 --- a/src/Hacknet/ui/HacknetUpgradeElem.tsx +++ b/src/Hacknet/ui/HacknetUpgradeElem.tsx @@ -24,21 +24,21 @@ interface IProps { rerender: () => void; } -const serversMap: { [key: string]: string } = {}; -const companiesMap: { [key: string]: string } = {}; +const serversMap: Record = {}; +const companiesMap: Record = {}; export function HacknetUpgradeElem(props: IProps): React.ReactElement { const [selectedServer, setSelectedServer] = useState( serversMap[props.upg.name] ? serversMap[props.upg.name] : FactionNames.ECorp.toLowerCase(), ); - function changeTargetServer(event: SelectChangeEvent): void { + function changeTargetServer(event: SelectChangeEvent): void { setSelectedServer(event.target.value); serversMap[props.upg.name] = event.target.value; } const [selectedCompany, setSelectedCompany] = useState( companiesMap[props.upg.name] ? companiesMap[props.upg.name] : companiesMetadata[0].name, ); - function changeTargetCompany(event: SelectChangeEvent): void { + function changeTargetCompany(event: SelectChangeEvent): void { setSelectedCompany(event.target.value); companiesMap[props.upg.name] = event.target.value; } diff --git a/src/Infiltration/ui/Difficulty.ts b/src/Infiltration/ui/Difficulty.ts index 4ee06aa39..a0963abb8 100644 --- a/src/Infiltration/ui/Difficulty.ts +++ b/src/Infiltration/ui/Difficulty.ts @@ -1,6 +1,4 @@ -interface DifficultySetting { - [key: string]: number; -} +type DifficultySetting = Record; interface DifficultySettings { Trivial: DifficultySetting; diff --git a/src/Infiltration/ui/Victory.tsx b/src/Infiltration/ui/Victory.tsx index 2912e0ecd..1e689364e 100644 --- a/src/Infiltration/ui/Victory.tsx +++ b/src/Infiltration/ui/Victory.tsx @@ -48,7 +48,7 @@ export function Victory(props: IProps): React.ReactElement { quitInfiltration(); } - function changeDropdown(event: SelectChangeEvent): void { + function changeDropdown(event: SelectChangeEvent): void { setFaction(event.target.value); } diff --git a/src/Literature/Literature.ts b/src/Literature/Literature.ts index 974160e5e..366a07d38 100644 --- a/src/Literature/Literature.ts +++ b/src/Literature/Literature.ts @@ -1,7 +1,11 @@ import { FilePath, asFilePath } from "../Paths/FilePath"; import type { LiteratureName } from "./data/LiteratureNames"; -type LiteratureConstructorParams = { title: string; filename: LiteratureName; text: string }; +interface LiteratureConstructorParams { + title: string; + filename: LiteratureName; + text: string; +} /** * Lore / world building literature files that can be found on servers. * These files can be read by the player diff --git a/src/Locations/ui/ApplyToJobButton.tsx b/src/Locations/ui/ApplyToJobButton.tsx index 8e2868b5f..5b5c80255 100644 --- a/src/Locations/ui/ApplyToJobButton.tsx +++ b/src/Locations/ui/ApplyToJobButton.tsx @@ -8,12 +8,12 @@ import { Player } from "@player"; import Button from "@mui/material/Button"; import Tooltip from "@mui/material/Tooltip"; -type IProps = { +interface IProps { company: Company; entryPosType: CompanyPosition; onClick: (e: React.MouseEvent) => void; text: string; -}; +} /** React Component for a button that's used to apply for a job */ export function ApplyToJobButton(props: IProps): React.ReactElement { diff --git a/src/Locations/ui/City.tsx b/src/Locations/ui/City.tsx index 7d78ce566..8d9cc29ac 100644 --- a/src/Locations/ui/City.tsx +++ b/src/Locations/ui/City.tsx @@ -22,9 +22,9 @@ import { Theme } from "@mui/material/styles"; import makeStyles from "@mui/styles/makeStyles"; import createStyles from "@mui/styles/createStyles"; -type IProps = { +interface IProps { city: City; -}; +} const useStyles = makeStyles((theme: Theme) => createStyles({ @@ -70,9 +70,7 @@ function LocationLetter(location: Location, className: string): React.ReactEleme function ASCIICity(props: IProps): React.ReactElement { const locationLettersRegex = /[A-Z]/g; - const letterMap: { - [key: string]: number; - } = { + const letterMap: Record = { A: 0, B: 1, C: 2, diff --git a/src/Locations/ui/CompanyLocation.tsx b/src/Locations/ui/CompanyLocation.tsx index 94c5e24ac..4859eb6a4 100644 --- a/src/Locations/ui/CompanyLocation.tsx +++ b/src/Locations/ui/CompanyLocation.tsx @@ -27,9 +27,9 @@ import { QuitJobModal } from "../../Company/ui/QuitJobModal"; import { CompanyWork } from "../../Work/CompanyWork"; import { useRerender } from "../../ui/React/hooks"; -type IProps = { +interface IProps { locName: LocationName; -}; +} export function CompanyLocation(props: IProps): React.ReactElement { const [quitOpen, setQuitOpen] = useState(false); diff --git a/src/Locations/ui/CoresButton.tsx b/src/Locations/ui/CoresButton.tsx index 3df8e50ab..5ca0e9d13 100644 --- a/src/Locations/ui/CoresButton.tsx +++ b/src/Locations/ui/CoresButton.tsx @@ -8,9 +8,9 @@ import { Player } from "@player"; import { Money } from "../../ui/React/Money"; import { MathJax } from "better-react-mathjax"; -type IProps = { +interface IProps { rerender: () => void; -}; +} export function CoresButton(props: IProps): React.ReactElement { const homeComputer = Player.getHomeComputer(); diff --git a/src/Locations/ui/GenericLocation.tsx b/src/Locations/ui/GenericLocation.tsx index f839f5919..86d083a04 100644 --- a/src/Locations/ui/GenericLocation.tsx +++ b/src/Locations/ui/GenericLocation.tsx @@ -32,9 +32,9 @@ import { Page } from "../../ui/Router"; import { serverMetadata } from "../../Server/data/servers"; import { Tooltip } from "@mui/material"; -type IProps = { +interface IProps { loc: Location; -}; +} export function GenericLocation({ loc }: IProps): React.ReactElement { /** diff --git a/src/Locations/ui/GymLocation.tsx b/src/Locations/ui/GymLocation.tsx index 8eaf1684b..425a785a5 100644 --- a/src/Locations/ui/GymLocation.tsx +++ b/src/Locations/ui/GymLocation.tsx @@ -18,9 +18,9 @@ import { ClassWork, Classes } from "../../Work/ClassWork"; import { calculateCost } from "../../Work/Formulas"; import { GymType } from "../../Enums"; -type IProps = { +interface IProps { loc: Location; -}; +} export function GymLocation(props: IProps): React.ReactElement { function train(stat: GymType): void { diff --git a/src/Locations/ui/RamButton.tsx b/src/Locations/ui/RamButton.tsx index daedd902f..0f97eb8e2 100644 --- a/src/Locations/ui/RamButton.tsx +++ b/src/Locations/ui/RamButton.tsx @@ -13,9 +13,9 @@ import { formatRam } from "../../ui/formatNumber"; import { MathJax } from "better-react-mathjax"; import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers"; -type IProps = { +interface IProps { rerender: () => void; -}; +} export function RamButton(props: IProps): React.ReactElement { const homeComputer = Player.getHomeComputer(); diff --git a/src/Locations/ui/SpecialLocation.tsx b/src/Locations/ui/SpecialLocation.tsx index ebf9d0b86..6a85209cd 100644 --- a/src/Locations/ui/SpecialLocation.tsx +++ b/src/Locations/ui/SpecialLocation.tsx @@ -38,9 +38,9 @@ import { ArcadeRoot } from "../../Arcade/ui/ArcadeRoot"; import { FactionNames } from "../../Faction/data/FactionNames"; import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers"; -type IProps = { +interface IProps { loc: Location; -}; +} export function SpecialLocation(props: IProps): React.ReactElement { const setRerender = useState(false)[1]; diff --git a/src/Locations/ui/TorButton.tsx b/src/Locations/ui/TorButton.tsx index bd1c8b5bc..a663248a8 100644 --- a/src/Locations/ui/TorButton.tsx +++ b/src/Locations/ui/TorButton.tsx @@ -36,9 +36,9 @@ export function purchaseTorRouter(): void { ); } -type IProps = { +interface IProps { rerender: () => void; -}; +} export function TorButton(props: IProps): React.ReactElement { function buy(): void { diff --git a/src/Locations/ui/UniversityLocation.tsx b/src/Locations/ui/UniversityLocation.tsx index 436f2ea81..20e613625 100644 --- a/src/Locations/ui/UniversityLocation.tsx +++ b/src/Locations/ui/UniversityLocation.tsx @@ -19,9 +19,9 @@ import { ClassWork, Classes } from "../../Work/ClassWork"; import { calculateCost } from "../../Work/Formulas"; import { UniversityClassType } from "../../Enums"; -type IProps = { +interface IProps { loc: Location; -}; +} export function UniversityLocation(props: IProps): React.ReactElement { function take(classType: UniversityClassType): void { diff --git a/src/Milestones/Milestone.ts b/src/Milestones/Milestone.ts index 641cabe1f..4bba47b0d 100644 --- a/src/Milestones/Milestone.ts +++ b/src/Milestones/Milestone.ts @@ -1,4 +1,4 @@ -export type Milestone = { +export interface Milestone { title: string; fulfilled: () => boolean; -}; +} diff --git a/src/Milestones/Milestones.ts b/src/Milestones/Milestones.ts index d12e64f75..a1214689c 100644 --- a/src/Milestones/Milestones.ts +++ b/src/Milestones/Milestones.ts @@ -24,7 +24,7 @@ export const Milestones: Milestone[] = [ title: "Gain root access on CSEC", fulfilled: (): boolean => { const server = GetServer("CSEC"); - if (!server || !server.hasOwnProperty("hasAdminRights")) return false; + if (!server || !Object.hasOwn(server, "hasAdminRights")) return false; return server instanceof Server && server.hasAdminRights; }, }, @@ -32,7 +32,7 @@ export const Milestones: Milestone[] = [ title: "Install the backdoor on CSEC", fulfilled: (): boolean => { const server = GetServer("CSEC"); - if (!server || !server.hasOwnProperty("backdoorInstalled")) return false; + if (!server || !Object.hasOwn(server, "backdoorInstalled")) return false; return server instanceof Server && server.backdoorInstalled; }, }, diff --git a/src/Netscript/APIWrapper.ts b/src/Netscript/APIWrapper.ts index 968269dd4..cfa097bd6 100644 --- a/src/Netscript/APIWrapper.ts +++ b/src/Netscript/APIWrapper.ts @@ -15,11 +15,11 @@ export type InternalAPI = { [key in keyof API]: API[key] extends APIFn ? InternalFn : InternalAPI; }; -export type NetscriptContext = { +export interface NetscriptContext { workerScript: WorkerScript; function: string; functionPath: string; -}; +} class NSProxyHandler> { ns: API; diff --git a/src/Netscript/NetscriptHelpers.ts b/src/Netscript/NetscriptHelpers.ts index 7ab0eaf54..ddc7bb404 100644 --- a/src/Netscript/NetscriptHelpers.ts +++ b/src/Netscript/NetscriptHelpers.ts @@ -28,7 +28,7 @@ import { RunningScript } from "../Script/RunningScript"; import { toNative } from "../NetscriptFunctions/toNative"; import { ScriptIdentifier } from "./ScriptIdentifier"; import { findRunningScripts, findRunningScriptByPid } from "../Script/ScriptHelpers"; -import { arrayToString } from "../utils/helpers/arrayToString"; +import { arrayToString } from "../utils/helpers/ArrayHelpers"; import { HacknetServer } from "../Hacknet/HacknetServer"; import { BaseServer } from "../Server/BaseServer"; import { dialogBoxCreate } from "../ui/React/DialogBox"; @@ -112,9 +112,8 @@ export function assertObjectType( "TYPE", ); } - const objHas = Object.prototype.hasOwnProperty.bind(obj); for (const [key, val] of Object.entries(desiredObject)) { - if (!objHas(key)) { + if (!Object.hasOwn(obj, key)) { throw makeRuntimeErrorMsg( ctx, `Object provided for argument ${name} is missing required property ${key}.`, @@ -269,40 +268,12 @@ function makeRuntimeErrorMsg(ctx: NetscriptContext, msg: string, type = "RUNTIME })(); if (!filename) continue; - interface ILine { - line: string; - func: string; - } - - function parseChromeStackline(line: string): ILine | null { - const lineRe = /.*:(\d+):\d+.*/; - const funcRe = /.*at (.+) \(.*/; - - const lineMatch = line.match(lineRe); - const funcMatch = line.match(funcRe); - if (lineMatch && funcMatch) { - return { line: lineMatch[1], func: funcMatch[1] }; - } - return null; - } let call = { line: "-1", func: "unknown" }; const chromeCall = parseChromeStackline(stackline); if (chromeCall) { call = chromeCall; } - function parseFirefoxStackline(line: string): ILine | null { - const lineRe = /.*:(\d+):\d+$/; - const lineMatch = line.match(lineRe); - - const lio = line.lastIndexOf("@"); - - if (lineMatch && lio !== -1) { - return { line: lineMatch[1], func: line.slice(0, lio) }; - } - return null; - } - const firefoxCall = parseFirefoxStackline(stackline); if (firefoxCall) { call = firefoxCall; @@ -315,6 +286,23 @@ function makeRuntimeErrorMsg(ctx: NetscriptContext, msg: string, type = "RUNTIME let rejectMsg = `${caller}: ${msg}`; if (userstack.length !== 0) rejectMsg += `\n\nStack:\n${userstack.join("\n")}`; return makeBasicErrorMsg(ws, rejectMsg, type); + + interface ILine { + line: string; + func: string; + } + function parseChromeStackline(line: string): ILine | null { + const lineMatch = line.match(/.*:(\d+):\d+.*/); + const funcMatch = line.match(/.*at (.+) \(.*/); + if (lineMatch && funcMatch) return { line: lineMatch[1], func: funcMatch[1] }; + return null; + } + function parseFirefoxStackline(line: string): ILine | null { + const lineMatch = line.match(/.*:(\d+):\d+$/); + const lio = line.lastIndexOf("@"); + if (lineMatch && lio !== -1) return { line: lineMatch[1], func: line.slice(0, lio) }; + return null; + } } /** Validate requested number of threads for h/g/w options */ diff --git a/src/Netscript/WorkerScripts.ts b/src/Netscript/WorkerScripts.ts index 24008cffe..bf3422697 100644 --- a/src/Netscript/WorkerScripts.ts +++ b/src/Netscript/WorkerScripts.ts @@ -1,4 +1,4 @@ import { WorkerScript } from "./WorkerScript"; /** Global pool of all active scripts (scripts that are currently running) */ -export const workerScripts: Map = new Map(); +export const workerScripts = new Map(); diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 346ebbc9d..e7a4419d1 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -50,7 +50,7 @@ import { } from "./ui/formatNumber"; import { convertTimeMsToTimeElapsedString } from "./utils/StringHelperFunctions"; import { LogBoxEvents, LogBoxCloserEvents, LogBoxPositionEvents, LogBoxSizeEvents } from "./ui/React/LogBoxManager"; -import { arrayToString } from "./utils/helpers/arrayToString"; +import { arrayToString } from "./utils/helpers/ArrayHelpers"; import { NetscriptGang } from "./NetscriptFunctions/Gang"; import { NetscriptSleeve } from "./NetscriptFunctions/Sleeve"; import { NetscriptExtra } from "./NetscriptFunctions/Extra"; @@ -787,7 +787,7 @@ export const ns: InternalAPI = { for (const byPid of server.runningScriptMap.values()) { for (const pid of byPid.keys()) { - if (safetyguard === true && pid == ctx.workerScript.pid) continue; + if (safetyguard && pid == ctx.workerScript.pid) continue; killWorkerScriptByPid(pid); ++scriptsKilled; } @@ -851,13 +851,13 @@ export const ns: InternalAPI = { const destMessage = destServer.messages.find((message) => message === litFilePath); if (destMessage) { - helpers.log(ctx, () => `File '${litFilePath}' was already on '${destServer?.hostname}'.`); + helpers.log(ctx, () => `File '${litFilePath}' was already on '${destServer.hostname}'.`); continue; } // It exists in sourceServer.messages, so it's a valid name. destServer.messages.push(litFilePath as LiteratureName); - helpers.log(ctx, () => `File '${litFilePath}' copied over to '${destServer?.hostname}'.`); + helpers.log(ctx, () => `File '${litFilePath}' copied over to '${destServer.hostname}'.`); continue; } return noFailures; diff --git a/src/NetscriptFunctions/Corporation.ts b/src/NetscriptFunctions/Corporation.ts index 1033d2ee2..1e15d3153 100644 --- a/src/NetscriptFunctions/Corporation.ts +++ b/src/NetscriptFunctions/Corporation.ts @@ -186,7 +186,7 @@ export function NetscriptCorporation(): InternalAPI { } function hasResearched(division: Industry, researchName: CorpResearchName): boolean { - return division.researched[researchName] === undefined ? false : (division.researched[researchName] as boolean); + return division.researched[researchName] ?? false; } function bribe(factionName: string, amountCash: number): boolean { diff --git a/src/NetscriptFunctions/Extra.ts b/src/NetscriptFunctions/Extra.ts index 4d0712a65..6f101d3ff 100644 --- a/src/NetscriptFunctions/Extra.ts +++ b/src/NetscriptFunctions/Extra.ts @@ -8,7 +8,7 @@ import { helpers } from "../Netscript/NetscriptHelpers"; import { Terminal } from "../Terminal"; import { RamCostConstants } from "../Netscript/RamCostGenerator"; -export type INetscriptExtra = { +export interface INetscriptExtra { heart: { break(): number; }; @@ -19,7 +19,7 @@ export type INetscriptExtra = { rainbow(guess: string): void; iKnowWhatImDoing(): void; printRaw(value: React.ReactNode): void; -}; +} export function NetscriptExtra(): InternalAPI { return { @@ -30,7 +30,9 @@ export function NetscriptExtra(): InternalAPI { exploit: () => () => Player.giveExploit(Exploit.UndocumentedFunctionCall), bypass: (ctx) => (doc) => { // reset both fields first - type temporary = { completely_unused_field: unknown }; + interface temporary { + completely_unused_field: unknown; + } const d = doc as temporary; d.completely_unused_field = undefined; const real_document = document as unknown as temporary; @@ -53,7 +55,7 @@ export function NetscriptExtra(): InternalAPI { }; recur(2); console.warn("I am sure that this variable is false."); - if (x !== false) { + if (x) { console.warn("Reality has been altered!"); Player.giveExploit(Exploit.RealityAlteration); } @@ -67,7 +69,7 @@ export function NetscriptExtra(): InternalAPI { }, iKnowWhatImDoing: (ctx) => () => { helpers.log(ctx, () => "Unlocking unsupported feature: window.tprintRaw"); - // @ts-ignore window has no tprintRaw property defined + // @ts-expect-error window has no tprintRaw property defined window.tprintRaw = Terminal.printRaw.bind(Terminal); }, printRaw: (ctx) => (value) => { diff --git a/src/NetscriptFunctions/Flags.ts b/src/NetscriptFunctions/Flags.ts index 2b9682c84..8071b3650 100644 --- a/src/NetscriptFunctions/Flags.ts +++ b/src/NetscriptFunctions/Flags.ts @@ -4,15 +4,13 @@ import { ScriptArg } from "../Netscript/ScriptArg"; import { NetscriptContext } from "../Netscript/APIWrapper"; type FlagType = StringConstructor | NumberConstructor | BooleanConstructor | StringConstructor[]; -type FlagsRet = { [key: string]: ScriptArg | string[] }; +type FlagsRet = Record; export function Flags(ctx: NetscriptContext | string[]): (data: unknown) => FlagsRet { const vargs = Array.isArray(ctx) ? ctx : ctx.workerScript.args; return (schema: unknown): FlagsRet => { schema = toNative(schema); if (!Array.isArray(schema)) throw new Error("flags schema passed in is invalid."); - const args: { - [key: string]: FlagType; - } = {}; + const args: Record = {}; for (const d of schema) { let t: FlagType = String; @@ -28,7 +26,7 @@ export function Flags(ctx: NetscriptContext | string[]): (data: unknown) => Flag } const ret: FlagsRet = libarg(args, { argv: vargs }); for (const d of schema) { - if (!ret.hasOwnProperty("--" + d[0]) || !ret.hasOwnProperty("-" + d[0])) ret[d[0]] = d[1]; + if (!Object.hasOwn(ret, "--" + d[0]) || !Object.hasOwn(ret, "-" + d[0])) ret[d[0]] = d[1]; } for (const key of Object.keys(ret)) { if (!key.startsWith("-")) continue; diff --git a/src/NetscriptFunctions/Grafting.ts b/src/NetscriptFunctions/Grafting.ts index 2072a7e35..8d67595fe 100644 --- a/src/NetscriptFunctions/Grafting.ts +++ b/src/NetscriptFunctions/Grafting.ts @@ -10,6 +10,7 @@ import { Router } from "../ui/GameRoot"; import { Page } from "../ui/Router"; import { GraftingWork } from "../Work/GraftingWork"; import { helpers } from "../Netscript/NetscriptHelpers"; +import { augmentationExists } from "../Augmentation/AugmentationHelpers"; export function NetscriptGrafting(): InternalAPI { const checkGraftingAPIAccess = (ctx: NetscriptContext): void => { @@ -25,7 +26,7 @@ export function NetscriptGrafting(): InternalAPI { getAugmentationGraftPrice: (ctx) => (_augName) => { const augName = helpers.string(ctx, "augName", _augName); checkGraftingAPIAccess(ctx); - if (!getGraftingAvailableAugs().includes(augName) || !StaticAugmentations.hasOwnProperty(augName)) { + if (!getGraftingAvailableAugs().includes(augName) || augmentationExists(augName)) { throw helpers.makeRuntimeErrorMsg(ctx, `Invalid aug: ${augName}`); } const graftableAug = new GraftableAugmentation(StaticAugmentations[augName]); @@ -35,7 +36,7 @@ export function NetscriptGrafting(): InternalAPI { getAugmentationGraftTime: (ctx) => (_augName) => { const augName = helpers.string(ctx, "augName", _augName); checkGraftingAPIAccess(ctx); - if (!getGraftingAvailableAugs().includes(augName) || !StaticAugmentations.hasOwnProperty(augName)) { + if (!getGraftingAvailableAugs().includes(augName) || !augmentationExists(augName)) { throw helpers.makeRuntimeErrorMsg(ctx, `Invalid aug: ${augName}`); } const graftableAug = new GraftableAugmentation(StaticAugmentations[augName]); @@ -57,7 +58,7 @@ export function NetscriptGrafting(): InternalAPI { if (player.city !== CityName.NewTokyo) { throw helpers.makeRuntimeErrorMsg(ctx, "You must be in New Tokyo to begin grafting an Augmentation."); } - if (!getGraftingAvailableAugs().includes(augName) || !StaticAugmentations.hasOwnProperty(augName)) { + if (!getGraftingAvailableAugs().includes(augName) || !augmentationExists(augName)) { helpers.log(ctx, () => `Invalid aug: ${augName}`); return false; } diff --git a/src/NetscriptFunctions/Infiltration.ts b/src/NetscriptFunctions/Infiltration.ts index a6deecc34..4f16b2c03 100644 --- a/src/NetscriptFunctions/Infiltration.ts +++ b/src/NetscriptFunctions/Infiltration.ts @@ -11,8 +11,9 @@ import { FactionNames } from "../Faction/data/FactionNames"; import { Factions } from "../Faction/Factions"; import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper"; import { checkEnum } from "../utils/helpers/enum"; -import { CityName, LocationName } from "../Enums"; +import { LocationName } from "../Enums"; import { helpers } from "../Netscript/NetscriptHelpers"; +import { FilterTruthy } from "../utils/helpers/ArrayHelpers"; export function NetscriptInfiltration(): InternalAPI { const getLocationsWithInfiltrations = Object.values(Locations).filter( @@ -41,12 +42,15 @@ export function NetscriptInfiltration(): InternalAPI { }; return { getPossibleLocations: () => () => { - return getLocationsWithInfiltrations - .filter((l) => l.city) //Guarantees no locations with a "null" entry, which should not be infiltratable anyway. - .map((l) => ({ - city: l.city as CityName, - name: l.name, - })); + return FilterTruthy( + getLocationsWithInfiltrations.map((l) => { + if (!l.city) return false; + return { + city: l.city, + name: l.name, + }; + }), + ); }, getInfiltration: (ctx) => (_location) => { const location = helpers.string(ctx, "location", _location); diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index b55ce50f5..9d040775f 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -693,7 +693,7 @@ export function NetscriptSingularity(): InternalAPI { return Object.entries(CompanyPositions) .filter((_position) => Companies[companyName].hasPosition(_position[0])) - .map((_position) => _position[1]["name"]); + .map((_position) => _position[1].name); }, getCompanyPositionInfo: (ctx) => (_companyName, _positionName) => { helpers.checkSingularityAccess(ctx); diff --git a/src/NetscriptFunctions/StockMarket.ts b/src/NetscriptFunctions/StockMarket.ts index 4de4d3a8d..43bfd9cfe 100644 --- a/src/NetscriptFunctions/StockMarket.ts +++ b/src/NetscriptFunctions/StockMarket.ts @@ -305,7 +305,7 @@ export function NetscriptStockMarket(): InternalAPI { const orders: StockOrder = {}; - const stockMarketOrders = StockMarket["Orders"]; + const stockMarketOrders = StockMarket.Orders; for (const symbol of Object.keys(stockMarketOrders)) { const orderBook = stockMarketOrders[symbol]; if (orderBook.constructor === Array && orderBook.length > 0) { diff --git a/src/NetscriptFunctions/UserInterface.ts b/src/NetscriptFunctions/UserInterface.ts index 3db2c84c6..8a0b1bc35 100644 --- a/src/NetscriptFunctions/UserInterface.ts +++ b/src/NetscriptFunctions/UserInterface.ts @@ -86,7 +86,7 @@ export function NetscriptUserInterface(): InternalAPI { getGameInfo: () => () => { const version = CONSTANTS.VersionString; const commit = hash(); - const platform = navigator.userAgent.toLowerCase().indexOf(" electron/") > -1 ? "Steam" : "Browser"; + const platform = navigator.userAgent.toLowerCase().includes(" electron/") ? "Steam" : "Browser"; const gameInfo = { version, diff --git a/src/NetscriptFunctions/toNative.ts b/src/NetscriptFunctions/toNative.ts index d68b7b144..93a966a42 100644 --- a/src/NetscriptFunctions/toNative.ts +++ b/src/NetscriptFunctions/toNative.ts @@ -10,10 +10,10 @@ interface PseudoObject { const isPseudoObject = (v: unknown): v is PseudoObject => !!v && typeof v === "object" && - v.hasOwnProperty("properties") && - v.hasOwnProperty("getter") && - v.hasOwnProperty("setter") && - v.hasOwnProperty("proto"); + Object.hasOwn(v, "properties") && + Object.hasOwn(v, "getter") && + Object.hasOwn(v, "setter") && + Object.hasOwn(v, "proto"); // the acorn interpreter has a bug where it doesn't convert arrays correctly. // so we have to more or less copy it here. @@ -23,7 +23,7 @@ export function toNative(pseudoObj: unknown): unknown { return pseudoObj; // it wasn't a pseudo object anyway. } - if (pseudoObj.hasOwnProperty("class") && pseudoObj.class === "Array") { + if (Object.hasOwn(pseudoObj, "class") && pseudoObj.class === "Array") { const arr: unknown[] = []; const length = defaultInterpreter.getProperty(pseudoObj, "length"); if (typeof length === "number") { diff --git a/src/NetscriptJSEvaluator.ts b/src/NetscriptJSEvaluator.ts index d96f14981..22532ec2a 100644 --- a/src/NetscriptJSEvaluator.ts +++ b/src/NetscriptJSEvaluator.ts @@ -39,7 +39,7 @@ export const config = { // or changes a script and then changes it back). // Modules can never be garbage collected by Javascript, so it's good to try // to keep from making more than we need. -const moduleCache: Map> = new Map(); +const moduleCache = new Map>(); const cleanup = new FinalizationRegistry((mapKey: string) => { // A new entry can be created with the same key, before this callback is called. if (moduleCache.get(mapKey)?.deref() === undefined) { @@ -122,7 +122,7 @@ function generateLoadedModule(script: Script, scripts: Map b.start - a.start); - let newCode = script.code as string; + let newCode = script.code; // Loop through each node and replace the script name with a blob url. for (const node of importNodes) { const filename = resolveScriptFilePath(node.filename, root, ".js"); @@ -155,7 +155,7 @@ function generateLoadedModule(script: Script, scripts: Map; + }); // We can *immediately* invalidate the Blob, because we've already started the fetch // by starting the import. From now on, any imports using the blob's URL *must* // directly return the module, without even attempting to fetch, due to the way diff --git a/src/NetscriptPort.ts b/src/NetscriptPort.ts index f2975ca38..81c3a8555 100644 --- a/src/NetscriptPort.ts +++ b/src/NetscriptPort.ts @@ -44,7 +44,7 @@ export function writePort(n: PortNumber, value: unknown): PortData | null { } const { data, resolvers } = getPort(n); data.push(value); - while (resolvers.length > 0) (resolvers.pop() as Resolver)(); + while (resolvers.length > 0) resolvers.pop()?.(); if (data.length > Settings.MaxPortCapacity) return data.shift() as PortData; return null; } @@ -58,7 +58,7 @@ export function tryWritePort(n: PortNumber, value: unknown): boolean { const { data, resolvers } = getPort(n); if (data.length >= Settings.MaxPortCapacity) return false; data.push(value); - while (resolvers.length > 0) (resolvers.pop() as Resolver)(); + while (resolvers.length > 0) resolvers.pop()?.(); return true; } diff --git a/src/NetscriptWorker.ts b/src/NetscriptWorker.ts index 91cc8dd1e..f5e2eae18 100644 --- a/src/NetscriptWorker.ts +++ b/src/NetscriptWorker.ts @@ -23,7 +23,7 @@ import { Settings } from "./Settings/Settings"; import { generate } from "escodegen"; import { dialogBoxCreate } from "./ui/React/DialogBox"; -import { arrayToString } from "./utils/helpers/arrayToString"; +import { arrayToString } from "./utils/helpers/ArrayHelpers"; import { roundToTwo } from "./utils/helpers/roundToTwo"; import { parse } from "acorn"; @@ -34,7 +34,7 @@ import { handleUnknownError, CompleteRunOptions, getRunningScriptsByArgs } from import { resolveScriptFilePath, ScriptFilePath } from "./Paths/ScriptFilePath"; import { root } from "./Paths/Directory"; -export const NetscriptPorts: Map = new Map(); +export const NetscriptPorts = new Map(); export function prestigeWorkerScripts(): void { for (const ws of workerScripts.values()) { @@ -345,7 +345,7 @@ export function updateOnlineScriptTimes(numCycles = 1): void { * into worker scripts so that they will start running */ export function loadAllRunningScripts(): void { - const skipScriptLoad = window.location.href.toLowerCase().indexOf("?noscripts") !== -1; + const skipScriptLoad = window.location.href.toLowerCase().includes("?noscripts"); if (skipScriptLoad) { Terminal.warn("Skipped loading player scripts during startup"); console.info("Skipping the load of any scripts during startup"); @@ -403,7 +403,7 @@ export function runScriptFromScript( } // Check if admin rights on host, fail if not. - if (host.hasAdminRights == false) { + if (!host.hasAdminRights) { workerScript.log(caller, () => `You do not have root access on '${host.hostname}'`); return 0; } diff --git a/src/Paths/Directory.ts b/src/Paths/Directory.ts index 17ceee140..55e850ede 100644 --- a/src/Paths/Directory.ts +++ b/src/Paths/Directory.ts @@ -31,7 +31,7 @@ const invalidCharacters = ["/", "*", "?", "[", "]", "!", "\\", "~", "|", "#", '" export const oneValidCharacter = `[^${escapeRegExp(invalidCharacters.join(""))}]`; /** Regex string for matching the directory part of a valid filepath */ -export const directoryRegexString = `^(?(?:${oneValidCharacter}+\\\/)*)`; +export const directoryRegexString = `^(?(?:${oneValidCharacter}+\\/)*)`; /** Actual RegExp for validating that an entire string is a BasicDirectory */ const basicDirectoryRegex = new RegExp(directoryRegexString + "$"); diff --git a/src/Paths/FilePath.ts b/src/Paths/FilePath.ts index 1c1e7abbb..d4e92bc26 100644 --- a/src/Paths/FilePath.ts +++ b/src/Paths/FilePath.ts @@ -69,7 +69,7 @@ export function resolveFilePath(path: string, base = "" as FilePath | Directory) /** Remove the file part from an absolute path (FilePath or DirectoryPath - no modification is done for a DirectoryPath) */ function getBaseDirectory(path: FilePath | Directory): Directory { - return path.replace(/[^\/\*]+\.[^\/\*]+$/, "") as Directory; + return path.replace(/[^/]+\.[^/]+$/, "") as Directory; } /** Combine an absolute DirectoryPath and FilePath to create a new FilePath */ export function combinePath(directory: Directory, file: T): T { diff --git a/src/PersonObjects/Player/PlayerObject.ts b/src/PersonObjects/Player/PlayerObject.ts index 18cb5048e..f37495d8d 100644 --- a/src/PersonObjects/Player/PlayerObject.ts +++ b/src/PersonObjects/Player/PlayerObject.ts @@ -59,7 +59,7 @@ export class PlayerObject extends Person implements IPlayer { scriptProdSinceLastAug = 0; sleeves: Sleeve[] = []; sleevesFromCovenant = 0; - sourceFiles: JSONMap = new JSONMap(); + sourceFiles = new JSONMap(); exploits: Exploit[] = []; achievements: PlayerAchievement[] = []; terminalCommandHistory: string[] = []; diff --git a/src/PersonObjects/Player/PlayerObjectGeneralMethods.ts b/src/PersonObjects/Player/PlayerObjectGeneralMethods.ts index f14e7d085..b2e6790ab 100644 --- a/src/PersonObjects/Player/PlayerObjectGeneralMethods.ts +++ b/src/PersonObjects/Player/PlayerObjectGeneralMethods.ts @@ -284,12 +284,10 @@ export function applyForJob(this: PlayerObject, entryPosType: CompanyPosition, s return false; } - while (true) { - const nextPos = getNextCompanyPositionHelper(pos); - if (nextPos == null) break; - if (company.hasPosition(nextPos) && this.isQualified(company, nextPos)) { - pos = nextPos; - } else break; + let nextPos = getNextCompanyPositionHelper(pos); + while (nextPos && company.hasPosition(nextPos) && this.isQualified(company, nextPos)) { + pos = nextPos; + nextPos = getNextCompanyPositionHelper(pos); } //Check if player already has the assigned job diff --git a/src/PersonObjects/Sleeve/ui/SleeveElem.tsx b/src/PersonObjects/Sleeve/ui/SleeveElem.tsx index 2d93726a8..d00e79c06 100644 --- a/src/PersonObjects/Sleeve/ui/SleeveElem.tsx +++ b/src/PersonObjects/Sleeve/ui/SleeveElem.tsx @@ -34,14 +34,15 @@ function getWorkDescription(sleeve: Sleeve, progress: number): string { `This sleeve is currently attempting to perform ${work.actionName}.\n\n` + `Progress: ${formatPercent(progress)}` ); - case WorkType.CRIME: + case WorkType.CRIME: { const crime = work.getCrime(); return ( `This sleeve is currently attempting ${crime.workName} (Success Rate: ${formatPercent( crime.successRate(sleeve), )}).\n\n` + `Progress: ${formatPercent(progress)}` ); - case WorkType.FACTION: + } + case WorkType.FACTION: { // This isn't the way this should be handled... const workNames = { [FactionWorkType.field]: "Field Work", @@ -50,6 +51,7 @@ function getWorkDescription(sleeve: Sleeve, progress: number): string { }; const doing = workNames[work.factionWorkType] ?? "nothing"; return `This sleeve is currently doing ${doing} for ${work.factionName}.`; + } case WorkType.INFILTRATE: return ( "This sleeve is currently attempting to infiltrate synthoid communities to generate additional contracts and operations.\nThis activity is less efficient the more sleeves are assigned to it.\n\n" + diff --git a/src/PersonObjects/Sleeve/ui/TaskSelector.tsx b/src/PersonObjects/Sleeve/ui/TaskSelector.tsx index c1ef70ce2..433f3ae55 100644 --- a/src/PersonObjects/Sleeve/ui/TaskSelector.tsx +++ b/src/PersonObjects/Sleeve/ui/TaskSelector.tsx @@ -249,19 +249,20 @@ function getABC(sleeve: Sleeve): [string, string, string] { switch (work.type) { case WorkType.COMPANY: return ["Work for Company", work.companyName, "------"]; - case WorkType.FACTION: + case WorkType.FACTION: { const workNames = { [FactionWorkType.field]: "Field Work", [FactionWorkType.hacking]: "Hacking Contracts", [FactionWorkType.security]: "Security Work", }; return ["Work for Faction", work.factionName, workNames[work.factionWorkType] ?? ""]; + } case WorkType.BLADEBURNER: if (work.actionType === "Contracts") { return ["Perform Bladeburner Actions", "Take on contracts", work.actionName]; } return ["Perform Bladeburner Actions", work.actionName, "------"]; - case WorkType.CLASS: + case WorkType.CLASS: { if (!work.isGym()) return ["Take University Course", work.classType, work.location]; const gymNames: Record = { [GymType.strength]: "Train Strength", @@ -270,6 +271,7 @@ function getABC(sleeve: Sleeve): [string, string, string] { [GymType.agility]: "Train Agility", }; return ["Workout at Gym", gymNames[work.classType as GymType], work.location]; + } case WorkType.CRIME: return ["Commit Crime", checkEnum(CrimeType, work.crimeType) ? work.crimeType : "Shoplift", "------"]; case WorkType.SUPPORT: @@ -305,7 +307,7 @@ export function TaskSelector(props: IProps): React.ReactElement { props.setABC([s0, s1, details2[0]]); } - function onS0Change(event: SelectChangeEvent): void { + function onS0Change(event: SelectChangeEvent): void { const n = event.target.value; const detailsF = tasks[n]; if (detailsF === undefined) throw new Error(`No function for task '${s0}'`); @@ -317,12 +319,12 @@ export function TaskSelector(props: IProps): React.ReactElement { props.setABC([n, details.first[0], details2[0]]); } - function onS1Change(event: SelectChangeEvent): void { + function onS1Change(event: SelectChangeEvent): void { setS1(event.target.value); props.setABC([s0, event.target.value, s2]); } - function onS2Change(event: SelectChangeEvent): void { + function onS2Change(event: SelectChangeEvent): void { setS2(event.target.value); props.setABC([s0, s1, event.target.value]); } diff --git a/src/Prestige.ts b/src/Prestige.ts index e1e584186..75305f2de 100755 --- a/src/Prestige.ts +++ b/src/Prestige.ts @@ -72,19 +72,9 @@ export function prestigeAugmentation(): void { // Re-create foreign servers initForeignServers(Player.getHomeComputer()); - // Gain favor for Companies - for (const member of Object.keys(Companies)) { - if (Companies.hasOwnProperty(member)) { - Companies[member].gainFavor(); - } - } - - // Gain favor for factions - for (const member of Object.keys(Factions)) { - if (Factions.hasOwnProperty(member)) { - Factions[member].gainFavor(); - } - } + // Gain favor for Companies and Factions + for (const company of Object.values(Companies)) company.gainFavor(); + for (const faction of Object.values(Factions)) faction.gainFavor(); // Stop a Terminal action if there is one. if (Terminal.action !== null) { @@ -207,19 +197,9 @@ export function prestigeSourceFile(flume: boolean): void { } homeComp.cpuCores = 1; - // Reset favor for Companies - for (const member of Object.keys(Companies)) { - if (Companies.hasOwnProperty(member)) { - Companies[member].favor = 0; - } - } - - // Reset favor for factions - for (const member of Object.keys(Factions)) { - if (Factions.hasOwnProperty(member)) { - Factions[member].favor = 0; - } - } + // Reset favor for Companies and Factions + for (const company of Object.values(Companies)) company.favor = 0; + for (const faction of Object.values(Factions)) faction.favor = 0; // Stop a Terminal action if there is one if (Terminal.action !== null) { @@ -227,10 +207,8 @@ export function prestigeSourceFile(flume: boolean): void { } // Delete all Augmentations - for (const name of Object.keys(StaticAugmentations)) { - if (StaticAugmentations.hasOwnProperty(name)) { - delete StaticAugmentations[name]; - } + for (const name of Object.getOwnPropertyNames(StaticAugmentations)) { + delete StaticAugmentations[name]; } // Give levels of NeuroFluxGovernor for Source-File 12. Must be done here before Augmentations are recalculated diff --git a/src/Programs/Program.ts b/src/Programs/Program.ts index 8c8e36b95..d165baeb8 100644 --- a/src/Programs/Program.ts +++ b/src/Programs/Program.ts @@ -8,11 +8,11 @@ export interface IProgramCreate { time: number; tooltip: string; } -type ProgramConstructorParams = { +interface ProgramConstructorParams { name: CompletedProgramName; create: IProgramCreate | null; run: (args: string[], server: BaseServer) => void; -}; +} export class Program { name: ProgramFilePath & CompletedProgramName; diff --git a/src/Programs/ui/ProgramsRoot.tsx b/src/Programs/ui/ProgramsRoot.tsx index 2a397bca2..fd9aaafe6 100644 --- a/src/Programs/ui/ProgramsRoot.tsx +++ b/src/Programs/ui/ProgramsRoot.tsx @@ -88,7 +88,7 @@ export function ProgramsRoot(): React.ReactElement { {!Player.hasProgram(program.name) && create.req() && - (isCreateProgramWork(Player.currentWork) && Player.currentWork?.programName === program.name ? ( + (isCreateProgramWork(Player.currentWork) && Player.currentWork.programName === program.name ? ( //Button if the program is currently being worked on