mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-19 20:55:44 +01:00
FIX: singularity faction donation formula (#619)
This commit is contained in:
parent
08e3afd125
commit
78ca279df7
@ -1,7 +1,31 @@
|
||||
import { Person as IPerson } from "@nsdefs";
|
||||
import { Player } from "@player";
|
||||
|
||||
import { CONSTANTS } from "../../Constants";
|
||||
import { currentNodeMults } from "../../BitNode/BitNodeMultipliers";
|
||||
import { Person as IPerson } from "@nsdefs";
|
||||
import { Faction } from "../Faction";
|
||||
|
||||
export function repFromDonation(amt: number, person: IPerson): number {
|
||||
return (amt / CONSTANTS.DonateMoneyToRepDivisor) * person.mults.faction_rep * currentNodeMults.FactionWorkRepGain;
|
||||
}
|
||||
|
||||
export function repNeededToDonate(): number {
|
||||
return Math.floor(CONSTANTS.BaseFavorToDonate * currentNodeMults.RepToDonateToFaction);
|
||||
}
|
||||
|
||||
export function canDonate(amt: number): boolean {
|
||||
return !isNaN(amt) && amt > 0 && Player.money >= amt;
|
||||
}
|
||||
|
||||
/** Donates money to the faction provided and returns repuation gained */
|
||||
export function donate(amt: number, faction: Faction) {
|
||||
if (!canDonate(amt)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const repGain = repFromDonation(amt, Player);
|
||||
Player.loseMoney(amt, "other");
|
||||
faction.playerReputation += repGain;
|
||||
|
||||
return repGain;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import React, { useState } from "react";
|
||||
import { CONSTANTS } from "../../Constants";
|
||||
import { Faction } from "../Faction";
|
||||
import { Player } from "@player";
|
||||
import { repFromDonation } from "../formulas/donation";
|
||||
import { canDonate, donate, repFromDonation } from "../formulas/donation";
|
||||
import { Favor } from "../../ui/React/Favor";
|
||||
|
||||
import { Money } from "../../ui/React/Money";
|
||||
@ -17,44 +17,34 @@ import Paper from "@mui/material/Paper";
|
||||
import Button from "@mui/material/Button";
|
||||
import { NumberInput } from "../../ui/React/NumberInput";
|
||||
|
||||
interface IProps {
|
||||
type DonateOptionProps = {
|
||||
faction: Faction;
|
||||
disabled: boolean;
|
||||
favorToDonate: number;
|
||||
rerender: () => void;
|
||||
}
|
||||
};
|
||||
|
||||
/** React component for a donate option on the Faction UI */
|
||||
export function DonateOption(props: IProps): React.ReactElement {
|
||||
export function DonateOption({ faction, favorToDonate, disabled, rerender }: DonateOptionProps): React.ReactElement {
|
||||
const [donateAmt, setDonateAmt] = useState<number>(NaN);
|
||||
const digits = (CONSTANTS.DonateMoneyToRepDivisor + "").length - 1;
|
||||
|
||||
function canDonate(): boolean {
|
||||
if (isNaN(donateAmt)) return false;
|
||||
if (isNaN(donateAmt) || donateAmt <= 0) return false;
|
||||
if (Player.money < donateAmt) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function donate(): void {
|
||||
const fac = props.faction;
|
||||
const amt = donateAmt;
|
||||
if (isNaN(amt)) return;
|
||||
if (!canDonate()) return;
|
||||
Player.loseMoney(amt, "other");
|
||||
const repGain = repFromDonation(amt, Player);
|
||||
props.faction.playerReputation += repGain;
|
||||
dialogBoxCreate(
|
||||
<>
|
||||
You just donated <Money money={amt} /> to {fac.name} to gain <Reputation reputation={repGain} /> reputation.
|
||||
</>,
|
||||
);
|
||||
props.rerender();
|
||||
function onDonate(): void {
|
||||
const repGain = donate(donateAmt, faction);
|
||||
if (repGain > 0) {
|
||||
dialogBoxCreate(
|
||||
<>
|
||||
You just donated <Money money={donateAmt} /> to {faction.name} to gain <Reputation reputation={repGain} />{" "}
|
||||
reputation.
|
||||
</>,
|
||||
);
|
||||
rerender();
|
||||
}
|
||||
}
|
||||
|
||||
function Status(): React.ReactElement {
|
||||
if (isNaN(donateAmt)) return <></>;
|
||||
if (!canDonate()) {
|
||||
if (!canDonate(donateAmt)) {
|
||||
if (Player.money < donateAmt) return <Typography>Insufficient funds</Typography>;
|
||||
return <Typography>Invalid donate amount entered!</Typography>;
|
||||
}
|
||||
@ -68,19 +58,19 @@ export function DonateOption(props: IProps): React.ReactElement {
|
||||
return (
|
||||
<Paper sx={{ my: 1, p: 1 }}>
|
||||
<Status />
|
||||
{props.disabled ? (
|
||||
{disabled ? (
|
||||
<Typography>
|
||||
Unlock donations at <Favor favor={props.favorToDonate} /> favor with {props.faction.name}
|
||||
Unlock donations at <Favor favor={favorToDonate} /> favor with {faction.name}
|
||||
</Typography>
|
||||
) : (
|
||||
<>
|
||||
<NumberInput
|
||||
onChange={setDonateAmt}
|
||||
placeholder={"Donation amount"}
|
||||
disabled={props.disabled}
|
||||
disabled={disabled}
|
||||
InputProps={{
|
||||
endAdornment: (
|
||||
<Button onClick={donate} disabled={props.disabled || !canDonate()}>
|
||||
<Button onClick={onDonate} disabled={disabled || !canDonate(donateAmt)}>
|
||||
donate
|
||||
</Button>
|
||||
),
|
||||
|
@ -10,21 +10,19 @@ import { DonateOption } from "./DonateOption";
|
||||
import { Info } from "./Info";
|
||||
import { Option } from "./Option";
|
||||
|
||||
import { CONSTANTS } from "../../Constants";
|
||||
|
||||
import { currentNodeMults } from "../../BitNode/BitNodeMultipliers";
|
||||
import { Faction } from "../Faction";
|
||||
|
||||
import { Router } from "../../ui/GameRoot";
|
||||
import { Page } from "../../ui/Router";
|
||||
import { Player } from "@player";
|
||||
|
||||
import { Typography, Button } from "@mui/material";
|
||||
|
||||
import { CovenantPurchasesRoot } from "../../PersonObjects/Sleeve/ui/CovenantPurchasesRoot";
|
||||
import { FactionName, FactionWorkType } from "@enums";
|
||||
import { GangButton } from "./GangButton";
|
||||
import { FactionWork } from "../../Work/FactionWork";
|
||||
import { useRerender } from "../../ui/React/hooks";
|
||||
import { repNeededToDonate } from "../formulas/donation";
|
||||
|
||||
interface IProps {
|
||||
faction: Faction;
|
||||
@ -107,9 +105,8 @@ function MainPage({ faction, rerender, onAugmentations }: IMainProps): React.Rea
|
||||
|
||||
// Flags for whether special options (gang, sleeve purchases, donate, etc.)
|
||||
// should be shown
|
||||
const favorToDonate = Math.floor(CONSTANTS.BaseFavorToDonate * currentNodeMults.RepToDonateToFaction);
|
||||
const favorToDonate = repNeededToDonate();
|
||||
const canDonate = faction.favor >= favorToDonate;
|
||||
|
||||
const canPurchaseSleeves = faction.name === FactionName.TheCovenant && Player.bitNodeN === 10;
|
||||
|
||||
return (
|
||||
|
@ -42,6 +42,7 @@ import { calculateHackingTime } from "../Hacking";
|
||||
import { Server } from "../Server/Server";
|
||||
import { netscriptCanHack } from "../Hacking/netscriptCanHack";
|
||||
import { FactionInfos } from "../Faction/FactionInfo";
|
||||
import { donate, repNeededToDonate } from "../Faction/formulas/donation";
|
||||
import { InternalAPI, NetscriptContext, removedFunction } from "../Netscript/APIWrapper";
|
||||
import { enterBitNode } from "../RedPill";
|
||||
import { ClassWork } from "../Work/ClassWork";
|
||||
@ -1027,18 +1028,18 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
helpers.log(ctx, () => `You do not have enough money to donate ${formatMoney(amt)} to '${facName}'`);
|
||||
return false;
|
||||
}
|
||||
const repNeededToDonate = Math.floor(CONSTANTS.BaseFavorToDonate * currentNodeMults.RepToDonateToFaction);
|
||||
if (faction.favor < repNeededToDonate) {
|
||||
|
||||
if (faction.favor < repNeededToDonate()) {
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`You do not have enough favor to donate to this faction. Have ${faction.favor}, need ${repNeededToDonate}`,
|
||||
`You do not have enough favor to donate to this faction. Have ${
|
||||
faction.favor
|
||||
}, need ${repNeededToDonate()}`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
const repGain = (amt / CONSTANTS.DonateMoneyToRepDivisor) * Player.mults.faction_rep;
|
||||
faction.playerReputation += repGain;
|
||||
Player.loseMoney(amt, "other");
|
||||
const repGain = donate(amt, faction);
|
||||
helpers.log(ctx, () => `${formatMoney(amt)} donated to '${facName}' for ${formatReputation(repGain)} reputation`);
|
||||
return true;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user