mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-28 08:57:32 +01:00
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
This commit is contained in:
parent
82f6bbee13
commit
b95261d905
@ -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.",
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user