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

79 lines
2.3 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";
2021-10-07 22:56:01 +02:00
import { GetServer } from "../../Server/AllServers";
2021-09-05 01:09:30 +02:00
import { Server } from "../../Server/Server";
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";
2021-12-14 01:46:08 +01:00
import { serverMetadata } from "../../Server/data/servers";
import { Box } from "@mui/material";
import { ClassType } from "../../utils/WorkType";
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 {
2021-12-14 01:46:08 +01:00
const serverMeta = serverMetadata.find((s) => s.specialName === props.loc.name);
const server = GetServer(serverMeta ? serverMeta.hostname : "");
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
}
function train(stat: ClassType): void {
2021-09-25 21:34:12 +02:00
const loc = props.loc;
2022-01-18 15:49:06 +01:00
props.p.startClass(calculateCost(), loc.expMult, stat);
props.p.startFocusing();
props.router.toWork();
2021-09-05 01:09:30 +02:00
}
2021-09-25 21:34:12 +02:00
function trainStrength(): void {
train(ClassType.GymStrength);
2021-09-05 01:09:30 +02:00
}
2021-09-25 21:34:12 +02:00
function trainDefense(): void {
train(ClassType.GymDefense);
2021-09-05 01:09:30 +02:00
}
2021-09-25 21:34:12 +02:00
function trainDexterity(): void {
train(ClassType.GymDexterity);
2021-09-05 01:09:30 +02:00
}
2021-09-25 21:34:12 +02:00
function trainAgility(): void {
train(ClassType.GymAgility);
2021-09-05 01:09:30 +02:00
}
2021-09-25 21:34:12 +02:00
const cost = CONSTANTS.ClassGymBaseCost * calculateCost();
return (
2022-04-07 01:30:08 +02:00
<Box sx={{ display: "grid", width: "fit-content" }}>
2021-09-25 21:34:12 +02:00
<Button onClick={trainStrength}>
Train Strength (<Money money={cost} player={props.p} /> / sec)
</Button>
<Button onClick={trainDefense}>
Train Defense (<Money money={cost} player={props.p} /> / sec)
</Button>
<Button onClick={trainDexterity}>
Train Dexterity (<Money money={cost} player={props.p} /> / sec)
</Button>
<Button onClick={trainAgility}>
Train Agility (<Money money={cost} player={props.p} /> / sec)
</Button>
</Box>
2021-09-25 21:34:12 +02:00
);
}