mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-28 18:43:49 +01:00
DARKWEB: Update DarkWeb.tsx to buy all possible programs using buy -a (#1240)
This commit is contained in:
parent
6f009679ad
commit
bfb9841832
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user