mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-22 06:02:26 +01:00
removed the ability to bribe for shares
This commit is contained in:
parent
ebae95dd4a
commit
18c3572423
@ -89,5 +89,11 @@ Singularity
|
||||
|
||||
stock.buy and stock.sell
|
||||
------------------------
|
||||
|
||||
These 2 functions were renamed to stock.buyStock and stock.sellStock because 'buy' and 'sell'
|
||||
are very common tokens that would trick the ram calculation.
|
||||
are very common tokens that would trick the ram calculation.
|
||||
|
||||
corporation.bribe
|
||||
-----------------
|
||||
|
||||
The ability to give stocks as bribe has been removed. The signature is now bribe(faction, money)
|
@ -28,37 +28,27 @@ export function BribeFactionModal(props: IProps): React.ReactElement {
|
||||
});
|
||||
const corp = useCorporation();
|
||||
const [money, setMoney] = useState<number>(NaN);
|
||||
const [stock, setStock] = useState<number>(NaN);
|
||||
const [selectedFaction, setSelectedFaction] = useState(factions.length > 0 ? factions[0] : "");
|
||||
const disabled =
|
||||
(money === 0 && stock === 0) ||
|
||||
isNaN(money) ||
|
||||
isNaN(stock) ||
|
||||
money < 0 ||
|
||||
stock < 0 ||
|
||||
corp.funds < money ||
|
||||
stock > corp.numShares;
|
||||
const disabled = money === 0 || isNaN(money) || money < 0 || corp.funds < money;
|
||||
|
||||
function changeFaction(event: SelectChangeEvent<string>): void {
|
||||
setSelectedFaction(event.target.value);
|
||||
}
|
||||
|
||||
function repGain(money: number, stock: number): number {
|
||||
return (money + stock * corp.sharePrice) / CorporationConstants.BribeToRepRatio;
|
||||
function repGain(money: number): number {
|
||||
return money / CorporationConstants.BribeToRepRatio;
|
||||
}
|
||||
|
||||
function getRepText(money: number, stock: number): string {
|
||||
if (money === 0 && stock === 0) return "";
|
||||
if (isNaN(money) || isNaN(stock) || money < 0 || stock < 0) {
|
||||
function getRepText(money: number): string {
|
||||
if (money === 0) return "";
|
||||
if (isNaN(money) || money < 0) {
|
||||
return "ERROR: Invalid value(s) entered";
|
||||
} else if (corp.funds < money) {
|
||||
return "ERROR: You do not have this much money to bribe with";
|
||||
} else if (stock > corp.numShares) {
|
||||
return "ERROR: You do not have this many shares to bribe with";
|
||||
} else {
|
||||
return (
|
||||
"You will gain " +
|
||||
numeralWrapper.formatReputation(repGain(money, stock)) +
|
||||
numeralWrapper.formatReputation(repGain(money)) +
|
||||
" reputation with " +
|
||||
selectedFaction +
|
||||
" with this bribe"
|
||||
@ -66,16 +56,15 @@ export function BribeFactionModal(props: IProps): React.ReactElement {
|
||||
}
|
||||
}
|
||||
|
||||
function bribe(money: number, stock: number): void {
|
||||
function bribe(money: number): void {
|
||||
const fac = Factions[selectedFaction];
|
||||
if (disabled) return;
|
||||
const rep = repGain(money, stock);
|
||||
const rep = repGain(money);
|
||||
dialogBoxCreate(
|
||||
"You gained " + numeralWrapper.formatReputation(rep) + " reputation with " + fac.name + " by bribing them.",
|
||||
);
|
||||
fac.playerReputation += rep;
|
||||
corp.funds = corp.funds - money;
|
||||
corp.numShares -= stock;
|
||||
props.onClose();
|
||||
}
|
||||
|
||||
@ -99,10 +88,9 @@ export function BribeFactionModal(props: IProps): React.ReactElement {
|
||||
})}
|
||||
</Select>
|
||||
</Box>
|
||||
<Typography>{getRepText(money ? money : 0, stock ? stock : 0)}</Typography>
|
||||
<Typography>{getRepText(money ? money : 0)}</Typography>
|
||||
<NumberInput onChange={setMoney} placeholder="Corporation funds" />
|
||||
<NumberInput sx={{ mx: 1 }} onChange={setStock} placeholder="Stock Shares" />
|
||||
<Button disabled={disabled} sx={{ mx: 1 }} onClick={() => bribe(money ? money : 0, stock ? stock : 0)}>
|
||||
<Button disabled={disabled} sx={{ mx: 1 }} onClick={() => bribe(money ? money : 0)}>
|
||||
Bribe
|
||||
</Button>
|
||||
</Modal>
|
||||
|
@ -203,23 +203,21 @@ export function NetscriptCorporation(player: IPlayer): InternalAPI<NSCorporation
|
||||
return division.researched[researchName] === undefined ? false : (division.researched[researchName] as boolean);
|
||||
}
|
||||
|
||||
function bribe(factionName: string, amountCash: number, amountShares: number): boolean {
|
||||
function bribe(factionName: string, amountCash: number): boolean {
|
||||
if (!player.factions.includes(factionName)) throw new Error("Invalid faction name");
|
||||
if (isNaN(amountCash) || amountCash < 0 || isNaN(amountShares) || amountShares < 0)
|
||||
if (isNaN(amountCash) || amountCash < 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;
|
||||
const repGain = amountCash / CorporationConstants.BribeToRepRatio;
|
||||
faction.playerReputation += repGain;
|
||||
corporation.funds = corporation.funds - amountCash;
|
||||
corporation.numShares -= amountShares;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1034,12 +1032,11 @@ export function NetscriptCorporation(player: IPlayer): InternalAPI<NSCorporation
|
||||
},
|
||||
bribe:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_factionName: unknown, _amountCash: unknown, _amountShares: unknown): boolean => {
|
||||
(_factionName: unknown, _amountCash: unknown): boolean => {
|
||||
checkAccess(ctx);
|
||||
const factionName = ctx.helper.string("factionName", _factionName);
|
||||
const amountCash = ctx.helper.number("amountCash", _amountCash);
|
||||
const amountShares = ctx.helper.number("amountShares", _amountShares);
|
||||
return bribe(factionName, amountCash, amountShares);
|
||||
return bribe(factionName, amountCash);
|
||||
},
|
||||
getBonusTime: (ctx: NetscriptContext) => (): number => {
|
||||
checkAccess(ctx);
|
||||
|
3
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
3
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -6928,10 +6928,9 @@ export interface Corporation extends WarehouseAPI, OfficeAPI {
|
||||
* Bribe a faction
|
||||
* @param factionName - Faction name
|
||||
* @param amountCash - Amount of money to bribe
|
||||
* @param amountShares - Amount of shares to bribe
|
||||
* @returns True if successful, false if not
|
||||
*/
|
||||
bribe(factionName: string, amountCash: number, amountShares: number): boolean;
|
||||
bribe(factionName: string, amountCash: number): boolean;
|
||||
/**
|
||||
* Get corporation data
|
||||
* @returns Corporation data
|
||||
|
@ -40,3 +40,9 @@ function rerender(): void {
|
||||
throw new Error("You accidentally called window.print instead of ns.print");
|
||||
};
|
||||
})();
|
||||
|
||||
(function () {
|
||||
window.prompt = () => {
|
||||
throw new Error("You accidentally called window.prompt instead of ns.prompt");
|
||||
};
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user