MISC: Refactor favor code (#1321)

This commit is contained in:
catloversg
2024-05-29 02:04:16 +07:00
committed by GitHub
parent b8d3109158
commit c2a56a6150
14 changed files with 117 additions and 68 deletions
+10 -4
View File
@@ -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);
}