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";
|
2021-06-13 17:05:40 +02:00
|
|
|
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";
|
2022-03-27 09:53:13 +02:00
|
|
|
import {
|
|
|
|
calculateInfiltratorsRepReward,
|
|
|
|
calculateSellInformationCashReward,
|
|
|
|
calculateTradeInformationRepReward,
|
|
|
|
} from "../formulas/victory";
|
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-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();
|
2022-09-13 00:00:09 +02:00
|
|
|
Router.toCity();
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2021-06-13 17:05:40 +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);
|
2021-06-13 17:05:40 +02:00
|
|
|
|
2022-09-13 00:00:09 +02:00
|
|
|
const isMemberOfInfiltrators = Player.factions.includes(FactionNames.ShadowsOfAnarchy);
|
2022-03-23 16:23:01 +01:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
function sell(): void {
|
2022-03-23 16:23:01 +01:00
|
|
|
handleInfiltrators();
|
2022-09-13 00:00:09 +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 {
|
|
|
|
if (faction === "none") return;
|
2022-05-23 17:31:28 +02:00
|
|
|
handleInfiltrators();
|
2021-09-05 01:09:30 +02:00
|
|
|
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 {
|
2022-04-22 21:30:49 +02:00
|
|
|
inviteToFaction(Factions[FactionNames.ShadowsOfAnarchy]);
|
2022-03-23 16:23:01 +01:00
|
|
|
if (isMemberOfInfiltrators) {
|
2022-04-22 21:30:49 +02:00
|
|
|
soa.playerReputation += infiltrationRepGain;
|
2022-03-23 16:23:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
<Money money={moneyGain} />
|
|
|
|
</Button>
|
|
|
|
</Box>
|
|
|
|
<Button onClick={quitInfiltration} sx={{ width: "100%", mt: 1 }}>
|
|
|
|
Quit
|
|
|
|
</Button>
|
|
|
|
</Paper>
|
2021-09-05 01:09:30 +02:00
|
|
|
);
|
|
|
|
}
|