| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- '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.paodekuai.isTableExistAsync(session.uid, String(msg.tableId),reload).nodeify(next);
-
- });
- // 加入桌子
- proto.joinTable = P.coroutine(function* (msg, session, next) {
- // console.warn("加入桌子han");
- 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.paodekuai.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 > 255) {
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
- if((other & 2) && ((other & 4) || (other & 32))){
- // 勾选了炸弹不可拆时不能勾选四带二和四带三
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
- if(!((other & 8) || (other & 16))){
- //“没有选择张数”
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
-
- var upId = msg.upId;////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值
- // console.warn("创建房间的other",other,msg.other);
- if(round != 10 && round != 20 && round != 30){//////游戏局数不合法
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
- if(playercount != 2 && playercount != 3){//////游戏人数不合法
- 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.paodekuai.creatOrjoinTableAsync(session.uid, round,type, kind,playercount,upId,other,agentId).nodeify(next);
- // return this.app.controllers.paodekuai.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 > 255) {
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
- if((other & 2) && ((other & 4) || (other & 32))){
- // 勾选了炸弹不可拆时不能勾选四带二和四带三
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
- if(!((other & 8) || (other & 16))){
- //“没有选择张数”
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
- var upId = msg.upId || "";////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值
- // console.warn("创建房间的other",other,msg.other);
- if(round != 10 && round != 20 && round != 30){//////游戏局数不合法
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
- if(playerAllCount != 2 && playerAllCount != 3){//////游戏人数不合法
- 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.paodekuai.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.paodekuai.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.paodekuai.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.paodekuai.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.paodekuai.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.paodekuai.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.paodekuai.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.paodekuai.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 cards = msg.cards;
- let isArr = msg.cards instanceof Array;////////判断参数是否是个数组
- if (!cards || !isArr) {
- return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
- }
- return this.app.controllers.paodekuai.outCardAsync(session.uid, cards).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.paodekuai.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.paodekuai.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.paodekuai.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.paodekuai.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.paodekuai.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.paodekuai.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.paodekuai.agreeOverAsync(session.uid).nodeify(next);
- });
|