From 0140b9beb7cd1ccb2301384e5d5b2cc3d1861e90 Mon Sep 17 00:00:00 2001 From: SabreCat Date: Mon, 31 Jul 2023 16:38:30 -0500 Subject: [PATCH] feat(chat): veteran awards --- .../2023/20230801_veteran_pet_ladder.js | 144 ++++++++++++++++++ website/common/locales/en/pets.json | 1 + .../script/content/gear/sets/special/index.js | 3 + .../gear/sets/special/special-contributor.js | 36 +++++ website/common/script/content/stable.js | 2 + 5 files changed, 186 insertions(+) create mode 100644 migrations/archive/2023/20230801_veteran_pet_ladder.js diff --git a/migrations/archive/2023/20230801_veteran_pet_ladder.js b/migrations/archive/2023/20230801_veteran_pet_ladder.js new file mode 100644 index 0000000000..718881caca --- /dev/null +++ b/migrations/archive/2023/20230801_veteran_pet_ladder.js @@ -0,0 +1,144 @@ +/* eslint-disable no-console */ +const MIGRATION_NAME = '20230801_veteran_pet_ladder'; +import { model as User } from '../../../website/server/models/user'; + +const progressCount = 1000; +let count = 0; + +async function updateUser (user) { + count++; + + const set = {}; + let push = { notifications: { $each: [] }}; + + set.migration = MIGRATION_NAME; + if (user.items.pets['Fox-Veteran']) { + set['items.pets.Dragon-Veteran'] = 5; + push.notifications.$each.push({ + type: 'ITEM_RECEIVED', + data: { + icon: 'icon_pet_veteran_dragon', + title: 'You’ve received a Veteran Pet!', + text: 'To commemorate being here for a new era of Habitca, we’ve awarded you a Veteran Dragon.', + destination: '/inventory/stable', + }, + seen: false, + }); + } else if (user.items.pets['Bear-Veteran']) { + set['items.pets.Fox-Veteran'] = 5; + push.notifications.$each.push({ + type: 'ITEM_RECEIVED', + data: { + icon: 'icon_pet_veteran_fox', + title: 'You’ve received a Veteran Pet!', + text: 'To commemorate being here for a new era of Habitca, we’ve awarded you a Veteran Fox.', + destination: '/inventory/stable', + }, + seen: false, + }); + } else if (user.items.pets['Lion-Veteran']) { + set['items.pets.Bear-Veteran'] = 5; + push.notifications.$each.push({ + type: 'ITEM_RECEIVED', + data: { + icon: 'icon_pet_veteran_bear', + title: 'You’ve received a Veteran Pet!', + text: 'To commemorate being here for a new era of Habitca, we’ve awarded you a Veteran Bear.', + destination: '/inventory/stable', + }, + seen: false, + }); + } else if (user.items.pets['Tiger-Veteran']) { + set['items.pets.Lion-Veteran'] = 5; + push.notifications.$each.push({ + type: 'ITEM_RECEIVED', + data: { + icon: 'icon_pet_veteran_lion', + title: 'You’ve received a Veteran Pet!', + text: 'To commemorate being here for a new era of Habitca, we’ve awarded you a Veteran Lion.', + destination: '/inventory/stable', + }, + seen: false, + }); + } else if (user.items.pets['Wolf-Veteran']) { + set['items.pets.Tiger-Veteran'] = 5; + push.notifications.$each.push({ + type: 'ITEM_RECEIVED', + data: { + icon: 'icon_pet_veteran_tiger', + title: 'You’ve received a Veteran Pet!', + text: 'To commemorate being here for a new era of Habitca, we’ve awarded you a Veteran Tiger.', + destination: '/inventory/stable', + }, + seen: false, + }); + } else { + set['items.pets.Wolf-Veteran'] = 5; + push.notifications.$each.push({ + type: 'ITEM_RECEIVED', + data: { + icon: 'icon_pet_veteran_wolf', + title: 'You’ve received a Veteran Pet!', + text: 'To commemorate being here for a new era of Habitca, we’ve awarded you a Veteran Wolf.', + destination: '/inventory/stable', + }, + seen: false, + }); + } + + if (user.contributor.level > 0) { + set['items.gear.owned.armor_special_heroicTunic'] = true; + set['items.gear.owned.back_special_heroicAureole'] = true; + set['items.gear.owned.head_special_heroicCirclet'] = true; + push.notifications.$each.push({ + type: 'ITEM_RECEIVED', + data: { + icon: 'heroic_set_icon', + title: 'You’ve received the Heroic Set!', + text: 'To commemorate your hard work as a contributor, we’ve awarded you the Heroic Circlet, Heroic Aureole, and Heroic Tunic.', + destination: '/inventory/equipment', + }, + seen: false, + }); + } + + if (count % progressCount === 0) console.warn(`${count} ${user._id}`); + + return await User.update({_id: user._id}, {$set: set, $push: push}).exec(); +} + +export default async function processUsers () { + let query = { + migration: {$ne: MIGRATION_NAME}, + 'auth.timestamps.loggedin': { $gt: new Date('2023-07-01') }, + }; + + const fields = { + _id: 1, + items: 1, + migration: 1, + contributor: 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/website/common/locales/en/pets.json b/website/common/locales/en/pets.json index 001ed2ad8c..40441cd3f8 100644 --- a/website/common/locales/en/pets.json +++ b/website/common/locales/en/pets.json @@ -19,6 +19,7 @@ "veteranLion": "Veteran Lion", "veteranBear": "Veteran Bear", "veteranFox": "Veteran Fox", + "veteranDragon": "Veteran Dragon", "cerberusPup": "Cerberus Pup", "hydra": "Hydra", "mantisShrimp": "Mantis Shrimp", diff --git a/website/common/script/content/gear/sets/special/index.js b/website/common/script/content/gear/sets/special/index.js index 1600001bb8..b0d22c5a1d 100644 --- a/website/common/script/content/gear/sets/special/index.js +++ b/website/common/script/content/gear/sets/special/index.js @@ -27,6 +27,7 @@ const armor = { 1: contributorGear.armorSpecial1, 2: backerGear.armorSpecial2, takeThis: takeThisGear.armorSpecialTakeThis, + heroicTunic: contributorGear.armorSpecialHeroicTunic, finnedOceanicArmor: { text: t('armorSpecialFinnedOceanicArmorText'), notes: t('armorSpecialFinnedOceanicArmorNotes', { str: 15 }), @@ -868,6 +869,7 @@ const back = { wondercon_red: wonderconGear.backSpecialWonderconRed, // eslint-disable-line camelcase wondercon_black: wonderconGear.backSpecialWonderconBlack, // eslint-disable-line camelcase takeThis: takeThisGear.backSpecialTakeThis, + heroicAureole: contributorGear.backSpecialHeroicAureole, snowdriftVeil: { text: t('backSpecialSnowdriftVeilText'), notes: t('backSpecialSnowdriftVeilNotes'), @@ -1204,6 +1206,7 @@ const head = { 1: contributorGear.headSpecial1, 2: backerGear.headSpecial2, takeThis: takeThisGear.headSpecialTakeThis, + heroicCirclet: contributorGear.headSpecialHeroicCirclet, fireCoralCirclet: { text: t('headSpecialFireCoralCircletText'), notes: t('headSpecialFireCoralCircletNotes', { per: 15 }), diff --git a/website/common/script/content/gear/sets/special/special-contributor.js b/website/common/script/content/gear/sets/special/special-contributor.js index c5de25b1c6..19955473b0 100644 --- a/website/common/script/content/gear/sets/special/special-contributor.js +++ b/website/common/script/content/gear/sets/special/special-contributor.js @@ -66,10 +66,46 @@ const weaponSpecialCritical = { }, }; +const armorSpecialHeroicTunic = { + text: t('armorSpecialHeroicTunicText'), + notes: t('armorSpecialHeroicTunicNotes', { attrs: 7 }), + con: 7, + str: 7, + per: 7, + int: 7, + value: 175, + canOwn: ownsItem('armor_special_heroicTunic'), +}; + +const backSpecialHeroicAureole = { + text: t('backSpecialHeroicAureoleText'), + notes: t('backSpecialHeroicAureoleNotes', { attrs: 7 }), + con: 7, + str: 7, + per: 7, + int: 7, + value: 175, + canOwn: ownsItem('armor_special_heroicAureole'), +}; + +const headSpecialHeroicCirclet = { + text: t('headSpecialHeroicCircletText'), + notes: t('headSpecialHeroicCircletNotes', { attrs: 7 }), + con: 7, + str: 7, + per: 7, + int: 7, + value: 175, + canOwn: ownsItem('head_special_heroicCirclet'), +}; + export { armorSpecial1, headSpecial1, shieldSpecial1, weaponSpecial1, weaponSpecialCritical, + armorSpecialHeroicTunic, + backSpecialHeroicAureole, + headSpecialHeroicCirclet, }; diff --git a/website/common/script/content/stable.js b/website/common/script/content/stable.js index 457ecd60ee..7985b017b9 100644 --- a/website/common/script/content/stable.js +++ b/website/common/script/content/stable.js @@ -92,6 +92,7 @@ const canFindSpecial = { 'Lion-Veteran': false, 'Bear-Veteran': false, 'Fox-Veteran': false, + 'Dragon-Veteran': false, // Thanksgiving pet ladder 'Turkey-Base': false, @@ -181,6 +182,7 @@ const specialPets = { 'Gryphon-Gryphatrice': 'gryphatrice', 'Gryphatrice-Jubilant': 'jubilantGryphatrice', 'JackOLantern-RoyalPurple': 'royalPurpleJackolantern', + 'Dragon-Veteran': 'veteranDragon', }; const specialMounts = {