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:
catloversg
2024-05-13 04:49:11 +07:00
committed by GitHub
parent da6262c856
commit 7f5bc5700e
3 changed files with 64 additions and 50 deletions
+8 -22
View File
@@ -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);