DARKWEB: Update DarkWeb.tsx to buy all possible programs using buy -a (#1240)

This commit is contained in:
TheAimMan 2024-05-09 05:18:03 -04:00 committed by GitHub
parent 6f009679ad
commit bfb9841832
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,10 +1,9 @@
import React from "react"; import React from "react";
import { DarkWebItems } from "./DarkWebItems"; import { DarkWebItems } from "./DarkWebItems";
import { formatMoney } from "../ui/formatNumber";
import { Player } from "@player"; import { Player } from "@player";
import { Terminal } from "../Terminal"; import { Terminal } from "../Terminal";
import { SpecialServers } from "../Server/data/SpecialServers"; import { SpecialServers } from "../Server/data/SpecialServers";
import { formatMoney } from "../ui/formatNumber";
import { Money } from "../ui/React/Money"; import { Money } from "../ui/React/Money";
import { DarkWebItem } from "./DarkWebItem"; import { DarkWebItem } from "./DarkWebItem";
import { isCreateProgramWork } from "../Work/CreateProgramWork"; import { isCreateProgramWork } from "../Work/CreateProgramWork";
@ -86,13 +85,17 @@ export function buyDarkwebItem(itemName: string): void {
export function buyAllDarkwebItems(): void { export function buyAllDarkwebItems(): void {
const itemsToBuy: DarkWebItem[] = []; const itemsToBuy: DarkWebItem[] = [];
let cost = 0;
for (const key of Object.keys(DarkWebItems) as (keyof typeof DarkWebItems)[]) { for (const key of Object.keys(DarkWebItems) as (keyof typeof DarkWebItems)[]) {
const item = DarkWebItems[key]; const item = DarkWebItems[key];
if (!Player.hasProgram(item.program)) { if (!Player.hasProgram(item.program)) {
itemsToBuy.push(item); itemsToBuy.push(item);
cost += item.price; if (item.price > Player.money) {
Terminal.error("Need " + formatMoney(item.price - Player.money) + " more to purchase " + item.program);
return;
} else {
buyDarkwebItem(item.program);
}
} }
} }
@ -101,12 +104,8 @@ export function buyAllDarkwebItems(): void {
return; return;
} }
if (cost > Player.money) { if (itemsToBuy.length > 0) {
Terminal.error("Not enough money to purchase remaining programs, " + formatMoney(cost) + " required"); Terminal.print("All programs have been purchased.");
return; return;
} }
for (const item of itemsToBuy) {
buyDarkwebItem(item.program);
}
} }