BUGFIX: Duplicated augmentation when buying after grafting (#1536)

This commit is contained in:
catloversg
2024-08-05 03:11:00 +07:00
committed by GitHub
parent e5a63b4116
commit eeac3f7dd1
5 changed files with 40 additions and 19 deletions

View File

@ -20,12 +20,19 @@ export function AugmentationsDev(): React.ReactElement {
function setAugmentationDropdown(event: SelectChangeEvent): void {
setAugmentation(event.target.value as AugmentationName);
}
function queueAug(): void {
if (Player.hasAugmentation(augmentation)) {
return;
}
Player.queueAugmentation(augmentation);
}
function queueAllAugs(): void {
for (const augName of Object.values(AugmentationName)) {
if (Player.hasAugmentation(augName)) {
continue;
}
Player.queueAugmentation(augName);
}
}

View File

@ -2,7 +2,6 @@ import type { Augmentation } from "../Augmentation/Augmentation";
import type { Faction } from "./Faction";
import { Augmentations } from "../Augmentation/Augmentations";
import { PlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation";
import { AugmentationName, FactionDiscovery } from "@enums";
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
@ -84,11 +83,7 @@ export function purchaseAugmentation(aug: Augmentation, fac: Faction, sing = fal
}
dialogBoxCreate(txt);
} else if (augCosts.moneyCost === 0 || Player.money >= augCosts.moneyCost) {
const queuedAugmentation = new PlayerOwnedAugmentation(aug.name);
if (aug.name == AugmentationName.NeuroFluxGovernor) {
queuedAugmentation.level = aug.getNextLevel();
}
Player.queuedAugmentations.push(queuedAugmentation);
Player.queueAugmentation(aug.name);
Player.loseMoney(augCosts.moneyCost, "augmentations");

View File

@ -156,7 +156,7 @@ export const GraftingRoot = (): React.ReactElement => {
Router.toPage(Page.Work);
}}
confirmationText={
<>
<Typography component="div" paddingBottom="1rem">
Cancelling grafting will <b>not</b> save grafting progress, and the money you spend will <b>not</b>{" "}
be returned.
{!Player.hasAugmentation(AugmentationName.CongruityImplant) && (
@ -166,7 +166,7 @@ export const GraftingRoot = (): React.ReactElement => {
Additionally, grafting an Augmentation will increase the potency of the Entropy virus.
</>
)}
</>
</Typography>
}
/>
<Box sx={{ maxHeight: 330, overflowY: "scroll" }}>

View File

@ -50,6 +50,8 @@ import { achievements } from "../../Achievements/Achievements";
import { isCompanyWork } from "../../Work/CompanyWork";
import { isMember } from "../../utils/EnumHelper";
import { canAccessBitNodeFeature } from "../../BitNode/BitNodeUtils";
import { AlertEvents } from "../../ui/React/AlertManager";
import { Augmentations } from "../../Augmentation/Augmentations";
export function init(this: PlayerObject): void {
/* Initialize Player's home computer */
@ -455,21 +457,30 @@ export function setBitNodeNumber(this: PlayerObject, n: number): void {
}
export function queueAugmentation(this: PlayerObject, name: AugmentationName): void {
for (const aug of this.queuedAugmentations) {
if (aug.name == name) {
console.warn(`tried to queue ${name} twice, this may be a bug`);
return;
if (name !== AugmentationName.NeuroFluxGovernor) {
for (const aug of this.queuedAugmentations) {
if (name === aug.name) {
AlertEvents.emit(`Tried to queue ${name} twice. This is a bug. Please contact developers.`);
return;
}
}
for (const aug of this.augmentations) {
if (aug.name === name) {
AlertEvents.emit(
`Tried to queue ${name}, but this augmentation was installed. This is a bug. Please contact developers.`,
);
return;
}
}
}
for (const aug of this.augmentations) {
if (aug.name == name) {
console.warn(`tried to queue ${name} twice, this may be a bug`);
return;
}
const queuedAugmentation = new PlayerOwnedAugmentation(name);
if (name === AugmentationName.NeuroFluxGovernor) {
const augmentation = Augmentations[name];
queuedAugmentation.level = augmentation.getNextLevel();
}
this.queuedAugmentations.push(new PlayerOwnedAugmentation(name));
this.queuedAugmentations.push(queuedAugmentation);
}
/************* Coding Contracts **************/

View File

@ -59,6 +59,14 @@ export class GraftingWork extends Work {
if (!cancelled) {
applyAugmentation({ name: augName, level: 1 });
// Remove this augmentation from the list of queued augmentations.
for (let i = 0; i < Player.queuedAugmentations.length; ++i) {
if (Player.queuedAugmentations[i].name === augName) {
Player.queuedAugmentations.splice(i, 1);
break;
}
}
if (!Player.hasAugmentation(AugmentationName.CongruityImplant, true)) {
Player.entropy += 1;
Player.applyEntropy(Player.entropy);