Merge pull request #6962 from piousbox/shared-code-user-score-task
shared-code-user-score-task
This commit is contained in:
@@ -11,7 +11,7 @@ function cloneDropItem (drop) {
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function(user, modifiers, req) {
|
||||
module.exports = function randomDrop (user, modifiers, req) {
|
||||
var acceptableDrops, base, base1, base2, chance, drop, dropK, dropMultiplier, name, name1, name2, quest, rarity, ref, ref1, ref2, ref3, task;
|
||||
task = modifiers.task;
|
||||
chance = _.min([Math.abs(task.value - 21.27), 37.5]) / 150 + .02;
|
||||
|
||||
@@ -4,7 +4,8 @@ import {
|
||||
MAX_STAT_POINTS
|
||||
} from '../constants';
|
||||
import { toNextLevel } from '../statHelpers';
|
||||
module.exports = function (user, stats, req, analytics) {
|
||||
|
||||
module.exports = function updateStats (user, stats, req, analytics) {
|
||||
let allocatedStatPoints;
|
||||
let totalStatPoints;
|
||||
let experienceToNextLevel;
|
||||
|
||||
@@ -27,7 +27,7 @@ function _calculateDelta (task, direction, cron) {
|
||||
|
||||
// Checklists
|
||||
if (task.checklist && task.checklist.length > 0) {
|
||||
// If the Daily, only dock them them a portion based on their checklist completion
|
||||
// If the Daily, only dock them a portion based on their checklist completion
|
||||
if (direction === 'down' && task.type === 'daily' && cron) {
|
||||
nextDelta *= 1 - _.reduce(task.checklist, (m, i) => m + (i.completed ? 1 : 0), 0) / task.checklist.length;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ function _calculateDelta (task, direction, cron) {
|
||||
|
||||
// Approximates the reverse delta for the task value
|
||||
// This is meant to return the task value to its original value when unchecking a task.
|
||||
// First, calculate the the value using the normal way for our first guess although
|
||||
// First, calculate the value using the normal way for our first guess although
|
||||
// it will be a bit off
|
||||
function _calculateReverseDelta (task, direction) {
|
||||
let currVal = _getTaskValue(task.value);
|
||||
@@ -185,6 +185,7 @@ module.exports = function scoreTask (options = {}, req = {}) {
|
||||
// ===== starting to actually do stuff, most of above was definitions =====
|
||||
if (task.type === 'habit') {
|
||||
delta += _changeTaskValue(user, task, direction, times, cron);
|
||||
|
||||
// Add habit value to habit-history (if different)
|
||||
if (delta > 0) {
|
||||
_addPoints(user, task, stats, direction, delta);
|
||||
@@ -213,17 +214,25 @@ module.exports = function scoreTask (options = {}, req = {}) {
|
||||
task.streak += 1;
|
||||
// Give a streak achievement when the streak is a multiple of 21
|
||||
if (task.streak % 21 === 0) user.achievements.streak = user.achievements.streak ? user.achievements.streak + 1 : 1;
|
||||
} else {
|
||||
task.completed = true;
|
||||
} else if (direction === 'down') {
|
||||
// Remove a streak achievement if streak was a multiple of 21 and the daily was undone
|
||||
if (task.streak % 21 === 0) user.achievements.streak = user.achievements.streak ? user.achievements.streak - 1 : 0;
|
||||
task.streak -= 1;
|
||||
task.completed = false;
|
||||
}
|
||||
}
|
||||
} else if (task.type === 'todo') {
|
||||
if (cron) { // don't touch stats on cron
|
||||
delta += _changeTaskValue(user, task, direction, times, cron);
|
||||
} else {
|
||||
task.dateCompleted = direction === 'up' ? new Date() : undefined;
|
||||
if (direction === 'up') {
|
||||
task.dateCompleted = new Date();
|
||||
task.completed = true;
|
||||
} else if (direction === 'down') {
|
||||
task.completed = false;
|
||||
task.dateCompleted = undefined;
|
||||
}
|
||||
|
||||
delta += _changeTaskValue(user, task, direction, times, cron);
|
||||
if (direction === 'down') delta = _calculateDelta(task, direction, delta); // recalculate delta for unchecking so the gp and exp come out correctly
|
||||
|
||||
Reference in New Issue
Block a user