瀏覽代碼

refactoring

tags/v0.3.3^2
Shaun Kichenbrand 4 年之前
父節點
當前提交
042ce6fb5d
共有 4 個文件被更改,包括 84 次插入70 次删除
  1. +4
    -0
      src/server/components/gatherer.js
  2. +46
    -42
      src/server/components/social.js
  3. +4
    -28
      src/server/world/map.js
  4. +30
    -0
      src/server/world/map/mapObjects.js

+ 4
- 0
src/server/components/gatherer.js 查看文件

@@ -81,6 +81,10 @@ module.exports = {
return;
}

this.completeGathering(gathering, isFish);
},

completeGathering: function (gathering, isFish) {
let resourceNode = gathering.resourceNode;
let gatherResult = extend({
obj: gathering


+ 46
- 42
src/server/components/social.js 查看文件

@@ -137,6 +137,49 @@ module.exports = {
}
},

sendPrivateMessage: function (messageString) {
let playerName = '';
//Check if there's a space in the name
if (messageString[1] === "'") {
playerName = messageString.substring(2, messageString.indexOf("'", 2));
messageString = messageString.replace("@'" + playerName + "' ", '');
} else {
playerName = messageString.substring(1, messageString.indexOf(' '));
messageString = messageString.replace('@' + playerName + ' ', '');
}

if (playerName === this.obj.name)
return;

let target = cons.players.find(p => p.name === playerName);
if (!target)
return;

this.obj.socket.emit('event', {
event: 'onGetMessages',
data: {
messages: [{
class: 'color-yellowB',
message: '(you to ' + playerName + '): ' + messageString,
type: 'chat',
source: this.obj.name
}]
}
});

target.socket.emit('event', {
event: 'onGetMessages',
data: {
messages: [{
class: 'color-yellowB',
message: '(' + this.obj.name + ' to you): ' + messageString,
type: 'chat',
source: this.obj.name
}]
}
});
},

chat: function (msg) {
if (!msg.data.message)
return;
@@ -201,48 +244,9 @@ module.exports = {
};
events.emit('onBeforeSendMessage', msgEvent);
messageString = msgEvent.msg;
if (messageString[0] === '@') {
let playerName = '';
//Check if there's a space in the name
if (messageString[1] === "'") {
playerName = messageString.substring(2, messageString.indexOf("'", 2));
messageString = messageString.replace("@'" + playerName + "' ", '');
} else {
playerName = messageString.substring(1, messageString.indexOf(' '));
messageString = messageString.replace('@' + playerName + ' ', '');
}

if (playerName === this.obj.name)
return;

let target = cons.players.find(p => p.name === playerName);
if (!target)
return;

this.obj.socket.emit('event', {
event: 'onGetMessages',
data: {
messages: [{
class: 'color-yellowB',
message: '(you to ' + playerName + '): ' + messageString,
type: 'chat',
source: this.obj.name
}]
}
});

target.socket.emit('event', {
event: 'onGetMessages',
data: {
messages: [{
class: 'color-yellowB',
message: '(' + this.obj.name + ' to you): ' + messageString,
type: 'chat',
source: this.obj.name
}]
}
});
} else if (messageString[0] === '$')
if (messageString[0] === '@')
this.sendPrivateMessage(messageString);
else if (messageString[0] === '$')
this.sendCustomChannelMessage(msg);
else if (messageString[0] === '%')
this.sendPartyMessage(msg);


+ 4
- 28
src/server/world/map.js 查看文件

@@ -6,6 +6,8 @@ let globalZone = require('../config/zoneBase');
let randomMap = require('./randomMap');
let events = require('../misc/events');

const mapObjects = require('./map/mapObjects');

let mapFile = null;
let mapScale = null;
let padding = null;
@@ -370,34 +372,8 @@ module.exports = {
} else if (cell.width === 24)
blueprint.x++;

if (cell.polyline) {
let lowX = this.size.w;
let lowY = this.size.h;
let highX = 0;
let highY = 0;

blueprint.area = cell.polyline.map(function (v) {
let x = ~~((v.x + cell.x) / mapScale);
let y = ~~((v.y + cell.y) / mapScale);

if (x < lowX)
lowX = x;
if (x > highX)
highX = x;

if (y < lowY)
lowY = y;
if (y > highY)
highY = y;

return [x, y];
});

blueprint.x = lowX;
blueprint.y = lowY;
blueprint.width = (highX - lowX);
blueprint.height = (highY - lowY);
}
if (cell.polyline)
mapObjects.polyline(this.size, blueprint, cell, mapScale);

if (layerName === 'rooms') {
if (blueprint.properties.exit) {


+ 30
- 0
src/server/world/map/mapObjects.js 查看文件

@@ -0,0 +1,30 @@
module.exports = {
polyline: function (size, blueprint, cell, mapScale) {
let lowX = size.w;
let lowY = size.h;
let highX = 0;
let highY = 0;

blueprint.area = cell.polyline.map(function (v) {
let x = ~~((v.x + cell.x) / mapScale);
let y = ~~((v.y + cell.y) / mapScale);

if (x < lowX)
lowX = x;
if (x > highX)
highX = x;

if (y < lowY)
lowY = y;
if (y > highY)
highY = y;

return [x, y];
});

blueprint.x = lowX;
blueprint.y = lowY;
blueprint.width = (highX - lowX);
blueprint.height = (highY - lowY);
}
};

Loading…
取消
儲存