From f223b5dd2a5cd73ac17c1dccaaf8347889a0df79 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Wed, 31 Jan 2024 18:06:50 +0100 Subject: [PATCH] Implement schedule for quest bundles --- .../script/content/constants/schedule.js | 200 ++++++++++++------ website/common/script/libs/shops.js | 8 +- website/common/script/ops/buy/buyQuestGem.js | 1 + website/common/script/ops/buy/purchase.js | 5 + 4 files changed, 151 insertions(+), 63 deletions(-) diff --git a/website/common/script/content/constants/schedule.js b/website/common/script/content/constants/schedule.js index 3cf37c411b..7f9a13904d 100644 --- a/website/common/script/content/constants/schedule.js +++ b/website/common/script/content/constants/schedule.js @@ -46,17 +46,23 @@ export const MONTHLY_SCHEDULE = { { type: 'petQuests', matcher: inListMatcher([ - 'ghost_stag', - 'trex_undead', - 'harpy', - 'sabretooth', - 'dolphin', + 'nudibranch', + 'seaserpent', + 'gryphon', + 'yarn', + 'axolotl', ]), }, { type: 'hatchingPotionQuests', matcher: inListMatcher([ - 'ruby', + 'silver', + ]), + }, + { + type: 'bundles', + matcher: inListMatcher([ + 'winterQuests', ]), }, ], @@ -80,17 +86,22 @@ export const MONTHLY_SCHEDULE = { { type: 'petQuests', matcher: inListMatcher([ - 'nudibranch', - 'seaserpent', - 'gryphon', - 'yarn', - 'axolotl', + 'rooster', + 'slime', + 'peacock', + 'bunny', ]), }, { type: 'hatchingPotionQuests', matcher: inListMatcher([ - 'silver', + 'pinkMarble', + ]), + }, + { + type: 'bundles', + matcher: inListMatcher([ + 'cuddleBuddies', ]), }, ], @@ -114,16 +125,21 @@ export const MONTHLY_SCHEDULE = { { type: 'petQuests', matcher: inListMatcher([ - 'rooster', - 'slime', - 'peacock', - 'bunny', + 'frog', + 'spider', + 'cow', + 'pterodactyl', ]), }, { type: 'hatchingPotionQuests', matcher: inListMatcher([ - 'pinkMarble', + ]), + }, + { + type: 'bundles', + matcher: inListMatcher([ + 'birdBuddies', ]), }, ], @@ -147,15 +163,22 @@ export const MONTHLY_SCHEDULE = { { type: 'petQuests', matcher: inListMatcher([ - 'frog', - 'spider', - 'cow', - 'pterodactyl', + 'snake', + 'monkey', + 'falcon', + 'aligator', ]), }, { type: 'hatchingPotionQuests', matcher: inListMatcher([ + 'mossyStone', + ]), + }, + { + type: 'bundles', + matcher: inListMatcher([ + 'hugabug', ]), }, ], @@ -179,16 +202,21 @@ export const MONTHLY_SCHEDULE = { { type: 'petQuests', matcher: inListMatcher([ - 'snake', - 'monkey', - 'falcon', - 'aligator', + 'octopus', + 'horse', + 'kraken', + 'sloth', ]), }, { type: 'hatchingPotionQuests', matcher: inListMatcher([ - 'mossyStone', + ]), + }, + { + type: 'bundles', + matcher: inListMatcher([ + 'splashyPals', ]), }, ], @@ -212,15 +240,28 @@ export const MONTHLY_SCHEDULE = { { type: 'petQuests', matcher: inListMatcher([ - 'octopus', - 'horse', - 'kraken', - 'sloth', + 'trex', + 'unicorn', + 'veolociraptor', + 'hippo', ]), }, { type: 'hatchingPotionQuests', matcher: inListMatcher([ + 'turquiose', + ]), + }, + { + type: 'bundles', + matcher: inListMatcher([ + 'rockingReptiles', + ]), + }, + { + type: 'bundles', + matcher: inListMatcher([ + 'delightfulDinos', ]), }, ], @@ -244,16 +285,28 @@ export const MONTHLY_SCHEDULE = { { type: 'petQuests', matcher: inListMatcher([ - 'trex', - 'unicorn', - 'veolociraptor', - 'hippo', + 'whale', + 'seahorse', + 'armadillo', + 'guineapig', ]), }, { type: 'hatchingPotionQuests', matcher: inListMatcher([ - 'turquiose', + 'fluorite', + ]), + }, + { + type: 'bundles', + matcher: inListMatcher([ + 'winterQuests', + ]), + }, + { + type: 'bundles', + matcher: inListMatcher([ + 'aquaticAmigos', ]), }, ], @@ -277,16 +330,22 @@ export const MONTHLY_SCHEDULE = { { type: 'petQuests', matcher: inListMatcher([ - 'whale', - 'seahorse', - 'armadillo', - 'guineapig', + 'turtle', + 'penguin', + 'butterfly', + 'cheetah', ]), }, { type: 'hatchingPotionQuests', matcher: inListMatcher([ - 'fluorite', + 'blackPearl', + ]), + }, + { + type: 'bundles', + matcher: inListMatcher([ + 'featheredFriends', ]), }, ], @@ -310,16 +369,22 @@ export const MONTHLY_SCHEDULE = { { type: 'petQuests', matcher: inListMatcher([ - 'turtle', - 'penguin', - 'butterfly', - 'cheetah', + 'squirrel', + 'triceratops', + 'treeling', + 'beetle', ]), }, { type: 'hatchingPotionQuests', matcher: inListMatcher([ - 'blackPearl', + 'bronze', + ]), + }, + { + type: 'bundles', + matcher: inListMatcher([ + 'farmFriends', ]), }, ], @@ -343,16 +408,22 @@ export const MONTHLY_SCHEDULE = { { type: 'petQuests', matcher: inListMatcher([ - 'squirrel', - 'triceratops', - 'treeling', - 'beetle', + 'snail', + 'rock', + 'ferret', + 'hedgehog', ]), }, { type: 'hatchingPotionQuests', matcher: inListMatcher([ - 'bronze', + 'onyx', + ]), + }, + { + type: 'bundles', + matcher: inListMatcher([ + 'witchyFamiliars', ]), }, ], @@ -376,16 +447,23 @@ export const MONTHLY_SCHEDULE = { { type: 'petQuests', matcher: inListMatcher([ - 'snail', - 'rock', - 'ferret', - 'hedgehog', + 'sheep', + 'kangaroo', + 'owl', + 'rat', + 'badger', ]), }, { type: 'hatchingPotionQuests', matcher: inListMatcher([ - 'onyx', + 'amber', + ]), + }, + { + type: 'bundles', + matcher: inListMatcher([ + 'forestFriends', ]), }, ], @@ -409,17 +487,17 @@ export const MONTHLY_SCHEDULE = { { type: 'petQuests', matcher: inListMatcher([ - 'sheep', - 'kangaroo', - 'owl', - 'rat', - 'badger', + 'ghost_stag', + 'trex_undead', + 'harpy', + 'sabretooth', + 'dolphin', ]), }, { type: 'hatchingPotionQuests', matcher: inListMatcher([ - 'amber', + 'ruby', ]), }, ], diff --git a/website/common/script/libs/shops.js b/website/common/script/libs/shops.js index b1b0574dbb..ab75ed6a71 100644 --- a/website/common/script/libs/shops.js +++ b/website/common/script/libs/shops.js @@ -265,14 +265,18 @@ shops.getQuestShopCategories = function getQuestShopCategories (user, language) * ] * */ + const scheduledMatchers = assembleScheduledMatchers(new Date()); const bundleCategory = { identifier: 'bundle', text: i18n.t('questBundles', language), }; + const bundleMatchers = scheduledMatchers.filter(matcher => matcher.type === 'bundles').map(matcher => matcher.matcher); + console.log(bundleMatchers); bundleCategory.items = sortBy(values(content.bundles) - .filter(bundle => bundle.type === 'quests' && bundle.canBuy()) + .filter(bundle => bundle.type === 'quests' + && bundleMatchers.map(matcher => matcher(bundle.key)).every(matcher => matcher === true)) .map(bundle => getItemInfo(user, 'bundles', bundle, officialPinnedItems, language))); if (bundleCategory.items.length > 0) { @@ -289,7 +293,7 @@ shops.getQuestShopCategories = function getQuestShopCategories (user, language) .filter(quest => quest.canBuy(user) && quest.category === type); if (type === 'pet' || type === 'hatchingPotion') { - const matchers = assembleScheduledMatchers(new Date()) + const matchers = scheduledMatchers .filter(matcher => matcher.type === `${type}Quests`).map(matcher => matcher.matcher); filteredQuests = filteredQuests.filter(quest => matchers.map(matcher => matcher(quest.key)) .every(matcher => matcher === true)); diff --git a/website/common/script/ops/buy/buyQuestGem.js b/website/common/script/ops/buy/buyQuestGem.js index 9e5521f907..392b8b5ebd 100644 --- a/website/common/script/ops/buy/buyQuestGem.js +++ b/website/common/script/ops/buy/buyQuestGem.js @@ -53,6 +53,7 @@ export class BuyQuestWithGemOperation extends AbstractGemItemOperation { // esli } const matchers = assembleScheduledMatchers(new Date()).filter(matcher => matcher.type === `${item.category}Quests`).map(matcher => matcher.matcher); + console.log(item, matchers); if (matchers.length && !matchers.some(matcher => matcher(item.key))) { throw new NotAuthorized(this.i18n('notAvailable', { key: item.key })); } diff --git a/website/common/script/ops/buy/purchase.js b/website/common/script/ops/buy/purchase.js index 64786c7516..3788eb778b 100644 --- a/website/common/script/ops/buy/purchase.js +++ b/website/common/script/ops/buy/purchase.js @@ -13,6 +13,7 @@ import { import { removeItemByPath } from '../pinnedGearUtils'; import getItemInfo from '../../libs/getItemInfo'; import updateUserBalance from '../updateUserBalance'; +import { assembleScheduledMatchers } from '../../content/constants/schedule'; function getItemAndPrice (user, type, key, req) { let item; @@ -54,6 +55,10 @@ async function purchaseItem (user, item, price, type, key) { if (user.markModified) user.markModified('items.gear.owned'); } else if (type === 'bundles') { const subType = item.type; + const matchers = assembleScheduledMatchers(new Date()).filter(matcher => matcher.type === 'bundles').map(matcher => matcher.matcher); + if (matchers.length && !matchers.some(matcher => matcher(item.key))) { + throw new NotAuthorized(i18n.t('notAvailable', { key: item.key })); + } forEach(item.bundleKeys, bundledKey => { if (!user.items[subType][bundledKey] || user.items[subType][bundledKey] < 0) { user.items[subType][bundledKey] = 0;