diff --git a/app/modules/analyzer/objectDamage.ts b/app/modules/analyzer/objectDamage.ts index fa26662db..e7a59817f 100644 --- a/app/modules/analyzer/objectDamage.ts +++ b/app/modules/analyzer/objectDamage.ts @@ -11,7 +11,7 @@ import type { SubWeaponId, } from "../in-game-lists"; import { damageTypeToWeaponType, DAMAGE_RECEIVERS } from "./constants"; -import { roundToTwoDecimalPlaces } from "~/utils/number"; +import { roundToNDecimalPlaces } from "~/utils/number"; import { objectHitPoints } from "./objectHitPoints"; /** Keys to check in the json. Lower index takes priority over higher. If key is omitted means any key with valid weapon id is okay. One json key can only map to one DamageType. */ @@ -136,7 +136,7 @@ export function calculateDamage({ hitPoints: damageReceiverHp, damages: analyzed.stats.damages.map((damage) => { const multiplier = multipliers[damage.type]![receiver]; - const damagePerHit = roundToTwoDecimalPlaces(damage.value * multiplier); + const damagePerHit = roundToNDecimalPlaces(damage.value * multiplier); const hitsToDestroy = Math.ceil(damageReceiverHp / damagePerHit); diff --git a/app/modules/analyzer/stats.ts b/app/modules/analyzer/stats.ts index c6059f83c..5bd3badd0 100644 --- a/app/modules/analyzer/stats.ts +++ b/app/modules/analyzer/stats.ts @@ -22,7 +22,7 @@ import { } from "./utils"; import { assertUnreachable } from "~/utils/types"; import { semiRandomId } from "~/utils/strings"; -import { roundToTwoDecimalPlaces } from "~/utils/number"; +import { roundToNDecimalPlaces } from "~/utils/number"; export function buildStats({ weaponSplId, @@ -642,8 +642,8 @@ function shotSpreadAir( const reducedExtraSpread = extraSpread * (1 - effect); return { - baseValue: roundToTwoDecimalPlaces(jumpSpread), - value: roundToTwoDecimalPlaces(reducedExtraSpread + groundSpread), + baseValue: roundToNDecimalPlaces(jumpSpread), + value: roundToNDecimalPlaces(reducedExtraSpread + groundSpread), modifiedBy: SHOT_SPREAD_AIR_ABILITY, }; } @@ -788,9 +788,9 @@ export function subStats( const toValue = (effect: number) => { switch (type) { case "NO_CHANGE": - return roundToTwoDecimalPlaces(effect); + return roundToNDecimalPlaces(effect); case "HP": - return roundToTwoDecimalPlaces(hpDivided(effect)); + return roundToNDecimalPlaces(hpDivided(effect), 1); case "TIME": return framesToSeconds(effect); default: @@ -906,8 +906,8 @@ function subDefToxicMistMovementReduction( }); return { - baseValue: roundToTwoDecimalPlaces(baseEffect * 100), - value: roundToTwoDecimalPlaces(effect * 100), + baseValue: roundToNDecimalPlaces(baseEffect * 100), + value: roundToNDecimalPlaces(effect * 100), modifiedBy: SUB_DEF_TOXIC_MIST_MOVEMENT_REDUCTION_KEY, }; } @@ -930,10 +930,11 @@ function subDefAngleShooterDamage( invariant(angleShooterDirectDamage); return { - baseValue: roundToTwoDecimalPlaces( - (angleShooterDirectDamage * baseEffect) / 10 + baseValue: roundToNDecimalPlaces( + (angleShooterDirectDamage * baseEffect) / 10, + 1 ), - value: roundToTwoDecimalPlaces((angleShooterDirectDamage * effect) / 10), + value: roundToNDecimalPlaces((angleShooterDirectDamage * effect) / 10, 1), modifiedBy: SUB_DEF_ANGLE_SHOOTER_DAMAGE_KEY, }; } @@ -952,8 +953,8 @@ function subDefSplashWallDamagePercentage( }); return { - baseValue: roundToTwoDecimalPlaces(baseEffect * 100), - value: roundToTwoDecimalPlaces(effect * 100), + baseValue: roundToNDecimalPlaces(baseEffect * 100), + value: roundToNDecimalPlaces(effect * 100), modifiedBy: SUB_DEF_SPLASH_WALL_DAMAGE_PERCENTAGE_KEY, }; } @@ -972,8 +973,8 @@ function subDefSprinklerDamagePercentage( }); return { - baseValue: roundToTwoDecimalPlaces(baseEffect * 100), - value: roundToTwoDecimalPlaces(effect * 100), + baseValue: roundToNDecimalPlaces(baseEffect * 100), + value: roundToNDecimalPlaces(effect * 100), modifiedBy: SUB_DEF_SPRINKLER_DAMAGE_PERCENTAGE_KEY, }; } @@ -992,8 +993,8 @@ function subDefBombDamageLightPercentage( }); return { - baseValue: roundToTwoDecimalPlaces(baseEffect * 100), - value: roundToTwoDecimalPlaces(effect * 100), + baseValue: roundToNDecimalPlaces(baseEffect * 100), + value: roundToNDecimalPlaces(effect * 100), modifiedBy: SUB_DEF_BOMB_DAMAGE_LIGHT_PERCENTAGE_KEY, }; } @@ -1012,8 +1013,8 @@ function subDefBombDamageHeavyPercentage( }); return { - baseValue: roundToTwoDecimalPlaces(baseEffect * 100), - value: roundToTwoDecimalPlaces(effect * 100), + baseValue: roundToNDecimalPlaces(baseEffect * 100), + value: roundToNDecimalPlaces(effect * 100), modifiedBy: SUB_DEF_BOMB_DAMAGE_HEAVY_PERCENTAGE_KEY, }; } @@ -1099,8 +1100,8 @@ function specialDamageDistance( }); return { - baseValue: roundToTwoDecimalPlaces(baseEffect), - value: roundToTwoDecimalPlaces(effect), + baseValue: roundToNDecimalPlaces(baseEffect), + value: roundToNDecimalPlaces(effect), modifiedBy: SPECIAL_DAMAGE_DISTANCE_KEY, }; } @@ -1123,8 +1124,8 @@ function specialPaintRadius( }); return { - baseValue: roundToTwoDecimalPlaces(baseEffect), - value: roundToTwoDecimalPlaces(effect), + baseValue: roundToNDecimalPlaces(baseEffect), + value: roundToNDecimalPlaces(effect), modifiedBy: SPECIAL_PAINT_RADIUS_KEY, }; } @@ -1200,8 +1201,8 @@ function specialHookInkConsumptionPercentage( }); return { - baseValue: roundToTwoDecimalPlaces(baseEffect * 100), - value: roundToTwoDecimalPlaces(effect * 100), + baseValue: roundToNDecimalPlaces(baseEffect * 100), + value: roundToNDecimalPlaces(effect * 100), modifiedBy: SPECIAL_HOOK_INK_CONSUMPTION_PERCENTAGE_KEY, }; } @@ -1229,8 +1230,8 @@ function specialInkConsumptionPerSecondPercentage( }); return { - baseValue: roundToTwoDecimalPlaces(baseEffect * 100), - value: roundToTwoDecimalPlaces(effect * 100), + baseValue: roundToNDecimalPlaces(baseEffect * 100), + value: roundToNDecimalPlaces(effect * 100), modifiedBy: SPECIAL_INK_CONSUMPTION_PER_SECOND_PERCENTAGE_KEY, }; } @@ -1258,8 +1259,8 @@ function specialReticleRadius( }); return { - baseValue: roundToTwoDecimalPlaces(baseEffect), - value: roundToTwoDecimalPlaces(effect), + baseValue: roundToNDecimalPlaces(baseEffect), + value: roundToNDecimalPlaces(effect), modifiedBy: SPECIAL_RETICLE_RADIUS_KEY, }; } @@ -1287,8 +1288,8 @@ function specialThrowDistance( }); return { - baseValue: roundToTwoDecimalPlaces(baseEffect), - value: roundToTwoDecimalPlaces(effect), + baseValue: roundToNDecimalPlaces(baseEffect), + value: roundToNDecimalPlaces(effect), modifiedBy: SPECIAL_THROW_DISTANCE_KEY, }; } @@ -1316,8 +1317,8 @@ function specialAutoChargeRate( }); return { - baseValue: roundToTwoDecimalPlaces(baseEffect * 100), - value: roundToTwoDecimalPlaces(effect * 100), + baseValue: roundToNDecimalPlaces(baseEffect * 100), + value: roundToNDecimalPlaces(effect * 100), modifiedBy: SPECIAL_AUTO_CHARGE_RATE_KEY, }; } @@ -1345,8 +1346,8 @@ function specialMaxRadius( }); return { - baseValue: roundToTwoDecimalPlaces(baseEffect), - value: roundToTwoDecimalPlaces(effect), + baseValue: roundToNDecimalPlaces(baseEffect), + value: roundToNDecimalPlaces(effect), modifiedBy: SPECIAL_MAX_RADIUS_KEY, }; } @@ -1387,12 +1388,12 @@ function specialRadiusRange( }); return { - baseValue: `${roundToTwoDecimalPlaces( + baseValue: `${roundToNDecimalPlaces( radiusMin.baseEffect - )}-${roundToTwoDecimalPlaces(radiusMax.baseEffect)}`, - value: `${roundToTwoDecimalPlaces( - radiusMin.effect - )}-${roundToTwoDecimalPlaces(radiusMax.effect)}`, + )}-${roundToNDecimalPlaces(radiusMax.baseEffect)}`, + value: `${roundToNDecimalPlaces(radiusMin.effect)}-${roundToNDecimalPlaces( + radiusMax.effect + )}`, modifiedBy: SPECIAL_RADIUS_RANGE_KEY, }; } diff --git a/app/routes/plus/voting/results.tsx b/app/routes/plus/voting/results.tsx index 77c4ec576..e6325ea85 100644 --- a/app/routes/plus/voting/results.tsx +++ b/app/routes/plus/voting/results.tsx @@ -9,7 +9,7 @@ import { lastCompletedVoting } from "~/modules/plus-server"; import { db } from "~/db"; import type { PlusVotingResultByMonthYear } from "~/db/models/plusVotes/queries.server"; import type { PlusVotingResult } from "~/db/types"; -import { roundToTwoDecimalPlaces } from "~/utils/number"; +import { roundToNDecimalPlaces } from "~/utils/number"; import { makeTitle } from "~/utils/strings"; import type { Unpacked } from "~/utils/types"; import styles from "~/styles/plus-history.css"; @@ -147,7 +147,7 @@ function Results({ function databaseAvgToPercentage(score: number) { const scoreNormalized = score + 1; - return roundToTwoDecimalPlaces((scoreNormalized / 2) * 100); + return roundToNDecimalPlaces((scoreNormalized / 2) * 100); } function scoreForDisplaying( diff --git a/app/utils/number.ts b/app/utils/number.ts index e2a50a234..c3dd188e3 100644 --- a/app/utils/number.ts +++ b/app/utils/number.ts @@ -1,3 +1,3 @@ -export function roundToTwoDecimalPlaces(num: number) { - return Number((Math.round(num * 100) / 100).toFixed(2)); +export function roundToNDecimalPlaces(num: number, n = 2) { + return Number((Math.round(num * 100) / 100).toFixed(n)); }