2021-03-31 06:45:21 +02:00
|
|
|
import * as 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";
|
|
|
|
import { SpecialServerIps } from "../Server/SpecialServerIps";
|
|
|
|
import { post, postElement } from "../ui/postToTerminal";
|
|
|
|
import { Money } from "../ui/React/Money";
|
2017-08-30 19:44:29 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
import { isValidIPAddress } from "../../utils/helpers/isValidIPAddress";
|
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-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-05 01:09:30 +02:00
|
|
|
if (darkwebIp == Player.getCurrentServer().ip) {
|
|
|
|
post(
|
|
|
|
"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
|
|
|
}
|
|
|
|
|
|
|
|
//Handler for dark web commands. The terminal's executeCommand() function will pass
|
|
|
|
//dark web-specific commands into this. It will pass in the raw split command array
|
|
|
|
//rather than the command string
|
2021-03-14 07:08:24 +01:00
|
|
|
export function executeDarkwebTerminalCommand(commandArray: string[]): void {
|
2021-09-05 01:09:30 +02:00
|
|
|
if (commandArray.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (commandArray[0]) {
|
|
|
|
case "buy": {
|
|
|
|
if (commandArray.length != 2) {
|
|
|
|
post("Incorrect number of arguments. Usage: ");
|
|
|
|
post("buy -l");
|
|
|
|
post("buy [item name]");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const arg = commandArray[1];
|
|
|
|
if (arg == "-l" || arg == "-1" || arg == "--list") {
|
|
|
|
listAllDarkwebItems();
|
|
|
|
} else {
|
|
|
|
buyDarkwebItem(arg);
|
|
|
|
}
|
|
|
|
break;
|
2017-05-05 17:50:55 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
default:
|
|
|
|
post("Command not found");
|
|
|
|
break;
|
|
|
|
}
|
2017-05-05 17:50:55 +02:00
|
|
|
}
|
|
|
|
|
2021-05-01 09:17:31 +02:00
|
|
|
function listAllDarkwebItems(): void {
|
2021-09-05 01:09:30 +02:00
|
|
|
for (const key in DarkWebItems) {
|
|
|
|
const item = DarkWebItems[key];
|
|
|
|
postElement(
|
|
|
|
<>
|
|
|
|
{item.program} - <Money money={item.price} player={Player} /> -{" "}
|
|
|
|
{item.description}
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
}
|
2017-05-05 17:50:55 +02:00
|
|
|
}
|
|
|
|
|
2021-03-14 07:08:24 +01:00
|
|
|
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) {
|
|
|
|
post("Unrecognized item: " + itemName);
|
|
|
|
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)) {
|
|
|
|
post("You already have the " + item.program + " program");
|
|
|
|
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)) {
|
|
|
|
post("Not enough money to purchase " + item.program);
|
|
|
|
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);
|
|
|
|
post(
|
|
|
|
"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
|
|
|
}
|