From 3a5c22b3817a104328a9c921581f578a327014f4 Mon Sep 17 00:00:00 2001 From: Kalista Payne Date: Mon, 10 Nov 2025 18:01:04 -0600 Subject: [PATCH] feat(numbers!): rounding --- .../components/groups/questSidebarSection.vue | 8 +++---- website/client/src/components/ui/statsbar.vue | 2 +- website/client/src/filters/roundBigNumber.js | 6 ++--- website/client/src/libs/notifications.js | 2 +- website/client/src/mixins/notifications.js | 10 ++------ website/client/src/mixins/scoreTask.js | 2 +- website/client/src/mixins/spells.js | 2 +- website/common/script/ops/scoreTask.js | 24 ++++++++++++------- website/server/models/group.js | 8 +++---- 9 files changed, 33 insertions(+), 31 deletions(-) diff --git a/website/client/src/components/groups/questSidebarSection.vue b/website/client/src/components/groups/questSidebarSection.vue index 5b1e695388..d784ed29f5 100644 --- a/website/client/src/components/groups/questSidebarSection.vue +++ b/website/client/src/components/groups/questSidebarSection.vue @@ -134,10 +134,10 @@ > {{ (Math.ceil(parseFloat(group.quest.progress.hp) * 100) / 100) - | localizeNumber(user.preferences.language, { toFixed:2 }) + | localizeNumber(user.preferences.language, { toFixed: 0 }) }} / {{ parseFloat(questData.boss.hp) - | localizeNumber(user.preferences.language, { toFixed:2 }) + | localizeNumber(user.preferences.language, { toFixed: 0 }) }} HP @@ -160,7 +160,7 @@ {{ (user.party.quest.progress.up || 0) | floor(10) - | localizeNumber(user.preferences.language, { toFixed:1 }) + | localizeNumber(user.preferences.language, { toFixed: 0 }) }} {{ $t('pendingDamageLabel') }} @@ -198,7 +198,7 @@ class="float-left" >{{ $t('rage') }} {{ parseFloat(group.quest.progress.rage) - | localizeNumber(user.preferences.language, { toFixed: 2 }) + | localizeNumber(user.preferences.language, { toFixed: 0 }) }} / {{ questData.boss.rage.value | localizeNumber(user.preferences.language) diff --git a/website/client/src/components/ui/statsbar.vue b/website/client/src/components/ui/statsbar.vue index 7c28fe0658..cbf8d8b91b 100644 --- a/website/client/src/components/ui/statsbar.vue +++ b/website/client/src/components/ui/statsbar.vue @@ -113,7 +113,7 @@ export default { filters: { statFloor (value) { if (value < 1 && value > 0) { - return Math.ceil(value * 10) / 10; + return 1; } return Math.floor(value); }, diff --git a/website/client/src/filters/roundBigNumber.js b/website/client/src/filters/roundBigNumber.js index 18f54a9368..1c720238d2 100644 --- a/website/client/src/filters/roundBigNumber.js +++ b/website/client/src/filters/roundBigNumber.js @@ -1,15 +1,15 @@ import round from './round'; function _convertToThousand (num) { - return `${(num / (10 ** 3)).toFixed(1)}k`; + return `${(num / (10 ** 3)).toFixed(0)}k`; } function _convertToMillion (num) { - return `${(num / (10 ** 6)).toFixed(1)}m`; + return `${(num / (10 ** 6)).toFixed(0)}m`; } function _convertToBillion (num) { - return `${(num / (10 ** 9)).toFixed(1)}b`; + return `${(num / (10 ** 9)).toFixed(0)}b`; } export default function roundBigNumber (num) { diff --git a/website/client/src/libs/notifications.js b/website/client/src/libs/notifications.js index 7ab27a27a2..ca8627f49b 100644 --- a/website/client/src/libs/notifications.js +++ b/website/client/src/libs/notifications.js @@ -43,7 +43,7 @@ export function getSign (number) { } export function round (number, nDigits) { - return Math.abs(number.toFixed(nDigits || 1)); + return Math.abs(number.toFixed(nDigits || 0)); } export function getXPMessage (val) { diff --git a/website/client/src/mixins/notifications.js b/website/client/src/mixins/notifications.js index d489005cc1..ef78f8ed5d 100644 --- a/website/client/src/mixins/notifications.js +++ b/website/client/src/mixins/notifications.js @@ -4,19 +4,13 @@ import { getDropClass, getXPMessage, getSign, round, } from '@/libs/notifications'; -// See https://stackoverflow.com/questions/4187146/truncate-number-to-two-decimal-places-without-rounding -function toFixedWithoutRounding (num, fixed) { - const re = new RegExp(`^-?\\d+(?:\.\\d{0,${(fixed || -1)}})?`); // eslint-disable-line no-useless-escape - return num.toString().match(re)[0]; -} - export const NotificationMixins = { computed: { ...mapState({ notifications: 'notificationStore' }), }, methods: { coins (money) { - return this.round(money, 2); + return this.round(money, 0); }, crit (val) { const message = `${this.$t('critBonus')} ${Math.round(val)} %`; @@ -57,7 +51,7 @@ export const NotificationMixins = { }, mp (val) { const cleanMp = `${val}`.replace('-', '').replace('+', ''); - this.notify(`${this.sign(val)} ${toFixedWithoutRounding(cleanMp, 1)}`, 'mp', 'glyphicon glyphicon-fire', this.sign(val)); + this.notify(`${this.sign(val)} ${cleanMp < 0 ? Math.floor(cleanMp) : Math.ceil(cleanMp)}`, 'mp', 'glyphicon glyphicon-fire', this.sign(val)); }, purchased (itemName) { this.text(this.$t('purchasedItem', { diff --git a/website/client/src/mixins/scoreTask.js b/website/client/src/mixins/scoreTask.js index 492cabf46d..e92b197a8a 100644 --- a/website/client/src/mixins/scoreTask.js +++ b/website/client/src/mixins/scoreTask.js @@ -84,7 +84,7 @@ export default { if (quest && user.party.quest && user.party.quest.key) { const userQuest = Content.quests[user.party.quest.key]; if (quest.progressDelta && userQuest.boss) { - this.damage(quest.progressDelta.toFixed(1)); + this.damage(quest.progressDelta.toFixed(0)); } else if (quest.collection && userQuest.collect) { user.party.quest.progress.collectedItems += 1; this.quest('questCollection', quest.collection); diff --git a/website/client/src/mixins/spells.js b/website/client/src/mixins/spells.js index 0b2c445b02..fcfa5a1049 100644 --- a/website/client/src/mixins/spells.js +++ b/website/client/src/mixins/spells.js @@ -179,7 +179,7 @@ export default { if (questProgress > 0) { const userQuest = quests.quests[this.user.party.quest.key]; if (userQuest.boss) { - this.damage(questProgress.toFixed(1)); + this.damage(questProgress.toFixed(0)); } else if (userQuest.collection && userQuest.collect) { this.quest('questCollection', questProgress); } diff --git a/website/common/script/ops/scoreTask.js b/website/common/script/ops/scoreTask.js index b1451c1b12..d071941cdd 100644 --- a/website/common/script/ops/scoreTask.js +++ b/website/common/script/ops/scoreTask.js @@ -51,8 +51,10 @@ function _calculateDelta (task, direction, cron) { nextDelta *= 1 + reduce(task.checklist, (m, i) => m + (i.completed ? 1 : 0), 0); } } - - return nextDelta; + if (nextDelta < 0) { + return Math.floor(nextDelta); + } + return Math.ceil(nextDelta); } // Approximates the reverse delta for the task value @@ -89,12 +91,15 @@ function _calculateReverseDelta (task, direction) { nextDelta *= 1 + reduce(task.checklist, (m, i) => m + (i.completed ? 1 : 0), 0); } - return nextDelta; + if (nextDelta < 0) { + return Math.floor(nextDelta); + } + return Math.ceil(nextDelta); } function _gainMP (user, val) { val *= user._tmp.crit || 1; // eslint-disable-line no-param-reassign - user.stats.mp += val; + user.stats.mp += Math.ceil(val); if (user.stats.mp >= statsComputed(user).maxMP) user.stats.mp = statsComputed(user).maxMP; if (user.stats.mp < 0) { @@ -111,7 +116,7 @@ function _subtractPoints (user, task, stats, delta) { if (conBonus < 0.1) conBonus = 0.1; const hpMod = delta * conBonus * task.priority * 2; // constant 2 multiplier for better results - stats.hp += Math.round(hpMod * 10) / 10; // round to 1dp + stats.hp += Math.round(hpMod); // round to 0dp return stats.hp; } @@ -128,12 +133,12 @@ function _addPoints (user, task, stats, direction, delta) { // ===== PERCEPTION ===== // TODO Increases Gold gained from tasks by .3% per point. const perBonus = 1 + statsComputed(user).per * 0.02; - const gpMod = delta * task.priority * _crit * perBonus; + const gpMod = Math.ceil(delta * task.priority * _crit * perBonus); if (task.streak) { const currStreak = direction === 'down' ? task.streak - 1 : task.streak; const streakBonus = currStreak / 100 + 1; // eg, 1-day streak is 1.01, 2-day is 1.02, etc - const afterStreak = gpMod * streakBonus; + const afterStreak = Math.ceil(gpMod * streakBonus); if (currStreak > 0 && gpMod > 0) { // keep this on-hand for later, so we can notify streak-bonus user._tmp.streakBonus = afterStreak - gpMod; @@ -183,7 +188,10 @@ function _changeTaskValue (user, task, direction, times, cron) { addToDelta += nextDelta; }); - return addToDelta; + if (addToDelta < 0) { + return Math.floor(addToDelta); + } + return Math.ceil(addToDelta); } function _updateCounter (task, direction, times) { diff --git a/website/server/models/group.js b/website/server/models/group.js index 2517d01162..be06678ef7 100644 --- a/website/server/models/group.js +++ b/website/server/models/group.js @@ -1066,21 +1066,21 @@ schema.methods._processBossQuest = async function processBossQuest (options) { type: 'boss_dont_attack', user: user.profile.name, quest: group.quest.key, - userDamage: progress.up.toFixed(1), + userDamage: progress.up.toFixed(0), }, }); promises.push(groupMessage.save()); } else { const groupMessage = await group.sendChat({ message: `\`${shared.i18n.t('chatBossDamage', { - username: user.profile.name, bossName: quest.boss.name('en'), userDamage: progress.up.toFixed(1), bossDamage: Math.abs(down).toFixed(1), + username: user.profile.name, bossName: quest.boss.name('en'), userDamage: progress.up.toFixed(0), bossDamage: Math.abs(down).toFixed(0), }, user.preferences.language)}\``, info: { type: 'boss_damage', user: user.profile.name, quest: group.quest.key, - userDamage: progress.up.toFixed(1), - bossDamage: Math.abs(down).toFixed(1), + userDamage: progress.up.toFixed(0), + bossDamage: Math.abs(down).toFixed(0), }, }); promises.push(groupMessage.save());