bitburner-src/src/Locations/ui/GymLocation.tsx

78 lines
2.2 KiB
TypeScript
Raw Normal View History

/**
* React Subcomponent for displaying a location's UI, when that location is a gym
*
* This subcomponent renders all of the buttons for training at the gym
*/
import * as React from "react";
2021-09-25 21:34:12 +02:00
import Button from "@mui/material/Button";
2021-09-05 01:09:30 +02:00
import { Location } from "../Location";
2021-09-05 01:09:30 +02:00
import { CONSTANTS } from "../../Constants";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { getServer } from "../../Server/ServerHelpers";
import { Server } from "../../Server/Server";
import { SpecialServerIps } from "../../Server/SpecialServerIps";
2021-09-05 01:09:30 +02:00
import { Money } from "../../ui/React/Money";
2021-09-20 07:45:32 +02:00
import { IRouter } from "../../ui/Router";
type IProps = {
2021-09-05 01:09:30 +02:00
loc: Location;
p: IPlayer;
2021-09-20 07:45:32 +02:00
router: IRouter;
2021-09-05 01:09:30 +02:00
};
2021-09-25 21:34:12 +02:00
export function GymLocation(props: IProps): React.ReactElement {
function calculateCost(): number {
const ip = SpecialServerIps.getIp(props.loc.name);
2021-09-05 01:09:30 +02:00
const server = getServer(ip);
2021-09-25 21:34:12 +02:00
if (server == null || !server.hasOwnProperty("backdoorInstalled")) return props.loc.costMult;
2021-09-05 01:09:30 +02:00
const discount = (server as Server).backdoorInstalled ? 0.9 : 1;
2021-09-25 21:34:12 +02:00
return props.loc.costMult * discount;
2021-09-05 01:09:30 +02:00
}
2021-09-25 21:34:12 +02:00
function train(stat: string): void {
const loc = props.loc;
props.p.startClass(props.router, calculateCost(), loc.expMult, stat);
2021-09-05 01:09:30 +02:00
}
2021-09-25 21:34:12 +02:00
function trainStrength(): void {
train(CONSTANTS.ClassGymStrength);
2021-09-05 01:09:30 +02:00
}
2021-09-25 21:34:12 +02:00
function trainDefense(): void {
train(CONSTANTS.ClassGymDefense);
2021-09-05 01:09:30 +02:00
}
2021-09-25 21:34:12 +02:00
function trainDexterity(): void {
train(CONSTANTS.ClassGymDexterity);
2021-09-05 01:09:30 +02:00
}
2021-09-25 21:34:12 +02:00
function trainAgility(): void {
train(CONSTANTS.ClassGymAgility);
2021-09-05 01:09:30 +02:00
}
2021-09-25 21:34:12 +02:00
const cost = CONSTANTS.ClassGymBaseCost * calculateCost();
return (
<>
<Button onClick={trainStrength}>
Train Strength (<Money money={cost} player={props.p} /> / sec)
</Button>
<br />
<Button onClick={trainDefense}>
Train Defense (<Money money={cost} player={props.p} /> / sec)
</Button>
<br />
<Button onClick={trainDexterity}>
Train Dexterity (<Money money={cost} player={props.p} /> / sec)
</Button>
<br />
<Button onClick={trainAgility}>
Train Agility (<Money money={cost} player={props.p} /> / sec)
</Button>
</>
);
}