2021-10-27 02:26:05 +02:00
|
|
|
import React from "react";
|
2021-09-05 01:09:30 +02:00
|
|
|
import { DarkWebItems } from "./DarkWebItems";
|
2017-08-30 19:44:29 +02:00
|
|
|
|
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-10-07 23:55:49 +02:00
|
|
|
import { SpecialServers } from "../Server/data/SpecialServers";
|
2021-12-28 08:11:41 +01:00
|
|
|
import { numeralWrapper } from "../ui/numeralFormat";
|
2021-10-27 02:26:05 +02:00
|
|
|
import { Money } from "../ui/React/Money";
|
2021-12-20 06:55:35 +01:00
|
|
|
import { DarkWebItem } from "./DarkWebItem";
|
2022-07-10 07:37:36 +02:00
|
|
|
import { isCreateProgramWork } from "../Work/CreateProgramWork";
|
2017-08-30 19:44:29 +02:00
|
|
|
|
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. " +
|
2021-12-28 08:11:41 +01:00
|
|
|
"Use the 'buy -l' command to display a list of all the items you can buy. Use 'buy [item-name]' " +
|
2022-01-05 23:15:48 +01:00
|
|
|
"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 {
|
2022-01-16 01:45:03 +01:00
|
|
|
for (const key of Object.keys(DarkWebItems)) {
|
2021-09-05 01:09:30 +02:00
|
|
|
const item = DarkWebItems[key];
|
2021-12-20 17:51:08 +01:00
|
|
|
|
|
|
|
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(
|
2021-12-22 14:27:06 +01:00
|
|
|
<>
|
2021-12-20 17:51:08 +01:00
|
|
|
<span>{item.program}</span> - <span>{cost}</span> - <span>{item.description}</span>
|
2021-12-22 14:27:06 +01:00
|
|
|
</>,
|
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
|
2021-12-20 06:55:35 +01:00
|
|
|
let item: DarkWebItem | null = null;
|
|
|
|
|
2022-01-16 01:45:03 +01:00
|
|
|
for (const key of Object.keys(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");
|
2021-12-20 06:55:35 +01:00
|
|
|
|
2022-04-13 06:21:51 +02:00
|
|
|
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-12-20 06:55:35 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2021-12-28 08:11:41 +01:00
|
|
|
|
|
|
|
export function buyAllDarkwebItems(): void {
|
|
|
|
const itemsToBuy: DarkWebItem[] = [];
|
|
|
|
let cost = 0;
|
|
|
|
|
2022-01-16 01:45:03 +01:00
|
|
|
for (const key of Object.keys(DarkWebItems)) {
|
2021-12-28 08:11:41 +01:00
|
|
|
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) {
|
2022-04-07 01:30:08 +02:00
|
|
|
Terminal.error(
|
|
|
|
"Not enough money to purchase remaining programs, " + numeralWrapper.formatMoney(cost) + " required",
|
|
|
|
);
|
2021-12-28 08:11:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const item of itemsToBuy) {
|
|
|
|
buyDarkwebItem(item.program);
|
|
|
|
}
|
|
|
|
}
|