Permalink
Browse files

misc:update

  • Loading branch information...
1 parent 7eb7477 commit a05567a2ebb5357e2d163327f4c805cebef9588f lwj committed Nov 21, 2012
Showing 480 changed files with 57,029 additions and 0 deletions.
View
@@ -0,0 +1,23 @@
+.project
+logs/*
+logs/tmp
+*.log
+logs/*
+*/node-log.log
+/game-server/logs/*
+!.gitignore
+/web-server/logs/*
+!.gitignore
+/node_modules/*
+/game-server/node_modules/*
+/web-server/node_modules/*
+/shared/node_modules/*
+.project
+.settings/
+**/*.svn
+*.svn
+*.sublime-project
+*.sublime-workspace
+*.swp
+.DS_Store
+.idea
View
@@ -0,0 +1,20 @@
+{
+ "predef": [
+ "describe",
+ "it",
+ "before",
+ "after",
+ "window",
+ "__resources__"
+ ],
+ "es5": true,
+ "node": true,
+ "eqeqeq": true,
+ "undef": true,
+ "curly": true,
+ "bitwise": true,
+ "immed": false,
+ "newcap": true,
+ "nonew": true,
+ "white": false
+}
View
22 LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2012 Netease, Inc. and other pomelo contributors
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,15 @@
+.project
+*.log
+*/node-log.log
+logs/*.log
+!.gitignore
+node_modules/*
+.project
+.settings/
+**/*.svn
+*.svn
+*.sublime-project
+*.sublime-workspace
+*.swp
+.DS_Store
+.idea
View
@@ -0,0 +1,21 @@
+{
+ "predef": [
+ "describe",
+ "it",
+ "before",
+ "after",
+ "window",
+ "__resources__"
+ ],
+ "es5": true,
+ "node": true,
+ "eqeqeq": true,
+ "undef": true,
+ "curly": true,
+ "bitwise": true,
+ "immed": false,
+ "newcap": true,
+ "nonew": true,
+ "white": false,
+ "smarttabs": true
+}
View
@@ -0,0 +1,97 @@
+var pomelo = require('pomelo');
+var world = require('./app/domain/world');
+var area = require('./app/domain/area/area');
+var dataApi = require('./app/util/dataApi');
+var routeUtil = require('./app/util/routeUtil');
+var playerFilter = require('./app/servers/area/filter/playerFilter');
+var ChatService = require('./app/services/chatService');
+
+/**
+ * Init app for client
+ */
+var app = pomelo.createApp();
+app.set('name', 'lord of pomelo');
+
+// Configure for production enviroment
+app.configure('production', function() {
+ // enable the system monitor modules
+ app.enable('systemMonitor');
+});
+
+// configure for global
+app.configure('production|development', function() {
+ var sceneInfo = require('./app/modules/sceneInfo');
+ var onlineUser = require('./app/modules/onlineUser');
+ if(typeof app.registerAdmin === 'function'){
+ app.registerAdmin(sceneInfo, {app: app});
+ app.registerAdmin(onlineUser, {app: app});
+ }
+ //Set areasIdMap, a map from area id to serverId.
+ if (app.serverType !== 'master') {
+ var areas = app.get('servers').area;
+ var areaIdMap = {};
+ for(var id in areas){
+ areaIdMap[areas[id].area] = areas[id].id;
+ }
+ app.set('areaIdMap', areaIdMap);
+ }
+ // proxy configures
+ app.set('proxyConfig', {
+ cacheMsg: true,
+ interval: 30,
+ lazyConnection: true,
+ enableRpcLog: true
+ });
+
+ // remote configures
+ app.set('remoteConfig', {
+ cacheMsg: true,
+ interval: 30
+ });
+
+ // route configures
+ app.route('area', routeUtil.area);
+ app.route('connector', routeUtil.connector);
+
+ app.loadConfig('mysql', app.getBase() + '/../shared/config/mysql.json');
+ app.filter(pomelo.timeout());
+});
+
+// Configure for auth server
+app.configure('production|development', 'auth', function() {
+ // load session congfigures
+ app.set('session', require('./config/session.json'));
+});
+
+// Configure for area server
+app.configure('production|development', 'area', function(){
+ app.filter(pomelo.filters.serial());
+ app.before(playerFilter());
+
+ var areaId = app.get('curServer').area;
+ if(!areaId || areaId < 0) {
+ throw new Error('load area config failed');
+ }
+ world.init(dataApi.area.all());
+ area.init(dataApi.area.findById(areaId));
+});
+
+// Configure database
+app.configure('production|development', 'area|auth|connector|master', function() {
+ var dbclient = require('./app/dao/mysql/mysql').init(app);
+ app.set('dbclient', dbclient);
+ app.load(pomelo.sync, {path:__dirname + '/app/dao/mapping', dbclient: dbclient});
+});
+
+// Configure for chat server
+app.configure('production|development', 'chat', function() {
+ app.set('chatService', new ChatService(app));
+});
+
+//start
+app.start();
+
+// Uncaught exception handler
+process.on('uncaughtException', function(err) {
+ console.error(' Caught exception: ' + err.stack);
+});
@@ -0,0 +1,38 @@
+var bt = require('pomelo-bt');
+
+var Action = function(opts) {
+ this.blackboard = opts.blackboard;
+};
+
+module.exports = Action;
+
+var pro = Action.prototype;
+
+/**
+ * Find the near by player and hates the player.
+ *
+ * @return {Number} bt.RES_SUCCESS if find a player and hates him;
+ * bt.RES_FAIL if no player nearby.
+ */
+pro.doAction = function() {
+ var character = this.blackboard.curCharacter;
+ if(character.target || character.haters.length) {
+ //have a target already
+ return bt.RES_SUCCESS;
+ }
+
+ var area = this.blackboard.area;
+ //TODO: remove magic range: 300
+ var players = area.getEntitiesByPos({x: character.x, y: character.y}, ['player'], 300);
+ if(players && players.length) {
+ //TODO: remove magic hate point: 5
+ character.increaseHateFor(players[0].enitityId, 5);
+ return bt.RES_SUCCESS;
+ }
+ //TODO: implements reset logic
+ return bt.RES_FAIL;
+};
+
+module.exports.create = function() {
+ return Action;
+};
@@ -0,0 +1,97 @@
+var bt = require('pomelo-bt');
+var BTNode = bt.Node;
+var util = require('util');
+var formula = require('../../consts/formula');
+var consts = require('../../consts/consts');
+
+var Action = function(opts) {
+ BTNode.call(this, opts.blackboard);
+};
+util.inherits(Action, BTNode);
+
+module.exports = Action;
+
+var pro = Action.prototype;
+
+/**
+ * Move the character to the target.
+ *
+ * @return {Number} bt.RES_SUCCESS if the character already next to the target;
+ * bt.RES_WAIT if the character need to move to the target;
+ * bt.RES_FAIL if any fails
+ */
+pro.doAction = function() {
+ var character = this.blackboard.curCharacter;
+ var targetId = this.blackboard.curTarget;
+ var distance = this.blackboard.distanceLimit || 200;
+ var target = this.blackboard.area.getEntity(targetId);
+
+ if(!target) {
+ // target has disappeared or died
+ character.forgetHater(targetId);
+ return bt.RES_FAIL;
+ }
+
+ if(targetId !== character.target) {
+ //target has changed
+ this.blackboard.curTarget = null;
+ this.blackboard.distanceLimit = 0;
+ this.blackboard.targetPos = null;
+ this.blackboard.moved = false;
+ return bt.RES_FAIL;
+ }
+
+ if(formula.inRange(character, target, distance)) {
+ this.blackboard.area.timer().abortAction('move', character.entityId);
+ this.blackboard.distanceLimit = 0;
+ this.blackboard.moved = false;
+ return bt.RES_SUCCESS;
+ }
+
+ if(character.type === consts.EntityType.MOB) {
+ if(Math.abs(character.x - character.spawnX) > 500 ||
+ Math.abs(character.y - character.spawnY) > 500) {
+ //we move too far and it is time to turn back
+ character.forgetHater(targetId);
+ this.blackboard.moved = false;
+ return bt.RES_FAIL;
+ }
+ }
+
+
+ var targetPos = this.blackboard.targetPos;
+ var closure = this;
+
+ if(!this.blackboard.moved){
+ character.move(target.x, target.y, false, function(err, result){
+ if(err || result === false){
+ closure.blackboard.moved = false;
+ character.target = null;
+ }
+ });
+
+ this.blackboard.targetPos = {x: target.x, y : target.y};
+ this.blackboard.moved = true;
+ } else if(targetPos && (targetPos.x !== target.x || targetPos.y !== target.y)) {
+ var dis1 = formula.distance(targetPos.x, targetPos.y, target.x, target.y);
+ var dis2 = formula.distance(character.x, character.y, target.x, target.y);
+
+ //target position has changed
+ if(((dis1 * 3 > dis2) && (dis1 < distance)) || !this.blackboard.moved){
+ targetPos.x = target.x;
+ targetPos.y = target.y;
+
+ character.move(target.x, target.y, false, function(err, result){
+ if(err || result === false){
+ closure.blackboard.moved = false;
+ character.target = null;
+ }
+ });
+ }
+ }
+ return bt.RES_WAIT;
+};
+
+module.exports.create = function() {
+ return Action;
+};
@@ -0,0 +1,30 @@
+var bt = require('pomelo-bt');
+var BTNode = bt.Node;
+var util = require('util');
+
+var Action = function(opts) {
+ BTNode.call(this, opts.blackboard);
+};
+util.inherits(Action, BTNode);
+
+module.exports = Action;
+
+var pro = Action.prototype;
+
+/**
+ * Move the current mob into patrol module and remove it from ai module.
+ *
+ * @return {Number} bt.RES_SUCCESS if everything ok;
+ * bt.RES_FAIL if any error.
+ */
+pro.doAction = function() {
+ var character = this.blackboard.curCharacter;
+ var area = this.blackboard.area;
+
+ area.timer().patrol(character.entityId);
+ return bt.RES_SUCCESS;
+};
+
+module.exports.create = function() {
+ return Action;
+};
Oops, something went wrong.

0 comments on commit a05567a

Please sign in to comment.