mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Login Incentives (#8230)
* feat(incentives): login bennies WIP * feat(content): incentive prize content WIP * fix(content): placeholders pass tests * WIP(content): Bard instrument placeholder * feat(content): Incentives build * chore(sprites): compile and fix some strings * WIP(incentives): quests and backgrounds * fix(quests): correct buy/launch handling * [WIP] Incentives rewarding (#8226) * Added login incentive rewards * Updated incentive rewards * Added incentive modal and updated notification structure * Added analytics to sleeping * Added login incentives to user analytics * Fixed unit tests and ensured that prizes are incremented and not replaced * Updated style of daily login incentive modal * Added rewards modal * Added translations * Added loigin incentive ui elements to profile * Updated login incentives structure and abstracted to common.content * Added dynamic display for login incentives on profile * Added purple potion image * Updated daily login modal * Fixed progress calculation * Added bard gear * Updated login incentive rewards * Fixed styles and text * Added multiple read for notifications * Fixed lint issues * Fixed styles and added 50 limit * Updated quest keys * Added login incentives reward page * Fixed tests * Fixed linting and tests * Read named notifications route. Add image for backgrounds * Fixed style issues and added tranlsations to login incentive notification * Hided abiltiy to purchase incentive backgrounds and added message to detail how to unlock * Updated awarded message * Fixed text and updated progress counter to display better * Fixed purple potion reward text * Fixed check in backgrouns reward text * fix(quest): pass tests * Added display of multiple rewards * Updated modal styles * Fixed neagtive 50 issue * Remvoed total count from daily login incentives modal * Fixed magic paw display * fix(awards): give bunnies again * WIP(incentives): more progress on BG shop * fix(incentives): actually award backgrounds * fix(incentives): more BG fixy * fix(backgrounds): don't gem-buy checkin bgs * Added dust bunny notification * fix(incentives): don't redisplay bunny award * chore(news): Bailey and different promo sprite
This commit is contained in:
@@ -10,6 +10,8 @@ const CRON_SAFE_MODE = nconf.get('CRON_SAFE_MODE') === 'true';
|
||||
const CRON_SEMI_SAFE_MODE = nconf.get('CRON_SEMI_SAFE_MODE') === 'true';
|
||||
const shouldDo = common.shouldDo;
|
||||
const scoreTask = common.ops.scoreTask;
|
||||
const i18n = common.i18n;
|
||||
const loginIncentives = common.content.loginIncentives;
|
||||
// const maxPMs = 200;
|
||||
|
||||
export async function recoverCron (status, locals) {
|
||||
@@ -110,9 +112,63 @@ function performSleepTasks (user, tasksByType, now) {
|
||||
});
|
||||
}
|
||||
|
||||
function trackCronAnalytics (analytics, user, _progress, options) {
|
||||
analytics.track('Cron', {
|
||||
category: 'behavior',
|
||||
gaLabel: 'Cron Count',
|
||||
gaValue: user.flags.cronCount,
|
||||
uuid: user._id,
|
||||
user,
|
||||
resting: user.preferences.sleep,
|
||||
cronCount: user.flags.cronCount,
|
||||
progressUp: _.min([_progress.up, 900]),
|
||||
progressDown: _progress.down,
|
||||
headers: options.headers,
|
||||
loginIncentives: user.loginIncentives,
|
||||
});
|
||||
}
|
||||
|
||||
function awardLoginIncentives (user) {
|
||||
if (user.loginIncentives > 50) return;
|
||||
let notificationData = {};
|
||||
notificationData.message = i18n.t('checkinEarned', user.preferences.language);
|
||||
|
||||
let loginIncentive = loginIncentives[user.loginIncentives];
|
||||
|
||||
if (loginIncentive.rewardKey) {
|
||||
loginIncentive.assignReward(user);
|
||||
notificationData.reward = loginIncentive.reward;
|
||||
notificationData.rewardText = '';
|
||||
|
||||
// @TODO: Abstract this logic and share it across the server and client
|
||||
let count = 0;
|
||||
for (let reward of loginIncentive.reward) {
|
||||
if (reward.text) {
|
||||
notificationData.rewardText += reward.text(user.preferences.language);
|
||||
if (reward.key === 'RoyalPurple') {
|
||||
notificationData.rewardText = i18n.t('potion', {potionType: notificationData.rewardText}, user.preferences.language);
|
||||
}
|
||||
} else if (loginIncentive.rewardKey[0] === 'background_blue') {
|
||||
notificationData.rewardText = i18n.t('incentiveBackgrounds');
|
||||
}
|
||||
|
||||
if (loginIncentive.reward.length > 0 && count < loginIncentive.reward.length - 1) notificationData.rewardText += ', ';
|
||||
|
||||
count += 1;
|
||||
}
|
||||
|
||||
notificationData.rewardKey = loginIncentive.rewardKey;
|
||||
notificationData.message = i18n.t('unlockedCheckInReward', user.preferences.language);
|
||||
}
|
||||
|
||||
notificationData.nextRewardAt = loginIncentives[user.loginIncentives].nextRewardAt;
|
||||
user.addNotification('LOGIN_INCENTIVE', notificationData);
|
||||
}
|
||||
|
||||
// Perform various beginning-of-day reset actions.
|
||||
export function cron (options = {}) {
|
||||
let {user, tasksByType, analytics, now = new Date(), daysMissed, timezoneOffsetFromUserPrefs} = options;
|
||||
let _progress = {down: 0, up: 0, collectedItems: 0};
|
||||
|
||||
// Record pre-cron values of HP and MP to show notifications later
|
||||
let beforeCronStats = _.pick(user.stats, ['hp', 'mp']);
|
||||
@@ -133,10 +189,15 @@ export function cron (options = {}) {
|
||||
if (!CRON_SAFE_MODE) removeTerminatedSubscription(user);
|
||||
}
|
||||
|
||||
// Login Incentives
|
||||
user.loginIncentives++;
|
||||
awardLoginIncentives(user);
|
||||
|
||||
// User is resting at the inn.
|
||||
// On cron, buffs are cleared and all dailies are reset without performing damage
|
||||
if (user.preferences.sleep === true) {
|
||||
performSleepTasks(user, tasksByType, now);
|
||||
trackCronAnalytics(analytics, user, _progress, options);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -292,7 +353,7 @@ export function cron (options = {}) {
|
||||
|
||||
// After all is said and done, progress up user's effect on quest, return those values & reset the user's
|
||||
let progress = user.party.quest.progress;
|
||||
let _progress = _.cloneDeep(progress);
|
||||
_progress = _.cloneDeep(progress);
|
||||
_.merge(progress, {down: 0, up: 0, collectedItems: 0});
|
||||
|
||||
// Send notification for changes in HP and MP
|
||||
@@ -329,18 +390,7 @@ export function cron (options = {}) {
|
||||
|
||||
// Analytics
|
||||
user.flags.cronCount++;
|
||||
analytics.track('Cron', { // TODO also do while resting in the inn. https://github.com/HabitRPG/habitrpg/issues/7161#issuecomment-218214191
|
||||
category: 'behavior',
|
||||
gaLabel: 'Cron Count',
|
||||
gaValue: user.flags.cronCount,
|
||||
uuid: user._id,
|
||||
user,
|
||||
resting: user.preferences.sleep,
|
||||
cronCount: user.flags.cronCount,
|
||||
progressUp: _.min([_progress.up, 900]),
|
||||
progressDown: _progress.down,
|
||||
headers: options.headers,
|
||||
});
|
||||
trackCronAnalytics(analytics, user, _progress, options);
|
||||
|
||||
return _progress;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user