Merge pull request #2057 from hexnaught/remove-partial-exe-on-buy-patch

Remove any partially built/created .EXE files on buy from darknet
This commit is contained in:
hydroflame 2021-12-20 01:08:07 -05:00 committed by GitHub
commit e4345ebf68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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.",
);