CORPORATION: Clarify ns.corporation.bribe() (#1766)

This commit is contained in:
catloversg 2024-11-11 13:53:27 +07:00 committed by GitHub
parent c638d858c6
commit 40651a757d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 45 additions and 18 deletions

@ -4,7 +4,11 @@
## Corporation.bribe() method ## Corporation.bribe() method
Bribe a 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. 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.
**Signature:** **Signature:**

@ -18,7 +18,7 @@ export interface Corporation extends WarehouseAPI, OfficeAPI
| Method | Description | | Method | Description |
| --- | --- | | --- | --- |
| [acceptInvestmentOffer()](./bitburner.corporation.acceptinvestmentoffer.md) | Accept the investment offer. The value of offer is based on current corporation valuation. | | [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. 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) | <p>Bribe a faction. You must satisfy these conditions:</p><p>- 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.</p><p>- 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.</p> |
| [buyBackShares(amount)](./bitburner.corporation.buybackshares.md) | Buyback shares. Spend money from the player's wallet to transfer shares from public traders to the CEO. | | [buyBackShares(amount)](./bitburner.corporation.buybackshares.md) | Buyback shares. Spend money from the player's wallet to transfer shares from public traders to the CEO. |
| [createCorporation(corporationName, selfFund)](./bitburner.corporation.createcorporation.md) | Create a Corporation. | | [createCorporation(corporationName, selfFund)](./bitburner.corporation.createcorporation.md) | Create a Corporation. |
| [expandCity(divisionName, city)](./bitburner.corporation.expandcity.md) | Expand to a new city. | | [expandCity(divisionName, city)](./bitburner.corporation.expandcity.md) | Expand to a new city. |

@ -23,7 +23,7 @@ import {
issueNewSharesFailureReason, issueNewSharesFailureReason,
costOfCreatingCorporation, costOfCreatingCorporation,
} from "./helpers"; } from "./helpers";
import { PositiveInteger } from "../types"; import { PositiveInteger, Result } from "../types";
import { currentNodeMults } from "../BitNode/BitNodeMultipliers"; import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
import { Factions } from "../Faction/Factions"; import { Factions } from "../Faction/Factions";
@ -640,22 +640,38 @@ export function setProductMarketTA2(product: Product, on: boolean): void {
product.marketTa2 = on; product.marketTa2 = on;
} }
export function bribe(corporation: Corporation, fundsForBribing: number, factionName: FactionName): number { export function bribe(
corporation: Corporation,
fundsForBribing: number,
factionName: FactionName,
): Result<{ reputationGain: number }> {
if (corporation.valuation < corpConstants.bribeThreshold) { if (corporation.valuation < corpConstants.bribeThreshold) {
return 0; return {
success: false,
message: `The corporation valuation is below the threshold. Threshold: ${corpConstants.bribeThreshold}.`,
};
} }
if (fundsForBribing <= 0 || corporation.funds < fundsForBribing) { if (!Number.isFinite(fundsForBribing) || fundsForBribing <= 0 || corporation.funds < fundsForBribing) {
return 0; return {
success: false,
message: "Invalid amount of cash for bribing",
};
} }
const faction = Factions[factionName]; const faction = Factions[factionName];
const factionInfo = faction.getInfo(); const factionInfo = faction.getInfo();
if (!factionInfo.offersWork()) { if (!factionInfo.offersWork()) {
return 0; return {
success: false,
message: `${factionName} cannot be bribed. It does not offer any types of work.`,
};
} }
const reputationGain = fundsForBribing / corpConstants.bribeAmountPerReputation; const reputationGain = fundsForBribing / corpConstants.bribeAmountPerReputation;
faction.playerReputation += reputationGain; faction.playerReputation += reputationGain;
corporation.loseFunds(fundsForBribing, "bribery"); corporation.loseFunds(fundsForBribing, "bribery");
return reputationGain; return {
success: true,
reputationGain,
};
} }

@ -55,10 +55,10 @@ export function BribeFactionModal(props: IProps): React.ReactElement {
return; return;
} }
const faction = Factions[selectedFaction]; const faction = Factions[selectedFaction];
const reputationGain = actions.bribe(corp, money, faction.name); const result = actions.bribe(corp, money, faction.name);
if (reputationGain > 0) { if (result.success) {
dialogBoxCreate( dialogBoxCreate(
`You gained ${formatReputation(reputationGain)} reputation with ${faction.name} by bribing them.`, `You gained ${formatReputation(result.reputationGain)} reputation with ${faction.name} by bribing them.`,
); );
} }
props.onClose(); props.onClose();

@ -759,12 +759,12 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
bribe: (ctx) => (_factionName, _amountCash) => { bribe: (ctx) => (_factionName, _amountCash) => {
checkAccess(ctx); checkAccess(ctx);
const factionName = getEnumHelper("FactionName").nsGetMember(ctx, _factionName); const factionName = getEnumHelper("FactionName").nsGetMember(ctx, _factionName);
const amountCash = helpers.number(ctx, "amountCash", _amountCash); const amountCash = helpers.positiveNumber(ctx, "amountCash", _amountCash);
if (isNaN(amountCash) || amountCash <= 0) { const result = bribe(getCorporation(), amountCash, factionName);
throw new Error("Invalid value for amount field! Must be numeric and greater than 0."); if (!result.success) {
helpers.log(ctx, () => result.message);
} }
return result.success;
return bribe(getCorporation(), amountCash, factionName) > 0;
}, },
getBonusTime: (ctx) => () => { getBonusTime: (ctx) => () => {
checkAccess(ctx); checkAccess(ctx);

@ -8911,7 +8911,14 @@ export interface Corporation extends WarehouseAPI, OfficeAPI {
goPublic(numShares: number): boolean; goPublic(numShares: number): boolean;
/** /**
* Bribe a 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. * Bribe a faction. You must satisfy these conditions:
*
* - The corporation valuation must be greater than or equal to a threshold. You can use
* {@link Corporation.getCorporation | getCorporation} and {@link Corporation.getConstants | getConstants} to get this
* information.
*
* - 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.
* *
* @remarks * @remarks
* RAM cost: 20 GB * RAM cost: 20 GB