mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 21:53:50 +01:00
Unify error handling
This commit is contained in:
parent
88505e9378
commit
ba1a10b4f7
31
src/Casino/Game.tsx
Normal file
31
src/Casino/Game.tsx
Normal file
@ -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<T, U> extends React.Component<T, U> {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
40
src/Locations/LocationsHelpers.tsx
Normal file
40
src/Locations/LocationsHelpers.tsx
Normal file
@ -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.",
|
||||||
|
);
|
||||||
|
}
|
@ -24,7 +24,7 @@ import { Settings } from "./Settings/Settings";
|
|||||||
|
|
||||||
import { generate } from "escodegen";
|
import { generate } from "escodegen";
|
||||||
|
|
||||||
import { dialogBoxCreate } from "./ui/React/DialogBox";
|
import { dialogBoxCreate} from "./ui/React/DialogBox";
|
||||||
import { arrayToString } from "./utils/helpers/arrayToString";
|
import { arrayToString } from "./utils/helpers/arrayToString";
|
||||||
import { roundToTwo } from "./utils/helpers/roundToTwo";
|
import { roundToTwo } from "./utils/helpers/roundToTwo";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user