bitburner-src/src/DarkWeb/DarkWeb.tsx

72 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-09-05 01:09:30 +02:00
import { DarkWebItems } from "./DarkWebItems";
2021-09-05 01:09:30 +02:00
import { Player } from "../Player";
2021-09-16 08:52:45 +02:00
import { Terminal } from "../Terminal";
2021-09-05 01:09:30 +02:00
import { SpecialServerIps } from "../Server/SpecialServerIps";
2021-09-16 08:52:45 +02:00
import { numeralWrapper } from "../ui/numeralFormat";
2021-09-05 01:09:30 +02:00
import { isValidIPAddress } from "../../utils/helpers/isValidIPAddress";
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-09-05 01:09:30 +02:00
if (SpecialServerIps.hasOwnProperty("Darkweb Server")) {
const darkwebIp = SpecialServerIps.getIp("Darkweb Server");
if (!isValidIPAddress(darkwebIp)) {
return;
2017-05-05 17:50:55 +02:00
}
2021-09-24 00:47:43 +02:00
const server = Player.getCurrentServer();
if (server !== null && darkwebIp == server.ip) {
2021-09-16 08:52:45 +02:00
Terminal.print(
2021-09-05 01:09:30 +02:00
"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.",
);
}
}
2017-05-05 17:50:55 +02:00
}
2021-09-16 01:50:44 +02:00
export function listAllDarkwebItems(): void {
2021-09-05 01:09:30 +02:00
for (const key in DarkWebItems) {
const item = DarkWebItems[key];
2021-09-16 08:52:45 +02:00
Terminal.print(`${item.program} - ${numeralWrapper.formatMoney(item.price)} - ${item.description}`);
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 = null;
for (const key in DarkWebItems) {
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-09-16 08:52:45 +02:00
Terminal.print("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
if (Player.money.lt(item.price)) {
2021-09-16 08:52:45 +02:00
Terminal.print("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
Player.loseMoney(item.price);
Player.getHomeComputer().programs.push(item.program);
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
}