MakeCachetaXieYi.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. var Global = require("Global")
  2. var ProtocolGameServer = require("ProtocolGameServer")
  3. var GameProtocol = require("CachetaGameProtocol")
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. },
  8. statics: {
  9. makeGameData(m, s, data) {
  10. switch (m) {
  11. case ProtocolGameServer.MDM_GF_FRAME: {
  12. return this.makeFrameGameData(s, data);
  13. }
  14. break;
  15. case ProtocolGameServer.MDM_GF_GAME: {
  16. return this.makeGFGameData(s, data);
  17. }
  18. break;
  19. case ProtocolGameServer.MDM_GR_PRIVATE: {
  20. return this.makePrivateGameData(s, data);
  21. }
  22. break;
  23. default:
  24. break;
  25. }
  26. return null;
  27. },
  28. makePrivateGameData(s, data) {
  29. switch (s) {
  30. case ProtocolGameServer.SUB_GR_PRIVATE_DISMISS: {
  31. return this.makePrivateDismiss(data);
  32. }
  33. break;
  34. default:
  35. break;
  36. }
  37. return null;
  38. },
  39. makeFrameGameData(s, data) {
  40. switch (s) {
  41. case ProtocolGameServer.SUB_GR_TABLE_TALK: {
  42. return this.makeTableTalk(data);
  43. }
  44. case ProtocolGameServer.SUB_GR_TABLE_VOICE: {
  45. return this.makeTabelVoice(data);
  46. }
  47. default:
  48. break;
  49. }
  50. return null;
  51. },
  52. makeGFGameData(s, data) {
  53. switch (s) {
  54. case GameProtocol.SUB_C_GET_CARD: {//玩家抓牌
  55. return this.makeGetCard(data);
  56. }
  57. break;
  58. case GameProtocol.SUB_C_OUT_CARD: {//玩家出牌
  59. return this.makeOutCard(data);
  60. }
  61. break;
  62. case GameProtocol.SUB_C_HU_CARD: {//
  63. return this.makeHuCard(data);
  64. }
  65. break;
  66. case GameProtocol.SUB_C_TEST_CARD:{
  67. return this.makeTestCard(data);
  68. }
  69. case GameProtocol.SUB_C_MING_CARD:{
  70. return this.makeMingCard(data);
  71. }
  72. case GameProtocol.SUB_C_CANCEL_TRUSTEE:{
  73. return this.makeTrustee(data);
  74. }
  75. break;
  76. default:
  77. break;
  78. }
  79. return null;
  80. },
  81. makeTableTalk: function (data) {//SUB_GR_TABLE_TALK
  82. var arrayBuffer = new ArrayBuffer(138 + data.TalkSize + 8);
  83. var dv = new DataView(arrayBuffer);
  84. dv.pos = 8;
  85. Global.SetUint8(dv, data.Type);
  86. Global.SetUint8(dv, data.ChairID);
  87. Global.WriteChar(dv, data.String, 128);
  88. Global.SetUint32(dv, data.TalkSize);
  89. for (let index = 0; index < data.TalkSize; index++) {
  90. // if(index < data.TalkSize) {
  91. // }
  92. // else{
  93. // Global.SetUint8(dv, 0);
  94. // }
  95. Global.SetUint8(dv, data.TalkData[index]);
  96. }
  97. return dv;
  98. },
  99. makeTabelVoice: function (data) {//
  100. var str = Global.ToUTF_8(data.SerVerID, true);
  101. var len = str.length - 2 + 4;
  102. var arrayBuffer = new ArrayBuffer(len + 1 + 8);
  103. var dv = new DataView(arrayBuffer);
  104. dv.pos = 8;
  105. Global.SetUint8(dv, data.ChairID);
  106. Global.WriteString(dv, data.SerVerID);
  107. return dv;
  108. },
  109. makePrivateDismiss: function (data) { //SUB_GR_PRIVATE_DISMISS
  110. var arrayBuffer = new ArrayBuffer(1 + 8);
  111. var dv = new DataView(arrayBuffer);
  112. dv.pos = 8;
  113. Global.SetUint8(dv, data.Dismiss);
  114. return dv;
  115. },
  116. ///////////游戏逻辑
  117. makeGetCard: function (data) {//抓牌请求
  118. var arrayBuffer = new ArrayBuffer(8 + 1);
  119. var dv = new DataView(arrayBuffer);
  120. dv.pos = 8;
  121. Global.SetInt8(dv, data.bGetTableCard);
  122. return dv;
  123. },
  124. makeOutCard: function (data) {//出牌请求
  125. var arrayBuffer = new ArrayBuffer(8 + 1 + 1);
  126. var dv = new DataView(arrayBuffer);
  127. dv.pos = 8;
  128. Global.SetInt8(dv, data.cbOutCardData);
  129. Global.SetInt8(dv, data.bTing);
  130. return dv;
  131. },
  132. makeHuCard: function (data) {//
  133. var arrayBuffer = new ArrayBuffer(8);
  134. var dv = new DataView(arrayBuffer);
  135. dv.pos = 8;
  136. return dv;
  137. },
  138. makeMingCard(data) {
  139. var arrayBuffer = new ArrayBuffer(8);
  140. var dv = new DataView(arrayBuffer);
  141. dv.pos = 8;
  142. return dv;
  143. },
  144. makeTestCard: function (data) {//获取牌组
  145. var arrayBuffer = new ArrayBuffer(8+1*10+1);
  146. var dv = new DataView(arrayBuffer);
  147. dv.pos = 8;
  148. for(let i = 0; i < data.cbHandCard.length; ++i) {
  149. Global.SetInt8(dv, data.cbHandCard[i]);
  150. }
  151. // cbMagicCard
  152. Global.SetInt8(dv, data.cbMagicCard);
  153. return dv;
  154. },
  155. makeTrustee(data) {
  156. var arrayBuffer = new ArrayBuffer(8);
  157. var dv = new DataView(arrayBuffer);
  158. dv.pos = 8;
  159. return dv;
  160. },
  161. },
  162. start() {
  163. },
  164. });