Merge branch 'develop' into api-v3
This commit is contained in:
@@ -91,6 +91,12 @@ let armor = {
|
||||
mystery: '201509',
|
||||
value: 0,
|
||||
},
|
||||
201511: {
|
||||
text: t('armorMystery201511Text'),
|
||||
notes: t('armorMystery201511Notes'),
|
||||
mystery: '201511',
|
||||
value: 0,
|
||||
},
|
||||
301404: {
|
||||
text: t('armorMystery301404Text'),
|
||||
notes: t('armorMystery301404Notes'),
|
||||
@@ -238,6 +244,12 @@ let head = {
|
||||
mystery: '201509',
|
||||
value: 0,
|
||||
},
|
||||
201511: {
|
||||
text: t('headMystery201511Text'),
|
||||
notes: t('headMystery201511Notes'),
|
||||
mystery: '201511',
|
||||
value: 0,
|
||||
},
|
||||
301404: {
|
||||
text: t('headMystery301404Text'),
|
||||
notes: t('headMystery301404Notes'),
|
||||
|
||||
@@ -952,7 +952,8 @@ api.specialPets = {
|
||||
'JackOLantern-Base': 'jackolantern',
|
||||
'Mammoth-Base': 'mammoth',
|
||||
'Tiger-Veteran': 'veteranTiger',
|
||||
'Phoenix-Base': 'phoenix'
|
||||
'Phoenix-Base': 'phoenix',
|
||||
'Turkey-Gilded': 'gildedTurkey',
|
||||
};
|
||||
|
||||
api.specialMounts = {
|
||||
|
||||
@@ -106,6 +106,11 @@ let mysterySets = {
|
||||
end: '2015-11-02',
|
||||
text: 'Horned Goblin Set',
|
||||
},
|
||||
201511: {
|
||||
start: '2015-11-25',
|
||||
end: '2015-12-02',
|
||||
text: 'Wood Warrior Set',
|
||||
},
|
||||
301404: {
|
||||
start: '3014-03-24',
|
||||
end: '3014-04-02',
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
------------------------------------------------------
|
||||
Cron and time / day functions
|
||||
------------------------------------------------------
|
||||
*/
|
||||
import _ from 'lodash';
|
||||
import moment from 'moment';
|
||||
|
||||
export const DAY_MAPPING = {
|
||||
0: 'su',
|
||||
1: 'm',
|
||||
2: 't',
|
||||
3: 'w',
|
||||
4: 'th',
|
||||
5: 'f',
|
||||
6: 's',
|
||||
};
|
||||
|
||||
/*
|
||||
Each time we perform date maths (cron, task-due-days, etc), we need to consider user preferences.
|
||||
Specifically {dayStart} (custom day start) and {timezoneOffset}. This function sanitizes / defaults those values.
|
||||
{now} is also passed in for various purposes, one example being the test scripts scripts testing different "now" times.
|
||||
*/
|
||||
|
||||
function sanitizeOptions (o) {
|
||||
let ref = Number(o.dayStart || 0);
|
||||
let dayStart = !_.isNaN(ref) && ref >= 0 && ref <= 24 ? ref : 0;
|
||||
let timezoneOffset = o.timezoneOffset ? Number(o.timezoneOffset) : Number(moment().zone());
|
||||
// TODO: check and clean timezoneOffset as for dayStart (e.g., might not be a number)
|
||||
let now = o.now ? moment(o.now).zone(timezoneOffset) : moment().zone(timezoneOffset);
|
||||
|
||||
// return a new object, we don't want to add "now" to user object
|
||||
return {
|
||||
dayStart,
|
||||
timezoneOffset,
|
||||
now,
|
||||
};
|
||||
}
|
||||
|
||||
export function startOfWeek (options = {}) {
|
||||
let o = sanitizeOptions(options);
|
||||
|
||||
return moment(o.now).startOf('week');
|
||||
}
|
||||
|
||||
/*
|
||||
This is designed for use with any date that has an important time portion (e.g., when comparing the current date-time with the previous cron's date-time for determing if cron should run now).
|
||||
It changes the time portion of the date-time to be the Custom Day Start hour, so that the date-time is now the user's correct start of day.
|
||||
It SUBTRACTS a day if the date-time's original hour is before CDS (e.g., if your CDS is 5am and it's currently 4am, it's still the previous day).
|
||||
This is NOT suitable for manipulating any dates that are displayed to the user as a date with no time portion, such as a Daily's Start Dates (e.g., a Start Date of today shows only the date, so it should be considered to be today even if the hidden time portion is before CDS).
|
||||
*/
|
||||
|
||||
export function startOfDay (options = {}) {
|
||||
let o = sanitizeOptions(options);
|
||||
let dayStart = moment(o.now).startOf('day').add({ hours: o.dayStart });
|
||||
|
||||
if (moment(o.now).hour() < o.dayStart) {
|
||||
dayStart.subtract({ days: 1 });
|
||||
}
|
||||
return dayStart;
|
||||
}
|
||||
|
||||
/*
|
||||
Absolute diff from "yesterday" till now
|
||||
*/
|
||||
|
||||
export function daysSince (yesterday, options = {}) {
|
||||
let o = sanitizeOptions(options);
|
||||
|
||||
return startOfDay(_.defaults({ now: o.now }, o)).diff(startOfDay(_.defaults({ now: yesterday }, o)), 'days');
|
||||
}
|
||||
|
||||
/*
|
||||
Should the user do this task on this date, given the task's repeat options and user.preferences.dayStart?
|
||||
*/
|
||||
|
||||
export function shouldDo (day, dailyTask, options = {}) {
|
||||
if (dailyTask.type !== 'daily') {
|
||||
return false;
|
||||
}
|
||||
let o = sanitizeOptions(options);
|
||||
let startOfDayWithCDSTime = startOfDay(_.defaults({ now: day }, o));
|
||||
|
||||
// The time portion of the Start Date is never visible to or modifiable by the user so we must ignore it.
|
||||
// Therefore, we must also ignore the time portion of the user's day start (startOfDayWithCDSTime), otherwise the date comparison will be wrong for some times.
|
||||
// NB: The user's day start date has already been converted to the PREVIOUS day's date if the time portion was before CDS.
|
||||
let taskStartDate = moment(dailyTask.startDate).zone(o.timezoneOffset);
|
||||
|
||||
taskStartDate = moment(taskStartDate).startOf('day');
|
||||
if (taskStartDate > startOfDayWithCDSTime.startOf('day')) {
|
||||
return false; // Daily starts in the future
|
||||
}
|
||||
if (dailyTask.frequency === 'daily') { // "Every X Days"
|
||||
if (!dailyTask.everyX) {
|
||||
return false; // error condition
|
||||
}
|
||||
let daysSinceTaskStart = startOfDayWithCDSTime.startOf('day').diff(taskStartDate, 'days');
|
||||
|
||||
return daysSinceTaskStart % dailyTask.everyX === 0;
|
||||
} else if (dailyTask.frequency === 'weekly') { // "On Certain Days of the Week"
|
||||
if (!dailyTask.repeat) {
|
||||
return false; // error condition
|
||||
}
|
||||
let dayOfWeekNum = startOfDayWithCDSTime.day(); // e.g., 0 for Sunday
|
||||
|
||||
return dailyTask.repeat[DAY_MAPPING[dayOfWeekNum]];
|
||||
} else {
|
||||
return false; // error condition - unexpected frequency string
|
||||
}
|
||||
}
|
||||
+21
-186
@@ -1,4 +1,10 @@
|
||||
var $w, _, api, content, i18n, moment, preenHistory, sanitizeOptions, sortOrder,
|
||||
import {
|
||||
daysSince,
|
||||
shouldDo,
|
||||
} from '../../common/script/cron';
|
||||
import * as statHelpers from './statHelpers';
|
||||
|
||||
var $w, _, api, content, i18n, moment, preenHistory, sortOrder,
|
||||
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
moment = require('moment');
|
||||
@@ -12,6 +18,13 @@ i18n = require('./i18n');
|
||||
api = module.exports = {};
|
||||
|
||||
api.i18n = i18n;
|
||||
api.shouldDo = shouldDo;
|
||||
|
||||
api.maxLevel = statHelpers.MAX_LEVEL;
|
||||
api.capByLevel = statHelpers.capByLevel;
|
||||
api.maxHealth = statHelpers.MAX_HEALTH;
|
||||
api.tnl = statHelpers.toNextLevel;
|
||||
api.diminishingReturns = statHelpers.diminishingReturns;
|
||||
|
||||
$w = api.$w = function(s) {
|
||||
return s.split(' ');
|
||||
@@ -61,184 +74,6 @@ api.planGemLimits = {
|
||||
convCap: 25
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
------------------------------------------------------
|
||||
Time / Day
|
||||
------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Each time we're performing date math (cron, task-due-days, etc), we need to take user preferences into consideration.
|
||||
Specifically {dayStart} (custom day start) and {timezoneOffset}. This function sanitizes / defaults those values.
|
||||
{now} is also passed in for various purposes, one example being the test scripts scripts testing different "now" times
|
||||
*/
|
||||
|
||||
sanitizeOptions = function(o) {
|
||||
var dayStart, now, ref, timezoneOffset;
|
||||
dayStart = !_.isNaN(+o.dayStart) && (0 <= (ref = +o.dayStart) && ref <= 24) ? +o.dayStart : 0;
|
||||
timezoneOffset = o.timezoneOffset ? +o.timezoneOffset : +moment().zone();
|
||||
now = o.now ? moment(o.now).zone(timezoneOffset) : moment(+(new Date)).zone(timezoneOffset);
|
||||
return {
|
||||
dayStart: dayStart,
|
||||
timezoneOffset: timezoneOffset,
|
||||
now: now
|
||||
};
|
||||
};
|
||||
|
||||
api.startOfWeek = api.startOfWeek = function(options) {
|
||||
var o;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
o = sanitizeOptions(options);
|
||||
return moment(o.now).startOf('week');
|
||||
};
|
||||
|
||||
api.startOfDay = function(options) {
|
||||
var dayStart, o;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
o = sanitizeOptions(options);
|
||||
dayStart = moment(o.now).startOf('day').add({
|
||||
hours: o.dayStart
|
||||
});
|
||||
if (moment(o.now).hour() < o.dayStart) {
|
||||
dayStart.subtract({
|
||||
days: 1
|
||||
});
|
||||
}
|
||||
return dayStart;
|
||||
};
|
||||
|
||||
api.dayMapping = {
|
||||
0: 'su',
|
||||
1: 'm',
|
||||
2: 't',
|
||||
3: 'w',
|
||||
4: 'th',
|
||||
5: 'f',
|
||||
6: 's'
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Absolute diff from "yesterday" till now
|
||||
*/
|
||||
|
||||
api.daysSince = function(yesterday, options) {
|
||||
var o;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
o = sanitizeOptions(options);
|
||||
return api.startOfDay(_.defaults({
|
||||
now: o.now
|
||||
}, o)).diff(api.startOfDay(_.defaults({
|
||||
now: yesterday
|
||||
}, o)), 'days');
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Should the user do this task on this date, given the task's repeat options and user.preferences.dayStart?
|
||||
*/
|
||||
|
||||
api.shouldDo = function(day, dailyTask, options) {
|
||||
var dayOfWeekCheck, dayOfWeekNum, daysSinceTaskStart, everyXCheck, o, startOfDayWithCDSTime, taskStartDate;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
if (dailyTask.type !== 'daily') {
|
||||
return false;
|
||||
}
|
||||
o = sanitizeOptions(options);
|
||||
startOfDayWithCDSTime = api.startOfDay(_.defaults({
|
||||
now: day
|
||||
}, o));
|
||||
taskStartDate = moment(dailyTask.startDate).zone(o.timezoneOffset);
|
||||
taskStartDate = moment(taskStartDate).startOf('day');
|
||||
if (taskStartDate > startOfDayWithCDSTime.startOf('day')) {
|
||||
return false;
|
||||
}
|
||||
if (dailyTask.frequency === 'daily') {
|
||||
if (!dailyTask.everyX) {
|
||||
return false;
|
||||
}
|
||||
daysSinceTaskStart = startOfDayWithCDSTime.startOf('day').diff(taskStartDate, 'days');
|
||||
everyXCheck = daysSinceTaskStart % dailyTask.everyX === 0;
|
||||
return everyXCheck;
|
||||
} else if (dailyTask.frequency === 'weekly') {
|
||||
if (!dailyTask.repeat) {
|
||||
return false;
|
||||
}
|
||||
dayOfWeekNum = startOfDayWithCDSTime.day();
|
||||
dayOfWeekCheck = dailyTask.repeat[api.dayMapping[dayOfWeekNum]];
|
||||
return dayOfWeekCheck;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
------------------------------------------------------
|
||||
Level cap
|
||||
------------------------------------------------------
|
||||
*/
|
||||
|
||||
api.maxLevel = 100;
|
||||
|
||||
api.capByLevel = function(lvl) {
|
||||
if (lvl > api.maxLevel) {
|
||||
return api.maxLevel;
|
||||
} else {
|
||||
return lvl;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
------------------------------------------------------
|
||||
Health cap
|
||||
------------------------------------------------------
|
||||
*/
|
||||
|
||||
api.maxHealth = 50;
|
||||
|
||||
|
||||
/*
|
||||
------------------------------------------------------
|
||||
Scoring
|
||||
------------------------------------------------------
|
||||
*/
|
||||
|
||||
api.tnl = function(lvl) {
|
||||
return Math.round(((Math.pow(lvl, 2) * 0.25) + (10 * lvl) + 139.75) / 10) * 10;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
A hyperbola function that creates diminishing returns, so you can't go to infinite (eg, with Exp gain).
|
||||
{max} The asymptote
|
||||
{bonus} All the numbers combined for your point bonus (eg, task.value * user.stats.int * critChance, etc)
|
||||
{halfway} (optional) the point at which the graph starts bending
|
||||
*/
|
||||
|
||||
api.diminishingReturns = function(bonus, max, halfway) {
|
||||
if (halfway == null) {
|
||||
halfway = max / 2;
|
||||
}
|
||||
return max * (bonus / (bonus + halfway));
|
||||
};
|
||||
|
||||
api.monod = function(bonus, rateOfIncrease, max) {
|
||||
return rateOfIncrease * max * bonus / (rateOfIncrease * bonus + max);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Preen history for users with > 7 history entries
|
||||
This takes an infinite array of single day entries [day day day day day...], and turns it into a condensed array
|
||||
@@ -293,7 +128,6 @@ api.preenTodos = function(tasks) {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Update the in-browser store with new gear. FIXME this was in user.fns, but it was causing strange issues there
|
||||
*/
|
||||
@@ -535,7 +369,7 @@ api.taskClasses = function(task, filters, dayStart, lastCron, showCompleted, mai
|
||||
classes += " beingEdited";
|
||||
}
|
||||
if (type === 'todo' || type === 'daily') {
|
||||
if (completed || (type === 'daily' && !api.shouldDo(+(new Date), task, {
|
||||
if (completed || (type === 'daily' && !shouldDo(+(new Date), task, {
|
||||
dayStart: dayStart
|
||||
}))) {
|
||||
classes += " completed";
|
||||
@@ -861,6 +695,7 @@ api.wrap = function(user, main) {
|
||||
_.each(['per', 'int', 'con', 'str', 'points', 'gp', 'exp', 'mp'], function(value) {
|
||||
return stats[value] = 0;
|
||||
});
|
||||
// TODO during refactoring: move all gear code from rebirth() to its own function and then call it in reset() as well
|
||||
gear = user.items.gear;
|
||||
_.each(['equipped', 'costume'], function(type) {
|
||||
gear[type] = {};
|
||||
@@ -1558,9 +1393,9 @@ api.wrap = function(user, main) {
|
||||
} else {
|
||||
if (user.preferences.autoEquip) {
|
||||
user.items.gear.equipped[item.type] = item.key;
|
||||
message = user.fns.handleTwoHanded(item, null, req);
|
||||
}
|
||||
user.items.gear.owned[item.key] = true;
|
||||
message = user.fns.handleTwoHanded(item, null, req);
|
||||
if (message == null) {
|
||||
message = i18n.t('messageBought', {
|
||||
itemText: item.text(req.language)
|
||||
@@ -2326,7 +2161,7 @@ api.wrap = function(user, main) {
|
||||
}
|
||||
}
|
||||
dropMultiplier = ((ref1 = user.purchased) != null ? (ref2 = ref1.plan) != null ? ref2.customerId : void 0 : void 0) ? 2 : 1;
|
||||
if ((api.daysSince(user.items.lastDrop.date, user.preferences) === 0) && (user.items.lastDrop.count >= dropMultiplier * (5 + Math.floor(user._statsComputed.per / 25) + (user.contributor.level || 0)))) {
|
||||
if ((daysSince(user.items.lastDrop.date, user.preferences) === 0) && (user.items.lastDrop.count >= dropMultiplier * (5 + Math.floor(user._statsComputed.per / 25) + (user.contributor.level || 0)))) {
|
||||
return;
|
||||
}
|
||||
if (((ref3 = user.flags) != null ? ref3.dropsEnabled : void 0) && user.fns.predictableRandom(user.stats.exp) < chance) {
|
||||
@@ -2533,7 +2368,7 @@ api.wrap = function(user, main) {
|
||||
options = {};
|
||||
}
|
||||
now = +options.now || +(new Date);
|
||||
daysMissed = api.daysSince(user.lastCron, _.defaults({
|
||||
daysMissed = daysSince(user.lastCron, _.defaults({
|
||||
now: now
|
||||
}, user.preferences));
|
||||
if (!(daysMissed > 0)) {
|
||||
@@ -2599,7 +2434,7 @@ api.wrap = function(user, main) {
|
||||
thatDay = moment(now).subtract({
|
||||
days: 1
|
||||
});
|
||||
if (api.shouldDo(thatDay.toDate(), daily, user.preferences) || completed) {
|
||||
if (shouldDo(thatDay.toDate(), daily, user.preferences) || completed) {
|
||||
_.each(daily.checklist, (function(box) {
|
||||
box.completed = false;
|
||||
return true;
|
||||
@@ -2653,7 +2488,7 @@ api.wrap = function(user, main) {
|
||||
thatDay = moment(now).subtract({
|
||||
days: n + 1
|
||||
});
|
||||
if (api.shouldDo(thatDay.toDate(), task, user.preferences)) {
|
||||
if (shouldDo(thatDay.toDate(), task, user.preferences)) {
|
||||
scheduleMisses++;
|
||||
if (user.stats.buffs.stealth) {
|
||||
user.stats.buffs.stealth--;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
------------------------------------------------------
|
||||
Level cap
|
||||
------------------------------------------------------
|
||||
*/
|
||||
|
||||
export const MAX_LEVEL = 100;
|
||||
|
||||
export function capByLevel (lvl) {
|
||||
if (lvl > MAX_LEVEL) {
|
||||
return MAX_LEVEL;
|
||||
} else {
|
||||
return lvl;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
------------------------------------------------------
|
||||
Health cap
|
||||
------------------------------------------------------
|
||||
*/
|
||||
|
||||
export const MAX_HEALTH = 50;
|
||||
|
||||
/*
|
||||
------------------------------------------------------
|
||||
Scoring
|
||||
------------------------------------------------------
|
||||
*/
|
||||
|
||||
export function toNextLevel (lvl) {
|
||||
return Math.round((Math.pow(lvl, 2) * 0.25 + 10 * lvl + 139.75) / 10) * 10;
|
||||
}
|
||||
|
||||
/*
|
||||
A hyperbola function that creates diminishing returns, so you can't go to infinite (eg, with Exp gain).
|
||||
{max} The asymptote
|
||||
{bonus} All the numbers combined for your point bonus (eg, task.value * user.stats.int * critChance, etc)
|
||||
{halfway} (optional) the point at which the graph starts bending
|
||||
*/
|
||||
|
||||
export function diminishingReturns (bonus, max, halfway = max / 2) {
|
||||
return max * (bonus / (bonus + halfway));
|
||||
}
|
||||
Reference in New Issue
Block a user