bitburner-src/src/Infiltration/ui/InfiltrationRoot.tsx

45 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-09-18 01:43:08 +02:00
import React, { useState } from "react";
2021-09-18 10:01:07 +02:00
import { Location } from "../../Locations/Location";
2022-09-13 00:00:09 +02:00
import { Router } from "../../ui/GameRoot";
import { Player } from "../../Player";
import { calculateDifficulty, calculateReward } from "../formulas/game";
2022-04-25 01:51:30 +02:00
import { Game } from "./Game";
import { Intro } from "./Intro";
2021-09-18 01:43:08 +02:00
interface IProps {
2021-09-18 10:01:07 +02:00
location: Location;
2021-09-18 01:43:08 +02:00
}
2021-12-03 21:11:31 +01:00
2021-09-18 01:43:08 +02:00
export function InfiltrationRoot(props: IProps): React.ReactElement {
const [start, setStart] = useState(false);
2021-09-18 10:01:07 +02:00
if (props.location.infiltrationData === undefined) throw new Error("Trying to do infiltration on invalid location.");
const startingSecurityLevel = props.location.infiltrationData.startingSecurityLevel;
2022-09-13 00:00:09 +02:00
const difficulty = calculateDifficulty(Player, startingSecurityLevel);
const reward = calculateReward(Player, startingSecurityLevel);
2021-09-18 01:43:08 +02:00
function cancel(): void {
2022-09-13 00:00:09 +02:00
Router.toCity();
2021-09-18 01:43:08 +02:00
}
return (
<div style={{ display: "flex", alignItems: "center", height: "calc(100vh - 16px)" }}>
2022-04-24 23:51:00 +02:00
{start ? (
<Game
StartingDifficulty={startingSecurityLevel}
Difficulty={difficulty}
Reward={reward}
MaxLevel={props.location.infiltrationData.maxClearanceLevel}
/>
) : (
<Intro
Location={props.location}
Difficulty={difficulty}
MaxLevel={props.location.infiltrationData.maxClearanceLevel}
start={() => setStart(true)}
cancel={cancel}
/>
)}
</div>
2021-09-18 01:43:08 +02:00
);
}