From b95261d905bda9a18296a24f421bee12d06095fd Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 20 Dec 2021 05:55:35 +0000 Subject: [PATCH] fix(darkweb:buy) remove partial exe on buy Remove any matching partial .exe item when buying it from the dark web. Resolves danielyxie/bitburner#2024 --- src/DarkWeb/DarkWeb.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/DarkWeb/DarkWeb.tsx b/src/DarkWeb/DarkWeb.tsx index 7840b9904..fbe3c0696 100644 --- a/src/DarkWeb/DarkWeb.tsx +++ b/src/DarkWeb/DarkWeb.tsx @@ -5,6 +5,7 @@ import { Player } from "../Player"; import { Terminal } from "../Terminal"; import { SpecialServers } from "../Server/data/SpecialServers"; import { Money } from "../ui/React/Money"; +import { DarkWebItem } from "./DarkWebItem"; //Posts a "help" message if connected to DarkWeb export function checkIfConnectedToDarkweb(): void { @@ -33,7 +34,8 @@ export function buyDarkwebItem(itemName: string): void { itemName = itemName.toLowerCase(); // find the program that matches, if any - let item = null; + let item: DarkWebItem | null = null; + for (const key in DarkWebItems) { const i = DarkWebItems[key]; if (i.program.toLowerCase() == itemName) { @@ -61,7 +63,19 @@ export function buyDarkwebItem(itemName: string): void { // buy and push Player.loseMoney(item.price, "other"); + + const programsRef = Player.getHomeComputer().programs; + // Remove partially created program if there is one + const existingPartialExeIndex = programsRef.findIndex( + (program) => item?.program && program.startsWith(item?.program), + ); + // findIndex returns -1 if there is no match, we only want to splice on a match + if (existingPartialExeIndex > -1) { + programsRef.splice(existingPartialExeIndex, 1); + } + // Add the newly bought, full .exe Player.getHomeComputer().programs.push(item.program); + Terminal.print( "You have purchased the " + item.program + " program. The new program can be found on your home computer.", );