mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 01:33:54 +01:00
Add bribe
This commit is contained in:
parent
ea88f5f150
commit
62f40b3dc1
@ -59,6 +59,7 @@ import { IndustryResearchTrees, IndustryStartingCosts } from "../Corporation/Ind
|
|||||||
import { CorporationConstants } from "../Corporation/data/Constants";
|
import { CorporationConstants } from "../Corporation/data/Constants";
|
||||||
import { IndustryUpgrades } from "../Corporation/IndustryUpgrades";
|
import { IndustryUpgrades } from "../Corporation/IndustryUpgrades";
|
||||||
import { ResearchMap } from "../Corporation/ResearchMap";
|
import { ResearchMap } from "../Corporation/ResearchMap";
|
||||||
|
import { Factions } from "../Faction/Factions";
|
||||||
|
|
||||||
export function NetscriptCorporation(
|
export function NetscriptCorporation(
|
||||||
player: IPlayer,
|
player: IPlayer,
|
||||||
@ -189,6 +190,25 @@ export function NetscriptCorporation(
|
|||||||
return division.researched[researchName] === undefined ? false : division.researched[researchName] as boolean;
|
return division.researched[researchName] === undefined ? false : division.researched[researchName] as boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bribe(factionName: string, amountCash: number, amountShares: number): boolean {
|
||||||
|
if (!player.factions.includes(factionName)) throw new Error("Invalid faction name");
|
||||||
|
if (isNaN(amountCash) || amountCash < 0 || isNaN(amountShares) || amountShares < 0) throw new Error("Invalid value for amount field! Must be numeric, grater than 0.");
|
||||||
|
const corporation = getCorporation();
|
||||||
|
if (corporation.funds < amountCash) return false;
|
||||||
|
if (corporation.numShares < amountShares) return false;
|
||||||
|
const faction = Factions[factionName]
|
||||||
|
const info = faction.getInfo();
|
||||||
|
if (!info.offersWork()) return false;
|
||||||
|
if (player.hasGangWith(factionName)) return false;
|
||||||
|
|
||||||
|
const repGain = (amountCash + amountShares * corporation.sharePrice) / CorporationConstants.BribeToRepRatio;
|
||||||
|
faction.playerReputation += repGain;
|
||||||
|
corporation.funds = corporation.funds - amountCash;
|
||||||
|
corporation.numShares -= amountShares;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function getCorporation(): ICorporation {
|
function getCorporation(): ICorporation {
|
||||||
const corporation = player.corporation;
|
const corporation = player.corporation;
|
||||||
if (corporation === null) throw new Error("cannot be called without a corporation");
|
if (corporation === null) throw new Error("cannot be called without a corporation");
|
||||||
@ -396,7 +416,7 @@ export function NetscriptCorporation(
|
|||||||
const cityName = helper.string("buyMaterial", "cityName", acityName);
|
const cityName = helper.string("buyMaterial", "cityName", acityName);
|
||||||
const materialName = helper.string("buyMaterial", "materialName", amaterialName);
|
const materialName = helper.string("buyMaterial", "materialName", amaterialName);
|
||||||
const amt = helper.number("buyMaterial", "amt", aamt);
|
const amt = helper.number("buyMaterial", "amt", aamt);
|
||||||
if (amt < 0) throw new Error("Invalid value for ammount field! Must be numeric and grater than 0");
|
if (amt < 0) throw new Error("Invalid value for amount field! Must be numeric and grater than 0");
|
||||||
const material = getMaterial(divisionName, cityName, materialName);
|
const material = getMaterial(divisionName, cityName, materialName);
|
||||||
BuyMaterial(material, amt);
|
BuyMaterial(material, amt);
|
||||||
},
|
},
|
||||||
@ -747,10 +767,17 @@ export function NetscriptCorporation(
|
|||||||
checkAccess("acceptInvestmentOffer");
|
checkAccess("acceptInvestmentOffer");
|
||||||
return acceptInvestmentOffer();
|
return acceptInvestmentOffer();
|
||||||
},
|
},
|
||||||
goPublic(anumShares: any): boolean {
|
goPublic: function(anumShares: any): boolean {
|
||||||
checkAccess("acceptInvestmentOffer");
|
checkAccess("acceptInvestmentOffer");
|
||||||
const numShares = helper.number("goPublic", "numShares", anumShares);
|
const numShares = helper.number("goPublic", "numShares", anumShares);
|
||||||
return goPublic(numShares);
|
return goPublic(numShares);
|
||||||
},
|
},
|
||||||
|
bribe: function(afactionName: string, aamountCash: any, aamountShares: any): boolean {
|
||||||
|
checkAccess("bribe");
|
||||||
|
const factionName = helper.string("bribe", "factionName", afactionName);
|
||||||
|
const amountCash = helper.number("bribe", "amountCash", aamountCash);
|
||||||
|
const amountShares = helper.number("bribe", "amountShares", aamountShares);
|
||||||
|
return bribe(factionName, amountCash, amountShares);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
8
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
8
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -6425,6 +6425,14 @@ export interface Corporation extends WarehouseAPI, OfficeAPI {
|
|||||||
* @returns true if you successfully go public, false if not
|
* @returns true if you successfully go public, false if not
|
||||||
*/
|
*/
|
||||||
goPublic(numShares: number): boolean;
|
goPublic(numShares: number): boolean;
|
||||||
|
/**
|
||||||
|
* Bribe a faction
|
||||||
|
* @param factionName - Faction name
|
||||||
|
* @param amountCash - Amount of money to bribe
|
||||||
|
* @param amountShares - Amount of shares to bribe
|
||||||
|
* @return True if successful, false if not
|
||||||
|
*/
|
||||||
|
bribe(factionName: string, amountCash: number, amountShares: number): boolean;
|
||||||
/**
|
/**
|
||||||
* Get corporation data
|
* Get corporation data
|
||||||
* @returns Corporation data
|
* @returns Corporation data
|
||||||
|
Loading…
Reference in New Issue
Block a user