feat(plans): add consecutive-month benefits for subscribers

This commit is contained in:
Tyler Renelle 2014-11-17 16:36:03 -08:00
parent a6944ec072
commit 76be625f6d
3 changed files with 88 additions and 33 deletions

View file

@ -13624,6 +13624,29 @@ api.backgrounds = {
}
};
api.subscriptionBlocks = {
"1": {
months: 1,
price: 5,
key: 'basic_earned'
},
"3": {
months: 3,
price: 15,
key: 'basic_3mo'
},
"6": {
months: 6,
price: 30,
key: 'basic_6mo'
},
"12": {
months: 12,
price: 48,
key: 'basic_12mo'
}
};
repeat = {
m: true,
t: true,
@ -14926,11 +14949,12 @@ api.wrap = function(user, main) {
return typeof cb === "function" ? cb(null, _.pick(user, $w('items stats'))) : void 0;
},
purchase: function(req, cb, ga) {
var convCap, convRate, item, key, type, _ref, _ref1, _ref2, _ref3;
var convCap, convRate, item, key, type, _ref, _ref1, _ref2;
_ref = req.params, type = _ref.type, key = _ref.key;
if (type === 'gems' && key === 'gem') {
_ref1 = api.planGemLimits, convRate = _ref1.convRate, convCap = _ref1.convCap;
if (!((_ref2 = user.purchased) != null ? (_ref3 = _ref2.plan) != null ? _ref3.planId : void 0 : void 0)) {
convRate = api.planGemLimits.convRate;
convCap = api.planGemLimits + user.purchased.plan.consecutive.gemCapExtra;
if (!((_ref1 = user.purchased) != null ? (_ref2 = _ref1.plan) != null ? _ref2.planId : void 0 : void 0)) {
return typeof cb === "function" ? cb({
code: 401,
message: "Must subscribe to purchase gems with GP"
@ -15822,7 +15846,7 @@ api.wrap = function(user, main) {
{user}
*/
cron: function(options) {
var clearBuffs, daysMissed, expTally, lvl, lvlDiv2, now, perfect, plan, progress, todoTally, _base, _base1, _base2, _base3, _progress, _ref, _ref1, _ref2, _ref3, _ref4;
var clearBuffs, daysMissed, expTally, lvl, lvlDiv2, now, perfect, plan, progress, todoTally, _base, _base1, _base2, _base3, _progress, _ref, _ref1, _ref2;
if (options == null) {
options = {};
}
@ -15838,12 +15862,6 @@ api.wrap = function(user, main) {
if (user.items.lastDrop.count > 0) {
user.items.lastDrop.count = 0;
}
if ((_ref = user.purchased) != null ? (_ref1 = _ref.plan) != null ? _ref1.customerId : void 0 : void 0) {
if (moment(user.purchased.plan.dateUpdated).format('MMYYYY') !== moment().format('MMYYYY')) {
user.purchased.plan.gemsBought = 0;
user.purchased.plan.dateUpdated = new Date();
}
}
perfect = true;
clearBuffs = {
str: 0,
@ -15942,7 +15960,7 @@ api.wrap = function(user, main) {
date: now,
value: expTally
});
if (!((_ref2 = user.purchased) != null ? (_ref3 = _ref2.plan) != null ? _ref3.customerId : void 0 : void 0)) {
if (!((_ref = user.purchased) != null ? (_ref1 = _ref.plan) != null ? _ref1.customerId : void 0 : void 0)) {
user.fns.preenUserHistory();
if (typeof user.markModified === "function") {
user.markModified('history');
@ -15963,14 +15981,37 @@ api.wrap = function(user, main) {
if (user.stats.mp > user._statsComputed.maxMP) {
user.stats.mp = user._statsComputed.maxMP;
}
plan = (_ref4 = user.purchased) != null ? _ref4.plan : void 0;
if (plan && plan.customerId && plan.dateTerminated && moment(plan.dateTerminated).isBefore(+(new Date))) {
_.merge(user.purchased.plan, {
planId: null,
customerId: null,
paymentMethod: null
});
user.markModified('purchased.plan');
plan = (_ref2 = user.purchased) != null ? _ref2.plan : void 0;
if (plan != null ? plan.customerId : void 0) {
if (moment(plan.dateUpdated).format('MMYYYY') !== moment().format('MMYYYY')) {
plan.gemsBought = 0;
plan.dateUpdated = new Date();
plan.consecutive.count++;
if (plan.consecutive.offset > 0) {
plan.consecutive.offset--;
} else if (plan.consecutive.count % 3 === 0) {
plan.consecutive.trinkets++;
plan.consecutive.gemCapExtra += 5;
if (plan.consecutive.gemCapExtra > 25) {
plan.consecutive.gemCapExtra = 25;
}
}
}
if (plan.dateTerminated && moment(plan.dateTerminated).isBefore(+(new Date))) {
_.merge(plan, {
planId: null,
customerId: null,
paymentMethod: null
});
_.merge(plan.consecutive, {
count: 0,
offset: 0,
gemCapExtra: 0
});
if (typeof user.markModified === "function") {
user.markModified('purchased.plan');
}
}
}
progress = user.party.quest.progress;
_progress = _.cloneDeep(progress);

View file

@ -1371,6 +1371,12 @@ api.backgrounds =
text: t('backgroundSouthPoleText')
notes: t('backgroundSouthPoleNotes')
api.subscriptionBlocks =
"1": months:1, price:5, key: 'basic_earned'
"3": months:3, price:15, key: 'basic_3mo'
"6": months:6, price:30, key: 'basic_6mo'
"12": months:12, price:48, key: 'basic_12mo'
repeat = {m:true,t:true,w:true,th:true,f:true,s:true,su:true}
api.userDefaults =
habits: [

View file

@ -694,7 +694,8 @@ api.wrap = (user, main=true) ->
{type,key} = req.params
if type is 'gems' and key is 'gem'
{convRate,convCap} = api.planGemLimits
{convRate} = api.planGemLimits
convCap = api.planGemLimits + user.purchased.plan.consecutive.gemCapExtra
return cb?({code:401,message:"Must subscribe to purchase gems with GP"},req) unless user.purchased?.plan?.planId
return cb?({code:401,message:"Not enough Gold"}) unless user.stats.gp >= convRate
return cb?({code:401,message:"You've reached the Gold=>Gem conversion cap (#{convCap}) for this month. We have this to prevent abuse / farming. The cap will reset within the first three days of next month."}) if user.purchased.plan.gemsBought >= convCap
@ -1377,13 +1378,6 @@ api.wrap = (user, main=true) ->
if user.items.lastDrop.count > 0
user.items.lastDrop.count = 0
# Reset caps for subscribers
if user.purchased?.plan?.customerId
if moment(user.purchased.plan.dateUpdated).format('MMYYYY') != moment().format('MMYYYY')
#+moment().format('D') >= +moment(user.purchased.plan.dateCreated).format('D') and
user.purchased.plan.gemsBought = 0
user.purchased.plan.dateUpdated = new Date()
# "Perfect Day" achievement for perfect-days
perfect = true
clearBuffs = {str:0,int:0,per:0,con:0,stealth:0,streaks:false}
@ -1466,16 +1460,30 @@ api.wrap = (user, main=true) ->
else clearBuffs
# Add 10 MP, or 10% of max MP if that'd be more. Perform this after Perfect Day for maximum benefit
user.stats.mp += _.max([10,.1 * user._statsComputed.maxMP])
user.stats.mp = user._statsComputed.maxMP if user.stats.mp > user._statsComputed.maxMP
# If user cancelled subscription, we give them until 30day's end until it terminates
# end-of-month perks for subscribers
plan = user.purchased?.plan
if plan && plan.customerId && plan.dateTerminated && moment(plan.dateTerminated).isBefore(+new Date)
_.merge user.purchased.plan, {planId:null, customerId:null, paymentMethod:null}
user.markModified 'purchased.plan'
if plan?.customerId
if moment(plan.dateUpdated).format('MMYYYY') != moment().format('MMYYYY')
plan.gemsBought = 0 # reset gem-cap
plan.dateUpdated = new Date()
# For every month, inc their "consecutive months" counter. Give perks based on consecutive blocks
# If they already got perks for those blocks (eg, 6mo subscription, subscription gifts, etc) - then dec the offset until it hits 0
# TODO use month diff instead of ++ / --?
plan.consecutive.count++
if plan.consecutive.offset > 0
plan.consecutive.offset--
else if plan.consecutive.count%3==0 # every 3 months
plan.consecutive.trinkets++
plan.consecutive.gemCapExtra+=5
plan.consecutive.gemCapExtra=25 if plan.consecutive.gemCapExtra>25 # cap it at 50 (hard 25 limit + extra 25)
# If user cancelled subscription, we give them until 30day's end until it terminates
if plan.dateTerminated && moment(plan.dateTerminated).isBefore(+new Date)
_.merge plan, {planId:null, customerId:null, paymentMethod:null}
_.merge plan.consecutive, {count:0, offset:0, gemCapExtra:0}
user.markModified? 'purchased.plan'
# After all is said and done, progress up user's effect on quest, return those values & reset the user's
progress = user.party.quest.progress; _progress = _.cloneDeep progress