mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-30 12:57:06 +02:00
MISC: Refactor favor code (#1321)
This commit is contained in:
@@ -2,12 +2,18 @@
|
||||
// see https://en.wikipedia.org/wiki/Geometric_series#Closed-form_formula
|
||||
// for information on how to calculate this
|
||||
|
||||
import { clampNumber } from "../../utils/helpers/clampNumber";
|
||||
|
||||
export const MaxFavor = 35331;
|
||||
|
||||
export function favorToRep(f: number): number {
|
||||
const raw = 25000 * (Math.pow(1.02, f) - 1);
|
||||
return Math.round(raw * 10000) / 10000; // round to make things easier.
|
||||
return clampNumber(25000 * (Math.pow(1.02, f) - 1), 0);
|
||||
}
|
||||
|
||||
export function repToFavor(r: number): number {
|
||||
const raw = Math.log(r / 25000 + 1) / Math.log(1.02);
|
||||
return Math.round(raw * 10000) / 10000; // round to make things easier.
|
||||
return clampNumber(Math.log(r / 25000 + 1) / Math.log(1.02), 0, MaxFavor);
|
||||
}
|
||||
|
||||
export function calculateFavorAfterResetting(favor: number, playerReputation: number) {
|
||||
return repToFavor(favorToRep(favor) + playerReputation);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user