'use strict'; var quick = require('quick-pomelo'); var P = quick.Promise; var _ = require('lodash'); var C = require('../../../../share/constant'); var Handler = function (app) { this.app = app; }; module.exports = function (app) { return new Handler(app); }; var proto = Handler.prototype; // 判断桌子是否存在 proto.isTableExist = P.coroutine(function* (msg, session, next) { // console.warn("XXXXXXXXXXXXXX000"); if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } if (!msg.tableId) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } var reload = parseInt(msg.reload) || 0;//ts++重入 1为重入 return this.app.controllers.sxjiang.isTableExistAsync(session.uid, String(msg.tableId),reload).nodeify(next); }); // 加入桌子 proto.joinTable = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } if (!msg.tableId) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } return this.app.controllers.sxjiang.joinTableAsync(session.uid, String(msg.tableId)).nodeify(next); }); //////TL++创建或者加入桌子,用于玩家通过战绩分享进来之后 proto.creatOrjoinTable = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } if (!msg.upId) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } if (!msg.other) { if(msg.other != 0){ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } } var round = parseInt(msg.round); var type = parseInt(msg.type) || 0; var kind = parseInt(msg.kind) || 1;////平搓还是冲刺 = 1代表平搓 = 2代表冲刺 if(kind != 1 && kind != 2){ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是平搓也不是冲刺 } var playercount = parseInt(msg.playercount) || 4;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局 var other = parseInt(msg.other) || 0;////TL++2人3人的游戏规则 if (other < 0 || other > 4095) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } if(!((other & 64) || (other & 1024) || (other & 2048))&& (other & 512)){ //“红中个数”=0的时候不能勾选“无红中胡加一码” return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } if((!(other & 1)) && (!(other & 2)) && (!(other & 4))){ //没有勾选任何奖码方式,如159奖码,摸几奖几,一码全中 if((other & 8) || (other & 16) || (other & 32) || (other & 512)){ //没有勾选任何奖码方式的话指定奖码张数是不合法的 return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } } var upId = msg.upId;////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值 // console.warn("创建房间的other",other,msg.other); if(round != 24 && round != 16 && round != 8){//////游戏局数不合法 return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } if(playercount != 2 && playercount != 3 && playercount != 4){//////游戏人数不合法 return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } var agentId=msg.agentId || "";//数据库中agenter(推广员)数据表的主键(_id) // console.warn("创建或者加入桌子 agentId "+agentId+" session.uid "+session.uid); return this.app.controllers.sxjiang.creatOrjoinTableAsync(session.uid, round,type, kind,playercount,upId,other,agentId).nodeify(next); // return this.app.controllers.sxjiang.creatOrjoinTableAsync(session.uid, msg).nodeify(next); }); // 创建桌子 proto.createTable = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } if (!msg.other) { if(msg.other != 0){ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } } var round = parseInt(msg.round); var type = parseInt(msg.type) || 0; var gameKindTL = parseInt(msg.gameKindTL) || 1;////平搓还是冲刺 = 1代表平搓 = 2代表冲刺 if(gameKindTL != 1 && gameKindTL != 2){ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是平搓也不是冲刺 } var playerAllCount = parseInt(msg.playerAllCount) || 4;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局 var other = parseInt(msg.other) || 0;////TL++2人3人的游戏规则 if (other < 0 || other > 4095) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } if(!((other & 64) || (other & 1024) || (other & 2048))&& (other & 512)){ //“红中个数”=0的时候不能勾选“无红中胡加一码” return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } if((!(other & 1)) && (!(other & 2)) && (!(other & 4))){ //没有勾选任何奖码方式,如159奖码,摸几奖几,一码全中 if((other & 8) || (other & 16) || (other & 32) || (other & 512)){ //没有勾选任何奖码方式的话指定奖码张数是不合法的 return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } } var upId = msg.upId || "";////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值 // console.warn("创建房间的other",other,msg.other); if(round != 24 && round != 16 && round != 8){//////游戏局数不合法 return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } if(playerAllCount != 2 && playerAllCount != 3 && playerAllCount != 4){//////游戏人数不合法 return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } var agentId=msg.agentId || ""; // console.warn("创建桌子, "+agentId+" session.uid "+session.uid);//数据库中agenter(推广员)数据表的主键(_id) return this.app.controllers.sxjiang.createTableAsync(session.uid, round, type,gameKindTL,playerAllCount,upId,other,agentId).nodeify(next);/////修改局数 }); // TL++,得到玩家位置 proto.sendLocation = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.sxjiang.sendLocationAsync(session.uid, msg).nodeify(next); }); // 得到玩家位置 proto.getLocation = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.sxjiang.getLocationAsync(session.uid, msg).nodeify(next); }); // 离开桌子 proto.leaveTable = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.sxjiang.leaveTableAsync(session.uid).nodeify(next); }); // 坐下 proto.seat = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var chairId = parseInt(msg.chairId); if (!chairId && chairId != 0) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } return this.app.controllers.sxjiang.seatAsync(session.uid, chairId).nodeify(next); }); // 站起 proto.stand = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.sxjiang.standAsync(session.uid).nodeify(next); }); // 准备 proto.ready = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.sxjiang.readyGameAsync(session.uid).nodeify(next); }); // 开始 proto.startGame = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.sxjiang.startGameAsync(session.uid).nodeify(next); }); // 出牌 proto.outCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var card = parseInt(msg.card); if (!card) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } return this.app.controllers.sxjiang.outCardAsync(session.uid, card).nodeify(next); }); // 杠牌 proto.gangCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var card = parseInt(msg.card); var type = parseInt(msg.type); if (!card || !type) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } return this.app.controllers.sxjiang.gangCardAsync(session.uid, card, type).nodeify(next); }); // 碰牌 proto.pengCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var card = parseInt(msg.card); if (!card) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } return this.app.controllers.sxjiang.pengCardAsync(session.uid, card).nodeify(next); }); // 吃牌 proto.eatCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var card = parseInt(msg.card); var type = parseInt(msg.type); if (!card || !type) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } return this.app.controllers.sxjiang.eatCardAsync(session.uid, card, type).nodeify(next); }); // 胡牌 proto.succCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.sxjiang.succCardAsync(session.uid).nodeify(next); }); // 放弃 proto.giveUp = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.sxjiang.giveUpAsync(session.uid).nodeify(next); }); /////TL++,海底捞月 proto.haidilaoyue = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.sxjiang.haiDiLaoYue(session.uid,msg).nodeify(next); }); /////TL++,操作是否自动出牌 proto.autoOutCard = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return next(null, { code: C.FAILD, msg: "敬请期待" }); // return this.app.controllers.sxjiang.autoOutCard(session.uid).nodeify(next); }); // 聊天 proto.chat = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.sxjiang.sendMsgAsync(session.uid, msg).nodeify(next); }); // 收费聊天 proto.vchat = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var chairId = parseInt(msg.chairId); if (!(chairId >= 0)) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } if (!msg.msg) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } return this.app.controllers.sxjiang.vsendMsgAsync(session.uid, chairId, msg.msg).nodeify(next); }); // 角色信息 proto.roleInfo = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } var chairId = parseInt(msg.chairId); if (!(chairId >= 0)) { return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR }); } return this.app.controllers.sxjiang.roleInfoAsync(session.uid, chairId).nodeify(next); }); // 请求结束 proto.overTable = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.sxjiang.overTableAsync(session.uid).nodeify(next); }); // 拒绝结束 proto.refuseOver = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.sxjiang.refuseOverAsync(session.uid).nodeify(next); }); // 同意结束 proto.agreeOver = P.coroutine(function* (msg, session, next) { if (!session.uid) { return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN }); } return this.app.controllers.sxjiang.agreeOverAsync(session.uid).nodeify(next); });