diff --git a/migrations/archive/2023/20231017_pet_group_achievements.js b/migrations/archive/2023/20231017_pet_group_achievements.js new file mode 100644 index 0000000000..25c46f2c16 --- /dev/null +++ b/migrations/archive/2023/20231017_pet_group_achievements.js @@ -0,0 +1,118 @@ +/* eslint-disable no-console */ +const MIGRATION_NAME = '20231017_pet_group_achievements'; +import { model as User } from '../../../website/server/models/user'; + +const progressCount = 1000; +let count = 0; + +async function updateUser (user) { + count++; + + const set = { + migration: MIGRATION_NAME, + }; + + if (user && user.items && user.items.pets) { + const pets = user.items.pets; + if (pets['Armadillo-Base'] + && pets['Armadillo-CottonCandyBlue'] + && pets['Armadillo-CottonCandyPink'] + && pets['Armadillo-Desert'] + && pets['Armadillo-Golden'] + && pets['Armadillo-Red'] + && pets['Armadillo-Shade'] + && pets['Armadillo-Skeleton'] + && pets['Armadillo-White'] + && pets['Armadillo-Zombie'] + && pets['Cactus-Base'] + && pets['Cactus-CottonCandyBlue'] + && pets['Cactus-CottonCandyPink'] + && pets['Cactus-Desert'] + && pets['Cactus-Golden'] + && pets['Cactus-Red'] + && pets['Cactus-Shade'] + && pets['Cactus-Skeleton'] + && pets['Cactus-White'] + && pets['Cactus-Zombie'] + && pets['Fox-Base'] + && pets['Fox-CottonCandyBlue'] + && pets['Fox-CottonCandyPink'] + && pets['Fox-Desert'] + && pets['Fox-Golden'] + && pets['Fox-Red'] + && pets['Fox-Shade'] + && pets['Fox-Skeleton'] + && pets['Fox-White'] + && pets['Fox-Zombie'] + && pets['Frog-Base'] + && pets['Frog-CottonCandyBlue'] + && pets['Frog-CottonCandyPink'] + && pets['Frog-Desert'] + && pets['Frog-Golden'] + && pets['Frog-Red'] + && pets['Frog-Shade'] + && pets['Frog-Skeleton'] + && pets['Frog-White'] + && pets['Frog-Zombie'] + && pets['Snake-Base'] + && pets['Snake-CottonCandyBlue'] + && pets['Snake-CottonCandyPink'] + && pets['Snake-Desert'] + && pets['Snake-Golden'] + && pets['Snake-Red'] + && pets['Snake-Shade'] + && pets['Snake-Skeleton'] + && pets['Snake-White'] + && pets['Snake-Zombie'] + && pets['Spider-Base'] + && pets['Spider-CottonCandyBlue'] + && pets['Spider-CottonCandyPink'] + && pets['Spider-Desert'] + && pets['Spider-Golden'] + && pets['Spider-Red'] + && pets['Spider-Shade'] + && pets['Spider-Skeleton'] + && pets['Spider-White'] + && pets['Spider-Zombie']) { + set['achievements.duneBuddy'] = true; + } + } + + if (count % progressCount === 0) console.warn(`${count} ${user._id}`); + + return await User.updateOne({ _id: user._id }, { $set: set }).exec(); +} + +export default async function processUsers () { + let query = { + migration: { $ne: MIGRATION_NAME }, + 'auth.timestamps.loggedin': { $gt: new Date('2023-09-16') }, + }; + + const fields = { + _id: 1, + items: 1, + }; + + while (true) { // eslint-disable-line no-constant-condition + const users = await User // eslint-disable-line no-await-in-loop + .find(query) + .limit(250) + .sort({_id: 1}) + .select(fields) + .lean() + .exec(); + + if (users.length === 0) { + console.warn('All appropriate users found and modified.'); + console.warn(`\n${count} users processed\n`); + break; + } else { + query._id = { + $gt: users[users.length - 1]._id, + }; + } + + await Promise.all(users.map(updateUser)); // eslint-disable-line no-await-in-loop + } +}; diff --git a/package-lock.json b/package-lock.json index d3c25c7a6b..b592250e9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "habitica", - "version": "5.7.0", + "version": "5.9.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2cab790d72..b6fc15f1fb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "habitica", "description": "A habit tracker app which treats your goals like a Role Playing Game.", - "version": "5.7.0", + "version": "5.9.1", "main": "./website/server/index.js", "dependencies": { "@babel/core": "^7.22.10", diff --git a/website/client/src/assets/css/sprites/spritesmith-main.css b/website/client/src/assets/css/sprites/spritesmith-main.css index 4edc504143..9fe581b598 100644 --- a/website/client/src/assets/css/sprites/spritesmith-main.css +++ b/website/client/src/assets/css/sprites/spritesmith-main.css @@ -153,6 +153,11 @@ width: 60px; height: 64px; } +.achievement-duneBuddy2x { + background-image: url('https://habitica-assets.s3.amazonaws.com/mobileApp/images/achievement-duneBuddy2x.png'); + width: 68px; + height: 68px; +} .achievement-dustDevil2x { background-image: url('https://habitica-assets.s3.amazonaws.com/mobileApp/images/achievement-dustDevil2x.png'); width: 48px; diff --git a/website/client/src/components/achievements/questCompleted.vue b/website/client/src/components/achievements/questCompleted.vue index 90c68775d0..78c38927b3 100644 --- a/website/client/src/components/achievements/questCompleted.vue +++ b/website/client/src/components/achievements/questCompleted.vue @@ -91,6 +91,7 @@ export default { this.close(); }, hide () { + this.$store.dispatch('user:statSync'); this.$store.dispatch('user:set', { 'party.quest.completed': '' }); }, }, diff --git a/website/client/src/components/userMenu/profile.vue b/website/client/src/components/userMenu/profile.vue index 0aa6493f54..726f927ef1 100644 --- a/website/client/src/components/userMenu/profile.vue +++ b/website/client/src/components/userMenu/profile.vue @@ -454,7 +454,7 @@ >
@@ -922,7 +922,6 @@ background: $white; margin: 0 auto; margin-bottom: 16px; - padding-top: 20px; } hr { diff --git a/website/client/src/components/userMenu/profileAchievs.vue b/website/client/src/components/userMenu/profileAchievs.vue index 06283bee38..999e785654 100644 --- a/website/client/src/components/userMenu/profileAchievs.vue +++ b/website/client/src/components/userMenu/profileAchievs.vue @@ -20,7 +20,7 @@ >
MAX_LEVEL_HARD_CAP) { - this.restoreValues.lvl = MAX_LEVEL_HARD_CAP; - } - const userChangedLevel = this.restoreValues.lvl !== this.user.stats.lvl; const userDidNotChangeExp = this.restoreValues.exp === this.user.stats.exp; if (userChangedLevel && userDidNotChangeExp) { @@ -265,6 +261,9 @@ export default { ) { this.restoreValues[stat] = this.user.stats[stat]; valid = false; + } else if (this.restoreValues[stat] > MAX_FIELD_HARD_CAP) { + this.restoreValues[stat] = MAX_FIELD_HARD_CAP; + valid = false; } } @@ -274,6 +273,9 @@ export default { || inputLevel < 1) { this.restoreValues.lvl = this.user.stats.lvl; valid = false; + } else if (inputLevel > MAX_LEVEL_HARD_CAP) { + this.restoreValues.lvl = MAX_LEVEL_HARD_CAP; + valid = false; } const inputStreak = Number(this.restoreValues.streak); diff --git a/website/client/src/store/actions/user.js b/website/client/src/store/actions/user.js index 84bb39adbe..7760c56c00 100644 --- a/website/client/src/store/actions/user.js +++ b/website/client/src/store/actions/user.js @@ -8,6 +8,7 @@ import disableClassesOp from '@/../../common/script/ops/disableClasses'; import openMysteryItemOp from '@/../../common/script/ops/openMysteryItem'; import { unEquipByType } from '../../../../common/script/ops/unequip'; import markPMSRead from '../../../../common/script/ops/markPMSRead'; +import updateStats from '../../../../common/script/fns/updateStats'; export function fetch (store, options = {}) { // eslint-disable-line no-shadow return loadAsyncResource({ @@ -179,6 +180,10 @@ export async function getPurchaseHistory () { return response.data.data; } +export function statSync (store) { + updateStats(store.state.user.data, store.state.user.data.stats); + return axios.post('/api/v4/user/stat-sync'); +} export function newPrivateMessageTo (store, params) { const { member } = params; diff --git a/website/common/locales/en/achievements.json b/website/common/locales/en/achievements.json index c23f622fd0..179d41e933 100644 --- a/website/common/locales/en/achievements.json +++ b/website/common/locales/en/achievements.json @@ -153,5 +153,8 @@ "achievementDinosaurDynastyModalText": "You collected all the bird and dinosaur pets!", "achievementBonelessBoss": "Boneless Boss", "achievementBonelessBossText": "Has hatched all standard colors of invertebrate pets: Beetle, Butterfly, Cuttlefish, Nudibranch, Octopus, Snail, and Spider!", - "achievementBonelessBossModalText": "You collected all the invertebrate pets!" + "achievementBonelessBossModalText": "You collected all the invertebrate pets!", + "achievementDuneBuddy": "Dune Buddy", + "achievementDuneBuddyText": "Has hatched all standard colors of desert dwelling pets: Armadillo, Cactus, Fox, Frog, Snake, and Spider!", + "achievementDuneBuddyNotes": "You collected all the desert dwelling pets!" } diff --git a/website/common/script/constants.js b/website/common/script/constants.js index b3ca1162a1..f58af46f8e 100644 --- a/website/common/script/constants.js +++ b/website/common/script/constants.js @@ -2,6 +2,7 @@ export const MAX_HEALTH = 50; export const MAX_LEVEL = 100; export const MAX_STAT_POINTS = MAX_LEVEL; export const MAX_LEVEL_HARD_CAP = 9999; +export const MAX_FIELD_HARD_CAP = 99999999; export const ATTRIBUTES = ['str', 'int', 'con', 'per']; export const MAX_INCENTIVES = 500; diff --git a/website/common/script/content/achievements.js b/website/common/script/content/achievements.js index bd2816168a..7510299357 100644 --- a/website/common/script/content/achievements.js +++ b/website/common/script/content/achievements.js @@ -193,6 +193,11 @@ const animalSetAchievs = { titleKey: 'achievementDomesticated', textKey: 'achievementDomesticatedText', }, + duneBuddy: { + icon: 'achievement-duneBuddy', + titleKey: 'achievementDuneBuddy', + textKey: 'achievementDuneBuddyText', + }, plantParent: { icon: 'achievement-plantParent', titleKey: 'achievementPlantParent', diff --git a/website/common/script/content/constants/animalSetAchievements.js b/website/common/script/content/constants/animalSetAchievements.js index a3b117c0db..89a35cdc12 100644 --- a/website/common/script/content/constants/animalSetAchievements.js +++ b/website/common/script/content/constants/animalSetAchievements.js @@ -72,6 +72,19 @@ const ANIMAL_SET_ACHIEVEMENTS = { achievementKey: 'domesticated', notificationType: 'ACHIEVEMENT_ANIMAL_SET', }, + duneBuddy: { + type: 'pet', + species: [ + 'Armadillo', + 'Cactus', + 'Fox', + 'Frog', + 'Snake', + 'Spider', + ], + achievementKey: 'duneBuddy', + notificationType: 'ACHIEVEMENT_ANIMAL_SET', + }, plantParent: { type: 'pet', species: [ diff --git a/website/common/script/content/constants/events.js b/website/common/script/content/constants/events.js index 737c44bece..3fa4310285 100644 --- a/website/common/script/content/constants/events.js +++ b/website/common/script/content/constants/events.js @@ -10,14 +10,14 @@ const gemsPromo = { export const EVENTS = { noEvent: { - start: '2023-11-01T00:00-04:00', - end: '2023-12-21T08:00-04:00', + start: '2023-11-01T00:00-05:00', + end: '2023-12-21T08:00-05:00', season: 'normal', npcImageSuffix: '', }, spooky_extra_gems: { - start: '2022-10-24T08:00-04:00', - end: '2022-10-31T23:59-04:00', + start: '2023-10-24T08:00-04:00', + end: '2023-10-31T23:59-04:00', gemsPromo, }, bundle202310: { diff --git a/website/common/script/index.js b/website/common/script/index.js index 3045e012ee..e8718670a0 100644 --- a/website/common/script/index.js +++ b/website/common/script/index.js @@ -11,6 +11,7 @@ import { MAX_INCENTIVES, MAX_LEVEL, MAX_LEVEL_HARD_CAP, + MAX_FIELD_HARD_CAP, MAX_STAT_POINTS, MAX_SUMMARY_SIZE_FOR_CHALLENGES, MAX_SUMMARY_SIZE_FOR_GUILDS, @@ -124,6 +125,7 @@ api.constants = { MAX_MESSAGE_LENGTH, MAX_GIFT_MESSAGE_LENGTH, MAX_LEVEL_HARD_CAP, + MAX_FIELD_HARD_CAP, }; // TODO Move these under api.constants api.maxLevel = MAX_LEVEL; diff --git a/website/common/script/libs/achievements.js b/website/common/script/libs/achievements.js index 9847f0c160..9bed55d795 100644 --- a/website/common/script/libs/achievements.js +++ b/website/common/script/libs/achievements.js @@ -223,6 +223,7 @@ function _getBasicAchievements (user, language) { _addSimple(result, user, { path: 'plantParent', language }); _addSimple(result, user, { path: 'dinosaurDynasty', language }); _addSimple(result, user, { path: 'bonelessBoss', language }); + _addSimple(result, user, { path: 'duneBuddy', language }); _addSimpleWithMasterCount(result, user, { path: 'beastMaster', language }); _addSimpleWithMasterCount(result, user, { path: 'mountMaster', language }); diff --git a/website/server/controllers/api-v3/user.js b/website/server/controllers/api-v3/user.js index c26a0802eb..02dc79a8cd 100644 --- a/website/server/controllers/api-v3/user.js +++ b/website/server/controllers/api-v3/user.js @@ -1775,4 +1775,26 @@ api.movePinnedItem = { }, }; +/** + * @api {post} /api/v3/user/stat-sync + * Request a refresh of user stats, including processing of pending level-ups + * @apiName StatSync + * @apiGroup User + * + * @apiSuccess {Object} data The user object + */ + +api.statSync = { + method: 'POST', + middlewares: [authWithHeaders()], + url: '/user/stat-sync', + async handler (req, res) { + const { user } = res.locals; + common.fns.updateStats(user, user.stats); + await user.save(); + + res.respond(200, user); + }, +}; + export default api; diff --git a/website/server/models/user/hooks.js b/website/server/models/user/hooks.js index a64d49fde9..217e1d39a2 100644 --- a/website/server/models/user/hooks.js +++ b/website/server/models/user/hooks.js @@ -362,6 +362,8 @@ schema.pre('save', true, function preSaveUser (next, done) { } } + // Enforce min/max values without displaying schema errors to end user + if (this.isDirectSelected('preferences')) { if ( _.isNaN(this.preferences.dayStart) @@ -372,6 +374,20 @@ schema.pre('save', true, function preSaveUser (next, done) { } } + if (this.isSelected('stats')) { + const statMaximum = common.constants.MAX_FIELD_HARD_CAP; + const levelMaximum = common.constants.MAX_LEVEL_HARD_CAP; + + _.each(['hp', 'mp', 'exp', 'gp'], stat => { + if (this.stats[stat] > statMaximum) { + this.stats[stat] = statMaximum; + } + }); + if (this.stats.lvl > levelMaximum) { + this.stats.lvl = levelMaximum; + } + } + // our own version incrementer if (this.isDirectSelected('_v')) { if (_.isNaN(this._v) || !_.isNumber(this._v)) this._v = 0; diff --git a/website/server/models/user/schema.js b/website/server/models/user/schema.js index 38a4dbaabe..f347606ab6 100644 --- a/website/server/models/user/schema.js +++ b/website/server/models/user/schema.js @@ -156,6 +156,7 @@ export const UserSchema = new Schema({ plantParent: Boolean, dinosaurDynasty: Boolean, bonelessBoss: Boolean, + duneBuddy: Boolean, // Onboarding Guide createdTask: Boolean, completedTask: Boolean,