mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Implement schedule for quest bundles
This commit is contained in:
committed by
Sabe Jones
parent
b3521be629
commit
f223b5dd2a
@@ -46,17 +46,23 @@ export const MONTHLY_SCHEDULE = {
|
|||||||
{
|
{
|
||||||
type: 'petQuests',
|
type: 'petQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'ghost_stag',
|
'nudibranch',
|
||||||
'trex_undead',
|
'seaserpent',
|
||||||
'harpy',
|
'gryphon',
|
||||||
'sabretooth',
|
'yarn',
|
||||||
'dolphin',
|
'axolotl',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'hatchingPotionQuests',
|
type: 'hatchingPotionQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'ruby',
|
'silver',
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bundles',
|
||||||
|
matcher: inListMatcher([
|
||||||
|
'winterQuests',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -80,17 +86,22 @@ export const MONTHLY_SCHEDULE = {
|
|||||||
{
|
{
|
||||||
type: 'petQuests',
|
type: 'petQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'nudibranch',
|
'rooster',
|
||||||
'seaserpent',
|
'slime',
|
||||||
'gryphon',
|
'peacock',
|
||||||
'yarn',
|
'bunny',
|
||||||
'axolotl',
|
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'hatchingPotionQuests',
|
type: 'hatchingPotionQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'silver',
|
'pinkMarble',
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bundles',
|
||||||
|
matcher: inListMatcher([
|
||||||
|
'cuddleBuddies',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -114,16 +125,21 @@ export const MONTHLY_SCHEDULE = {
|
|||||||
{
|
{
|
||||||
type: 'petQuests',
|
type: 'petQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'rooster',
|
'frog',
|
||||||
'slime',
|
'spider',
|
||||||
'peacock',
|
'cow',
|
||||||
'bunny',
|
'pterodactyl',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'hatchingPotionQuests',
|
type: 'hatchingPotionQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'pinkMarble',
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bundles',
|
||||||
|
matcher: inListMatcher([
|
||||||
|
'birdBuddies',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -147,15 +163,22 @@ export const MONTHLY_SCHEDULE = {
|
|||||||
{
|
{
|
||||||
type: 'petQuests',
|
type: 'petQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'frog',
|
'snake',
|
||||||
'spider',
|
'monkey',
|
||||||
'cow',
|
'falcon',
|
||||||
'pterodactyl',
|
'aligator',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'hatchingPotionQuests',
|
type: 'hatchingPotionQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
|
'mossyStone',
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bundles',
|
||||||
|
matcher: inListMatcher([
|
||||||
|
'hugabug',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -179,16 +202,21 @@ export const MONTHLY_SCHEDULE = {
|
|||||||
{
|
{
|
||||||
type: 'petQuests',
|
type: 'petQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'snake',
|
'octopus',
|
||||||
'monkey',
|
'horse',
|
||||||
'falcon',
|
'kraken',
|
||||||
'aligator',
|
'sloth',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'hatchingPotionQuests',
|
type: 'hatchingPotionQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'mossyStone',
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bundles',
|
||||||
|
matcher: inListMatcher([
|
||||||
|
'splashyPals',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -212,15 +240,28 @@ export const MONTHLY_SCHEDULE = {
|
|||||||
{
|
{
|
||||||
type: 'petQuests',
|
type: 'petQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'octopus',
|
'trex',
|
||||||
'horse',
|
'unicorn',
|
||||||
'kraken',
|
'veolociraptor',
|
||||||
'sloth',
|
'hippo',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'hatchingPotionQuests',
|
type: 'hatchingPotionQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
|
'turquiose',
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bundles',
|
||||||
|
matcher: inListMatcher([
|
||||||
|
'rockingReptiles',
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bundles',
|
||||||
|
matcher: inListMatcher([
|
||||||
|
'delightfulDinos',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -244,16 +285,28 @@ export const MONTHLY_SCHEDULE = {
|
|||||||
{
|
{
|
||||||
type: 'petQuests',
|
type: 'petQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'trex',
|
'whale',
|
||||||
'unicorn',
|
'seahorse',
|
||||||
'veolociraptor',
|
'armadillo',
|
||||||
'hippo',
|
'guineapig',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'hatchingPotionQuests',
|
type: 'hatchingPotionQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'turquiose',
|
'fluorite',
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bundles',
|
||||||
|
matcher: inListMatcher([
|
||||||
|
'winterQuests',
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bundles',
|
||||||
|
matcher: inListMatcher([
|
||||||
|
'aquaticAmigos',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -277,16 +330,22 @@ export const MONTHLY_SCHEDULE = {
|
|||||||
{
|
{
|
||||||
type: 'petQuests',
|
type: 'petQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'whale',
|
'turtle',
|
||||||
'seahorse',
|
'penguin',
|
||||||
'armadillo',
|
'butterfly',
|
||||||
'guineapig',
|
'cheetah',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'hatchingPotionQuests',
|
type: 'hatchingPotionQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'fluorite',
|
'blackPearl',
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bundles',
|
||||||
|
matcher: inListMatcher([
|
||||||
|
'featheredFriends',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -310,16 +369,22 @@ export const MONTHLY_SCHEDULE = {
|
|||||||
{
|
{
|
||||||
type: 'petQuests',
|
type: 'petQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'turtle',
|
'squirrel',
|
||||||
'penguin',
|
'triceratops',
|
||||||
'butterfly',
|
'treeling',
|
||||||
'cheetah',
|
'beetle',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'hatchingPotionQuests',
|
type: 'hatchingPotionQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'blackPearl',
|
'bronze',
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bundles',
|
||||||
|
matcher: inListMatcher([
|
||||||
|
'farmFriends',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -343,16 +408,22 @@ export const MONTHLY_SCHEDULE = {
|
|||||||
{
|
{
|
||||||
type: 'petQuests',
|
type: 'petQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'squirrel',
|
'snail',
|
||||||
'triceratops',
|
'rock',
|
||||||
'treeling',
|
'ferret',
|
||||||
'beetle',
|
'hedgehog',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'hatchingPotionQuests',
|
type: 'hatchingPotionQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'bronze',
|
'onyx',
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bundles',
|
||||||
|
matcher: inListMatcher([
|
||||||
|
'witchyFamiliars',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -376,16 +447,23 @@ export const MONTHLY_SCHEDULE = {
|
|||||||
{
|
{
|
||||||
type: 'petQuests',
|
type: 'petQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'snail',
|
'sheep',
|
||||||
'rock',
|
'kangaroo',
|
||||||
'ferret',
|
'owl',
|
||||||
'hedgehog',
|
'rat',
|
||||||
|
'badger',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'hatchingPotionQuests',
|
type: 'hatchingPotionQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'onyx',
|
'amber',
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bundles',
|
||||||
|
matcher: inListMatcher([
|
||||||
|
'forestFriends',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -409,17 +487,17 @@ export const MONTHLY_SCHEDULE = {
|
|||||||
{
|
{
|
||||||
type: 'petQuests',
|
type: 'petQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'sheep',
|
'ghost_stag',
|
||||||
'kangaroo',
|
'trex_undead',
|
||||||
'owl',
|
'harpy',
|
||||||
'rat',
|
'sabretooth',
|
||||||
'badger',
|
'dolphin',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'hatchingPotionQuests',
|
type: 'hatchingPotionQuests',
|
||||||
matcher: inListMatcher([
|
matcher: inListMatcher([
|
||||||
'amber',
|
'ruby',
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -265,14 +265,18 @@ shops.getQuestShopCategories = function getQuestShopCategories (user, language)
|
|||||||
* ]
|
* ]
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
const scheduledMatchers = assembleScheduledMatchers(new Date());
|
||||||
|
|
||||||
const bundleCategory = {
|
const bundleCategory = {
|
||||||
identifier: 'bundle',
|
identifier: 'bundle',
|
||||||
text: i18n.t('questBundles', language),
|
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)
|
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)));
|
.map(bundle => getItemInfo(user, 'bundles', bundle, officialPinnedItems, language)));
|
||||||
|
|
||||||
if (bundleCategory.items.length > 0) {
|
if (bundleCategory.items.length > 0) {
|
||||||
@@ -289,7 +293,7 @@ shops.getQuestShopCategories = function getQuestShopCategories (user, language)
|
|||||||
.filter(quest => quest.canBuy(user) && quest.category === type);
|
.filter(quest => quest.canBuy(user) && quest.category === type);
|
||||||
|
|
||||||
if (type === 'pet' || type === 'hatchingPotion') {
|
if (type === 'pet' || type === 'hatchingPotion') {
|
||||||
const matchers = assembleScheduledMatchers(new Date())
|
const matchers = scheduledMatchers
|
||||||
.filter(matcher => matcher.type === `${type}Quests`).map(matcher => matcher.matcher);
|
.filter(matcher => matcher.type === `${type}Quests`).map(matcher => matcher.matcher);
|
||||||
filteredQuests = filteredQuests.filter(quest => matchers.map(matcher => matcher(quest.key))
|
filteredQuests = filteredQuests.filter(quest => matchers.map(matcher => matcher(quest.key))
|
||||||
.every(matcher => matcher === true));
|
.every(matcher => matcher === true));
|
||||||
|
|||||||
@@ -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);
|
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))) {
|
if (matchers.length && !matchers.some(matcher => matcher(item.key))) {
|
||||||
throw new NotAuthorized(this.i18n('notAvailable', { key: item.key }));
|
throw new NotAuthorized(this.i18n('notAvailable', { key: item.key }));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
import { removeItemByPath } from '../pinnedGearUtils';
|
import { removeItemByPath } from '../pinnedGearUtils';
|
||||||
import getItemInfo from '../../libs/getItemInfo';
|
import getItemInfo from '../../libs/getItemInfo';
|
||||||
import updateUserBalance from '../updateUserBalance';
|
import updateUserBalance from '../updateUserBalance';
|
||||||
|
import { assembleScheduledMatchers } from '../../content/constants/schedule';
|
||||||
|
|
||||||
function getItemAndPrice (user, type, key, req) {
|
function getItemAndPrice (user, type, key, req) {
|
||||||
let item;
|
let item;
|
||||||
@@ -54,6 +55,10 @@ async function purchaseItem (user, item, price, type, key) {
|
|||||||
if (user.markModified) user.markModified('items.gear.owned');
|
if (user.markModified) user.markModified('items.gear.owned');
|
||||||
} else if (type === 'bundles') {
|
} else if (type === 'bundles') {
|
||||||
const subType = item.type;
|
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 => {
|
forEach(item.bundleKeys, bundledKey => {
|
||||||
if (!user.items[subType][bundledKey] || user.items[subType][bundledKey] < 0) {
|
if (!user.items[subType][bundledKey] || user.items[subType][bundledKey] < 0) {
|
||||||
user.items[subType][bundledKey] = 0;
|
user.items[subType][bundledKey] = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user