paodekuaiHandler.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. 'use strict';
  2. var quick = require('quick-pomelo');
  3. var P = quick.Promise;
  4. var _ = require('lodash');
  5. var C = require('../../../../share/constant');
  6. var Handler = function (app) {
  7. this.app = app;
  8. };
  9. module.exports = function (app) {
  10. return new Handler(app);
  11. };
  12. var proto = Handler.prototype;
  13. // 判断桌子是否存在
  14. proto.isTableExist = P.coroutine(function* (msg, session, next) {
  15. // console.warn("XXXXXXXXXXXXXX000");
  16. if (!session.uid) {
  17. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  18. }
  19. if (!msg.tableId) {
  20. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  21. }
  22. var reload = parseInt(msg.reload) || 0;//ts++重入 1为重入
  23. return this.app.controllers.paodekuai.isTableExistAsync(session.uid, String(msg.tableId),reload).nodeify(next);
  24. });
  25. // 加入桌子
  26. proto.joinTable = P.coroutine(function* (msg, session, next) {
  27. // console.warn("加入桌子han");
  28. if (!session.uid) {
  29. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  30. }
  31. if (!msg.tableId) {
  32. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  33. }
  34. return this.app.controllers.paodekuai.joinTableAsync(session.uid, String(msg.tableId)).nodeify(next);
  35. });
  36. //////TL++创建或者加入桌子,用于玩家通过战绩分享进来之后
  37. proto.creatOrjoinTable = P.coroutine(function* (msg, session, next) {
  38. if (!session.uid) {
  39. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  40. }
  41. if (!msg.upId) {
  42. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  43. }
  44. if (!msg.other) {
  45. if(msg.other != 0){
  46. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  47. }
  48. }
  49. var round = parseInt(msg.round);
  50. var type = parseInt(msg.type) || 0;
  51. var kind = parseInt(msg.kind) || 1;////平搓还是冲刺 = 1代表平搓 = 2代表冲刺
  52. if(kind != 1 && kind != 2){
  53. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是平搓也不是冲刺
  54. }
  55. var playercount = parseInt(msg.playercount) || 4;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
  56. var other = parseInt(msg.other) || 0;////TL++2人3人的游戏规则
  57. if (other < 0 || other > 255) {
  58. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  59. }
  60. if((other & 2) && ((other & 4) || (other & 32))){
  61. // 勾选了炸弹不可拆时不能勾选四带二和四带三
  62. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  63. }
  64. if(!((other & 8) || (other & 16))){
  65. //“没有选择张数”
  66. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  67. }
  68. var upId = msg.upId;////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值
  69. // console.warn("创建房间的other",other,msg.other);
  70. if(round != 10 && round != 20 && round != 30){//////游戏局数不合法
  71. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  72. }
  73. if(playercount != 2 && playercount != 3){//////游戏人数不合法
  74. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  75. }
  76. var agentId=msg.agentId || "";//数据库中agenter(推广员)数据表的主键(_id)
  77. // console.warn("创建或者加入桌子 agentId "+agentId+" session.uid "+session.uid);
  78. return this.app.controllers.paodekuai.creatOrjoinTableAsync(session.uid, round,type, kind,playercount,upId,other,agentId).nodeify(next);
  79. // return this.app.controllers.paodekuai.creatOrjoinTableAsync(session.uid, msg).nodeify(next);
  80. });
  81. // 创建桌子
  82. proto.createTable = P.coroutine(function* (msg, session, next) {
  83. if (!session.uid) {
  84. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  85. }
  86. if (!msg.other) {
  87. if(msg.other != 0){
  88. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  89. }
  90. }
  91. var round = parseInt(msg.round);
  92. var type = parseInt(msg.type) || 0;
  93. var gameKindTL = parseInt(msg.gameKindTL) || 1;////平搓还是冲刺 = 1代表平搓 = 2代表冲刺
  94. if(gameKindTL != 1 && gameKindTL != 2){
  95. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });/////既不是平搓也不是冲刺
  96. }
  97. var playerAllCount = parseInt(msg.playerAllCount) || 4;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
  98. var other = parseInt(msg.other) || 0;////TL++2人3人的游戏规则
  99. if (other < 0 || other > 255) {
  100. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  101. }
  102. if((other & 2) && ((other & 4) || (other & 32))){
  103. // 勾选了炸弹不可拆时不能勾选四带二和四带三
  104. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  105. }
  106. if(!((other & 8) || (other & 16))){
  107. //“没有选择张数”
  108. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  109. }
  110. var upId = msg.upId || "";////TL++主动创建房间的话此值为"",通过战绩分享自动创建的房间此变量有值
  111. // console.warn("创建房间的other",other,msg.other);
  112. if(round != 10 && round != 20 && round != 30){//////游戏局数不合法
  113. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  114. }
  115. if(playerAllCount != 2 && playerAllCount != 3){//////游戏人数不合法
  116. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  117. }
  118. var agentId=msg.agentId || "";
  119. console.warn("创建桌子, "+agentId+" session.uid "+session.uid);//数据库中agenter(推广员)数据表的主键(_id)
  120. return this.app.controllers.paodekuai.createTableAsync(session.uid, round, type,gameKindTL,playerAllCount,upId,other,agentId).nodeify(next);/////修改局数
  121. });
  122. // TL++,得到玩家位置
  123. proto.sendLocation = P.coroutine(function* (msg, session, next) {
  124. if (!session.uid) {
  125. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  126. }
  127. return this.app.controllers.paodekuai.sendLocationAsync(session.uid, msg).nodeify(next);
  128. });
  129. // 得到玩家位置
  130. proto.getLocation = P.coroutine(function* (msg, session, next) {
  131. if (!session.uid) {
  132. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  133. }
  134. return this.app.controllers.paodekuai.getLocationAsync(session.uid, msg).nodeify(next);
  135. });
  136. // 离开桌子
  137. proto.leaveTable = P.coroutine(function* (msg, session, next) {
  138. if (!session.uid) {
  139. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  140. }
  141. return this.app.controllers.paodekuai.leaveTableAsync(session.uid).nodeify(next);
  142. });
  143. // 坐下
  144. proto.seat = P.coroutine(function* (msg, session, next) {
  145. if (!session.uid) {
  146. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  147. }
  148. var chairId = parseInt(msg.chairId);
  149. if (!chairId && chairId != 0) {
  150. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  151. }
  152. return this.app.controllers.paodekuai.seatAsync(session.uid, chairId).nodeify(next);
  153. });
  154. // 站起
  155. proto.stand = P.coroutine(function* (msg, session, next) {
  156. if (!session.uid) {
  157. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  158. }
  159. return this.app.controllers.paodekuai.standAsync(session.uid).nodeify(next);
  160. });
  161. // 准备
  162. proto.ready = P.coroutine(function* (msg, session, next) {
  163. if (!session.uid) {
  164. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  165. }
  166. return this.app.controllers.paodekuai.readyGameAsync(session.uid).nodeify(next);
  167. });
  168. // 开始
  169. proto.startGame = P.coroutine(function* (msg, session, next) {
  170. if (!session.uid) {
  171. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  172. }
  173. return this.app.controllers.paodekuai.startGameAsync(session.uid).nodeify(next);
  174. });
  175. // 出牌
  176. proto.outCard = P.coroutine(function* (msg, session, next) {
  177. if (!session.uid) {
  178. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  179. }
  180. var cards = msg.cards;
  181. let isArr = msg.cards instanceof Array;////////判断参数是否是个数组
  182. if (!cards || !isArr) {
  183. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  184. }
  185. return this.app.controllers.paodekuai.outCardAsync(session.uid, cards).nodeify(next);
  186. });
  187. /////TL++,操作是否自动出牌
  188. proto.autoOutCard = P.coroutine(function* (msg, session, next) {
  189. if (!session.uid) {
  190. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  191. }
  192. // return next(null, { code: C.FAILD, msg: "敬请期待" });
  193. return this.app.controllers.paodekuai.autoOutCard(session.uid).nodeify(next);
  194. });
  195. // 聊天
  196. proto.chat = P.coroutine(function* (msg, session, next) {
  197. if (!session.uid) {
  198. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  199. }
  200. return this.app.controllers.paodekuai.sendMsgAsync(session.uid, msg).nodeify(next);
  201. });
  202. // 收费聊天
  203. proto.vchat = P.coroutine(function* (msg, session, next) {
  204. if (!session.uid) {
  205. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  206. }
  207. var chairId = parseInt(msg.chairId);
  208. if (!(chairId >= 0)) {
  209. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  210. }
  211. if (!msg.msg) {
  212. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  213. }
  214. return this.app.controllers.paodekuai.vsendMsgAsync(session.uid, chairId, msg.msg).nodeify(next);
  215. });
  216. // 角色信息
  217. proto.roleInfo = P.coroutine(function* (msg, session, next) {
  218. if (!session.uid) {
  219. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  220. }
  221. var chairId = parseInt(msg.chairId);
  222. if (!(chairId >= 0)) {
  223. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  224. }
  225. return this.app.controllers.paodekuai.roleInfoAsync(session.uid, chairId).nodeify(next);
  226. });
  227. // 请求结束
  228. proto.overTable = P.coroutine(function* (msg, session, next) {
  229. if (!session.uid) {
  230. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  231. }
  232. return this.app.controllers.paodekuai.overTableAsync(session.uid).nodeify(next);
  233. });
  234. // 拒绝结束
  235. proto.refuseOver = P.coroutine(function* (msg, session, next) {
  236. if (!session.uid) {
  237. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  238. }
  239. return this.app.controllers.paodekuai.refuseOverAsync(session.uid).nodeify(next);
  240. });
  241. // 同意结束
  242. proto.agreeOver = P.coroutine(function* (msg, session, next) {
  243. if (!session.uid) {
  244. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  245. }
  246. return this.app.controllers.paodekuai.agreeOverAsync(session.uid).nodeify(next);
  247. });