cleanup death handling

This commit is contained in:
Tyler Renelle 2013-12-07 11:30:24 -07:00
parent 86dae794b1
commit deb7e83394
2 changed files with 10 additions and 17 deletions

View file

@ -8771,25 +8771,20 @@ var global=self;/**
};
obj.revive = function(user) {
var candidate, count, item, k, lostItem, lostStat, v, _ref1;
var count, item, k, lostItem, lostStat, v, _ref1;
user.stats.hp = 50;
user.stats.exp = 0;
user.stats.gp = 0;
if (user.stats.lvl > 1) {
user.stats.lvl--;
}
if ((user.stats.str + user.stats.con + user.stats.per + user.stats.int) > 1) {
while (!lostStat) {
candidate = {
0: 'str',
1: 'con',
2: 'per',
3: 'int'
}[Math.random() * 4 | 0];
if (user.stats[candidate] > 0) {
lostStat = candidate;
}
lostStat = helpers.randomVal(_.reduce(['str', 'con', 'per', 'int'], (function(m, k) {
if (user.stats[v]) {
m[k] = k;
}
return m;
}), {}));
if (lostStat) {
user.stats[lostStat]--;
}
count = 0;

View file

@ -37,13 +37,11 @@ obj.revive = (user)->
user.stats.lvl-- if user.stats.lvl > 1
# Lose a stat point
if (user.stats.str + user.stats.con + user.stats.per + user.stats.int) > 1
until lostStat
candidate = {0:'str', 1:'con', 2:'per', 3:'int'}[Math.random()*4|0]
lostStat = candidate if user.stats[candidate] > 0
user.stats[lostStat]--
lostStat = helpers.randomVal _.reduce ['str','con','per','int'], ((m,k)->(m[k]=k if user.stats[v];m)), {}
user.stats[lostStat]-- if lostStat
# Lose a gear piece
# Can't use randomVal since we need k, not v
count = 0
for k,v of user.items.gear.owned
lostItem = k if Math.random() < (1 / ++count)