From 1a8dcad02bce1973f2fc7535fbb6bc71e4ef2739 Mon Sep 17 00:00:00 2001 From: catloversg <152669316+catloversg@users.noreply.github.com> Date: Tue, 6 Aug 2024 03:43:56 +0700 Subject: [PATCH] BUGFIX: Duplicated program in edge case (#1549) --- src/DevMenu/ui/ProgramsDev.tsx | 5 +++-- src/Message/MessageHelpers.tsx | 5 +---- src/PersonObjects/Player/PlayerObjectGeneralMethods.ts | 2 +- src/Prestige.ts | 6 +++--- src/Server/ServerHelpers.ts | 4 ++-- src/Work/CreateProgramWork.ts | 6 ++---- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/DevMenu/ui/ProgramsDev.tsx b/src/DevMenu/ui/ProgramsDev.tsx index f28b9836e..920e42914 100644 --- a/src/DevMenu/ui/ProgramsDev.tsx +++ b/src/DevMenu/ui/ProgramsDev.tsx @@ -18,12 +18,13 @@ export function ProgramsDev(): React.ReactElement { setProgram(event.target.value as CompletedProgramName); } function addProgram(): void { - if (!Player.hasProgram(program)) Player.getHomeComputer().programs.push(program); + Player.getHomeComputer().pushProgram(program); } function addAllPrograms(): void { + const home = Player.getHomeComputer(); for (const name of Object.values(CompletedProgramName)) { - if (!Player.hasProgram(name)) Player.getHomeComputer().programs.push(name); + home.pushProgram(name); } } diff --git a/src/Message/MessageHelpers.tsx b/src/Message/MessageHelpers.tsx index e87d9175b..a75502fa5 100644 --- a/src/Message/MessageHelpers.tsx +++ b/src/Message/MessageHelpers.tsx @@ -74,10 +74,7 @@ function checkForMessagesToSend(): void { } } else if (!recvd(MessageFilename.Jumper0) && Player.skills.hacking >= 25) { sendMessage(MessageFilename.Jumper0); - const homeComp = Player.getHomeComputer(); - if (!homeComp.programs.includes(CompletedProgramName.flight)) { - homeComp.programs.push(CompletedProgramName.flight); - } + Player.getHomeComputer().pushProgram(CompletedProgramName.flight); } else if (!recvd(MessageFilename.Jumper1) && Player.skills.hacking >= 40) { sendMessage(MessageFilename.Jumper1); } else if (!recvd(MessageFilename.CyberSecTest) && Player.skills.hacking >= 50) { diff --git a/src/PersonObjects/Player/PlayerObjectGeneralMethods.ts b/src/PersonObjects/Player/PlayerObjectGeneralMethods.ts index 63070fdb2..725a1d581 100644 --- a/src/PersonObjects/Player/PlayerObjectGeneralMethods.ts +++ b/src/PersonObjects/Player/PlayerObjectGeneralMethods.ts @@ -67,7 +67,7 @@ export function init(this: PlayerObject): void { this.currentServer = SpecialServers.Home; AddToAllServers(t_homeComp); - this.getHomeComputer().programs.push(CompletedProgramName.nuke); + this.getHomeComputer().pushProgram(CompletedProgramName.nuke); } export function prestigeAugmentation(this: PlayerObject): void { diff --git a/src/Prestige.ts b/src/Prestige.ts index fb0ea447e..ce7d684e3 100644 --- a/src/Prestige.ts +++ b/src/Prestige.ts @@ -80,11 +80,11 @@ export function prestigeAugmentation(): void { const aug = Augmentations[ownedAug.name]; Player.gainMoney(aug.startingMoney, "other"); for (const program of aug.programs) { - homeComp.programs.push(program); + homeComp.pushProgram(program); } } if (canAccessBitNodeFeature(5)) { - homeComp.programs.push(CompletedProgramName.formulas); + homeComp.pushProgram(CompletedProgramName.formulas); } // Re-create foreign servers @@ -248,7 +248,7 @@ export function prestigeSourceFile(isFlume: boolean): void { Player.reapplyAllSourceFiles(); if (canAccessBitNodeFeature(5)) { - homeComp.programs.push(CompletedProgramName.formulas); + homeComp.pushProgram(CompletedProgramName.formulas); } // BitNode 3: Corporatocracy diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts index ee6ad8419..a71870e61 100644 --- a/src/Server/ServerHelpers.ts +++ b/src/Server/ServerHelpers.ts @@ -197,9 +197,9 @@ export function prestigeHomeComputer(homeComp: Server): void { homeComp.serversOnNetwork = []; homeComp.isConnectedTo = true; homeComp.ramUsed = 0; - homeComp.programs.push(CompletedProgramName.nuke); + homeComp.pushProgram(CompletedProgramName.nuke); if (hasBitflume) { - homeComp.programs.push(CompletedProgramName.bitFlume); + homeComp.pushProgram(CompletedProgramName.bitFlume); } homeComp.messages.length = 0; //Remove .lit and .msg files diff --git a/src/Work/CreateProgramWork.ts b/src/Work/CreateProgramWork.ts index 0b087d00e..a1b4099bf 100644 --- a/src/Work/CreateProgramWork.ts +++ b/src/Work/CreateProgramWork.ts @@ -87,14 +87,12 @@ export class CreateProgramWork extends Work { dialogBoxCreate(lines.join("\n")); } - if (!Player.getHomeComputer().programs.includes(programName)) { - Player.getHomeComputer().programs.push(programName); - } + Player.getHomeComputer().pushProgram(programName); } else if (!Player.getHomeComputer().programs.includes(programName)) { //Incomplete case const perc = ((100 * this.unitCompleted) / this.unitNeeded()).toFixed(2); const incompleteName = asProgramFilePath(programName + "-" + perc + "%-INC"); - Player.getHomeComputer().programs.push(incompleteName); + Player.getHomeComputer().pushProgram(incompleteName); } }