2019-04-14 11:08:10 +02:00
|
|
|
/**
|
|
|
|
* React component for displaying a single augmentation for purchase through
|
|
|
|
* the faction UI
|
|
|
|
*/
|
|
|
|
import * as React from "react";
|
|
|
|
|
2021-09-13 00:03:07 +02:00
|
|
|
import { getNextNeurofluxLevel, hasAugmentationPrereqs, purchaseAugmentation } from "../FactionHelpers";
|
|
|
|
import { PurchaseAugmentationPopup } from "./PurchaseAugmentationPopup";
|
2019-04-14 11:08:10 +02:00
|
|
|
|
|
|
|
import { Augmentations } from "../../Augmentation/Augmentations";
|
|
|
|
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
|
|
|
|
import { Faction } from "../../Faction/Faction";
|
|
|
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
|
|
|
import { Settings } from "../../Settings/Settings";
|
2021-03-31 06:45:21 +02:00
|
|
|
import { Money } from "../../ui/React/Money";
|
|
|
|
import { Reputation } from "../../ui/React/Reputation";
|
2021-09-13 00:03:07 +02:00
|
|
|
import { createPopup } from "../../ui/React/createPopup";
|
2019-04-14 11:08:10 +02:00
|
|
|
import { IMap } from "../../types";
|
|
|
|
|
|
|
|
import { StdButton } from "../../ui/React/StdButton";
|
2021-03-31 06:45:21 +02:00
|
|
|
import { Augmentation as AugFormat } from "../../ui/React/Augmentation";
|
2019-04-14 11:08:10 +02:00
|
|
|
|
|
|
|
type IProps = {
|
2021-09-05 01:09:30 +02:00
|
|
|
augName: string;
|
|
|
|
faction: Faction;
|
|
|
|
p: IPlayer;
|
|
|
|
rerender: () => void;
|
|
|
|
};
|
2019-04-14 11:08:10 +02:00
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
export function PurchaseableAugmentation(props: IProps): React.ReactElement {
|
|
|
|
const aug = Augmentations[props.augName];
|
|
|
|
if (aug == null) throw new Error(`aug ${props.augName} does not exists`);
|
2021-09-05 01:09:30 +02:00
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
function getMoneyCost(): number {
|
|
|
|
return aug.baseCost * props.faction.getInfo().augmentationPriceMult;
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
function getRepCost(): number {
|
|
|
|
return aug.baseRepRequirement * props.faction.getInfo().augmentationRepRequirementMult;
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
function handleClick(): void {
|
2021-09-05 01:09:30 +02:00
|
|
|
if (!Settings.SuppressBuyAugmentationConfirmation) {
|
2021-09-13 00:03:07 +02:00
|
|
|
const popupId = "purchase-augmentation-popup";
|
|
|
|
createPopup(popupId, PurchaseAugmentationPopup, {
|
2021-09-18 01:43:08 +02:00
|
|
|
aug: aug,
|
|
|
|
faction: props.faction,
|
|
|
|
player: props.p,
|
|
|
|
rerender: props.rerender,
|
2021-09-13 00:03:07 +02:00
|
|
|
popupId: popupId,
|
|
|
|
});
|
2021-09-05 01:09:30 +02:00
|
|
|
} else {
|
2021-09-18 01:43:08 +02:00
|
|
|
purchaseAugmentation(aug, props.faction);
|
|
|
|
props.rerender();
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Whether the player has the prerequisite Augmentations
|
2021-09-18 01:43:08 +02:00
|
|
|
function hasPrereqs(): boolean {
|
|
|
|
return hasAugmentationPrereqs(aug);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Whether the player has enough rep for this Augmentation
|
2021-09-18 01:43:08 +02:00
|
|
|
function hasReputation(): boolean {
|
|
|
|
return props.faction.playerReputation >= getRepCost();
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Whether the player has this augmentations (purchased OR installed)
|
2021-09-18 01:43:08 +02:00
|
|
|
function owned(): boolean {
|
2021-09-05 01:09:30 +02:00
|
|
|
let owned = false;
|
2021-09-18 01:43:08 +02:00
|
|
|
for (const queuedAug of props.p.queuedAugmentations) {
|
|
|
|
if (queuedAug.name === props.augName) {
|
2021-09-05 01:09:30 +02:00
|
|
|
owned = true;
|
|
|
|
break;
|
|
|
|
}
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
for (const installedAug of props.p.augmentations) {
|
|
|
|
if (installedAug.name === props.augName) {
|
2021-09-05 01:09:30 +02:00
|
|
|
owned = true;
|
|
|
|
break;
|
|
|
|
}
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return owned;
|
|
|
|
}
|
2019-04-14 11:08:10 +02:00
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
if (aug == null) {
|
|
|
|
console.error(
|
|
|
|
`Invalid Augmentation when trying to create PurchaseableAugmentation display element: ${props.augName}`,
|
|
|
|
);
|
|
|
|
return <></>;
|
|
|
|
}
|
2019-04-14 11:08:10 +02:00
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
const moneyCost = getMoneyCost();
|
|
|
|
const repCost = getRepCost();
|
|
|
|
|
|
|
|
// Determine UI properties
|
|
|
|
let disabled = false;
|
|
|
|
let status: JSX.Element = <></>;
|
|
|
|
let color = "";
|
|
|
|
if (!hasPrereqs()) {
|
|
|
|
disabled = true;
|
|
|
|
status = <>LOCKED (Requires {aug.prereqs.map((aug) => AugFormat(aug))} as prerequisite)</>;
|
|
|
|
color = "red";
|
|
|
|
} else if (aug.name !== AugmentationNames.NeuroFluxGovernor && (aug.owned || owned())) {
|
|
|
|
disabled = true;
|
|
|
|
} else if (hasReputation()) {
|
|
|
|
status = (
|
|
|
|
<>
|
|
|
|
UNLOCKED (at {Reputation(repCost)} faction reputation) - <Money money={moneyCost} player={props.p} />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
disabled = true;
|
|
|
|
status = (
|
|
|
|
<>
|
|
|
|
LOCKED (Requires {Reputation(repCost)} faction reputation - <Money money={moneyCost} player={props.p} />)
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
color = "red";
|
|
|
|
}
|
2019-04-14 11:08:10 +02:00
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
const txtStyle: IMap<string> = {
|
|
|
|
display: "inline-block",
|
|
|
|
};
|
|
|
|
if (color !== "") {
|
|
|
|
txtStyle.color = color;
|
|
|
|
}
|
2019-04-14 11:08:10 +02:00
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
// Determine button txt
|
|
|
|
let btnTxt = aug.name;
|
|
|
|
if (aug.name === AugmentationNames.NeuroFluxGovernor) {
|
|
|
|
btnTxt += ` - Level ${getNextNeurofluxLevel()}`;
|
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
|
2021-09-18 01:43:08 +02:00
|
|
|
let tooltip = <></>;
|
|
|
|
if (typeof aug.info === "string")
|
|
|
|
tooltip = (
|
|
|
|
<>
|
|
|
|
<span dangerouslySetInnerHTML={{ __html: aug.info }} />
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
{aug.stats}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
else
|
|
|
|
tooltip = (
|
|
|
|
<>
|
|
|
|
{aug.info}
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
{aug.stats}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li key={aug.name}>
|
|
|
|
<span
|
|
|
|
style={{
|
|
|
|
margin: "4px",
|
|
|
|
padding: "4px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<StdButton
|
|
|
|
disabled={disabled}
|
|
|
|
onClick={handleClick}
|
2021-09-13 00:03:07 +02:00
|
|
|
style={{
|
2021-09-18 01:43:08 +02:00
|
|
|
display: "inline-block",
|
2021-09-13 00:03:07 +02:00
|
|
|
}}
|
2021-09-18 01:43:08 +02:00
|
|
|
text={btnTxt}
|
|
|
|
tooltip={tooltip}
|
|
|
|
/>
|
|
|
|
<p style={txtStyle}>{status}</p>
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
);
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|