2021-06-13 17:05:40 +02:00
|
|
|
import { Factions } from "../../Faction/Factions";
|
2021-09-05 01:09:30 +02:00
|
|
|
import React, { useState } from "react";
|
2021-09-17 01:23:03 +02:00
|
|
|
import Grid from "@mui/material/Grid";
|
2021-06-13 17:05:40 +02:00
|
|
|
import { Money } from "../../ui/React/Money";
|
|
|
|
import { Reputation } from "../../ui/React/Reputation";
|
|
|
|
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
|
2021-09-18 01:43:08 +02:00
|
|
|
import { use } from "../../ui/Context";
|
2021-10-01 19:08:37 +02:00
|
|
|
import Typography from "@mui/material/Typography";
|
|
|
|
import Button from "@mui/material/Button";
|
|
|
|
import MenuItem from "@mui/material/MenuItem";
|
|
|
|
import Select, { SelectChangeEvent } from "@mui/material/Select";
|
2022-03-23 16:23:01 +01:00
|
|
|
import { FactionNames } from "../../Faction/data/FactionNames";
|
2022-03-25 16:39:14 +01:00
|
|
|
import { LocationsMetadata } from "../../Locations/data/LocationsMetadata";
|
|
|
|
import { formatNumber } from "../../utils/StringHelperFunctions";
|
2021-06-13 17:05:40 +02:00
|
|
|
|
|
|
|
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;
|
2021-06-13 17:05:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function Victory(props: IProps): React.ReactElement {
|
2021-09-18 01:43:08 +02:00
|
|
|
const player = use.Player();
|
|
|
|
const router = use.Router();
|
2021-09-05 01:09:30 +02:00
|
|
|
const [faction, setFaction] = useState("none");
|
2021-06-13 17:05:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
function quitInfiltration(): void {
|
2022-03-23 16:23:01 +01:00
|
|
|
handleInfiltrators();
|
2021-09-18 01:43:08 +02:00
|
|
|
router.toCity();
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2021-06-13 17:05:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
const levelBonus = props.MaxLevel * Math.pow(1.01, props.MaxLevel);
|
2021-06-13 17:05:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
const repGain =
|
2021-12-03 21:11:31 +01:00
|
|
|
Math.pow(props.Reward + 1, 1.1) *
|
2021-09-05 01:09:30 +02:00
|
|
|
Math.pow(props.StartingDifficulty, 1.2) *
|
|
|
|
30 *
|
|
|
|
levelBonus *
|
2022-03-27 06:26:43 +02:00
|
|
|
player.infiltration_trade_mult *
|
2021-09-05 01:09:30 +02:00
|
|
|
BitNodeMultipliers.InfiltrationRep;
|
2021-06-13 17:05:40 +02:00
|
|
|
|
2022-03-23 16:23:01 +01:00
|
|
|
const infiltratorFaction = Factions[FactionNames.Infiltrators];
|
|
|
|
const isMemberOfInfiltrators = infiltratorFaction && infiltratorFaction.isMember;
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
const moneyGain =
|
2021-12-03 21:11:31 +01:00
|
|
|
Math.pow(props.Reward + 1, 2) *
|
2021-09-05 01:09:30 +02:00
|
|
|
Math.pow(props.StartingDifficulty, 3) *
|
|
|
|
3e3 *
|
|
|
|
levelBonus *
|
2022-03-27 06:26:43 +02:00
|
|
|
player.infiltration_sell_mult *
|
2021-09-05 01:09:30 +02:00
|
|
|
BitNodeMultipliers.InfiltrationMoney;
|
2021-06-13 17:05:40 +02:00
|
|
|
|
2022-03-25 16:39:14 +01:00
|
|
|
function calculateInfiltratorsRepReward(): number {
|
|
|
|
const maxStartingSecurityLevel = LocationsMetadata.reduce((acc, data): number => {
|
|
|
|
const startingSecurityLevel = data.infiltrationData?.startingSecurityLevel || 0;
|
|
|
|
return acc > startingSecurityLevel ? acc : startingSecurityLevel;
|
|
|
|
}, 0);
|
|
|
|
const baseRepGain = (props.StartingDifficulty / maxStartingSecurityLevel) * 10;
|
|
|
|
|
2022-03-27 06:26:43 +02:00
|
|
|
return (baseRepGain + player.infiltration_base_rep_increase) * player.infiltration_rep_mult;
|
2022-03-25 16:39:14 +01:00
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
function sell(): void {
|
2022-03-23 16:23:01 +01:00
|
|
|
handleInfiltrators();
|
2021-10-27 20:18:33 +02:00
|
|
|
player.gainMoney(moneyGain, "infiltration");
|
2021-09-05 01:09:30 +02:00
|
|
|
quitInfiltration();
|
|
|
|
}
|
2021-06-13 17:05:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
function trade(): void {
|
2022-03-23 16:23:01 +01:00
|
|
|
handleInfiltrators();
|
2021-09-05 01:09:30 +02:00
|
|
|
if (faction === "none") return;
|
|
|
|
Factions[faction].playerReputation += repGain;
|
|
|
|
quitInfiltration();
|
|
|
|
}
|
2021-06-13 17:05:40 +02:00
|
|
|
|
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);
|
|
|
|
}
|
2021-06-13 17:05:40 +02:00
|
|
|
|
2022-03-23 16:23:01 +01:00
|
|
|
function handleInfiltrators(): void {
|
|
|
|
player.hasCompletedAnInfiltration = true;
|
|
|
|
if (isMemberOfInfiltrators) {
|
2022-03-25 16:39:14 +01:00
|
|
|
infiltratorFaction.playerReputation += calculateInfiltratorsRepReward();
|
2022-03-23 16:23:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Grid container spacing={3}>
|
|
|
|
<Grid item xs={10}>
|
2021-10-01 19:08:37 +02:00
|
|
|
<Typography variant="h4">Infiltration successful!</Typography>
|
2021-09-05 01:09:30 +02:00
|
|
|
</Grid>
|
|
|
|
<Grid item xs={10}>
|
2021-10-01 19:08:37 +02:00
|
|
|
<Typography variant="h5" color="primary">
|
2022-03-23 16:23:01 +01:00
|
|
|
You{" "}
|
|
|
|
{isMemberOfInfiltrators ? (
|
|
|
|
<>
|
2022-03-25 16:39:14 +01:00
|
|
|
have gained {formatNumber(calculateInfiltratorsRepReward(), 2)} rep for {FactionNames.Infiltrators} and{" "}
|
2022-03-23 16:23:01 +01:00
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
)}
|
|
|
|
can trade the confidential information you found for money or reputation.
|
2021-10-01 19:08:37 +02:00
|
|
|
</Typography>
|
|
|
|
<Select value={faction} onChange={changeDropdown}>
|
|
|
|
<MenuItem key={"none"} value={"none"}>
|
2021-09-05 01:09:30 +02:00
|
|
|
{"none"}
|
2021-10-01 19:08:37 +02:00
|
|
|
</MenuItem>
|
2021-09-18 01:43:08 +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>
|
2021-09-05 01:09:30 +02:00
|
|
|
</Grid>
|
|
|
|
<Grid item xs={3}>
|
2021-10-01 19:08:37 +02:00
|
|
|
<Button onClick={sell}>
|
|
|
|
Sell for
|
|
|
|
<Money money={moneyGain} />
|
|
|
|
</Button>
|
2021-06-13 17:05:40 +02:00
|
|
|
</Grid>
|
2021-09-05 01:09:30 +02:00
|
|
|
<Grid item xs={3}>
|
2021-10-01 19:08:37 +02:00
|
|
|
<Button onClick={quitInfiltration}>Quit</Button>
|
2021-09-05 01:09:30 +02:00
|
|
|
</Grid>
|
|
|
|
</Grid>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|