mirror of
https://github.com/Kvan7/Exiled-Exchange-2.git
synced 2026-09-26 06:35:45 +00:00
fix some rounding
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { statSourcesTotal, translateStatWithRoll } from '@/parser/modifiers'
|
||||
import { ParsedItem } from '@/parser/ParsedItem'
|
||||
import { percentRoll } from '../price-check/filters/util'
|
||||
import { roundRoll } from '../price-check/filters/util'
|
||||
|
||||
export interface PreparedStat {
|
||||
matcher: string
|
||||
@@ -14,7 +14,7 @@ export function prepareMapStats (item: ParsedItem): PreparedStat[] {
|
||||
|
||||
const prepared = {
|
||||
matcher: translation.string,
|
||||
roll: roll && percentRoll(roll.value, 0, Math.floor, translation.dp)
|
||||
roll: roll && roundRoll(roll.value, translation.dp ?? false)
|
||||
}
|
||||
|
||||
if (translation.negate) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import { computed, defineComponent, PropType } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import type { StatCalculated } from '@/parser/modifiers'
|
||||
import { applyIncr } from '@/parser/advanced-mod-desc'
|
||||
import { percentRoll } from './util'
|
||||
import { roundRoll } from './util'
|
||||
import ItemModifierText from '@/web/ui/ItemModifierText.vue'
|
||||
|
||||
export default defineComponent({
|
||||
@@ -69,7 +69,7 @@ export default defineComponent({
|
||||
const rollValue = parsed.roll.value * (parsed.translation.negate ? -1 : 1)
|
||||
return {
|
||||
text: parsed.translation.string,
|
||||
roll: percentRoll(rollValue, 0, Math.floor, parsed.roll.dp),
|
||||
roll: roundRoll(rollValue, parsed.roll.dp),
|
||||
contribution: contribution!,
|
||||
contributes: true
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ParsedItem, ItemRarity, ItemCategory } from '@/parser'
|
||||
import { ModifierType, StatCalculated, StatRoll, statSourcesTotal, translateStatWithRoll } from '@/parser/modifiers'
|
||||
import { uniqueModFilterPartial } from './unique-roll'
|
||||
import { rollToFilter, percentRoll } from './util'
|
||||
import { rollToFilter, percentRoll, roundRoll } from './util'
|
||||
import { FilterTag, ItemHasEmptyModifier, StatFilter } from './interfaces'
|
||||
import { filterPseudo } from './pseudo'
|
||||
import { filterItemProp } from './pseudo/item-property'
|
||||
@@ -152,7 +152,7 @@ function itemModFilterPartial (
|
||||
if (roll) {
|
||||
if (calc.type === ModifierType.Enchant) {
|
||||
filter.roll = {
|
||||
value: percentRoll(roll.value, 0, Math.floor, dp),
|
||||
value: roundRoll(roll.value, dp),
|
||||
min: percentRoll(roll.value, 0, Math.floor, dp),
|
||||
max: percentRoll(roll.value, 0, Math.ceil, dp),
|
||||
default: {
|
||||
|
||||
@@ -1,26 +1,32 @@
|
||||
import type { StatFilter } from './interfaces'
|
||||
|
||||
function showDecimals (value: number, dp: number | boolean): number {
|
||||
function decimalPlaces (value: number, dp: number | boolean): number {
|
||||
if (typeof dp === 'number') {
|
||||
return dp
|
||||
} else if (!dp || Math.abs(value) > 2) {
|
||||
} else if (!dp || Math.abs(value) >= 10) {
|
||||
return 0
|
||||
} else {
|
||||
return Math.abs(value) < 1 ? 2 : 1
|
||||
return Math.abs(value) < 2 ? 2 : 1
|
||||
}
|
||||
}
|
||||
|
||||
export function roundRoll (value: number, dp: number | boolean) {
|
||||
const round = Math.pow(10, decimalPlaces(value, dp))
|
||||
// round value down (toward zero)
|
||||
return Math.trunc(value * round) / round
|
||||
}
|
||||
|
||||
export function percentRoll (value: number, p: number, method: Math['floor'] | Math['ceil'], dp: number | boolean = false): number {
|
||||
const res = value + value * p / 100
|
||||
|
||||
const rounding = Math.pow(10, showDecimals(value, dp))
|
||||
const rounding = Math.pow(10, decimalPlaces(value, dp))
|
||||
return method((res + Number.EPSILON) * rounding) / rounding
|
||||
}
|
||||
|
||||
export function percentRollDelta (value: number, delta: number, p: number, method: Math['floor'] | Math['ceil'], dp = false): number {
|
||||
const res = value + delta * p / 100
|
||||
|
||||
const rounding = Math.pow(10, showDecimals(value, dp))
|
||||
const rounding = Math.pow(10, decimalPlaces(value, dp))
|
||||
return method((res + Number.EPSILON) * rounding) / rounding
|
||||
}
|
||||
|
||||
@@ -34,7 +40,7 @@ export function rollToFilter (
|
||||
// disabled by default, so opts.neverNegated acts more like
|
||||
// acknowledgment of what you are doing
|
||||
return {
|
||||
value: percentRoll(roll, 0, Math.floor, dp),
|
||||
value: roundRoll(roll, dp ?? false),
|
||||
default: {
|
||||
min: percentRoll(roll, -percent * Math.sign(roll), Math.floor, dp),
|
||||
max: percentRoll(roll, +percent * Math.sign(roll), Math.ceil, dp)
|
||||
|
||||
Reference in New Issue
Block a user