Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix bugs

  • Loading branch information...
commit 589b3cf5d3bf640e28c7a5caef156032290c3972 1 parent 4f67ffb
@demon0925 demon0925 authored
View
13 game-server/app/consts/formula.js
@@ -72,6 +72,19 @@ formula.distance = function(x1, y1, x2, y2) {
return Math.sqrt(dx * dx + dy * dy);
};
+formula.dropItemLv = function(mobLv, heroLv){
+ var lv = Math.min(mobLv, heroLv);
+
+ var maxLv = Math.min(25, (lv - 1));
+ var limit = 4;
+ var num = 3;
+ var seed = Math.random()*limit;
+
+ var dif = Math.floor(maxLv*Math.pow(num,seed)/Math.pow(num, limit));
+
+ return lv - dif;
+}
+
/**
* convert the date according to format
* @param {Object} date
View
4 game-server/app/dao/equipmentsDao.js
@@ -60,8 +60,8 @@ equipmentsDao.getEquipmentsByPlayerId = function(playerId, cb) {
* @param {function} cb
*/
equipmentsDao.update = function(val, cb) {
- var sql = 'update Equipments set weapon = ?, armor = ?, helmet = ?, necklace = ?, ring = ?, belt = ?, shoes = ? where id = ?';
- var args = [val.weapon, val.armor, val.helmet, val.necklace, val.ring, val.belt, val.shoes, val.id];
+ var sql = 'update Equipments set weapon = ?, armor = ?, helmet = ?, necklace = ?, ring = ?, belt = ?, amulet = ?, legguard = ?, shoes = ? where id = ?';
+ var args = [val.weapon, val.armor, val.helmet, val.necklace, val.ring, val.belt, val.amulet, val.legguard, val.shoes, val.id];
pomelo.app.get('dbclient').query(sql, args, function(err, res) {
utils.invokeCallback(cb, err, res);
View
4 game-server/app/dao/mapping/equipmentsSync.js
@@ -1,7 +1,7 @@
module.exports = {
updateEquipments: function(dbclient, val, cb) {
- var sql = 'update Equipments set weapon = ?, armor = ?, helmet = ?, necklace = ?, ring = ?, belt = ?, shoes = ? where id = ?';
- var args = [val.weapon, val.armor, val.helmet, val.necklace, val.ring, val.belt, val.shoes, val.id];
+ var sql = 'update Equipments set weapon = ?, armor = ?, helmet = ?, necklace = ?, ring = ?, belt = ?, amulet = ?, legguard = ?, shoes = ? where id = ?';
+ var args = [val.weapon, val.armor, val.helmet, val.necklace, val.ring, val.belt, val.amulet, val.legguard, val.shoes, val.id];
dbclient.query(sql, args, function(err, res) {
if (err) {
View
3  game-server/app/dao/userDao.js
@@ -161,9 +161,10 @@ userDao.getPlayerAllInfo = function (playerId, cb) {
var fightSkills = results[3];
var tasks = results[4];
player.bag = bag;
- player.equipments = equipments;
+ player.setEquipments(equipments);
player.addFightSkills(fightSkills);
player.curTasks = tasks || {};
+
if (!!err){
utils.invokeCallback(cb,err);
}else{
View
2  game-server/app/domain/entity/item.js
@@ -21,7 +21,7 @@ var Item = function(opts) {
this.hp = opts.hp;
this.mp = opts.mp;
this.price = opts.price;
- this.playerLevel = opts.playerLevel;
+ this.heroLevel = opts.heroLevel;
this.imgId = opts.imgId;
this.lifetime = 30000;
this.time = Date.now();
View
23 game-server/app/domain/entity/mob.js
@@ -174,13 +174,12 @@ Mob.prototype.dropItems = function(player) {
var dropItems = [];
for (var i = 0; i<itemCount; i++) {
var itemType = Math.floor(Math.random()*10);
- if (itemType >= 2) {
+ if (itemType >= 4) {
var item = this._dropItem(player);
if(!!item){
dropItems.push(item);
}
- }
- else if (itemType < 2) {
+ }else{
var equipment = this._dropEquipment(player);
if(!!equipment){
dropItems.push(equipment);
@@ -228,7 +227,7 @@ Mob.prototype._dropItem = function(player) {
//Drop Equipment down
Mob.prototype._dropEquipment = function(player) {
- var level = Math.min(this.level, player.level);
+ var level = formula.dropItemLv(this.level, player.level);
var pos = area.map().genPos(this, 200);
if(!pos){
@@ -236,9 +235,8 @@ Mob.prototype._dropEquipment = function(player) {
return null;
}
- var equipments = dataApi.equipment.findSmaller('heroLevel', level);
- var length = equipments.length;
- var index = Math.floor(Math.random()*length);
+ var equipments = this.getEquipmentsByLevel(level);
+ var index = Math.floor(Math.random()*equipments.length);
var equipment = equipments[index];
var dropEquipment=new Equipment({
kindId : equipment.id,
@@ -261,6 +259,17 @@ Mob.prototype._dropEquipment = function(player) {
return dropEquipment;
};
+Mob.prototype.getEquipmentsByLevel = function(level){
+ while(level > 0){
+ var equipments = dataApi.equipment.findBy('heroLevel', level);
+ if(equipments.length > 0)
+ return equipments;
+ level--;
+ }
+
+ return [];
+}
+
//Reset position
Mob.prototype.resetPosition = function() {
this.setPosition(this.spawningX, this.spawningY);
View
11 game-server/app/domain/entity/player.js
@@ -131,13 +131,16 @@ Player.prototype.setTotalAttackAndDefence = function() {
* @api public
*/
Player.prototype.equip = function(kind, equipId) {
+ var index = -1;
var curEqId = this.equipments.get(kind);
this.equipments.equip(kind, equipId);
if (curEqId > 0) {
- this.bag.addItem({id: curEqId, type: 'equipment'});
+ index = this.bag.addItem({id: curEqId, type: 'equipment'});
}
this.setTotalAttackAndDefence();
+
+ return index;
};
/**
@@ -233,7 +236,6 @@ Player.prototype.pickItem = function(entityId) {
if(!formula.inRange(this, item, 200)) {
result.distance = 200;
result.result = consts.Pick.NOT_IN_RANGE;
- this.emit('pickItem', result);
return result;
}
@@ -427,6 +429,11 @@ Player.prototype.forEachHater = function(cb) {
}
};
+Player.prototype.setEquipments = function(equipments){
+ this.equipments = equipments;
+ this.setTotalAttackAndDefence();
+}
+
/**
* Get part of curTasks information.
* It aims to be passed to client
View
6 game-server/app/servers/area/handler/equipHandler.js
@@ -27,12 +27,8 @@ handler.equip = function(msg, session, next) {
return;
}
- var curEqId = player.equipments.get(eq.kind);
- player.equip(eq.kind, eq.id);
+ bagIndex = player.equip(eq.kind, eq.id);
player.bag.removeItem(msg.index);
- if (curEqId > 0) {
- bagIndex = player.bag.addItem({id: curEqId, type: 'equipment'});
- }
status = true;
}
View
7 game-server/app/servers/connector/handler/entryHandler.js
@@ -2,6 +2,7 @@ var Code = require('../../../../../shared/code');
var userDao = require('../../../dao/userDao');
var async = require('async');
var channelUtil = require('../../../util/channelUtil');
+var logger = require('pomelo-logger').getLogger(__filename);
module.exports = function(app) {
return new Handler(app);
@@ -84,6 +85,10 @@ var onUserLeave = function (app, session, reason) {
return;
}
- app.rpc.area.playerRemote.playerLeave(session, {playerId: session.get('playerId'), areaId: session.get('areaId')}, null);
+ app.rpc.area.playerRemote.playerLeave(session, {playerId: session.get('playerId'), areaId: session.get('areaId')}, function(err){
+ if(!!err){
+ logger.error('user leave error! %j', error);
+ }
+ });
app.rpc.chat.chatRemote.kick(session, session.uid, null);
};
View
2  game-server/app/util/dispatcher.js
@@ -1,6 +1,6 @@
var crc = require('crc');
module.exports.dispatch = function(uid, connectors) {
- var index = Math.abs(crc.crc32(Number(uid))) % connectors.length;
+ var index = Number(uid) % connectors.length;
return connectors[index];
};
View
2  web-server/public/js/model/item.js
@@ -20,7 +20,7 @@ __resources__["/item.js"] = {meta: {mimetype: "application/javascript"}, data: f
this.hp = opts.hp;
this.mp = opts.mp;
this.price = opts.price;
- this.playerLevel = opts.playerLevel;
+ this.heroLevel = opts.heroLevel;
this.imgId = opts.imgId;
Entity.call(this, opts);
};
View
4 web-server/public/js/model/noEntityNode.js
@@ -21,14 +21,14 @@ __resources__["/noEntityNode.js"] = {meta: {mimetype: "application/javascript"},
name = data.name + ' - ' + data.level;
break;
case EntityType.MOB:
- name = data.englishName + ' - ' + data.level + '-' + data.entityId;
+ name = data.englishName + ' - ' + data.level;
font = '';
break;
case EntityType.NPC:
name = data.englishName;
break;
default:
- name = data.englishName||data.name;
+ name = data.englishName + ' - ' + data.heroLevel;
font = '';
}
Please sign in to comment.
Something went wrong with that request. Please try again.