mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
feat(content): new pet color achievements
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import findIndex from 'lodash/findIndex';
|
||||
import forEach from 'lodash/forEach';
|
||||
import get from 'lodash/get';
|
||||
import keys from 'lodash/keys';
|
||||
import upperFirst from 'lodash/upperFirst';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
@@ -40,21 +43,24 @@ module.exports = function hatch (user, req = {}) {
|
||||
user.markModified('items.hatchingPotions');
|
||||
}
|
||||
|
||||
if (!user.achievements.backToBasics) {
|
||||
const petIndex = findIndex(content.basePetsMounts, (animal) => {
|
||||
return isNaN(user.items.pets[animal]) || user.items.pets[animal] <= 0;
|
||||
});
|
||||
if (petIndex === -1) {
|
||||
user.achievements.backToBasics = true;
|
||||
if (user.addNotification) {
|
||||
user.addNotification('ACHIEVEMENT_BACK_TO_BASICS', {
|
||||
achievement: 'backToBasics',
|
||||
message: `${i18n.t('modalAchievement')} ${i18n.t('achievementBackToBasics')}`,
|
||||
modalText: i18n.t('achievementBackToBasicsModalText'),
|
||||
});
|
||||
forEach(content.animalColorAchievements, (achievement) => {
|
||||
if (!user.achievements[achievement.petAchievement]) {
|
||||
const petIndex = findIndex(keys(content.dropEggs), (animal) => {
|
||||
return isNaN(user.items.pets[`${animal}-${achievement.color}`]) || user.items.pets[`${animal}-${achievement.color}`] <= 0;
|
||||
});
|
||||
if (petIndex === -1) {
|
||||
user.achievements[achievement.petAchievement] = true;
|
||||
if (user.addNotification) {
|
||||
const achievementString = `achievement${upperFirst(achievement.petAchievement)}`;
|
||||
user.addNotification(achievement.petNotificationType, {
|
||||
achievement: achievement.petAchievement,
|
||||
message: `${i18n.t('modalAchievement')} ${i18n.t(achievementString)}`,
|
||||
modalText: i18n.t(`${achievementString}ModalText`),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return [
|
||||
user.items,
|
||||
|
||||
Reference in New Issue
Block a user