bitburner-src/src/DarkWeb/DarkWeb.tsx

113 lines
3.3 KiB
TypeScript
Raw Normal View History

2021-10-27 02:26:05 +02:00
import React from "react";
2021-09-05 01:09:30 +02:00
import { DarkWebItems } from "./DarkWebItems";
import { Player } from "@player";
2021-09-16 08:52:45 +02:00
import { Terminal } from "../Terminal";
2021-10-07 23:55:49 +02:00
import { SpecialServers } from "../Server/data/SpecialServers";
import { formatMoney } from "../ui/formatNumber";
2021-10-27 02:26:05 +02:00
import { Money } from "../ui/React/Money";
import { DarkWebItem } from "./DarkWebItem";
2022-07-10 07:37:36 +02:00
import { isCreateProgramWork } from "../Work/CreateProgramWork";
2017-05-05 17:50:55 +02:00
//Posts a "help" message if connected to DarkWeb
2021-03-14 07:08:24 +01:00
export function checkIfConnectedToDarkweb(): void {
2021-10-07 23:55:49 +02:00
const server = Player.getCurrentServer();
if (server !== null && SpecialServers.DarkWeb == server.hostname) {
Terminal.print(
"You are now connected to the dark web. From the dark web you can purchase illegal items. " +
"Use the 'buy -l' command to display a list of all the items you can buy. Use 'buy [item-name]' " +
"to purchase an item. Use 'buy -a' to purchase all unowned items.",
2021-10-07 23:55:49 +02:00
);
2021-09-05 01:09:30 +02:00
}
2017-05-05 17:50:55 +02:00
}
2021-09-16 01:50:44 +02:00
export function listAllDarkwebItems(): void {
FILES: Path rework & typesafety (#479) * Added new types for various file paths, all in the Paths folder. * TypeSafety and other helper functions related to these types * Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands * Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way * Server.textFiles is now a map * TextFile no longer uses a fn property, now it is filename * Added a shared ContentFile interface for shared functionality between TextFile and Script. * related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa. * File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root. * Singularized the MessageFilename and LiteratureName enums * Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath). * Fix several issues with tab completion, which included pretty much a complete rewrite * Changed the autocomplete display options so there's less chance it clips outside the display area. * Turned CompletedProgramName into an enum. * Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine. * For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
for (const key of Object.keys(DarkWebItems) as (keyof typeof DarkWebItems)[]) {
2021-09-05 01:09:30 +02:00
const item = DarkWebItems[key];
const cost = Player.getHomeComputer().programs.includes(item.program) ? (
<span style={{ color: `green` }}>[OWNED]</span>
) : (
<Money money={item.price} />
);
2021-10-27 02:26:05 +02:00
Terminal.printRaw(
<>
<span>{item.program}</span> - <span>{cost}</span> - <span>{item.description}</span>
</>,
2021-10-27 02:26:05 +02:00
);
2021-09-05 01:09:30 +02:00
}
2017-05-05 17:50:55 +02:00
}
2021-09-16 01:50:44 +02:00
export function buyDarkwebItem(itemName: string): void {
2021-09-05 01:09:30 +02:00
itemName = itemName.toLowerCase();
2018-06-01 23:05:05 +02:00
2021-09-05 01:09:30 +02:00
// find the program that matches, if any
let item: DarkWebItem | null = null;
FILES: Path rework & typesafety (#479) * Added new types for various file paths, all in the Paths folder. * TypeSafety and other helper functions related to these types * Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands * Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way * Server.textFiles is now a map * TextFile no longer uses a fn property, now it is filename * Added a shared ContentFile interface for shared functionality between TextFile and Script. * related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa. * File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root. * Singularized the MessageFilename and LiteratureName enums * Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath). * Fix several issues with tab completion, which included pretty much a complete rewrite * Changed the autocomplete display options so there's less chance it clips outside the display area. * Turned CompletedProgramName into an enum. * Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine. * For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
for (const key of Object.keys(DarkWebItems) as (keyof typeof DarkWebItems)[]) {
2021-09-05 01:09:30 +02:00
const i = DarkWebItems[key];
if (i.program.toLowerCase() == itemName) {
item = i;
2017-05-05 17:50:55 +02:00
}
2021-09-05 01:09:30 +02:00
}
2017-05-05 17:50:55 +02:00
2021-09-05 01:09:30 +02:00
// return if invalid
if (item === null) {
2021-10-27 02:26:05 +02:00
Terminal.error("Unrecognized item: " + itemName);
2021-09-05 01:09:30 +02:00
return;
}
2018-06-01 23:05:05 +02:00
2021-09-05 01:09:30 +02:00
// return if the player already has it.
if (Player.hasProgram(item.program)) {
2021-09-16 08:52:45 +02:00
Terminal.print("You already have the " + item.program + " program");
2021-09-05 01:09:30 +02:00
return;
}
2018-06-01 23:05:05 +02:00
2021-09-05 01:09:30 +02:00
// return if the player doesn't have enough money
2021-11-12 02:42:19 +01:00
if (Player.money < item.price) {
2021-10-27 02:26:05 +02:00
Terminal.error("Not enough money to purchase " + item.program);
2021-09-05 01:09:30 +02:00
return;
}
2018-06-01 23:05:05 +02:00
2021-09-05 01:09:30 +02:00
// buy and push
2021-10-27 20:18:33 +02:00
Player.loseMoney(item.price, "other");
Player.getHomeComputer().pushProgram(item.program);
// Cancel if the program is in progress of writing
2022-07-10 07:37:36 +02:00
if (isCreateProgramWork(Player.currentWork) && Player.currentWork.programName === item.program) {
2022-07-14 23:43:08 +02:00
Player.finishWork(true);
}
2021-09-16 08:52:45 +02:00
Terminal.print(
"You have purchased the " + item.program + " program. The new program can be found on your home computer.",
);
2018-06-01 23:05:05 +02:00
}
export function buyAllDarkwebItems(): void {
const itemsToBuy: DarkWebItem[] = [];
let cost = 0;
FILES: Path rework & typesafety (#479) * Added new types for various file paths, all in the Paths folder. * TypeSafety and other helper functions related to these types * Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands * Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way * Server.textFiles is now a map * TextFile no longer uses a fn property, now it is filename * Added a shared ContentFile interface for shared functionality between TextFile and Script. * related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa. * File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root. * Singularized the MessageFilename and LiteratureName enums * Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath). * Fix several issues with tab completion, which included pretty much a complete rewrite * Changed the autocomplete display options so there's less chance it clips outside the display area. * Turned CompletedProgramName into an enum. * Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine. * For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
for (const key of Object.keys(DarkWebItems) as (keyof typeof DarkWebItems)[]) {
const item = DarkWebItems[key];
if (!Player.hasProgram(item.program)) {
itemsToBuy.push(item);
cost += item.price;
}
}
if (itemsToBuy.length === 0) {
Terminal.print("All available programs have been purchased already.");
return;
}
if (cost > Player.money) {
Terminal.error("Not enough money to purchase remaining programs, " + formatMoney(cost) + " required");
return;
}
for (const item of itemsToBuy) {
buyDarkwebItem(item.program);
}
}