feat(numbers!): rounding

This commit is contained in:
Kalista Payne
2025-11-10 18:01:04 -06:00
parent bee23efbef
commit 851f74850a
9 changed files with 33 additions and 31 deletions

View File

@@ -134,10 +134,10 @@
></div>
{{
(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 })
}}
<strong>HP</strong>
@@ -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') }}
</span>
@@ -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)

View File

@@ -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);
},

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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', {

View File

@@ -94,7 +94,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);

View File

@@ -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);
}

View File

@@ -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) {

View File

@@ -1051,21 +1051,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());