mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-25 10:42:51 +02:00
BUGFIX: calculateExp throws errors in edge cases (#2667)
This commit is contained in:
@@ -5,6 +5,11 @@ import { clampNumber } from "../../utils/helpers/clampNumber";
|
||||
* stat level. Stat-agnostic (same formula for every stat)
|
||||
*/
|
||||
export function calculateSkill(exp: number, mult = 1): number {
|
||||
// Mult can be 0 in BN12 when the player has a very high SF12 level. In this case, the skill level will never change
|
||||
// from its initial value (1 for most stats, except intelligence).
|
||||
if (mult === 0) {
|
||||
return 1;
|
||||
}
|
||||
const value = Math.floor(mult * (32 * Math.log(exp + 534.6) - 200));
|
||||
return clampNumber(value, 1);
|
||||
}
|
||||
@@ -12,7 +17,7 @@ export function calculateSkill(exp: number, mult = 1): number {
|
||||
export function calculateExp(skill: number, mult = 1): number {
|
||||
const floorSkill = Math.floor(skill);
|
||||
let value = Math.exp((skill / mult + 200) / 32) - 534.6;
|
||||
if (skill === floorSkill && Number.isFinite(skill)) {
|
||||
if (skill === floorSkill && Number.isFinite(skill) && Number.isFinite(value)) {
|
||||
// Check for floating point rounding issues that would cause the inverse
|
||||
// operation to return the wrong result.
|
||||
let calcSkill = calculateSkill(value, mult);
|
||||
|
||||
Reference in New Issue
Block a user