habitica/src/app/algos.coffee

68 lines
2 KiB
CoffeeScript
Raw Normal View History

2013-03-06 17:02:08 +00:00
XP = 15
HP = 2
2013-03-02 18:23:43 +00:00
priorityValue = (priority='!') ->
switch priority
when '!' then 1
when '!!' then 1.5
when '!!!' then 2
else 1
2013-03-02 18:23:43 +00:00
module.exports.tnl = (level) ->
2013-03-06 17:02:08 +00:00
if level >= 100
value = 0
else
value = Math.round(((Math.pow(level,2)*0.25)+(10 * level) + 139.75)/10)*10 # round to nearest 10
return value
2013-03-02 18:23:43 +00:00
###
Calculates Exp modificaiton based on level and weapon strength
{value} task.value for exp gain
{weaponStrength) weapon strength
{level} current user level
{priority} user-defined priority multiplier
2013-03-02 18:23:43 +00:00
###
2013-03-06 17:02:08 +00:00
module.exports.expModifier = (value, weaponStr, level, priority='!') ->
str = (level-1) / 2 # ultimately get this from user
2013-03-06 17:02:08 +00:00
totalStr = (str + weaponStr) / 100
strMod = 1 + totalStr
exp = value * XP * strMod * priorityValue(priority)
return Math.round(exp)
2013-03-02 18:23:43 +00:00
###
Calculates HP modification based on level and armor defence
{value} task.value for hp loss
{armorDefense} defense from armor
{helmDefense} defense from helm
{level} current user level
{priority} user-defined priority multiplier
2013-03-02 18:23:43 +00:00
###
2013-03-06 17:02:08 +00:00
module.exports.hpModifier = (value, armorDef, helmDef, shieldDef, level, priority='!') ->
def = (level-1) / 2 # ultimately get this from user?
2013-03-06 17:02:08 +00:00
totalDef = (def + armorDef + helmDef + shieldDef) / 100 #ultimate get this from user
defMod = 1 - totalDef
hp = value * HP * defMod * priorityValue(priority)
return Math.round(hp * 10)/10 # round to 1dp
2013-03-02 18:23:43 +00:00
###
Future use
{priority} user-defined priority multiplier
2013-03-02 18:23:43 +00:00
###
module.exports.gpModifier = (value, modifier, priority='!') ->
return value * modifier * priorityValue(priority)
2013-03-02 18:23:43 +00:00
###
Calculates the next task.value based on direction
Uses a capped inverse log y=.95^x, y>= -5
2013-03-02 18:23:43 +00:00
{currentValue} the current value of the task
{direction} up or down
###
module.exports.taskDeltaFormula = (currentValue, direction) ->
2013-03-06 17:02:08 +00:00
if currentValue < -47.27 then currentValue = -47.27
else if currentValue > 21.27 then currentValue = 21.27
delta = Math.pow(0.9747,currentValue)
return delta if direction is 'up'
return -delta