diff --git a/migrations/archive/2021/20211230_nye.js b/migrations/archive/2021/20211230_nye.js new file mode 100644 index 0000000000..923d37eb7b --- /dev/null +++ b/migrations/archive/2021/20211230_nye.js @@ -0,0 +1,135 @@ +/* eslint-disable no-console */ +const MIGRATION_NAME = '20211230_nye'; +import { model as User } from '../../../website/server/models/user'; +import { v4 as uuid } from 'uuid'; + +const progressCount = 1000; +let count = 0; + +async function updateUser (user) { + count++; + + const set = { migration: MIGRATION_NAME }; + let push; + + if (typeof user.items.gear.owned.head_special_nye2020 !== 'undefined') { + set['items.gear.owned.head_special_nye2021'] = false; + push = [ + { + type: 'marketGear', + path: 'gear.flat.head_special_nye2021', + _id: uuid(), + }, + ]; + } else if (typeof user.items.gear.owned.head_special_nye2019 !== 'undefined') { + set['items.gear.owned.head_special_nye2020'] = false; + push = [ + { + type: 'marketGear', + path: 'gear.flat.head_special_nye2020', + _id: uuid(), + }, + ]; + } else if (typeof user.items.gear.owned.head_special_nye2018 !== 'undefined') { + set['items.gear.owned.head_special_nye2019'] = false; + push = [ + { + type: 'marketGear', + path: 'gear.flat.head_special_nye2019', + _id: uuid(), + }, + ]; + } else if (typeof user.items.gear.owned.head_special_nye2017 !== 'undefined') { + set['items.gear.owned.head_special_nye2018'] = false; + push = [ + { + type: 'marketGear', + path: 'gear.flat.head_special_nye2018', + _id: uuid(), + }, + ]; + } else if (typeof user.items.gear.owned.head_special_nye2016 !== 'undefined') { + set['items.gear.owned.head_special_nye2017'] = false; + push = [ + { + type: 'marketGear', + path: 'gear.flat.head_special_nye2017', + _id: uuid(), + }, + ]; + } else if (typeof user.items.gear.owned.head_special_nye2015 !== 'undefined') { + set['items.gear.owned.head_special_nye2016'] = false; + push = [ + { + type: 'marketGear', + path: 'gear.flat.head_special_nye2016', + _id: uuid(), + }, + ]; + } else if (typeof user.items.gear.owned.head_special_nye2014 !== 'undefined') { + set['items.gear.owned.head_special_nye2015'] = false; + push = [ + { + type: 'marketGear', + path: 'gear.flat.head_special_nye2015', + _id: uuid(), + }, + ]; + } else if (typeof user.items.gear.owned.head_special_nye !== 'undefined') { + set['items.gear.owned.head_special_nye2014'] = false; + push = [ + { + type: 'marketGear', + path: 'gear.flat.head_special_nye2014', + _id: uuid(), + }, + ]; + } else { + set['items.gear.owned.head_special_nye'] = false; + push = [ + { + type: 'marketGear', + path: 'gear.flat.head_special_nye', + _id: uuid(), + }, + ]; + } + + if (count % progressCount === 0) console.warn(`${count} ${user._id}`); + + return await User.update({_id: user._id}, {$set: set, $push: {pinnedItems: {$each: push}}}).exec(); +} + +export default async function processUsers () { + let query = { + 'auth.timestamps.loggedin': {$gt: new Date('2021-12-01')}, + migration: {$ne: MIGRATION_NAME}, + }; + + 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], + }; + } + + await Promise.all(users.map(updateUser)); // eslint-disable-line no-await-in-loop + } +}; diff --git a/migrations/migration-runner.js b/migrations/migration-runner.js index c66ac2014a..aa166b371a 100644 --- a/migrations/migration-runner.js +++ b/migrations/migration-runner.js @@ -18,7 +18,7 @@ function setUpServer () { setUpServer(); // Replace this with your migration -const processUsers = require().default; +const processUsers = require('./archive/2021/20211230_nye').default; processUsers() .then(() => { diff --git a/website/common/locales/en/gear.json b/website/common/locales/en/gear.json index 50523018c2..d93d8f7f48 100644 --- a/website/common/locales/en/gear.json +++ b/website/common/locales/en/gear.json @@ -423,7 +423,10 @@ "weaponSpecialWinter2022MageText": "Pomegranate Staff", "weaponSpecialWinter2022MageNotes": "The berries on this staff contain an ancient magic to be wielded in winter. Increases Intelligence by <%= int %> and Perception by <%= per %>. Limited Edition 2021-2022 Winter Gear.", "weaponSpecialWinter2022HealerText": "Crystalline Ice Wand", - "weaponSpecialWinter2022HealerNotes": "Touch this solid-water implement to a friend's neck and they'll jump out of their chair! But they'll feel better afterward. Hopefully.Increases Intelligence by <%= int %>. Limited Edition 2021-2022 Winter Gear.", + "weaponSpecialWinter2022HealerNotes": "Touch this solid-water implement to a friend's neck and they'll jump out of their chair! But they'll feel better afterward. Hopefully. Increases Intelligence by <%= int %>. Limited Edition 2021-2022 Winter Gear.", + + "headSpecialNye2021Text": "Preposterous Party Hat", + "headSpecialNye2021Notes": "You've received a Preposterous Party Hat! Wear it with pride while ringing in the New Year! Confers no benefit.", "weaponMystery201411Text": "Pitchfork of Feasting", "weaponMystery201411Notes": "Stab your enemies or dig in to your favorite foods - this versatile pitchfork does it all! Confers no benefit. November 2014 Subscriber Item.", diff --git a/website/common/script/content/gear/sets/special/index.js b/website/common/script/content/gear/sets/special/index.js index e355ee5a7d..3761465bf9 100644 --- a/website/common/script/content/gear/sets/special/index.js +++ b/website/common/script/content/gear/sets/special/index.js @@ -1768,6 +1768,12 @@ const head = { winter2022Healer: { set: 'winter2022IceCrystalHealerSet', }, + nye2021: { + text: t('headSpecialNye2021Text'), + notes: t('headSpecialNye2021Notes'), + value: 0, + canOwn: ownsItem('head_special_nye2021'), + }, }; const headStats = { diff --git a/website/common/script/content/index.js b/website/common/script/content/index.js index 9b154f9b28..f697d8d9c6 100644 --- a/website/common/script/content/index.js +++ b/website/common/script/content/index.js @@ -111,7 +111,7 @@ api.cardTypes = { nye: { key: 'nye', messageOptions: 5, - yearRound: moment().isBefore('2021-01-02'), + yearRound: moment().isBefore('2022-01-02T20:00-04:00'), }, thankyou: { key: 'thankyou', diff --git a/website/common/script/content/spells.js b/website/common/script/content/spells.js index 63c81a17b9..615d489599 100644 --- a/website/common/script/content/spells.js +++ b/website/common/script/content/spells.js @@ -289,7 +289,7 @@ spells.special = { target: 'user', notes: t('spellSpecialSnowballAuraNotes'), canOwn () { - return false; + return moment().isBetween('2021-12-30T08:00-04:00', EVENTS.winter2022.end); }, cast (user, target, req) { if (!user.items.special.snowball) throw new NotAuthorized(t('spellNotOwned')(req.language)); @@ -435,7 +435,7 @@ spells.special = { target: 'user', notes: t('nyeCardNotes'), canOwn () { - return false; + return moment().isBetween('2021-12-30T08:00-04:00', '2022-01-02T20:00-04:00'); }, cast (user, target) { if (user === target) { diff --git a/website/server/models/user/hooks.js b/website/server/models/user/hooks.js index 6125f9e64b..66d2372dc4 100644 --- a/website/server/models/user/hooks.js +++ b/website/server/models/user/hooks.js @@ -144,10 +144,10 @@ function _setUpNewUser (user) { user.items.quests.dustbunnies = 1; user.purchased.background.violet = true; user.preferences.background = 'violet'; - if (moment().isBefore('2021-11-28T20:00-05:00')) { - user.migration = '20211124_harvest_feast'; - user.items.pets['Turkey-Base'] = 5; - user.items.currentPet = 'Turkey-Base'; + if (moment().isBefore('2022-01-02T20:00-05:00')) { + user.migration = '20211213_nye'; + user.items.gear.owned.head_special_nye = true; + user.items.gear.equipped.head = 'head_special_nye'; } user.markModified('items achievements');