mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
bug fix: needed to kill user before checking their exp - tnl() >= 0
when lvl == 0 Conflicts: test/test.coffee
This commit is contained in:
@@ -33,13 +33,6 @@ hpModifier = function(user, value) {
|
|||||||
|
|
||||||
updateStats = function(user, stats) {
|
updateStats = function(user, stats) {
|
||||||
var money, tnl;
|
var money, tnl;
|
||||||
if (stats.hp != null) {
|
|
||||||
if (stats.hp < 0) {
|
|
||||||
user.set('stats.lvl', 0);
|
|
||||||
} else {
|
|
||||||
user.set('stats.hp', stats.hp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (stats.exp != null) {
|
if (stats.exp != null) {
|
||||||
tnl = user.get('_tnl');
|
tnl = user.get('_tnl');
|
||||||
if (stats.exp >= tnl) {
|
if (stats.exp >= tnl) {
|
||||||
@@ -61,6 +54,13 @@ updateStats = function(user, stats) {
|
|||||||
}
|
}
|
||||||
user.set('stats.exp', stats.exp);
|
user.set('stats.exp', stats.exp);
|
||||||
}
|
}
|
||||||
|
if (stats.hp != null) {
|
||||||
|
if (stats.hp < 0) {
|
||||||
|
user.set('stats.lvl', 0);
|
||||||
|
} else {
|
||||||
|
user.set('stats.hp', stats.hp);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (stats.money != null) {
|
if (stats.money != null) {
|
||||||
if (!(typeof money !== "undefined" && money !== null) || money < 0) {
|
if (!(typeof money !== "undefined" && money !== null) || money < 0) {
|
||||||
money = 0.0;
|
money = 0.0;
|
||||||
|
|||||||
@@ -28,13 +28,6 @@ hpModifier = (user, value) ->
|
|||||||
|
|
||||||
# Setter for user.stats: handles death, leveling up, etc
|
# Setter for user.stats: handles death, leveling up, etc
|
||||||
updateStats = (user, stats) ->
|
updateStats = (user, stats) ->
|
||||||
if stats.hp?
|
|
||||||
# game over
|
|
||||||
if stats.hp < 0
|
|
||||||
user.set 'stats.lvl', 0 # this signifies dead
|
|
||||||
else
|
|
||||||
user.set 'stats.hp', stats.hp
|
|
||||||
|
|
||||||
if stats.exp?
|
if stats.exp?
|
||||||
# level up & carry-over exp
|
# level up & carry-over exp
|
||||||
tnl = user.get '_tnl'
|
tnl = user.get '_tnl'
|
||||||
@@ -58,12 +51,18 @@ updateStats = (user, stats) ->
|
|||||||
|
|
||||||
user.set 'stats.exp', stats.exp
|
user.set 'stats.exp', stats.exp
|
||||||
|
|
||||||
|
if stats.hp?
|
||||||
|
# game over
|
||||||
|
if stats.hp < 0
|
||||||
|
user.set 'stats.lvl', 0 # this signifies dead
|
||||||
|
else
|
||||||
|
user.set 'stats.hp', stats.hp
|
||||||
|
|
||||||
if stats.money?
|
if stats.money?
|
||||||
money = 0.0 if (!money? or money<0)
|
money = 0.0 if (!money? or money<0)
|
||||||
user.set 'stats.money', stats.money
|
user.set 'stats.money', stats.money
|
||||||
|
|
||||||
module.exports.score = score = (spec = {user:null, task:null, direction:null, cron:null}) ->
|
module.exports.score = score = (spec = {user:null, task:null, direction:null, cron:null}) ->
|
||||||
# console.log spec, "scoring.coffee: score( ->spec<- )"
|
|
||||||
[user, task, direction, cron] = [spec.user, spec.task, spec.direction, spec.cron]
|
[user, task, direction, cron] = [spec.user, spec.task, spec.direction, spec.cron]
|
||||||
|
|
||||||
# up / down was called by itself, probably as REST from 3rd party service
|
# up / down was called by itself, probably as REST from 3rd party service
|
||||||
|
|||||||
35
test/test.coffee
Normal file
35
test/test.coffee
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
url = 'http://localhost:3000'
|
||||||
|
utils = require('utils')
|
||||||
|
casper = require("casper").create()
|
||||||
|
|
||||||
|
# ---------- Main Stuff ------------
|
||||||
|
|
||||||
|
casper.start url, ->
|
||||||
|
@test.assertTitle "HabitRPG", "homepage title is the one expected"
|
||||||
|
|
||||||
|
|
||||||
|
# ---------- User Death ------------
|
||||||
|
casper.then ->
|
||||||
|
@repeat 55, ->
|
||||||
|
@click '.habits a[data-direction="down"]'
|
||||||
|
|
||||||
|
casper.then ->
|
||||||
|
userStats = @evaluate ->
|
||||||
|
window.DERBY.model.get('_user.stats')
|
||||||
|
utils.dump userStats
|
||||||
|
|
||||||
|
@test.assert(@visible('#dead-modal'), 'Revive Modal Visible')
|
||||||
|
@test.assert(userStats.hp == 0, 'User HP: 0')
|
||||||
|
@test.assert(userStats.lvl == 0, 'User Lvl: 0')
|
||||||
|
@test.assert(userStats.money == 0, 'User GP: 0')
|
||||||
|
|
||||||
|
# ---------- Misc Pages ------------
|
||||||
|
|
||||||
|
# casper.thenOpen "#{url}/terms", ->
|
||||||
|
# @test.assertTitle "Terms Of Use", "terms page works"
|
||||||
|
#
|
||||||
|
# casper.thenOpen "#{url}/privacy", ->
|
||||||
|
# @test.assertTitle "Privacy Policy", "privacy page works"
|
||||||
|
|
||||||
|
casper.run ->
|
||||||
|
@test.renderResults true
|
||||||
Reference in New Issue
Block a user