mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
limit free rebirth to once every 45 days
This commit is contained in:
@@ -4,6 +4,7 @@ import { BadRequest } from './errors';
|
|||||||
import count from '../count';
|
import count from '../count';
|
||||||
|
|
||||||
import isPinned from './isPinned';
|
import isPinned from './isPinned';
|
||||||
|
import isFreeRebirth from './isFreeRebirth';
|
||||||
import getOfficialPinnedItems from './getOfficialPinnedItems';
|
import getOfficialPinnedItems from './getOfficialPinnedItems';
|
||||||
|
|
||||||
import _mapValues from 'lodash/mapValues';
|
import _mapValues from 'lodash/mapValues';
|
||||||
@@ -296,7 +297,7 @@ module.exports = function getItemInfo (user, type, item, officialPinnedItems, la
|
|||||||
class: 'rebirth_orb',
|
class: 'rebirth_orb',
|
||||||
text: i18n.t('rebirthName'),
|
text: i18n.t('rebirthName'),
|
||||||
notes: i18n.t('rebirthPop'),
|
notes: i18n.t('rebirthPop'),
|
||||||
value: user.stats.lvl < 100 ? 6 : 0,
|
value: isFreeRebirth(user) ? 0 : 6,
|
||||||
currency: 'gems',
|
currency: 'gems',
|
||||||
path: 'special.rebirth_orb',
|
path: 'special.rebirth_orb',
|
||||||
pinType: 'rebirth_orb',
|
pinType: 'rebirth_orb',
|
||||||
|
|||||||
14
website/common/script/libs/isFreeRebirth.js
Normal file
14
website/common/script/libs/isFreeRebirth.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import moment from 'moment';
|
||||||
|
import { MAX_LEVEL } from '../constants';
|
||||||
|
|
||||||
|
module.exports = function isFreeRebirth (user) {
|
||||||
|
let daysFromLastFreeRebirth = user.flags.lastFreeRebirth;
|
||||||
|
|
||||||
|
if (daysFromLastFreeRebirth) {
|
||||||
|
daysFromLastFreeRebirth = moment().diff(moment(user.flags.lastFreeRebirth), 'days');
|
||||||
|
} else {
|
||||||
|
daysFromLastFreeRebirth = 999;
|
||||||
|
}
|
||||||
|
|
||||||
|
return user.stats.lvl >= MAX_LEVEL && daysFromLastFreeRebirth > 45;
|
||||||
|
};
|
||||||
@@ -7,12 +7,14 @@ import {
|
|||||||
} from '../libs/errors';
|
} from '../libs/errors';
|
||||||
import equip from './equip';
|
import equip from './equip';
|
||||||
import { removePinnedGearByClass } from './pinnedGearUtils';
|
import { removePinnedGearByClass } from './pinnedGearUtils';
|
||||||
|
import isFreeRebirth from '../libs/isFreeRebirth';
|
||||||
|
|
||||||
const USERSTATSLIST = ['per', 'int', 'con', 'str', 'points', 'gp', 'exp', 'mp'];
|
const USERSTATSLIST = ['per', 'int', 'con', 'str', 'points', 'gp', 'exp', 'mp'];
|
||||||
|
|
||||||
module.exports = function rebirth (user, tasks = [], req = {}, analytics) {
|
module.exports = function rebirth (user, tasks = [], req = {}, analytics) {
|
||||||
if (user.balance < 1.5 && user.stats.lvl < MAX_LEVEL) {
|
const notFree = !isFreeRebirth(user);
|
||||||
|
|
||||||
|
if (user.balance < 1.5 && notFree) {
|
||||||
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
|
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,7 +23,7 @@ module.exports = function rebirth (user, tasks = [], req = {}, analytics) {
|
|||||||
category: 'behavior',
|
category: 'behavior',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (user.stats.lvl < MAX_LEVEL) {
|
if (notFree) {
|
||||||
user.balance -= 1.5;
|
user.balance -= 1.5;
|
||||||
analyticsData.acquireMethod = 'Gems';
|
analyticsData.acquireMethod = 'Gems';
|
||||||
analyticsData.gemCost = 6;
|
analyticsData.gemCost = 6;
|
||||||
@@ -95,6 +97,10 @@ module.exports = function rebirth (user, tasks = [], req = {}, analytics) {
|
|||||||
user.achievements.rebirthLevel = lvl;
|
user.achievements.rebirthLevel = lvl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!notFree) {
|
||||||
|
user.flags.lastFreeRebirth = new Date();
|
||||||
|
}
|
||||||
|
|
||||||
if (user.addNotification) user.addNotification('REBIRTH_ACHIEVEMENT');
|
if (user.addNotification) user.addNotification('REBIRTH_ACHIEVEMENT');
|
||||||
|
|
||||||
user.stats.buffs = {};
|
user.stats.buffs = {};
|
||||||
|
|||||||
@@ -225,6 +225,7 @@ let schema = new Schema({
|
|||||||
classSelected: {$type: Boolean, default: false},
|
classSelected: {$type: Boolean, default: false},
|
||||||
mathUpdates: Boolean,
|
mathUpdates: Boolean,
|
||||||
rebirthEnabled: {$type: Boolean, default: false},
|
rebirthEnabled: {$type: Boolean, default: false},
|
||||||
|
lastFreeRebirth: Date,
|
||||||
levelDrops: {$type: Schema.Types.Mixed, default: () => {
|
levelDrops: {$type: Schema.Types.Mixed, default: () => {
|
||||||
return {};
|
return {};
|
||||||
}},
|
}},
|
||||||
|
|||||||
Reference in New Issue
Block a user