mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-03-07 19:14:37 +01:00
CORPORATION: Refactor bribery (#1268)
This also removes the useless restriction Player.hasGangWith(factionName). When the corporation is strong enough to bribe, the gang is useless. This problem was discussed on Discord.
This commit is contained in:
@ -10,7 +10,7 @@ import { OfficeSpace } from "./OfficeSpace";
|
||||
import { Material } from "./Material";
|
||||
import { Product } from "./Product";
|
||||
import { Warehouse } from "./Warehouse";
|
||||
import { IndustryType } from "@enums";
|
||||
import { FactionName, IndustryType } from "@enums";
|
||||
import { ResearchMap } from "./ResearchMap";
|
||||
import { isRelevantMaterial } from "./ui/Helpers";
|
||||
import { CityName } from "@enums";
|
||||
@ -25,6 +25,7 @@ import {
|
||||
} from "./helpers";
|
||||
import { PositiveInteger } from "../types";
|
||||
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
|
||||
import { Factions } from "../Faction/Factions";
|
||||
|
||||
export function createCorporation(corporationName: string, selfFund: boolean, restart: boolean): boolean {
|
||||
if (!Player.canAccessCorporation()) {
|
||||
@ -628,3 +629,23 @@ export function SetProductMarketTA1(product: Product, on: boolean): void {
|
||||
export function SetProductMarketTA2(product: Product, on: boolean): void {
|
||||
product.marketTa2 = on;
|
||||
}
|
||||
|
||||
export function bribe(corporation: Corporation, fundsForBribing: number, factionName: FactionName): number {
|
||||
if (corporation.valuation < corpConstants.bribeThreshold) {
|
||||
return 0;
|
||||
}
|
||||
if (fundsForBribing <= 0 || corporation.funds < fundsForBribing) {
|
||||
return 0;
|
||||
}
|
||||
const faction = Factions[factionName];
|
||||
const factionInfo = faction.getInfo();
|
||||
if (!factionInfo.offersWork()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const reputationGain = fundsForBribing / corpConstants.bribeAmountPerReputation;
|
||||
faction.playerReputation += reputationGain;
|
||||
corporation.loseFunds(fundsForBribing, "bribery");
|
||||
|
||||
return reputationGain;
|
||||
}
|
||||
|
@ -5,13 +5,15 @@ import { Box, Button, MenuItem, Select, SelectChangeEvent, Typography } from "@m
|
||||
|
||||
import { Player } from "@player";
|
||||
import { Factions } from "../../../Faction/Factions";
|
||||
import * as corpConstants from "../../data/Constants";
|
||||
import { formatReputation } from "../../../ui/formatNumber";
|
||||
import { dialogBoxCreate } from "../../../ui/React/DialogBox";
|
||||
import { Modal } from "../../../ui/React/Modal";
|
||||
import { useCorporation } from "../Context";
|
||||
import { NumberInput } from "../../../ui/React/NumberInput";
|
||||
import { getEnumHelper } from "../../../utils/EnumHelper";
|
||||
import { bribeAmountPerReputation } from "../../data/Constants";
|
||||
import * as actions from "../../Actions";
|
||||
import { Settings } from "../../../Settings/Settings";
|
||||
|
||||
interface IProps {
|
||||
open: boolean;
|
||||
@ -20,9 +22,9 @@ interface IProps {
|
||||
|
||||
export function BribeFactionModal(props: IProps): React.ReactElement {
|
||||
const factions = Player.factions.filter((name) => {
|
||||
const info = Factions[name].getInfo();
|
||||
if (!info.offersWork()) return false;
|
||||
if (Player.hasGangWith(name)) return false;
|
||||
if (!Factions[name].getInfo().offersWork()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
const corp = useCorporation();
|
||||
@ -35,46 +37,45 @@ export function BribeFactionModal(props: IProps): React.ReactElement {
|
||||
setSelectedFaction(event.target.value);
|
||||
}
|
||||
|
||||
function repGain(money: number): number {
|
||||
return money / corpConstants.bribeAmountPerReputation;
|
||||
}
|
||||
|
||||
function getRepText(money: number): string {
|
||||
if (money === 0) return "";
|
||||
if (isNaN(money) || money < 0) {
|
||||
return "ERROR: Invalid value(s) entered";
|
||||
return "Invalid value.";
|
||||
} else if (corp.funds < money) {
|
||||
return "ERROR: You do not have this much money to bribe with";
|
||||
return "Your corporation does not have enough funds.";
|
||||
} else {
|
||||
return (
|
||||
"You will gain " + formatReputation(repGain(money)) + " reputation with " + selectedFaction + " with this bribe"
|
||||
);
|
||||
return `You will gain ${formatReputation(
|
||||
money / bribeAmountPerReputation,
|
||||
)} reputation with ${selectedFaction} with this bribe.`;
|
||||
}
|
||||
}
|
||||
|
||||
function bribe(money: number): void {
|
||||
if (!selectedFaction) return;
|
||||
const fac = Factions[selectedFaction];
|
||||
if (disabled) return;
|
||||
const rep = repGain(money);
|
||||
dialogBoxCreate(`You gained ${formatReputation(rep)} reputation with ${fac.name} by bribing them.`);
|
||||
fac.playerReputation += rep;
|
||||
corp.loseFunds(money, "bribery");
|
||||
if (!selectedFaction || disabled) {
|
||||
return;
|
||||
}
|
||||
const faction = Factions[selectedFaction];
|
||||
const reputationGain = actions.bribe(corp, money, faction.name);
|
||||
if (reputationGain > 0) {
|
||||
dialogBoxCreate(
|
||||
`You gained ${formatReputation(reputationGain)} reputation with ${faction.name} by bribing them.`,
|
||||
);
|
||||
}
|
||||
props.onClose();
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal open={props.open} onClose={props.onClose}>
|
||||
<Typography>
|
||||
You can use Corporation funds or stock shares to bribe Faction Leaders in exchange for faction reputation.
|
||||
You can use corporation funds to bribe faction leaders in exchange for faction reputation.
|
||||
</Typography>
|
||||
<Box display="flex" alignItems="center">
|
||||
<Typography>Faction:</Typography>
|
||||
<Typography style={{ whiteSpace: "pre" }}>Faction: </Typography>
|
||||
<Select value={selectedFaction} onChange={changeFaction}>
|
||||
{factions.map((name) => {
|
||||
const info = Factions[name].getInfo();
|
||||
if (!info.offersWork()) return;
|
||||
if (Player.hasGangWith(name)) return;
|
||||
if (!Factions[name].getInfo().offersWork()) {
|
||||
return;
|
||||
}
|
||||
return (
|
||||
<MenuItem key={name} value={name}>
|
||||
{name}
|
||||
@ -83,8 +84,14 @@ export function BribeFactionModal(props: IProps): React.ReactElement {
|
||||
})}
|
||||
</Select>
|
||||
</Box>
|
||||
<Typography>{getRepText(money ? money : 0)}</Typography>
|
||||
<NumberInput onChange={setMoney} placeholder="Corporation funds" />
|
||||
<Typography color={!disabled ? Settings.theme.primary : Settings.theme.error}>
|
||||
{getRepText(money ? money : 0)}
|
||||
</Typography>
|
||||
<NumberInput
|
||||
onChange={setMoney}
|
||||
placeholder="Corporation funds"
|
||||
defaultValue={!disabled ? money.toExponential() : ""}
|
||||
/>
|
||||
<Button disabled={disabled} sx={{ mx: 1 }} onClick={() => bribe(money ? money : 0)}>
|
||||
Bribe
|
||||
</Button>
|
||||
|
@ -52,14 +52,14 @@ import {
|
||||
UpgradeWarehouseCost,
|
||||
createCorporation,
|
||||
removeDivision,
|
||||
bribe,
|
||||
} from "../Corporation/Actions";
|
||||
import { CorpUnlocks } from "../Corporation/data/CorporationUnlocks";
|
||||
import { CorpUpgrades } from "../Corporation/data/CorporationUpgrades";
|
||||
import { CorpUnlockName, CorpUpgradeName, CorpEmployeeJob, CityName, FactionName } from "@enums";
|
||||
import { CorpUnlockName, CorpUpgradeName, CorpEmployeeJob, CityName } from "@enums";
|
||||
import { IndustriesData, IndustryResearchTrees } from "../Corporation/data/IndustryData";
|
||||
import * as corpConstants from "../Corporation/data/Constants";
|
||||
import { ResearchMap } from "../Corporation/ResearchMap";
|
||||
import { Factions } from "../Faction/Factions";
|
||||
import { InternalAPI, NetscriptContext, setRemovedFunctions } from "../Netscript/APIWrapper";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { getEnumHelper } from "../utils/EnumHelper";
|
||||
@ -102,24 +102,6 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
return division.researched.has(researchName);
|
||||
}
|
||||
|
||||
function bribe(factionName: FactionName, amountCash: number): boolean {
|
||||
if (isNaN(amountCash) || amountCash < 0)
|
||||
throw new Error("Invalid value for amount field! Must be numeric, greater than 0.");
|
||||
|
||||
const corporation = getCorporation();
|
||||
if (corporation.funds < amountCash) return false;
|
||||
const faction = Factions[factionName];
|
||||
const info = faction.getInfo();
|
||||
if (!info.offersWork()) return false;
|
||||
if (Player.hasGangWith(factionName)) return false;
|
||||
|
||||
const repGain = amountCash / corpConstants.bribeAmountPerReputation;
|
||||
faction.playerReputation += repGain;
|
||||
corporation.loseFunds(amountCash, "bribery");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getCorporation(): Corporation {
|
||||
const corporation = Player.corporation;
|
||||
if (corporation === null) throw new Error("cannot be called without a corporation");
|
||||
@ -755,7 +737,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
goPublic: (ctx) => (_numShares) => {
|
||||
checkAccess(ctx);
|
||||
const corporation = getCorporation();
|
||||
if (corporation.public) throw helpers.errorMessage(ctx, "corporation is already public");
|
||||
if (corporation.public) throw helpers.errorMessage(ctx, "Corporation is already public");
|
||||
const numShares = helpers.number(ctx, "numShares", _numShares);
|
||||
GoPublic(corporation, numShares);
|
||||
return true;
|
||||
@ -774,7 +756,11 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
checkAccess(ctx);
|
||||
const factionName = getEnumHelper("FactionName").nsGetMember(ctx, _factionName);
|
||||
const amountCash = helpers.number(ctx, "amountCash", _amountCash);
|
||||
return bribe(factionName, amountCash);
|
||||
if (isNaN(amountCash) || amountCash <= 0) {
|
||||
throw new Error("Invalid value for amount field! Must be numeric and greater than 0.");
|
||||
}
|
||||
|
||||
return bribe(getCorporation(), amountCash, factionName) > 0;
|
||||
},
|
||||
getBonusTime: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
|
Reference in New Issue
Block a user