From adc39ad8254475ce4545e7bcc1c17ea9b57f544d Mon Sep 17 00:00:00 2001 From: catloversg <152669316+catloversg@users.noreply.github.com> Date: Sun, 16 Feb 2025 16:05:22 +0700 Subject: [PATCH] BUGFIX: ns.corporation.bribe can bribe faction that player is not member of (#1966) --- markdown/bitburner.corporation.bribe.md | 2 ++ markdown/bitburner.corporation.md | 2 +- src/Corporation/Actions.ts | 24 ++++++++++++++-------- src/ScriptEditor/NetscriptDefinitions.d.ts | 2 ++ 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/markdown/bitburner.corporation.bribe.md b/markdown/bitburner.corporation.bribe.md index 4e7638eb4..6a0c5122d 100644 --- a/markdown/bitburner.corporation.bribe.md +++ b/markdown/bitburner.corporation.bribe.md @@ -8,6 +8,8 @@ Bribe a faction. You must satisfy these conditions: - The corporation valuation must be greater than or equal to a threshold. You can use [getCorporation](./bitburner.corporation.getcorporation.md) and [getConstants](./bitburner.corporation.getconstants.md) to get this information. +- You must be a member of the specified faction. + - The specified faction must offer at least 1 type of work. You can use [getFactionWorkTypes](./bitburner.singularity.getfactionworktypes.md) to get the list of work types of a faction. **Signature:** diff --git a/markdown/bitburner.corporation.md b/markdown/bitburner.corporation.md index ed27e29b9..5d9fd08d3 100644 --- a/markdown/bitburner.corporation.md +++ b/markdown/bitburner.corporation.md @@ -18,7 +18,7 @@ export interface Corporation extends WarehouseAPI, OfficeAPI | Method | Description | | --- | --- | | [acceptInvestmentOffer()](./bitburner.corporation.acceptinvestmentoffer.md) | Accept the investment offer. The value of offer is based on current corporation valuation. | -| [bribe(factionName, amountCash)](./bitburner.corporation.bribe.md) |
Bribe a faction. You must satisfy these conditions:
- The corporation valuation must be greater than or equal to a threshold. You can use [getCorporation](./bitburner.corporation.getcorporation.md) and [getConstants](./bitburner.corporation.getconstants.md) to get this information.
- The specified faction must offer at least 1 type of work. You can use [getFactionWorkTypes](./bitburner.singularity.getfactionworktypes.md) to get the list of work types of a faction.
| +| [bribe(factionName, amountCash)](./bitburner.corporation.bribe.md) |Bribe a faction. You must satisfy these conditions:
- The corporation valuation must be greater than or equal to a threshold. You can use [getCorporation](./bitburner.corporation.getcorporation.md) and [getConstants](./bitburner.corporation.getconstants.md) to get this information.
- You must be a member of the specified faction.
- The specified faction must offer at least 1 type of work. You can use [getFactionWorkTypes](./bitburner.singularity.getfactionworktypes.md) to get the list of work types of a faction.
| | [buyBackShares(amount)](./bitburner.corporation.buybackshares.md) | Buyback shares. Spend money from the player's wallet to transfer shares from public traders to the CEO. | | [canCreateCorporation(selfFund)](./bitburner.corporation.cancreatecorporation.md) | Return whether the player can create a corporation. Does not require API access. | | [createCorporation(corporationName, selfFund)](./bitburner.corporation.createcorporation.md) |Create a Corporation. You should use [canCreateCorporation](./bitburner.corporation.cancreatecorporation.md) to check if you are unsure you can do it, because it throws an error in these cases:
- Use seed money outside BitNode 3.
- Be in a BitNode that has CorporationSoftcap (a BitNode modifier) less than 0.15.
| diff --git a/src/Corporation/Actions.ts b/src/Corporation/Actions.ts index 8d35b2f18..831ded7dc 100644 --- a/src/Corporation/Actions.ts +++ b/src/Corporation/Actions.ts @@ -28,7 +28,7 @@ import { import { PositiveInteger, Result } from "../types"; import { Factions } from "../Faction/Factions"; import { throwIfReachable } from "../utils/helpers/throwIfReachable"; -import { formatMoney } from "../ui/formatNumber"; +import { formatMoney, formatNumber } from "../ui/formatNumber"; export function createCorporation(corporationName: string, selfFund: boolean, restart: boolean): Result { const checkResult = canCreateCorporation(selfFund, restart); @@ -632,16 +632,24 @@ export function bribe( fundsForBribing: number, factionName: FactionName, ): Result<{ reputationGain: number }> { - if (corporation.valuation < corpConstants.bribeThreshold) { - return { - success: false, - message: `The corporation valuation is below the threshold. Threshold: ${corpConstants.bribeThreshold}.`, - }; - } if (!Number.isFinite(fundsForBribing) || fundsForBribing <= 0 || corporation.funds < fundsForBribing) { return { success: false, - message: "Invalid amount of cash for bribing", + message: "Invalid amount of cash for bribing.", + }; + } + if (corporation.valuation < corpConstants.bribeThreshold) { + return { + success: false, + message: `The corporation valuation is below the threshold. Threshold: ${formatNumber( + corpConstants.bribeThreshold, + )}.`, + }; + } + if (!Player.factions.includes(factionName)) { + return { + success: false, + message: `You are not a member of ${factionName}.`, }; } const faction = Factions[factionName]; diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 84392dabc..bb0e70cde 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -9354,6 +9354,8 @@ export interface Corporation extends WarehouseAPI, OfficeAPI { * {@link Corporation.getCorporation | getCorporation} and {@link Corporation.getConstants | getConstants} to get this * information. * + * - You must be a member of the specified faction. + * * - The specified faction must offer at least 1 type of work. You can use * {@link Singularity.getFactionWorkTypes | getFactionWorkTypes} to get the list of work types of a faction. *