mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
Merge branch 'develop' into negue/modal-notifications
This commit is contained in:
@@ -221,10 +221,8 @@ export default {
|
||||
...mapState({
|
||||
user: 'user.data',
|
||||
userHp: 'user.data.stats.hp',
|
||||
userExp: 'user.data.stats.exp',
|
||||
userGp: 'user.data.stats.gp',
|
||||
userMp: 'user.data.stats.mp',
|
||||
userLvl: 'user.data.stats.lvl',
|
||||
userNotifications: 'user.data.notifications',
|
||||
userAchievements: 'user.data.achievements', // @TODO: does this watch deeply?
|
||||
armoireEmpty: 'user.data.flags.armoireEmpty',
|
||||
@@ -233,9 +231,15 @@ export default {
|
||||
userClassSelect () {
|
||||
return !this.user.flags.classSelected && this.user.stats.lvl >= 10;
|
||||
},
|
||||
userHasClass () {
|
||||
return this.$store.getters['members:hasClass'](this.user);
|
||||
},
|
||||
invitedToQuest () {
|
||||
return this.user.party.quest.RSVPNeeded && !this.user.party.quest.completed;
|
||||
},
|
||||
userExpAndLvl () {
|
||||
return [this.user.stats.exp, this.user.stats.lvl];
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
userHp (after, before) {
|
||||
@@ -253,16 +257,6 @@ export default {
|
||||
|
||||
if (after < 0) this.playSound('Minus_Habit');
|
||||
},
|
||||
userExp (after, before) {
|
||||
if (after === before) return;
|
||||
if (this.user.stats.lvl === 0) return;
|
||||
|
||||
let exp = after - before;
|
||||
if (exp < -50) { // recalculate exp if user level up
|
||||
exp = toNextLevel(this.user.stats.lvl - 1) - before + after;
|
||||
}
|
||||
this.exp(exp);
|
||||
},
|
||||
userGp (after, before) {
|
||||
if (after === before) return;
|
||||
if (this.user.stats.lvl === 0) return;
|
||||
@@ -283,15 +277,11 @@ export default {
|
||||
},
|
||||
userMp (after, before) {
|
||||
if (after === before) return;
|
||||
if (!this.$store.getters['members:hasClass'](this.user)) return;
|
||||
if (!this.userHasClass) return;
|
||||
|
||||
let mana = after - before;
|
||||
const mana = after - before;
|
||||
this.mp(mana);
|
||||
},
|
||||
userLvl (after, before) {
|
||||
if (after <= before || this.$store.state.isRunningYesterdailies) return;
|
||||
this.showLevelUpNotifications(after);
|
||||
},
|
||||
userClassSelect (after) {
|
||||
if (this.user.needsCron) return;
|
||||
if (!after) return;
|
||||
@@ -315,6 +305,9 @@ export default {
|
||||
if (after !== true) return;
|
||||
this.$root.$emit('bv::show::modal', 'quest-invitation');
|
||||
},
|
||||
userExpAndLvl (after, before) {
|
||||
this.displayUserExpAndLvlNotifications(after[0], before[0], after[1], before[1]);
|
||||
},
|
||||
},
|
||||
mounted () {
|
||||
Promise.all([
|
||||
@@ -385,6 +378,35 @@ export default {
|
||||
debounceCheckUserAchievements: debounce(function debounceCheck () {
|
||||
this.checkUserAchievements();
|
||||
}, 700),
|
||||
displayUserExpAndLvlNotifications (afterExp, beforeExp, afterLvl, beforeLvl) {
|
||||
if (afterExp === beforeExp && afterLvl === beforeLvl) return;
|
||||
|
||||
// XP evaluation
|
||||
if (afterExp !== beforeExp) {
|
||||
if (this.user.stats.lvl === 0) return;
|
||||
|
||||
const lvlUps = afterLvl - beforeLvl;
|
||||
let exp = afterExp - beforeExp;
|
||||
|
||||
if (lvlUps > 0) {
|
||||
let level = Math.trunc(beforeLvl);
|
||||
exp += toNextLevel(level);
|
||||
|
||||
// loop if more than 1 lvl up
|
||||
for (let i = 1; i < lvlUps; i += 1) {
|
||||
level += 1;
|
||||
exp += toNextLevel(level);
|
||||
}
|
||||
}
|
||||
this.exp(exp);
|
||||
}
|
||||
|
||||
// Lvl evaluation
|
||||
if (afterLvl !== beforeLvl) {
|
||||
if (afterLvl <= beforeLvl || this.$store.state.isRunningYesterdailies) return;
|
||||
this.showLevelUpNotifications(afterLvl);
|
||||
}
|
||||
},
|
||||
checkUserAchievements () {
|
||||
if (this.user.needsCron) return;
|
||||
|
||||
@@ -560,7 +582,7 @@ export default {
|
||||
case 'CRON':
|
||||
if (notification.data) {
|
||||
if (notification.data.hp) this.hp(notification.data.hp, 'hp');
|
||||
if (notification.data.mp) this.mp(notification.data.mp);
|
||||
if (notification.data.mp && this.userHasClass) this.mp(notification.data.mp);
|
||||
}
|
||||
break;
|
||||
case 'SCORED_TASK':
|
||||
|
||||
Reference in New Issue
Block a user