mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 06:48:42 +02:00
MISC: ns.hacknet.spendHashes handles invalid targets in same way as UI (#2102)
This commit is contained in:
@@ -24,6 +24,7 @@ import { Server } from "../Server/Server";
|
||||
import { Companies } from "../Company/Companies";
|
||||
import { isMember } from "../utils/EnumHelper";
|
||||
import { canAccessBitNodeFeature } from "../BitNode/BitNodeUtils";
|
||||
import { checkServerOwnership, ServerOwnershipType } from "../Server/ServerHelpers";
|
||||
|
||||
// Returns a boolean indicating whether the player has Hacknet Servers
|
||||
// (the upgraded form of Hacknet Nodes)
|
||||
@@ -491,7 +492,14 @@ export function purchaseHashUpgrade(upgName: string, upgTarget: string, count =
|
||||
console.error(`Invalid target specified in purchaseHashUpgrade(): ${upgTarget}`);
|
||||
throw new Error(`'${upgTarget}' is not a server.`);
|
||||
}
|
||||
if (!(target instanceof Server)) throw new Error(`'${upgTarget}' is not a normal server.`);
|
||||
if (!(target instanceof Server)) {
|
||||
throw new Error(`'${upgTarget}' is not a normal server.`);
|
||||
}
|
||||
if (!checkServerOwnership(target, ServerOwnershipType.Foreign)) {
|
||||
throw new Error(
|
||||
`'${upgTarget}' is not a valid target. You can only perform this action on servers that you do not own.`,
|
||||
);
|
||||
}
|
||||
|
||||
target.changeMinimumSecurity(upg.value ** count, true);
|
||||
} catch (e) {
|
||||
@@ -507,7 +515,14 @@ export function purchaseHashUpgrade(upgName: string, upgTarget: string, count =
|
||||
console.error(`Invalid target specified in purchaseHashUpgrade(): ${upgTarget}`);
|
||||
throw new Error(`'${upgTarget}' is not a server.`);
|
||||
}
|
||||
if (!(target instanceof Server)) throw new Error(`'${upgTarget}' is not a normal server.`);
|
||||
if (!(target instanceof Server)) {
|
||||
throw new Error(`'${upgTarget}' is not a normal server.`);
|
||||
}
|
||||
if (!checkServerOwnership(target, ServerOwnershipType.Foreign)) {
|
||||
throw new Error(
|
||||
`'${upgTarget}' is not a valid target. You can only perform this action on servers that you do not own.`,
|
||||
);
|
||||
}
|
||||
|
||||
//Manually loop the change so as to properly handle the softcap
|
||||
for (let i = 0; i < count; i++) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { purchaseHashUpgrade } from "../HacknetHelpers";
|
||||
import { HashManager } from "../HashManager";
|
||||
import { HashUpgrade } from "../HashUpgrade";
|
||||
|
||||
import { ServerDropdown, ServerType } from "../../ui/React/ServerDropdown";
|
||||
import { ServerDropdown } from "../../ui/React/ServerDropdown";
|
||||
import { CompanyDropdown } from "../../ui/React/CompanyDropdown";
|
||||
|
||||
import { dialogBoxCreate } from "../../ui/React/DialogBox";
|
||||
@@ -18,6 +18,7 @@ import { SelectChangeEvent } from "@mui/material/Select";
|
||||
import { CompanyName, FactionName } from "@enums";
|
||||
import { PartialRecord } from "../../Types/Record";
|
||||
import { isMember } from "../../utils/EnumHelper";
|
||||
import { ServerOwnershipType } from "../../Server/ServerHelpers";
|
||||
|
||||
interface IProps {
|
||||
hashManager: HashManager;
|
||||
@@ -88,7 +89,7 @@ export function HacknetUpgradeElem(props: IProps): React.ReactElement {
|
||||
purchase={purchase}
|
||||
canPurchase={canPurchase}
|
||||
value={selectedServer}
|
||||
serverType={ServerType.Foreign}
|
||||
serverType={ServerOwnershipType.Foreign}
|
||||
onChange={changeTargetServer}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user