diff --git a/src/Casino/Game.tsx b/src/Casino/Game.tsx new file mode 100644 index 000000000..b20eda813 --- /dev/null +++ b/src/Casino/Game.tsx @@ -0,0 +1,31 @@ +import * as React from "react"; +import { IPlayer } from "../PersonObjects/IPlayer"; +import { dialogBoxCreate } from "../ui/React/DialogBox"; + +const gainLimit = 10e9; + +export function win(p: IPlayer, n: number): void { + p.gainMoney(n, "casino"); +} + +export function reachedLimit(p: IPlayer): boolean { + const reached = p.getCasinoWinnings() > gainLimit; + if (reached) { + dialogBoxCreate("Alright cheater get out of here. You're not allowed here anymore."); + } + return reached; +} + +export class Game extends React.Component { + win(p: IPlayer, n: number): void { + p.gainMoney(n, "casino"); + } + + reachedLimit(p: IPlayer): boolean { + const reached = p.getCasinoWinnings() > gainLimit; + if (reached) { + dialogBoxCreate("Alright cheater get out of here. You're not allowed here anymore."); + } + return reached; + } +} diff --git a/src/Locations/LocationsHelpers.tsx b/src/Locations/LocationsHelpers.tsx new file mode 100644 index 000000000..86e449f2e --- /dev/null +++ b/src/Locations/LocationsHelpers.tsx @@ -0,0 +1,40 @@ +/** + * Location and traveling-related helper functions. + * Mostly used for UI + */ +import { SpecialServers } from "../Server/data/SpecialServers"; +import { CONSTANTS } from "../Constants"; + +import { IPlayer } from "../PersonObjects/IPlayer"; +import { GetServer } from "../Server/AllServers"; + +import { dialogBoxCreate } from "../ui/React/DialogBox"; + +/** + * Attempt to purchase a TOR router + * @param {IPlayer} p - Player object + */ +export function purchaseTorRouter(p: IPlayer): void { + if (p.hasTorRouter()) { + dialogBoxCreate(`You already have a TOR Router!`); + return; + } + if (!p.canAfford(CONSTANTS.TorRouterCost)) { + dialogBoxCreate("You cannot afford to purchase the TOR router!"); + return; + } + p.loseMoney(CONSTANTS.TorRouterCost, "other"); + + const darkweb = GetServer(SpecialServers.DarkWeb); + if (!darkweb) { + throw new Error("Dark web is not a server."); + } + + p.getHomeComputer().serversOnNetwork.push(darkweb.hostname); + darkweb.serversOnNetwork.push(p.getHomeComputer().hostname); + dialogBoxCreate( + "You have purchased a TOR router!\n" + + "You now have access to the dark web from your home computer.\n" + + "Use the scan/scan-analyze commands to search for the dark web connection.", + ); +} diff --git a/src/NetscriptWorker.ts b/src/NetscriptWorker.ts index a69548656..847f3e622 100644 --- a/src/NetscriptWorker.ts +++ b/src/NetscriptWorker.ts @@ -24,7 +24,7 @@ import { Settings } from "./Settings/Settings"; import { generate } from "escodegen"; -import { dialogBoxCreate } from "./ui/React/DialogBox"; +import { dialogBoxCreate} from "./ui/React/DialogBox"; import { arrayToString } from "./utils/helpers/arrayToString"; import { roundToTwo } from "./utils/helpers/roundToTwo";