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

71 lines
2.4 KiB
TypeScript
Raw Normal View History

2021-09-18 01:43:08 +02:00
import { IPlayer } from "../../PersonObjects/IPlayer";
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";
2021-12-03 21:11:31 +01:00
import { calculateSkill } from "../../PersonObjects/formulas/skill";
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
function calcRawDiff(player: IPlayer, stats: number, startingDifficulty: number): number {
const difficulty = startingDifficulty - Math.pow(stats, 0.9) / 250 - player.intelligence / 1600;
2021-09-18 01:43:08 +02:00
if (difficulty < 0) return 0;
if (difficulty > 3) return 3;
return difficulty;
}
2021-12-03 21:11:31 +01:00
function calcDifficulty(player: IPlayer, startingDifficulty: number): number {
const totalStats = player.strength + player.defense + player.dexterity + player.agility + player.charisma;
return calcRawDiff(player, totalStats, startingDifficulty);
}
function calcReward(player: IPlayer, startingDifficulty: number): number {
const xpMult = 10 * 60 * 15;
const total =
calculateSkill(player.strength_exp_mult * xpMult, player.strength_mult) +
calculateSkill(player.defense_exp_mult * xpMult, player.defense_mult) +
calculateSkill(player.agility_exp_mult * xpMult, player.agility_mult) +
calculateSkill(player.dexterity_exp_mult * xpMult, player.dexterity_mult) +
calculateSkill(player.charisma_exp_mult * xpMult, player.charisma_mult);
return calcRawDiff(player, total, startingDifficulty);
}
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 startingDifficulty = props.location.infiltrationData.startingSecurityLevel;
2021-09-18 01:43:08 +02:00
const difficulty = calcDifficulty(player, startingDifficulty);
2021-12-03 21:11:31 +01:00
const reward = calcReward(player, startingDifficulty);
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={startingDifficulty}
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
/>
);
}