API: Add donationForRep() to Formulas (#1141)

This commit is contained in:
LJ
2025-02-11 23:05:32 -07:00
committed by GitHub
parent b61e93b246
commit 30075f3c07
4 changed files with 19 additions and 1 deletions

View File

@@ -9,6 +9,10 @@ export function repFromDonation(amt: number, person: IPerson): number {
return (amt / CONSTANTS.DonateMoneyToRepDivisor) * person.mults.faction_rep * currentNodeMults.FactionWorkRepGain;
}
export function donationForRep(rep: number, person: IPerson): number {
return (rep * CONSTANTS.DonateMoneyToRepDivisor) / person.mults.faction_rep / currentNodeMults.FactionWorkRepGain;
}
export function repNeededToDonate(): number {
return Math.floor(CONSTANTS.BaseFavorToDonate * currentNodeMults.RepToDonateToFaction);
}

View File

@@ -632,6 +632,7 @@ export const RamCosts: RamCostTree<NSFull> = {
calculateFavorToRep: 0,
calculateRepToFavor: 0,
repFromDonation: 0,
donationForRep: 0,
},
skills: {
calculateSkill: 0,

View File

@@ -37,7 +37,7 @@ import {
calculateAscensionPointsGain,
} from "../Gang/formulas/formulas";
import { favorToRep as calculateFavorToRep, repToFavor as calculateRepToFavor } from "../Faction/formulas/favor";
import { repFromDonation } from "../Faction/formulas/donation";
import { repFromDonation, donationForRep } from "../Faction/formulas/donation";
import { InternalAPI, NetscriptContext, setRemovedFunctions } from "../Netscript/APIWrapper";
import { helpers } from "../Netscript/NetscriptHelpers";
import { calculateCrimeWorkStats } from "../Work/Formulas";
@@ -128,6 +128,12 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
checkFormulasAccess(ctx);
return repFromDonation(amount, person);
},
donationForRep: (ctx) => (_reputation, _player) => {
const reputation = helpers.number(ctx, "reputation", _reputation);
const person = helpers.person(ctx, _player);
checkFormulasAccess(ctx);
return donationForRep(reputation, person);
},
},
skills: {
calculateSkill:

View File

@@ -5209,6 +5209,13 @@ interface ReputationFormulas {
* @param player - Player info, typically from {@link NS.getPlayer | getPlayer}
*/
repFromDonation(amount: number, player: Person): number;
/**
* Calculate the donation needed to gain an amount of reputation.
* @param reputation - Amount of reputation
* @param player - Player info, typically from {@link NS.getPlayer | getPlayer}
*/
donationForRep(reputation: number, player: Person): number;
}
/**