Browse Source

Fixes #156

tags/v0.1.3^2
Shaun 7 years ago
parent
commit
c534c2729d
2 changed files with 42 additions and 24 deletions
  1. +14
    -5
      src/server/components/notice.js
  2. +28
    -19
      src/server/components/stats.js

+ 14
- 5
src/server/components/notice.js View File

@@ -69,11 +69,13 @@ define([
}, [obj.serverId]); }, [obj.serverId]);
}, },


collisionExit: function(obj) {
if (!obj.player)
return;
else if ((this.maxLevel) && (obj.stats.values.level > this.maxLevel))
return;
collisionExit: function(obj, force) {
if (!force) {
if (!obj.player)
return;
else if ((this.maxLevel) && (obj.stats.values.level > this.maxLevel))
return;
}


this.callAction(obj, 'exit'); this.callAction(obj, 'exit');


@@ -83,6 +85,13 @@ define([
this.syncer.queue('onRemoveDialogue', { this.syncer.queue('onRemoveDialogue', {
src: this.obj.id src: this.obj.id
}, [obj.serverId]); }, [obj.serverId]);
},

events: {
onCellPlayerLevelUp: function(obj) {
if ((this.maxLevel) && (obj.stats.values.level > this.maxLevel))
this.collisionExit(obj, true);
}
} }
}; };
}); });

+ 28
- 19
src/server/components/stats.js View File

@@ -156,45 +156,54 @@ define([
}, },


getXp: function(amount) { getXp: function(amount) {
amount = ~~(amount * (1 + (this.values.xpIncrease / 100)));
var obj = this.obj;
var values = this.values;

amount = ~~(amount * (1 + (values.xpIncrease / 100)));


this.values.xpTotal = ~~(this.values.xpTotal + amount);
this.values.xp = ~~(this.values.xp + amount);
values.xpTotal = ~~(values.xpTotal + amount);
values.xp = ~~(values.xp + amount);


this.syncer.queue('onGetDamage', { this.syncer.queue('onGetDamage', {
id: this.obj.id,
id: obj.id,
event: true, event: true,
text: '+' + amount + ' xp' text: '+' + amount + ' xp'
}); });


var syncO = {}; var syncO = {};

var didLevelUp = false; var didLevelUp = false;
while (this.values.xp >= this.values.xpMax) {

while (values.xp >= values.xpMax) {
didLevelUp = true; didLevelUp = true;
this.values.xp -= this.values.xpMax;
this.values.level++;
values.xp -= values.xpMax;
values.level++;


this.values.hpMax += 40;
values.hpMax += 40;


this.syncer.queue('onGetDamage', { this.syncer.queue('onGetDamage', {
id: this.obj.id,
id: obj.id,
event: true, event: true,
text: 'level up' text: 'level up'
}); });


this.obj.syncer.setObject(true, 'stats', 'values', 'level', this.values.level);
this.obj.syncer.setObject(true, 'stats', 'values', 'hpMax', this.values.hpMax);
obj.syncer.setObject(true, 'stats', 'values', 'level', values.level);
obj.syncer.setObject(true, 'stats', 'values', 'hpMax', values.hpMax);


syncO.level = this.values.level;
syncO.level = values.level;


this.calcXpMax(); this.calcXpMax();
} }


if (didLevelUp)
this.obj.auth.doSave();
if (didLevelUp) {
var cellContents = obj.instance.physics.getCell(obj.x, obj.y);
cellContents.forEach(function(c) {
c.fireEvent('onCellPlayerLevelUp', obj);
});

obj.auth.doSave();
}


this.obj.syncer.setObject(true, 'stats', 'values', 'xp', this.values.xp);
obj.syncer.setObject(true, 'stats', 'values', 'xp', this.values.xp);


process.send({ process.send({
method: 'object', method: 'object',
@@ -237,13 +246,13 @@ define([
var amount = level * 10 * mult; var amount = level * 10 * mult;
if (Math.abs(levelDelta) <= 10) if (Math.abs(levelDelta) <= 10)
amount = ~~(((sourceLevel + levelDelta) * 10) * Math.pow(1 - (Math.abs(levelDelta) / 10), 2) * mult); amount = ~~(((sourceLevel + levelDelta) * 10) * Math.pow(1 - (Math.abs(levelDelta) / 10), 2) * mult);
else
else
amount = 0; amount = 0;


a.obj.stats.getXp(amount, this.obj); a.obj.stats.getXp(amount, this.obj);
} }
a.obj.fireEvent('afterKillMob', target); a.obj.fireEvent('afterKillMob', target);
} }




Loading…
Cancel
Save