2021-09-05 01:09:30 +02:00
|
|
|
import React, { useState } from "react";
|
2023-06-26 04:53:35 +02:00
|
|
|
import { Box, Button, MenuItem, Paper, Select, SelectChangeEvent, Typography } from "@mui/material";
|
|
|
|
|
|
|
|
import { Player } from "@player";
|
2023-06-12 06:34:20 +02:00
|
|
|
import { FactionName } from "@enums";
|
2023-06-26 04:53:35 +02:00
|
|
|
|
2022-04-25 01:51:30 +02:00
|
|
|
import { inviteToFaction } from "../../Faction/FactionHelpers";
|
|
|
|
import { Factions } from "../../Faction/Factions";
|
2022-09-13 00:00:09 +02:00
|
|
|
import { Router } from "../../ui/GameRoot";
|
2022-12-04 09:14:06 +01:00
|
|
|
import { Page } from "../../ui/Router";
|
2021-06-13 17:05:40 +02:00
|
|
|
import { Money } from "../../ui/React/Money";
|
|
|
|
import { Reputation } from "../../ui/React/Reputation";
|
2023-02-11 19:18:50 +01:00
|
|
|
import { formatNumberNoSuffix } from "../../ui/formatNumber";
|
2022-03-27 09:53:13 +02:00
|
|
|
import {
|
|
|
|
calculateInfiltratorsRepReward,
|
|
|
|
calculateSellInformationCashReward,
|
|
|
|
calculateTradeInformationRepReward,
|
|
|
|
} from "../formulas/victory";
|
2023-06-26 04:53:35 +02:00
|
|
|
import { getEnumHelper } from "../../utils/EnumHelper";
|
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 {
|
2023-06-26 04:53:35 +02:00
|
|
|
const [factionName, setFactionName] = 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-12-04 09:14:06 +01:00
|
|
|
Router.toPage(Page.City);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2021-06-13 17:05:40 +02:00
|
|
|
|
2023-06-12 06:34:20 +02:00
|
|
|
const soa = Factions[FactionName.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
|
|
|
|
2023-06-12 06:34:20 +02:00
|
|
|
const isMemberOfInfiltrators = Player.factions.includes(FactionName.ShadowsOfAnarchy);
|
2022-03-23 16:23:01 +01:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
function sell(): void {
|
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 {
|
2023-06-26 04:53:35 +02:00
|
|
|
if (!getEnumHelper("FactionName").isMember(factionName)) return;
|
|
|
|
Factions[factionName].playerReputation += repGain;
|
2021-09-05 01:09:30 +02:00
|
|
|
quitInfiltration();
|
|
|
|
}
|
2021-06-13 17:05:40 +02:00
|
|
|
|
2023-05-05 09:55:59 +02:00
|
|
|
function changeDropdown(event: SelectChangeEvent): void {
|
2023-06-26 04:53:35 +02:00
|
|
|
setFactionName(event.target.value);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2021-06-13 17:05:40 +02:00
|
|
|
|
2022-03-23 16:23:01 +01:00
|
|
|
function handleInfiltrators(): void {
|
2023-06-12 06:34:20 +02:00
|
|
|
inviteToFaction(Factions[FactionName.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 ? (
|
|
|
|
<>
|
2023-06-12 06:34:20 +02:00
|
|
|
have gained {formatNumberNoSuffix(infiltrationRepGain, 2)} rep for {FactionName.ShadowsOfAnarchy} and{" "}
|
2022-04-25 01:49:46 +02:00
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
)}
|
|
|
|
can trade the confidential information you found for money or reputation.
|
|
|
|
</Typography>
|
|
|
|
<Box sx={{ width: "fit-content" }}>
|
|
|
|
<Box sx={{ width: "100%" }}>
|
2023-06-26 04:53:35 +02:00
|
|
|
<Select value={factionName} 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}>
|
2022-11-25 14:00:26 +01:00
|
|
|
Trade for
|
|
|
|
<Reputation reputation={repGain} />
|
|
|
|
reputation
|
2021-10-01 19:08:37 +02:00
|
|
|
</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
|
|
|
);
|
|
|
|
}
|