mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-13 17:52:22 +00:00
export some scoring functions for use in testing
This commit is contained in:
parent
534e1be622
commit
80ac213fda
2 changed files with 99 additions and 30 deletions
|
|
@ -1,5 +1,5 @@
|
|||
// Generated by CoffeeScript 1.3.3
|
||||
var MODIFIER, async, content, cron, expModifier, helpers, hpModifier, model, moment, score, setModel, setupNotifications, updateStats, user, _;
|
||||
var MODIFIER, async, content, cron, expModifier, helpers, hpModifier, model, moment, score, setModel, setupNotifications, taskDeltaFormula, updateStats, user, _;
|
||||
|
||||
async = require('async');
|
||||
|
||||
|
|
@ -68,22 +68,66 @@ setupNotifications = function() {
|
|||
});
|
||||
};
|
||||
|
||||
expModifier = function(value) {
|
||||
var dmg, modified;
|
||||
dmg = user.get('items.weapon') * MODIFIER;
|
||||
dmg += (user.get('stats.lvl') - 1) * MODIFIER;
|
||||
/*
|
||||
Calculates Exp & GP modification based on weapon & lvl
|
||||
{value} task.value for gain
|
||||
{modifiers} may manually pass in stats as {weapon, exp}. This is used for testing
|
||||
*/
|
||||
|
||||
|
||||
expModifier = function(value, modifiers) {
|
||||
var dmg, lvl, modified, weapon, _ref;
|
||||
if (modifiers == null) {
|
||||
modifiers = null;
|
||||
}
|
||||
_ref = [user.get('items.weapon'), user.get('stats.lvl')], weapon = _ref[0], lvl = _ref[1];
|
||||
if (modifiers) {
|
||||
weapon = modifiers.weapon, lvl = modifiers.lvl;
|
||||
}
|
||||
dmg = weapon * MODIFIER;
|
||||
dmg += (lvl - 1) * MODIFIER;
|
||||
modified = value + (value * dmg);
|
||||
return modified;
|
||||
};
|
||||
|
||||
hpModifier = function(value) {
|
||||
var ac, modified;
|
||||
ac = user.get('items.armor') * MODIFIER;
|
||||
ac += (user.get('stats.lvl') - 1) * MODIFIER;
|
||||
/*
|
||||
Calculates HP-loss modification based on armor & lvl
|
||||
{value} task.value which is hurting us
|
||||
{modifiers} may manually pass in modifier as {armor, lvl}. This is used for testing
|
||||
*/
|
||||
|
||||
|
||||
hpModifier = function(value, modifiers) {
|
||||
var ac, armor, lvl, modified, _ref;
|
||||
if (modifiers == null) {
|
||||
modifiers = null;
|
||||
}
|
||||
_ref = [user.get('items.armor'), user.get('stats.lvl')], armor = _ref[0], lvl = _ref[1];
|
||||
if (modifiers) {
|
||||
armor = modifiers.armor, lvl = modifiers.lvl;
|
||||
}
|
||||
ac = armor * MODIFIER;
|
||||
ac += (lvl - 1) * MODIFIER;
|
||||
modified = value - (value * ac);
|
||||
return modified;
|
||||
};
|
||||
|
||||
/*
|
||||
Calculates the next task.value based on direction
|
||||
For negative values, use a line: something like y=-.1x+1
|
||||
For positibe values, taper off with inverse log: y=.9^x
|
||||
Would love to use inverse log for the whole thing, but after 13 fails it hits infinity. Revisit this formula later
|
||||
{currentValue} the current value of the task, determines it's next value
|
||||
{direction} 'up' or 'down'
|
||||
*/
|
||||
|
||||
|
||||
taskDeltaFormula = function(currentValue, direction) {
|
||||
var delta, sign;
|
||||
sign = direction === "up" ? 1 : -1;
|
||||
return delta = currentValue < 0 ? (-0.1 * currentValue + 1) * sign : (Math.pow(0.9, currentValue)) * sign;
|
||||
};
|
||||
|
||||
updateStats = function(stats) {
|
||||
var money, tnl;
|
||||
if (user.get('stats.lvl') === 0) {
|
||||
|
|
@ -127,7 +171,7 @@ updateStats = function(stats) {
|
|||
};
|
||||
|
||||
score = function(taskId, direction, options) {
|
||||
var adjustvalue, delta, exp, hp, lvl, modified, money, num, sign, task, taskObj, taskPath, type, userObj, value, _ref, _ref1, _ref2;
|
||||
var adjustvalue, delta, exp, hp, lvl, modified, money, num, task, taskObj, taskPath, type, userObj, value, _ref, _ref1, _ref2;
|
||||
if (options == null) {
|
||||
options = {
|
||||
cron: false,
|
||||
|
|
@ -155,8 +199,7 @@ score = function(taskId, direction, options) {
|
|||
});
|
||||
return;
|
||||
}
|
||||
sign = direction === "up" ? 1 : -1;
|
||||
delta = value < 0 ? (-0.1 * value + 1) * sign : (Math.pow(0.9, value)) * sign;
|
||||
delta = taskDeltaFormula(value, direction);
|
||||
delta *= options.times;
|
||||
adjustvalue = type !== 'reward';
|
||||
if ((type === 'habit') && (taskObj.up === false || taskObj.down === false)) {
|
||||
|
|
@ -284,8 +327,11 @@ cron = function() {
|
|||
};
|
||||
|
||||
module.exports = {
|
||||
MODIFIER: MODIFIER,
|
||||
setModel: setModel,
|
||||
MODIFIER: MODIFIER,
|
||||
score: score,
|
||||
cron: cron
|
||||
cron: cron,
|
||||
expModifier: expModifier,
|
||||
hpModifier: hpModifier,
|
||||
taskDeltaFormula: taskDeltaFormula
|
||||
};
|
||||
|
|
|
|||
|
|
@ -52,20 +52,44 @@ setupNotifications = ->
|
|||
if captures > args
|
||||
statsNotification('<i class="icon-chevron-up"></i> Level Up!', 'info')
|
||||
|
||||
# Calculates Exp modification based on weapon & lvl
|
||||
expModifier = (value) ->
|
||||
dmg = user.get('items.weapon') * MODIFIER # each new weapon increases exp gain
|
||||
dmg += (user.get('stats.lvl')-1) * MODIFIER # same for lvls
|
||||
###
|
||||
Calculates Exp & GP modification based on weapon & lvl
|
||||
{value} task.value for gain
|
||||
{modifiers} may manually pass in stats as {weapon, exp}. This is used for testing
|
||||
###
|
||||
expModifier = (value, modifiers=null) ->
|
||||
[weapon, lvl] = [user.get('items.weapon'), user.get('stats.lvl')]
|
||||
if modifiers then {weapon, lvl} = modifiers
|
||||
dmg = weapon * MODIFIER # each new weapon increases exp gain
|
||||
dmg += (lvl-1) * MODIFIER # same for lvls
|
||||
modified = value + (value * dmg)
|
||||
return modified
|
||||
|
||||
# Calculates HP-loss modification based on armor & lvl
|
||||
hpModifier = (value) ->
|
||||
ac = user.get('items.armor') * MODIFIER # each new armor decreases HP loss
|
||||
ac += (user.get('stats.lvl')-1) * MODIFIER # same for lvls
|
||||
###
|
||||
Calculates HP-loss modification based on armor & lvl
|
||||
{value} task.value which is hurting us
|
||||
{modifiers} may manually pass in modifier as {armor, lvl}. This is used for testing
|
||||
###
|
||||
hpModifier = (value, modifiers=null) ->
|
||||
[armor, lvl] = [user.get('items.armor'),user.get('stats.lvl')]
|
||||
if modifiers then {armor, lvl} = modifiers
|
||||
ac = armor * MODIFIER # each new armor decreases HP loss
|
||||
ac += (lvl-1) * MODIFIER # same for lvls
|
||||
modified = value - (value * ac)
|
||||
return modified
|
||||
|
||||
###
|
||||
Calculates the next task.value based on direction
|
||||
For negative values, use a line: something like y=-.1x+1
|
||||
For positibe values, taper off with inverse log: y=.9^x
|
||||
Would love to use inverse log for the whole thing, but after 13 fails it hits infinity. Revisit this formula later
|
||||
{currentValue} the current value of the task, determines it's next value
|
||||
{direction} 'up' or 'down'
|
||||
###
|
||||
taskDeltaFormula = (currentValue, direction) ->
|
||||
sign = if (direction == "up") then 1 else -1
|
||||
delta = if (currentValue < 0) then (( -0.1 * currentValue + 1 ) * sign) else (( Math.pow(0.9,currentValue) ) * sign)
|
||||
|
||||
# Setter for user.stats: handles death, leveling up, etc
|
||||
updateStats = (stats) ->
|
||||
# if user is dead, dont do anything
|
||||
|
|
@ -130,13 +154,7 @@ score = (taskId, direction, options={cron:false, times:1}) ->
|
|||
updateStats({hp: hp, exp: exp, money: money})
|
||||
return
|
||||
|
||||
|
||||
# For negative values, use a line: something like y=-.1x+1
|
||||
# For positibe values, taper off with inverse log: y=.9^x
|
||||
# Would love to use inverse log for the whole thing, but after 13 fails it hits infinity
|
||||
sign = if (direction == "up") then 1 else -1
|
||||
delta = if (value < 0) then (( -0.1 * value + 1 ) * sign) else (( Math.pow(0.9,value) ) * sign)
|
||||
|
||||
delta = taskDeltaFormula(value, direction)
|
||||
# If multiple days have passed, multiply times days missed
|
||||
delta *= options.times
|
||||
|
||||
|
|
@ -245,8 +263,13 @@ cron = ->
|
|||
|
||||
|
||||
module.exports = {
|
||||
MODIFIER: MODIFIER
|
||||
setModel: setModel
|
||||
MODIFIER: MODIFIER
|
||||
score: score
|
||||
cron: cron
|
||||
|
||||
# testing stuff
|
||||
expModifier: expModifier
|
||||
hpModifier: hpModifier
|
||||
taskDeltaFormula: taskDeltaFormula
|
||||
}
|
||||
Loading…
Reference in a new issue