habitica/website/common/script/content/constants/schedule.js

955 lines
19 KiB
JavaScript
Raw Normal View History

import moment from 'moment';
import nconf from 'nconf';
2024-01-31 21:52:44 +00:00
import SEASONAL_SETS from './seasonalSets';
2024-02-21 14:31:45 +00:00
import { getRepeatingEvents } from './events';
function isAfterNewSchedule (year, month) {
if (year >= 2025) {
return true;
} if (year === 2024) {
return month >= 6;
}
return false;
}
function backgroundMatcher (month1, month2, oddYear) {
return function call (key, date) {
const keyLength = key.length;
const month = parseInt(key.substring(keyLength - 6, keyLength - 4), 10);
const year = parseInt(key.substring(keyLength - 4, keyLength), 10);
if (isAfterNewSchedule(year, month)) {
return month === month1 && date.getFullYear() >= year && (date.getMonth() + 1) >= month;
}
return (month === month1 || month === month2) && year % 2 === (oddYear ? 1 : 0);
};
}
function timeTravelersMatcher (month1, month2) {
return function call (item, date) {
const month = parseInt(item.substring(4, 6), 10);
const year = parseInt(item.substring(0, 4), 10);
if (date.getFullYear() === year && (date.getMonth() + 1) >= month) {
return false;
}
return month === month1 || month === month2;
};
}
function inListMatcher (list) {
return function call (item) {
return list.indexOf(item) !== -1;
};
}
2024-04-23 15:50:45 +00:00
export const ALWAYS_AVAILABLE_CUSTOMIZATIONS = [
2024-02-01 14:06:32 +00:00
'animalSkins',
'rainbowSkins',
'rainbowHairColors',
'specialShirts',
'facialHair',
'baseHair1',
'baseHair2',
'baseHair3',
];
function customizationMatcher (list) {
return function call (item) {
if (ALWAYS_AVAILABLE_CUSTOMIZATIONS.indexOf(item) !== -1) {
return true;
}
return list.indexOf(item) !== -1;
};
}
export const FIRST_RELEASE_DAY = 1;
export const SECOND_RELEASE_DAY = 7;
export const THIRD_RELEASE_DAY = 14;
export const FOURTH_RELEASE_DAY = 21;
export const MONTHLY_SCHEDULE = {
2024-04-26 10:18:26 +00:00
// January
0: {
[FIRST_RELEASE_DAY]: [
{
type: 'timeTravelers',
matcher: timeTravelersMatcher(1, 7),
},
],
[SECOND_RELEASE_DAY]: [
{
type: 'backgrounds',
matcher: backgroundMatcher(1, 7, false),
},
],
[THIRD_RELEASE_DAY]: [
{
type: 'petQuests',
items: [
2024-01-31 17:06:50 +00:00
'nudibranch',
'seaserpent',
'gryphon',
'yarn',
'axolotl',
],
},
{
type: 'hatchingPotionQuests',
items: [
2024-01-31 17:06:50 +00:00
'silver',
],
2024-01-31 17:06:50 +00:00
},
{
type: 'bundles',
items: [
2024-01-31 17:06:50 +00:00
'winterQuests',
],
},
],
[FOURTH_RELEASE_DAY]: [
{
type: 'premiumHatchingPotions',
items: [
'Aurora',
2024-04-08 16:18:44 +00:00
'Cupid',
'IcySnow',
],
},
],
},
2024-04-26 10:18:26 +00:00
// February
1: {
[FIRST_RELEASE_DAY]: [
{
type: 'timeTravelers',
matcher: timeTravelersMatcher(2, 8),
},
],
[SECOND_RELEASE_DAY]: [
{
type: 'backgrounds',
matcher: backgroundMatcher(2, 8, false),
},
],
[THIRD_RELEASE_DAY]: [
{
type: 'petQuests',
items: [
2024-01-31 17:06:50 +00:00
'rooster',
'slime',
'peacock',
'bunny',
],
},
{
type: 'hatchingPotionQuests',
items: [
2024-01-31 17:06:50 +00:00
'pinkMarble',
],
2024-01-31 17:06:50 +00:00
},
{
type: 'bundles',
items: [
2024-01-31 17:06:50 +00:00
'cuddleBuddies',
2024-04-22 09:47:34 +00:00
'mythicalMarvels',
],
},
],
[FOURTH_RELEASE_DAY]: [
{
type: 'premiumHatchingPotions',
items: [
'PolkaDot',
2024-04-08 16:18:44 +00:00
'Celestial',
'RoseGold',
],
},
],
},
2024-04-26 10:18:26 +00:00
// March
2: {
[FIRST_RELEASE_DAY]: [
{
type: 'timeTravelers',
matcher: timeTravelersMatcher(3, 9),
},
],
[SECOND_RELEASE_DAY]: [
{
type: 'backgrounds',
matcher: backgroundMatcher(3, 9, false),
},
],
[THIRD_RELEASE_DAY]: [
{
type: 'petQuests',
items: [
2024-01-31 17:06:50 +00:00
'frog',
'spider',
'cow',
'pterodactyl',
],
},
{
type: 'hatchingPotionQuests',
items: [
],
2024-01-31 17:06:50 +00:00
},
{
type: 'bundles',
items: [
2024-01-31 17:06:50 +00:00
'birdBuddies',
],
},
],
[FOURTH_RELEASE_DAY]: [
{
type: 'premiumHatchingPotions',
items: [
'StainedGlass',
'Porcelain',
],
},
],
},
2024-04-26 10:18:26 +00:00
// April
3: {
[FIRST_RELEASE_DAY]: [
{
type: 'timeTravelers',
matcher: timeTravelersMatcher(4, 10),
},
],
[SECOND_RELEASE_DAY]: [
{
type: 'backgrounds',
matcher: backgroundMatcher(4, 10, false),
},
],
[THIRD_RELEASE_DAY]: [
{
type: 'petQuests',
items: [
2024-01-31 17:06:50 +00:00
'snake',
'monkey',
'falcon',
'alligator',
],
},
{
type: 'hatchingPotionQuests',
items: [
2024-04-24 14:31:09 +00:00
'stone',
],
2024-01-31 17:06:50 +00:00
},
{
type: 'bundles',
items: [
2024-01-31 17:06:50 +00:00
'hugabug',
],
},
],
[FOURTH_RELEASE_DAY]: [
{
type: 'premiumHatchingPotions',
items: [
'Shimmer',
'Glass',
],
},
],
},
2024-04-26 10:18:26 +00:00
// May
4: {
[FIRST_RELEASE_DAY]: [
{
type: 'timeTravelers',
matcher: timeTravelersMatcher(5, 11),
},
],
[SECOND_RELEASE_DAY]: [
{
type: 'backgrounds',
matcher: backgroundMatcher(5, 11, false),
},
],
[THIRD_RELEASE_DAY]: [
{
type: 'petQuests',
items: [
2024-01-31 17:06:50 +00:00
'octopus',
'horse',
'kraken',
'sloth',
],
},
{
type: 'hatchingPotionQuests',
items: [
],
2024-01-31 17:06:50 +00:00
},
{
type: 'bundles',
items: [
2024-01-31 17:06:50 +00:00
'splashyPals',
],
},
],
[FOURTH_RELEASE_DAY]: [
{
type: 'premiumHatchingPotions',
items: [
'Floral',
'Fairy',
'RoseQuartz',
],
},
],
},
2024-04-26 10:18:26 +00:00
// June
5: {
[FIRST_RELEASE_DAY]: [
{
type: 'timeTravelers',
matcher: timeTravelersMatcher(6, 12),
},
],
[SECOND_RELEASE_DAY]: [
{
type: 'backgrounds',
matcher: backgroundMatcher(6, 12, false),
},
],
[THIRD_RELEASE_DAY]: [
{
type: 'petQuests',
items: [
2024-01-31 17:06:50 +00:00
'trex',
'unicorn',
2024-04-24 14:31:09 +00:00
'velociraptor',
2024-01-31 17:06:50 +00:00
'hippo',
2024-05-08 00:36:39 +00:00
'giraffe',
],
},
{
type: 'hatchingPotionQuests',
items: [
2024-04-24 14:31:09 +00:00
'turquoise',
],
2024-01-31 17:06:50 +00:00
},
{
type: 'bundles',
items: [
2024-01-31 17:06:50 +00:00
'delightfulDinos',
2024-04-22 09:47:34 +00:00
'sandySidekicks',
],
},
],
[FOURTH_RELEASE_DAY]: [
{
type: 'premiumHatchingPotions',
items: [
'Rainbow',
'Sunshine',
2024-05-13 12:49:39 +00:00
'Koi',
],
},
],
},
2024-04-26 10:18:26 +00:00
// July
6: {
[FIRST_RELEASE_DAY]: [
{
type: 'timeTravelers',
matcher: timeTravelersMatcher(7, 1),
},
],
[SECOND_RELEASE_DAY]: [
{
type: 'backgrounds',
matcher: backgroundMatcher(7, 1, true),
},
],
[THIRD_RELEASE_DAY]: [
{
type: 'petQuests',
items: [
2024-01-31 17:06:50 +00:00
'whale',
2024-04-22 09:47:34 +00:00
'dilatory_derby',
2024-01-31 17:06:50 +00:00
'armadillo',
'guineapig',
],
},
{
type: 'hatchingPotionQuests',
items: [
2024-01-31 17:06:50 +00:00
'fluorite',
],
2024-01-31 17:06:50 +00:00
},
{
type: 'bundles',
items: [
2024-01-31 17:06:50 +00:00
'aquaticAmigos',
2024-04-22 09:47:34 +00:00
'jungleBuddies',
],
},
],
[FOURTH_RELEASE_DAY]: [
{
type: 'premiumHatchingPotions',
items: [
2024-04-08 16:18:44 +00:00
'Moonglow',
'Watery',
],
},
],
},
2024-04-26 10:18:26 +00:00
// August
7: {
[FIRST_RELEASE_DAY]: [
{
type: 'timeTravelers',
matcher: timeTravelersMatcher(8, 2),
},
],
[SECOND_RELEASE_DAY]: [
{
type: 'backgrounds',
matcher: backgroundMatcher(8, 2, true),
},
],
[THIRD_RELEASE_DAY]: [
{
type: 'petQuests',
items: [
2024-01-31 17:06:50 +00:00
'turtle',
'penguin',
'butterfly',
'cheetah',
],
},
{
type: 'hatchingPotionQuests',
items: [
2024-01-31 17:06:50 +00:00
'blackPearl',
],
2024-01-31 17:06:50 +00:00
},
{
type: 'bundles',
items: [
2024-01-31 17:06:50 +00:00
'featheredFriends',
],
},
],
[FOURTH_RELEASE_DAY]: [
{
type: 'premiumHatchingPotions',
items: [
'Aquatic',
'StarryNight',
'Sunset',
],
},
],
},
2024-04-26 10:18:26 +00:00
// September
8: {
[FIRST_RELEASE_DAY]: [
{
type: 'timeTravelers',
matcher: timeTravelersMatcher(9, 3),
},
],
[SECOND_RELEASE_DAY]: [
{
type: 'backgrounds',
matcher: backgroundMatcher(9, 3, true),
},
],
[THIRD_RELEASE_DAY]: [
{
type: 'petQuests',
items: [
2024-01-31 17:06:50 +00:00
'squirrel',
'triceratops',
'treeling',
'beetle',
],
},
{
type: 'hatchingPotionQuests',
items: [
2024-01-31 17:06:50 +00:00
'bronze',
],
2024-01-31 17:06:50 +00:00
},
{
type: 'bundles',
items: [
2024-01-31 17:06:50 +00:00
'farmFriends',
],
},
],
[FOURTH_RELEASE_DAY]: [
{
type: 'premiumHatchingPotions',
items: [
'Glow',
'AutumnLeaf',
'Shadow',
],
},
],
},
2024-04-26 10:18:26 +00:00
// October
9: {
[FIRST_RELEASE_DAY]: [
{
type: 'timeTravelers',
matcher: timeTravelersMatcher(10, 4),
},
],
[SECOND_RELEASE_DAY]: [
{
type: 'backgrounds',
matcher: backgroundMatcher(10, 4, true),
},
],
[THIRD_RELEASE_DAY]: [
{
type: 'petQuests',
items: [
2024-01-31 17:06:50 +00:00
'snail',
'rock',
'ferret',
'hedgehog',
],
},
{
type: 'hatchingPotionQuests',
items: [
2024-01-31 17:06:50 +00:00
'onyx',
],
2024-01-31 17:06:50 +00:00
},
{
type: 'bundles',
items: [
2024-01-31 17:06:50 +00:00
'witchyFamiliars',
],
},
],
[FOURTH_RELEASE_DAY]: [
{
type: 'premiumHatchingPotions',
items: [
'Vampire',
'Ghost',
'Spooky',
],
},
],
},
2024-04-26 10:18:26 +00:00
// November
10: {
[FIRST_RELEASE_DAY]: [
{
type: 'timeTravelers',
matcher: timeTravelersMatcher(11, 5),
},
],
[SECOND_RELEASE_DAY]: [
{
type: 'backgrounds',
matcher: backgroundMatcher(11, 5, true),
},
],
[THIRD_RELEASE_DAY]: [
{
type: 'petQuests',
items: [
2024-01-31 17:06:50 +00:00
'sheep',
'kangaroo',
'owl',
'rat',
'badger',
],
},
{
type: 'hatchingPotionQuests',
items: [
2024-01-31 17:06:50 +00:00
'amber',
],
2024-01-31 17:06:50 +00:00
},
{
type: 'bundles',
items: [
2024-01-31 17:06:50 +00:00
'forestFriends',
],
},
],
[FOURTH_RELEASE_DAY]: [
{
type: 'premiumHatchingPotions',
items: [
'Ember',
'Frost',
'Thunderstorm',
],
},
],
},
2024-04-26 10:18:26 +00:00
// December
11: {
[FIRST_RELEASE_DAY]: [
{
type: 'timeTravelers',
matcher: timeTravelersMatcher(12, 6),
},
],
[SECOND_RELEASE_DAY]: [
{
type: 'backgrounds',
matcher: backgroundMatcher(12, 6, true),
},
],
[THIRD_RELEASE_DAY]: [
{
type: 'petQuests',
items: [
2024-01-31 17:06:50 +00:00
'ghost_stag',
'trex_undead',
'harpy',
'sabretooth',
'dolphin',
],
},
{
type: 'hatchingPotionQuests',
items: [
2024-01-31 17:06:50 +00:00
'ruby',
],
},
2024-04-22 09:47:34 +00:00
{
type: 'bundles',
items: [
'rockingReptiles',
],
},
],
[FOURTH_RELEASE_DAY]: [
{
type: 'premiumHatchingPotions',
items: [
'Peppermint',
'Holly',
],
},
],
},
};
export const GALA_SWITCHOVER_DAY = 21;
2024-02-01 14:06:32 +00:00
export const GALA_KEYS = [
'winter',
'spring',
'summer',
'fall',
];
export const GALA_SCHEDULE = {
2024-04-26 10:18:26 +00:00
// Winter
2024-02-15 15:14:42 +00:00
0: {
startMonth: 11,
2024-04-26 11:03:34 +00:00
endMonth: 2,
matchers: [
2024-02-15 15:14:42 +00:00
{
type: 'seasonalGear',
items: SEASONAL_SETS.winter,
},
{
type: 'seasonalSpells',
items: [
'snowball',
],
},
{
type: 'seasonalQuests',
items: [
'evilsanta',
'evilsanta2',
],
},
{
type: 'customizations',
matcher: customizationMatcher([
'winteryHairColors',
'winterySkins',
]),
},
],
},
2024-04-26 10:18:26 +00:00
// Spring
2024-02-15 15:14:42 +00:00
1: {
startMonth: 2,
2024-04-26 11:03:34 +00:00
endMonth: 5,
matchers: [
2024-02-15 15:14:42 +00:00
{
type: 'seasonalGear',
items: SEASONAL_SETS.spring,
},
{
type: 'seasonalSpells',
items: [
'shinySeed',
],
},
{
type: 'seasonalQuests',
items: [
'egg',
],
},
2024-02-15 15:14:42 +00:00
{
type: 'customizations',
matcher: customizationMatcher([
'shimmerHairColors',
'pastelSkins',
]),
},
],
},
2024-04-26 10:18:26 +00:00
// Summer
2024-02-15 15:14:42 +00:00
2: {
startMonth: 5,
2024-04-26 11:03:34 +00:00
endMonth: 8,
matchers: [
2024-02-15 15:14:42 +00:00
{
type: 'seasonalGear',
items: SEASONAL_SETS.summer,
},
{
type: 'seasonalSpells',
items: [
'seafoam',
],
},
{
type: 'seasonalQuests',
items: [
],
},
2024-02-15 15:14:42 +00:00
{
type: 'customizations',
matcher: customizationMatcher([
2024-05-08 00:36:39 +00:00
'summerHairColors',
2024-02-15 15:14:42 +00:00
'splashySkins',
]),
},
],
},
2024-04-26 10:18:26 +00:00
// Fall
2024-02-15 15:14:42 +00:00
3: {
startMonth: 8,
2024-04-26 11:03:34 +00:00
endMonth: 11,
matchers: [
2024-02-15 15:14:42 +00:00
{
type: 'seasonalGear',
items: SEASONAL_SETS.fall,
},
{
type: 'seasonalSpells',
items: [
'spookySparkles',
],
},
{
type: 'seasonalQuests',
items: [
],
},
2024-02-15 15:14:42 +00:00
{
type: 'customizations',
matcher: customizationMatcher([
'hauntedHairColors',
'supernaturalSkins',
]),
},
],
},
};
const SWITCHOVER_TIME = nconf.get('CONTENT_SWITCHOVER_TIME_OFFSET') || process.env.CONTENT_SWITCHOVER_TIME_OFFSET || 0;
export const TYPE_SCHEDULE = {
timeTravelers: FIRST_RELEASE_DAY,
backgrounds: SECOND_RELEASE_DAY,
petQuests: THIRD_RELEASE_DAY,
hatchingPotionQuests: THIRD_RELEASE_DAY,
bundles: THIRD_RELEASE_DAY,
premiumHatchingPotions: FOURTH_RELEASE_DAY,
seasonalGear: GALA_SWITCHOVER_DAY,
seasonalSpells: GALA_SWITCHOVER_DAY,
seasonalQuests: GALA_SWITCHOVER_DAY,
customizations: GALA_SWITCHOVER_DAY,
};
2024-02-15 14:07:19 +00:00
function getDay (date) {
if (date === undefined) {
return 0;
}
const checkDate = new Date(date.getTime());
checkDate.setHours(checkDate.getHours() - SWITCHOVER_TIME);
return checkDate.getDate();
2024-02-15 14:07:19 +00:00
}
function getMonth (date) {
if (date === undefined) {
return 0;
}
return date instanceof moment ? date.month() : date.getMonth();
}
2024-02-01 14:06:32 +00:00
function getGalaIndex (date) {
const month = getMonth(date);
const todayDay = getDay(date);
2024-02-01 14:06:32 +00:00
let galaMonth = month;
const galaCount = Object.keys(GALA_SCHEDULE).length;
if (todayDay >= GALA_SWITCHOVER_DAY) {
galaMonth += 1;
}
2024-02-21 14:31:45 +00:00
if (galaMonth >= 12) {
return 0;
}
2024-02-01 14:06:32 +00:00
return parseInt((galaCount / 12) * galaMonth, 10);
}
export function assembleScheduledMatchers (date) {
const items = [];
const month = getMonth(date);
const todayDay = getDay(date);
const previousMonth = month === 0 ? 11 : month - 1;
for (const [day, value] of Object.entries(MONTHLY_SCHEDULE[previousMonth])) {
if (day > todayDay) {
items.push(...value);
}
}
for (const [day, value] of Object.entries(MONTHLY_SCHEDULE[month])) {
if (day <= todayDay) {
items.push(...value);
}
}
2024-04-26 11:03:34 +00:00
const gala = GALA_SCHEDULE[getGalaIndex(date)];
const galaMatchers = gala.matchers;
galaMatchers.forEach(matcher => {
matcher.endMonth = gala.endMonth;
});
items.push(...galaMatchers);
2024-05-08 15:42:40 +00:00
getRepeatingEvents(date).forEach(event => {
2024-02-21 14:31:45 +00:00
if (event.content) {
items.push(...event.content);
}
2024-05-08 15:42:40 +00:00
});
return items;
}
2024-01-31 21:52:44 +00:00
let cachedScheduleMatchers = null;
2024-04-02 17:14:53 +00:00
let cacheDate = null;
2024-01-31 21:52:44 +00:00
function makeMatcherClass (date) {
2024-03-06 11:02:38 +00:00
return {
matchers: [],
end: new Date(),
2024-03-06 11:02:38 +00:00
items: [],
matchingDate: date,
2024-03-06 11:02:38 +00:00
match (key) {
if (this.matchers.length === 0) {
if (this.items.length > 0) {
return inListMatcher(this.items)(key, this.matchingDate);
2024-03-06 11:02:38 +00:00
}
} else {
if (this.items.length > 0 && !inListMatcher(this.items)(key, this.matchingDate)) {
2024-03-06 11:02:38 +00:00
return false;
}
return this.matchers.every(m => m(key, this.matchingDate));
2024-03-06 11:02:38 +00:00
}
return false;
},
};
}
2024-04-26 11:15:30 +00:00
function makeEndDate (checkedDate, matcher) {
let end = moment.utc(checkedDate);
2024-04-26 11:03:34 +00:00
end.date(TYPE_SCHEDULE[matcher.type]);
end.hour(SWITCHOVER_TIME);
2024-05-07 13:17:22 +00:00
end.minute(0);
end.second(0);
2024-04-26 11:03:34 +00:00
if (matcher.endMonth !== undefined) {
end.month(matcher.endMonth);
2024-05-07 13:17:22 +00:00
} else if (end.date() <= checkedDate.getDate()) {
2024-04-26 11:03:34 +00:00
end = moment(end).add(1, 'months');
}
return end.toDate();
}
2024-05-07 13:17:22 +00:00
export function clearCachedMatchers () {
cacheDate = null;
cachedScheduleMatchers = null;
}
export function getAllScheduleMatchingGroups (date) {
2024-02-15 15:14:42 +00:00
const checkedDate = date || new Date();
2024-02-15 14:07:19 +00:00
if (cacheDate !== null && (getDay(checkedDate) !== getDay(cacheDate)
|| getMonth(checkedDate) !== getMonth(cacheDate))) {
// Clear cached matchers, since they are old
2024-05-07 13:17:22 +00:00
clearCachedMatchers();
2024-02-15 14:07:19 +00:00
}
2024-01-31 21:52:44 +00:00
if (!cachedScheduleMatchers) {
// No matchers exist, make new ones
2024-02-15 14:07:19 +00:00
cacheDate = new Date();
2024-04-02 17:14:53 +00:00
cachedScheduleMatchers = {};
2024-02-15 14:07:19 +00:00
assembleScheduledMatchers(checkedDate).forEach(matcher => {
2024-04-02 17:14:53 +00:00
if (!cachedScheduleMatchers[matcher.type]) {
2024-05-03 09:12:00 +00:00
cachedScheduleMatchers[matcher.type] = makeMatcherClass(checkedDate);
2024-01-31 21:52:44 +00:00
}
2024-04-26 11:03:34 +00:00
cachedScheduleMatchers[matcher.type].end = makeEndDate(checkedDate, matcher);
if (matcher.matcher instanceof Function) {
cachedScheduleMatchers[matcher.type].matchers.push(matcher.matcher);
} else if (matcher.items instanceof Array) {
cachedScheduleMatchers[matcher.type].items.push(...matcher.items);
}
2024-01-31 21:52:44 +00:00
});
}
2024-04-26 10:04:18 +00:00
return cachedScheduleMatchers;
}
export function getScheduleMatchingGroup (type, date) {
const matchingGroups = getAllScheduleMatchingGroups(date);
if (!matchingGroups[type]) {
// No matchers exist for this type
return {
items: [],
match () {
return true;
},
};
}
return matchingGroups[type];
2024-01-31 21:52:44 +00:00
}
2024-02-01 14:06:32 +00:00
export function getCurrentGalaKey (date) {
return GALA_KEYS[getGalaIndex(date || new Date())];
}
2024-02-15 15:14:42 +00:00
export function getCurrentGalaEvent (date) {
const checkedDate = date || new Date();
const index = getGalaIndex(checkedDate);
const key = GALA_KEYS[index];
const gala = GALA_SCHEDULE[index];
const today = new Date();
return {
event: key,
npcImageSuffix: `_${key}`,
season: key,
2024-05-06 09:53:12 +00:00
gear: true,
2024-02-15 15:14:42 +00:00
start: `${today.getFullYear()}.${gala.startMonth + 1}.${GALA_SWITCHOVER_DAY}`,
end: `${today.getFullYear()}.${gala.endMonth + 1}.${GALA_SWITCHOVER_DAY}`,
};
}