diff --git a/website/common/script/libs/getItemInfo.js b/website/common/script/libs/getItemInfo.js index d4317fc570..2450381381 100644 --- a/website/common/script/libs/getItemInfo.js +++ b/website/common/script/libs/getItemInfo.js @@ -4,6 +4,7 @@ import { BadRequest } from './errors'; import count from '../count'; import isPinned from './isPinned'; +import isFreeRebirth from './isFreeRebirth'; import getOfficialPinnedItems from './getOfficialPinnedItems'; import _mapValues from 'lodash/mapValues'; @@ -296,7 +297,7 @@ module.exports = function getItemInfo (user, type, item, officialPinnedItems, la class: 'rebirth_orb', text: i18n.t('rebirthName'), notes: i18n.t('rebirthPop'), - value: user.stats.lvl < 100 ? 6 : 0, + value: isFreeRebirth(user) ? 0 : 6, currency: 'gems', path: 'special.rebirth_orb', pinType: 'rebirth_orb', diff --git a/website/common/script/libs/isFreeRebirth.js b/website/common/script/libs/isFreeRebirth.js new file mode 100644 index 0000000000..16a42c2c63 --- /dev/null +++ b/website/common/script/libs/isFreeRebirth.js @@ -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; +}; diff --git a/website/common/script/ops/rebirth.js b/website/common/script/ops/rebirth.js index 7531de25a6..3b1fb44fa5 100644 --- a/website/common/script/ops/rebirth.js +++ b/website/common/script/ops/rebirth.js @@ -7,12 +7,14 @@ import { } from '../libs/errors'; import equip from './equip'; import { removePinnedGearByClass } from './pinnedGearUtils'; - +import isFreeRebirth from '../libs/isFreeRebirth'; const USERSTATSLIST = ['per', 'int', 'con', 'str', 'points', 'gp', 'exp', 'mp']; 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)); } @@ -21,7 +23,7 @@ module.exports = function rebirth (user, tasks = [], req = {}, analytics) { category: 'behavior', }; - if (user.stats.lvl < MAX_LEVEL) { + if (notFree) { user.balance -= 1.5; analyticsData.acquireMethod = 'Gems'; analyticsData.gemCost = 6; @@ -95,6 +97,10 @@ module.exports = function rebirth (user, tasks = [], req = {}, analytics) { user.achievements.rebirthLevel = lvl; } + if (!notFree) { + user.flags.lastFreeRebirth = new Date(); + } + if (user.addNotification) user.addNotification('REBIRTH_ACHIEVEMENT'); user.stats.buffs = {}; diff --git a/website/server/models/user/schema.js b/website/server/models/user/schema.js index 70d2dd58ce..0119969c12 100644 --- a/website/server/models/user/schema.js +++ b/website/server/models/user/schema.js @@ -225,6 +225,7 @@ let schema = new Schema({ classSelected: {$type: Boolean, default: false}, mathUpdates: Boolean, rebirthEnabled: {$type: Boolean, default: false}, + lastFreeRebirth: Date, levelDrops: {$type: Schema.Types.Mixed, default: () => { return {}; }},