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

46 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-09-18 01:43:08 +02:00
import React, { useState } from "react";
import { Intro } from "./Intro";
import { Game } from "./Game";
2021-09-18 10:01:07 +02:00
import { Location } from "../../Locations/Location";
2021-09-18 01:43:08 +02:00
import { use } from "../../ui/Context";
import { calculateDifficulty, calculateReward } from "../formulas/game";
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 player = use.Player();
const router = use.Router();
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;
const difficulty = calculateDifficulty(player, startingSecurityLevel);
const reward = calculateReward(player, startingSecurityLevel);
2021-09-18 01:43:08 +02:00
function cancel(): void {
router.toCity();
}
if (!start) {
return (
<Intro
Location={props.location}
Difficulty={difficulty}
2021-09-18 10:01:07 +02:00
MaxLevel={props.location.infiltrationData.maxClearanceLevel}
2021-09-18 01:43:08 +02:00
start={() => setStart(true)}
cancel={cancel}
/>
);
}
return (
<Game
StartingDifficulty={startingSecurityLevel}
2021-09-18 01:43:08 +02:00
Difficulty={difficulty}
2021-12-03 21:11:31 +01:00
Reward={reward}
2021-09-18 10:01:07 +02:00
MaxLevel={props.location.infiltrationData.maxClearanceLevel}
2021-09-18 01:43:08 +02:00
/>
);
}