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";
|
|
|
|
|
|
|
|
import {
|
|
|
|
getNextNeurofluxLevel,
|
|
|
|
hasAugmentationPrereqs,
|
|
|
|
purchaseAugmentation,
|
|
|
|
purchaseAugmentationBoxCreate,
|
|
|
|
} from "../FactionHelpers";
|
|
|
|
|
|
|
|
import { Augmentation } from "../../Augmentation/Augmentation";
|
|
|
|
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";
|
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 = {
|
|
|
|
augName: string;
|
|
|
|
faction: Faction;
|
|
|
|
p: IPlayer;
|
|
|
|
rerender: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const spanStyleMarkup = {
|
|
|
|
margin: "4px",
|
|
|
|
padding: "4px",
|
|
|
|
}
|
|
|
|
|
|
|
|
const inlineStyleMarkup = {
|
|
|
|
display: "inline-block",
|
|
|
|
}
|
|
|
|
|
|
|
|
export class PurchaseableAugmentation extends React.Component<IProps, any> {
|
2021-05-01 09:17:31 +02:00
|
|
|
aug: Augmentation;
|
2019-04-14 11:08:10 +02:00
|
|
|
|
|
|
|
constructor(props: IProps) {
|
|
|
|
super(props);
|
|
|
|
|
2021-05-01 09:17:31 +02:00
|
|
|
const aug = Augmentations[this.props.augName];
|
|
|
|
if(aug == null) throw new Error(`aug ${this.props.augName} does not exists`);
|
|
|
|
this.aug = aug;
|
2019-04-14 11:08:10 +02:00
|
|
|
|
|
|
|
this.handleClick = this.handleClick.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
getMoneyCost(): number {
|
2021-05-01 09:17:31 +02:00
|
|
|
return this.aug.baseCost * this.props.faction.getInfo().augmentationPriceMult;
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getRepCost(): number {
|
2021-05-01 09:17:31 +02:00
|
|
|
return this.aug.baseRepRequirement * this.props.faction.getInfo().augmentationRepRequirementMult;
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
|
|
|
|
2021-05-01 09:17:31 +02:00
|
|
|
handleClick(): void {
|
2019-04-14 11:08:10 +02:00
|
|
|
if (!Settings.SuppressBuyAugmentationConfirmation) {
|
2021-05-01 09:17:31 +02:00
|
|
|
purchaseAugmentationBoxCreate(this.aug, this.props.faction);
|
2019-04-14 11:08:10 +02:00
|
|
|
} else {
|
2021-05-01 09:17:31 +02:00
|
|
|
purchaseAugmentation(this.aug, this.props.faction);
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Whether the player has the prerequisite Augmentations
|
|
|
|
hasPrereqs(): boolean {
|
2021-05-01 09:17:31 +02:00
|
|
|
return hasAugmentationPrereqs(this.aug);
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Whether the player has enough rep for this Augmentation
|
|
|
|
hasReputation(): boolean {
|
|
|
|
return this.props.faction.playerReputation >= this.getRepCost();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Whether the player has this augmentations (purchased OR installed)
|
|
|
|
owned(): boolean {
|
|
|
|
let owned = false;
|
|
|
|
for (const queuedAug of this.props.p.queuedAugmentations) {
|
|
|
|
if (queuedAug.name === this.props.augName) {
|
|
|
|
owned = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const installedAug of this.props.p.augmentations) {
|
|
|
|
if (installedAug.name === this.props.augName) {
|
|
|
|
owned = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return owned;
|
|
|
|
}
|
|
|
|
|
2021-05-01 09:17:31 +02:00
|
|
|
render(): React.ReactNode {
|
2019-04-14 11:08:10 +02:00
|
|
|
if (this.aug == null) {
|
|
|
|
console.error(`Invalid Augmentation when trying to create PurchaseableAugmentation display element: ${this.props.augName}`);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const moneyCost = this.getMoneyCost();
|
|
|
|
const repCost = this.getRepCost();
|
|
|
|
|
|
|
|
// Determine UI properties
|
2021-04-30 05:52:56 +02:00
|
|
|
let disabled = false;
|
2021-03-31 06:45:21 +02:00
|
|
|
let status: JSX.Element = <></>;
|
2021-04-30 05:52:56 +02:00
|
|
|
let color = "";
|
2019-04-14 11:08:10 +02:00
|
|
|
if (!this.hasPrereqs()) {
|
|
|
|
disabled = true;
|
2021-03-31 06:45:21 +02:00
|
|
|
status = <>LOCKED (Requires {this.aug.prereqs.map(aug => AugFormat(aug))} as prerequisite)</>;
|
2019-04-14 11:08:10 +02:00
|
|
|
color = "red";
|
|
|
|
} else if (this.aug.name !== AugmentationNames.NeuroFluxGovernor && (this.aug.owned || this.owned())) {
|
|
|
|
disabled = true;
|
|
|
|
} else if (this.hasReputation()) {
|
2021-04-20 03:26:51 +02:00
|
|
|
status = <>UNLOCKED (at {Reputation(repCost)} faction reputation) - {Money(moneyCost)}</>;
|
2019-04-14 11:08:10 +02:00
|
|
|
} else {
|
|
|
|
disabled = true;
|
2021-03-31 06:45:21 +02:00
|
|
|
status = <>LOCKED (Requires {Reputation(repCost)} faction reputation - {Money(moneyCost)})</>;
|
2019-04-14 11:08:10 +02:00
|
|
|
color = "red";
|
|
|
|
}
|
|
|
|
|
|
|
|
const txtStyle: IMap<string> = {
|
|
|
|
display: "inline-block",
|
|
|
|
}
|
|
|
|
if (color !== "") { txtStyle.color = color; }
|
|
|
|
|
|
|
|
// Determine button txt
|
|
|
|
let btnTxt = this.aug.name;
|
|
|
|
if (this.aug.name === AugmentationNames.NeuroFluxGovernor) {
|
|
|
|
btnTxt += ` - Level ${getNextNeurofluxLevel()}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li>
|
|
|
|
<span style={spanStyleMarkup}>
|
|
|
|
<StdButton
|
|
|
|
disabled={disabled}
|
|
|
|
onClick={this.handleClick}
|
|
|
|
style={inlineStyleMarkup}
|
|
|
|
text={btnTxt}
|
2019-04-14 11:21:43 +02:00
|
|
|
tooltip={this.aug.info}
|
2019-04-14 11:08:10 +02:00
|
|
|
/>
|
2021-03-31 06:45:21 +02:00
|
|
|
<p style={txtStyle}>{status}</p>
|
2019-04-14 11:08:10 +02:00
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|