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

106 lines
3.5 KiB
TypeScript
Raw Normal View History

2022-04-25 01:51:30 +02:00
import { Box, Button, MenuItem, Paper, Select, SelectChangeEvent, Typography } from "@mui/material";
2021-09-05 01:09:30 +02:00
import React, { useState } from "react";
2022-04-25 01:51:30 +02:00
import { FactionNames } from "../../Faction/data/FactionNames";
import { inviteToFaction } from "../../Faction/FactionHelpers";
import { Factions } from "../../Faction/Factions";
2022-09-13 00:00:09 +02:00
import { Router } from "../../ui/GameRoot";
import { Player } from "@player";
import { Money } from "../../ui/React/Money";
import { Reputation } from "../../ui/React/Reputation";
2022-03-25 16:39:14 +01:00
import { formatNumber } from "../../utils/StringHelperFunctions";
import {
calculateInfiltratorsRepReward,
calculateSellInformationCashReward,
calculateTradeInformationRepReward,
} from "../formulas/victory";
interface IProps {
2021-09-05 01:09:30 +02:00
StartingDifficulty: number;
Difficulty: number;
2021-12-03 21:11:31 +01:00
Reward: number;
2021-09-05 01:09:30 +02:00
MaxLevel: number;
}
export function Victory(props: IProps): React.ReactElement {
2021-09-05 01:09:30 +02:00
const [faction, setFaction] = useState("none");
2021-09-05 01:09:30 +02:00
function quitInfiltration(): void {
handleInfiltrators();
2022-09-13 00:00:09 +02:00
Router.toCity();
2021-09-05 01:09:30 +02:00
}
2022-04-22 21:30:49 +02:00
const soa = Factions[FactionNames.ShadowsOfAnarchy];
2022-09-18 03:09:15 +02:00
const repGain = calculateTradeInformationRepReward(props.Reward, props.MaxLevel, props.StartingDifficulty);
const moneyGain = calculateSellInformationCashReward(props.Reward, props.MaxLevel, props.StartingDifficulty);
const infiltrationRepGain = calculateInfiltratorsRepReward(soa, props.StartingDifficulty);
2022-09-13 00:00:09 +02:00
const isMemberOfInfiltrators = Player.factions.includes(FactionNames.ShadowsOfAnarchy);
2021-09-05 01:09:30 +02:00
function sell(): void {
handleInfiltrators();
2022-09-13 00:00:09 +02:00
Player.gainMoney(moneyGain, "infiltration");
2021-09-05 01:09:30 +02:00
quitInfiltration();
}
2021-09-05 01:09:30 +02:00
function trade(): void {
if (faction === "none") return;
handleInfiltrators();
2021-09-05 01:09:30 +02:00
Factions[faction].playerReputation += repGain;
quitInfiltration();
}
2021-10-01 19:08:37 +02:00
function changeDropdown(event: SelectChangeEvent<string>): void {
2021-09-05 01:09:30 +02:00
setFaction(event.target.value);
}
function handleInfiltrators(): void {
2022-04-22 21:30:49 +02:00
inviteToFaction(Factions[FactionNames.ShadowsOfAnarchy]);
if (isMemberOfInfiltrators) {
2022-04-22 21:30:49 +02:00
soa.playerReputation += infiltrationRepGain;
}
}
2021-09-05 01:09:30 +02:00
return (
2022-04-25 01:49:46 +02:00
<Paper sx={{ p: 1, textAlign: "center", display: "flex", alignItems: "center", flexDirection: "column" }}>
<Typography variant="h4">Infiltration successful!</Typography>
<Typography variant="h5" color="primary" width="75%">
You{" "}
{isMemberOfInfiltrators ? (
<>
have gained {formatNumber(infiltrationRepGain, 2)} rep for {FactionNames.ShadowsOfAnarchy} and{" "}
</>
) : (
<></>
)}
can trade the confidential information you found for money or reputation.
</Typography>
<Box sx={{ width: "fit-content" }}>
<Box sx={{ width: "100%" }}>
<Select value={faction} onChange={changeDropdown} sx={{ mr: 1 }}>
2021-10-01 19:08:37 +02:00
<MenuItem key={"none"} value={"none"}>
2021-09-05 01:09:30 +02:00
{"none"}
2021-10-01 19:08:37 +02:00
</MenuItem>
2022-09-13 00:00:09 +02:00
{Player.factions
2021-09-05 01:09:30 +02:00
.filter((f) => Factions[f].getInfo().offersWork())
.map((f) => (
2021-10-01 19:08:37 +02:00
<MenuItem key={f} value={f}>
2021-09-05 01:09:30 +02:00
{f}
2021-10-01 19:08:37 +02:00
</MenuItem>
2021-09-05 01:09:30 +02:00
))}
2021-10-01 19:08:37 +02:00
</Select>
<Button onClick={trade}>
Trade for <Reputation reputation={repGain} /> reputation
</Button>
2022-04-25 01:49:46 +02:00
</Box>
<Button onClick={sell} sx={{ width: "100%" }}>
Sell for&nbsp;
<Money money={moneyGain} />
</Button>
</Box>
<Button onClick={quitInfiltration} sx={{ width: "100%", mt: 1 }}>
Quit
</Button>
</Paper>
2021-09-05 01:09:30 +02:00
);
}