mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-24 02:03:01 +02:00
big work
This commit is contained in:
@@ -7,7 +7,6 @@ import * as React from "react";
|
||||
import { getNextNeurofluxLevel, hasAugmentationPrereqs, purchaseAugmentation } from "../FactionHelpers";
|
||||
import { PurchaseAugmentationPopup } from "./PurchaseAugmentationPopup";
|
||||
|
||||
import { Augmentation } from "../../Augmentation/Augmentation";
|
||||
import { Augmentations } from "../../Augmentation/Augmentations";
|
||||
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
|
||||
import { Faction } from "../../Faction/Faction";
|
||||
@@ -28,63 +27,56 @@ type IProps = {
|
||||
rerender: () => void;
|
||||
};
|
||||
|
||||
export class PurchaseableAugmentation extends React.Component<IProps, any> {
|
||||
aug: Augmentation;
|
||||
export function PurchaseableAugmentation(props: IProps): React.ReactElement {
|
||||
const aug = Augmentations[props.augName];
|
||||
if (aug == null) throw new Error(`aug ${props.augName} does not exists`);
|
||||
|
||||
constructor(props: IProps) {
|
||||
super(props);
|
||||
|
||||
const aug = Augmentations[this.props.augName];
|
||||
if (aug == null) throw new Error(`aug ${this.props.augName} does not exists`);
|
||||
this.aug = aug;
|
||||
|
||||
this.handleClick = this.handleClick.bind(this);
|
||||
function getMoneyCost(): number {
|
||||
return aug.baseCost * props.faction.getInfo().augmentationPriceMult;
|
||||
}
|
||||
|
||||
getMoneyCost(): number {
|
||||
return this.aug.baseCost * this.props.faction.getInfo().augmentationPriceMult;
|
||||
function getRepCost(): number {
|
||||
return aug.baseRepRequirement * props.faction.getInfo().augmentationRepRequirementMult;
|
||||
}
|
||||
|
||||
getRepCost(): number {
|
||||
return this.aug.baseRepRequirement * this.props.faction.getInfo().augmentationRepRequirementMult;
|
||||
}
|
||||
|
||||
handleClick(): void {
|
||||
function handleClick(): void {
|
||||
if (!Settings.SuppressBuyAugmentationConfirmation) {
|
||||
const popupId = "purchase-augmentation-popup";
|
||||
createPopup(popupId, PurchaseAugmentationPopup, {
|
||||
aug: this.aug,
|
||||
faction: this.props.faction,
|
||||
player: this.props.p,
|
||||
aug: aug,
|
||||
faction: props.faction,
|
||||
player: props.p,
|
||||
rerender: props.rerender,
|
||||
popupId: popupId,
|
||||
});
|
||||
} else {
|
||||
purchaseAugmentation(this.aug, this.props.faction);
|
||||
purchaseAugmentation(aug, props.faction);
|
||||
props.rerender();
|
||||
}
|
||||
}
|
||||
|
||||
// Whether the player has the prerequisite Augmentations
|
||||
hasPrereqs(): boolean {
|
||||
return hasAugmentationPrereqs(this.aug);
|
||||
function hasPrereqs(): boolean {
|
||||
return hasAugmentationPrereqs(aug);
|
||||
}
|
||||
|
||||
// Whether the player has enough rep for this Augmentation
|
||||
hasReputation(): boolean {
|
||||
return this.props.faction.playerReputation >= this.getRepCost();
|
||||
function hasReputation(): boolean {
|
||||
return props.faction.playerReputation >= getRepCost();
|
||||
}
|
||||
|
||||
// Whether the player has this augmentations (purchased OR installed)
|
||||
owned(): boolean {
|
||||
function owned(): boolean {
|
||||
let owned = false;
|
||||
for (const queuedAug of this.props.p.queuedAugmentations) {
|
||||
if (queuedAug.name === this.props.augName) {
|
||||
for (const queuedAug of props.p.queuedAugmentations) {
|
||||
if (queuedAug.name === props.augName) {
|
||||
owned = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (const installedAug of this.props.p.augmentations) {
|
||||
if (installedAug.name === this.props.augName) {
|
||||
for (const installedAug of props.p.augmentations) {
|
||||
if (installedAug.name === props.augName) {
|
||||
owned = true;
|
||||
break;
|
||||
}
|
||||
@@ -93,96 +85,94 @@ export class PurchaseableAugmentation extends React.Component<IProps, any> {
|
||||
return owned;
|
||||
}
|
||||
|
||||
render(): React.ReactNode {
|
||||
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
|
||||
let disabled = false;
|
||||
let status: JSX.Element = <></>;
|
||||
let color = "";
|
||||
if (!this.hasPrereqs()) {
|
||||
disabled = true;
|
||||
status = <>LOCKED (Requires {this.aug.prereqs.map((aug) => AugFormat(aug))} as prerequisite)</>;
|
||||
color = "red";
|
||||
} else if (this.aug.name !== AugmentationNames.NeuroFluxGovernor && (this.aug.owned || this.owned())) {
|
||||
disabled = true;
|
||||
} else if (this.hasReputation()) {
|
||||
status = (
|
||||
<>
|
||||
UNLOCKED (at {Reputation(repCost)} faction reputation) - <Money money={moneyCost} player={this.props.p} />
|
||||
</>
|
||||
);
|
||||
} else {
|
||||
disabled = true;
|
||||
status = (
|
||||
<>
|
||||
LOCKED (Requires {Reputation(repCost)} faction reputation - <Money money={moneyCost} player={this.props.p} />)
|
||||
</>
|
||||
);
|
||||
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()}`;
|
||||
}
|
||||
|
||||
let tooltip = <></>;
|
||||
if (typeof this.aug.info === "string")
|
||||
tooltip = (
|
||||
<>
|
||||
<span dangerouslySetInnerHTML={{ __html: this.aug.info }} />
|
||||
<br />
|
||||
<br />
|
||||
{this.aug.stats}
|
||||
</>
|
||||
);
|
||||
else
|
||||
tooltip = (
|
||||
<>
|
||||
{this.aug.info}
|
||||
<br />
|
||||
<br />
|
||||
{this.aug.stats}
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<li key={this.aug.name}>
|
||||
<span
|
||||
style={{
|
||||
margin: "4px",
|
||||
padding: "4px",
|
||||
}}
|
||||
>
|
||||
<StdButton
|
||||
disabled={disabled}
|
||||
onClick={this.handleClick}
|
||||
style={{
|
||||
display: "inline-block",
|
||||
}}
|
||||
text={btnTxt}
|
||||
tooltip={tooltip}
|
||||
/>
|
||||
<p style={txtStyle}>{status}</p>
|
||||
</span>
|
||||
</li>
|
||||
if (aug == null) {
|
||||
console.error(
|
||||
`Invalid Augmentation when trying to create PurchaseableAugmentation display element: ${props.augName}`,
|
||||
);
|
||||
return <></>;
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
const txtStyle: IMap<string> = {
|
||||
display: "inline-block",
|
||||
};
|
||||
if (color !== "") {
|
||||
txtStyle.color = color;
|
||||
}
|
||||
|
||||
// Determine button txt
|
||||
let btnTxt = aug.name;
|
||||
if (aug.name === AugmentationNames.NeuroFluxGovernor) {
|
||||
btnTxt += ` - Level ${getNextNeurofluxLevel()}`;
|
||||
}
|
||||
|
||||
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}
|
||||
style={{
|
||||
display: "inline-block",
|
||||
}}
|
||||
text={btnTxt}
|
||||
tooltip={tooltip}
|
||||
/>
|
||||
<p style={txtStyle}>{status}</p>
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user