GameClientEngine_21201.js 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230
  1. var CGameLogic = require("GameLogic_21201");
  2. cc.Class({
  3. extends: cc.GameEngine,
  4. properties:
  5. {
  6. m_ViewNode: cc.Node,
  7. m_BtDissolve: cc.Node,
  8. m_BtExit: cc.Node,
  9. },
  10. // use this for initialization
  11. start: function () {
  12. this.Init();
  13. },
  14. Init: function () {
  15. if (this.m_bInit == true) return;
  16. this.m_bInit = true;
  17. //this.SInit();
  18. this.m_UserLocation = new Array();
  19. this.m_GameLogic = new CGameLogic(); //游戏逻辑
  20. GameDef.g_GameLogic = this.m_GameLogic;
  21. GameDef.g_GameEngine = this;
  22. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  23. for (var j = 0; j < GameDef.MAX_WEAVE; ++j) {
  24. this.m_WeaveItemArray[i][j] = GameDef.tagWeaveItem();
  25. }
  26. }
  27. // this.m_LeaveControl = this.node.getChildByName('LeaveCtrl').getComponent('LeaveControl');
  28. // this.m_LeaveControl.SetClientEngine(this);
  29. // this.m_LeaveControl.ShowView(false);
  30. },
  31. ctor: function () {
  32. //游戏变量
  33. this.m_wBankerUser = 0;
  34. this.m_wCurrentUser = 0;
  35. this.m_wActionMask = 0;
  36. this.m_bStustee = false;
  37. this.m_wTimeOutCount = 0;
  38. this.m_cbLeftCardCount = 0; //发牌数目
  39. this.m_GameLogic = null; //游戏逻辑
  40. this.m_WeaveItemArray = new Array();
  41. this.m_cbWeaveCount = new Array();
  42. this.m_bListen = new Array();
  43. for (var i = 0; i < 4; i++) {
  44. this.m_bListen[i] = false;
  45. this.m_cbWeaveCount[i] = 0;
  46. this.m_WeaveItemArray[i] = new Array();
  47. }
  48. this.m_cbCardIndex = new Array();
  49. for (var i = 0; i < 42; ++i) {//GameDef.MAX_INDEX
  50. this.m_cbCardIndex[i] = 0;
  51. }
  52. //玩家变量
  53. this.m_wCurrentUser = INVALID_CHAIR;
  54. this.m_SoundArr = new Array(
  55. ['BGM', 'BGM'],//.mp3
  56. ['GAME_START', 'GAME_START'],
  57. ['GAME_END', 'GAME_END'],
  58. ['GAME_WARN', 'GAME_WARN'],
  59. ['SEND_CARD', 'SEND_CARD'],
  60. ['CHUPAI', 'CHUPAI'],
  61. ['TIPAI', 'TIPAI'],
  62. // //女
  63. // ['W_CHI', 'w/CHI'],
  64. // ['W_HU', 'w/CHI_HU'],
  65. // ['W_ZIMO', 'w/ZIMO'],
  66. // ['W_GANG', 'w/GANG'],
  67. // ['W_PENG', 'w/PENG'],
  68. // ['W_TING', 'w/TING'],
  69. // ['W_ZHUNBEI', 'w/zhunbei'],
  70. // //男
  71. // ['M_CHI', 'm/CHI'],
  72. // ['M_HU', 'm/CHI_HU'],
  73. // ['M_ZIMO', 'm/ZIMO'],
  74. // ['M_GANG', 'm/GANG'],
  75. // ['M_PENG', 'm/PENG'],
  76. // ['M_TING', 'm/TING'],
  77. // ['M_ZHUNBEI', 'm/zhunbei'],
  78. );
  79. //出牌声音
  80. for (var j = 0; j < 4; j++) {
  81. //女
  82. this.m_SoundArr[this.m_SoundArr.length] = ["W_CHIL" + j, 'w/CHIL' + j];
  83. this.m_SoundArr[this.m_SoundArr.length] = ["W_HUL" + j, 'w/CHI_HUL' + j];
  84. this.m_SoundArr[this.m_SoundArr.length] = ["W_ZIMOL" + j, 'w/ZIMOL' + j];
  85. this.m_SoundArr[this.m_SoundArr.length] = ["W_GANGL" + j, 'w/GANGL' + j];
  86. this.m_SoundArr[this.m_SoundArr.length] = ["W_PENGL" + j, 'w/PENGL' + j];
  87. this.m_SoundArr[this.m_SoundArr.length] = ["W_TINGL" + j, 'w/TINGL' + j];
  88. this.m_SoundArr[this.m_SoundArr.length] = ["W_ZHUNBEIL" + j, 'w/zhunbeiL' + j];
  89. this.m_SoundArr[this.m_SoundArr.length] = ["W_BUHUAL" + j, 'w/BUHUAL' + j];
  90. //男
  91. this.m_SoundArr[this.m_SoundArr.length] = ["M_CHIL" + j, 'm/CHIL' + j];
  92. this.m_SoundArr[this.m_SoundArr.length] = ["M_HUL" + j, 'm/CHI_HUL' + j];
  93. this.m_SoundArr[this.m_SoundArr.length] = ["M_ZIMOL" + j, 'm/ZIMOL' + j];
  94. this.m_SoundArr[this.m_SoundArr.length] = ["M_GANGL" + j, 'm/GANGL' + j];
  95. this.m_SoundArr[this.m_SoundArr.length] = ["M_PENGL" + j, 'm/PENGL' + j];
  96. this.m_SoundArr[this.m_SoundArr.length] = ["M_TINGL" + j, 'm/TINGL' + j];
  97. this.m_SoundArr[this.m_SoundArr.length] = ["M_ZHUNBEIL" + j, 'm/zhunbeiL' + j];
  98. this.m_SoundArr[this.m_SoundArr.length] = ["M_BUHUAL" + j, 'm/BUHUAL' + j];
  99. for (var i = 1; i < 10; ++i) {
  100. this.m_SoundArr[this.m_SoundArr.length] = ["M_W_" + i + "L" + j, 'm/W_' + i + "L" + j];
  101. this.m_SoundArr[this.m_SoundArr.length] = ['W_W_' + i + "L" + j, 'w/W_' + i + "L" + j];
  102. this.m_SoundArr[this.m_SoundArr.length] = ["M_S_" + i + "L" + j, 'm/S_' + i + "L" + j];
  103. this.m_SoundArr[this.m_SoundArr.length] = ['W_S_' + i + "L" + j, 'w/S_' + i + "L" + j];
  104. this.m_SoundArr[this.m_SoundArr.length] = ["M_T_" + i + "L" + j, 'm/T_' + i + "L" + j];
  105. this.m_SoundArr[this.m_SoundArr.length] = ['W_T_' + i + "L" + j, 'w/T_' + i + "L" + j];
  106. this.m_SoundArr[this.m_SoundArr.length] = ["M_F_" + i + "L" + j, 'm/F_' + i + "L" + j];
  107. this.m_SoundArr[this.m_SoundArr.length] = ['W_F_' + i + "L" + j, 'w/F_' + i + "L" + j];
  108. }
  109. for (var i = 0; i < 12; ++i) {
  110. var num = "w_" + i;
  111. this.m_SoundArr[this.m_SoundArr.length] = ["Phrase_w" + (i + 1), 'ShortcutPhrase/' + num];
  112. num = "m_" + i;
  113. this.m_SoundArr[this.m_SoundArr.length] = ["Phrase_m" + (i + 1), 'ShortcutPhrase/' + num];
  114. }
  115. // for (var i = 0; i < 12; ++i) {
  116. // var num = "w_" + i+"L"+j;
  117. // this.m_SoundArr[this.m_SoundArr.length] = ["Phrase_w" + (i + 1)+"L"+j, 'ShortcutPhrase/' + num];
  118. // num = "m_" + i+"L"+j;
  119. // this.m_SoundArr[this.m_SoundArr.length] = ["Phrase_m" + (i + 1)+"L"+j, 'ShortcutPhrase/' + num];
  120. // }
  121. }
  122. // //出牌声音
  123. // for(var i=1;i<10;++i){
  124. // this.m_SoundArr[this.m_SoundArr.length] = ["M_W_"+i,'m/W_'+i];
  125. // this.m_SoundArr[this.m_SoundArr.length] = ['W_W_'+i,'w/W_'+i];
  126. // this.m_SoundArr[this.m_SoundArr.length] = ["M_S_"+i,'m/S_'+i];
  127. // this.m_SoundArr[this.m_SoundArr.length] = ['W_S_'+i,'w/S_'+i];
  128. // this.m_SoundArr[this.m_SoundArr.length] = ["M_T_"+i,'m/T_'+i];
  129. // this.m_SoundArr[this.m_SoundArr.length] = ['W_T_'+i,'w/T_'+i];
  130. // this.m_SoundArr[this.m_SoundArr.length] = ["M_F_"+i,'m/F_'+i];
  131. // this.m_SoundArr[this.m_SoundArr.length] = ['W_F_'+i,'w/F_'+i];
  132. // }
  133. // for (var i = 0; i < 12; ++i) {
  134. // var num = "w_" + i;
  135. // this.m_SoundArr[this.m_SoundArr.length] = ["Phrase_w" + (i + 1), 'ShortcutPhrase/' + num];
  136. // num = "m_" + i;
  137. // this.m_SoundArr[this.m_SoundArr.length] = ["Phrase_m" + (i + 1), 'ShortcutPhrase/' + num];
  138. // }
  139. this.m_szText = new Array(
  140. '快點動手!你是來打牌還是來當雕像?',
  141. '哇靠~盯這麼緊?打張牌來吃吃吧!',
  142. '拖什麼拖!我還得趕去談生意咧!',
  143. '等等,我接個電話,別偷牌啊!',
  144. '想這麼久幹嘛?出張二筒吧!',
  145. '不是阿大哥,在忙啥,動作這麼慢?',
  146. '有種再打同一張!這把我要胡到你哭!',
  147. '又是我放槍?這牌桌有毒吧!',
  148. ' 你家網路是撥接的喔?卡成這樣!',
  149. '老子回來了!看你急得跟什麼一樣!',
  150. ' 又胡!?這人是不是開外掛啦!',
  151. // '這咋又胡了呢,腦瓜子嗡一下子',
  152. );
  153. this.m_cbGameStatus = 0;
  154. this.m_bCanShowBigEnd = false;
  155. this.m_bEnd = false;
  156. this.m_bInit = false;
  157. this.m_bFirstCard = false;
  158. },
  159. //网络消息
  160. OnEventGameMessage: function (wSubCmdID, pData, wDataSize) {
  161. switch (wSubCmdID) {
  162. case GameDef.SUB_S_GAME_START: //游戏开始
  163. {
  164. return this.OnSubGameStart(pData, wDataSize);
  165. }
  166. case GameDef.SUB_S_OUT_CARD: //用户出牌
  167. {
  168. return this.OnSubOutCard(pData, wDataSize);
  169. }
  170. case GameDef.SUB_S_SEND_CARD: //发牌消息
  171. {
  172. return this.OnSubSendCard(pData, wDataSize);
  173. }
  174. case GameDef.SUB_S_OPERATE_NOTIFY: //操作提示
  175. {
  176. return this.OnSubOperateNotify(pData, wDataSize);
  177. }
  178. case GameDef.SUB_S_OPERATE_TIMER://别人有提示显示时间
  179. {
  180. return this.OnSubOperateTimer(pData, wDataSize);
  181. }
  182. case GameDef.SUB_S_OPERATE_RESULT: //操作结果
  183. {
  184. return this.OnSubOperateResult(pData, wDataSize);
  185. }
  186. case GameDef.SUB_S_GAME_END: //游戏结束
  187. {
  188. return this.OnSubGameEnd(pData, wDataSize);
  189. }
  190. case GameDef.SUB_S_TRUSTEE: //用户托管
  191. {
  192. return this.OnSubTrustee(pData, wDataSize);
  193. }
  194. case GameDef.SUB_S_LEAVE: //用户托管
  195. {
  196. return this.OnSubLeave(pData, wDataSize);
  197. }
  198. case GameDef.SUB_S_NEXT_READY: //下局准备
  199. {
  200. return this.OnSubNextReady(pData, wDataSize);
  201. }
  202. case GameDef.SUB_S_USER_DOUBLE: //用户加刚
  203. {
  204. return this.OnSubPlayerDouble(pData, wDataSize);
  205. }
  206. case GameDef.SUB_S_GAME_DOUBLE: //开始选刚
  207. {
  208. return this.OnSubStartDouble(pData, wDataSize);
  209. }
  210. case GameDef.SUB_S_UPDATE_CARD: //刷新
  211. {
  212. return this.OnUpdateCardData(pData, wDataSize);
  213. }
  214. case GameDef.SUB_S_TING:
  215. {
  216. return this.OnTing(pData, wDataSize);
  217. }
  218. case GameDef.SUB_S_REPLACE_CARD: //用户补牌
  219. {
  220. return this.OnSubReplaceCard(pData, wDataSize);
  221. }
  222. case GameDef.SUB_S_BANKER_CAN_OUT:
  223. {
  224. this.m_wCurrentUser = this.m_wBankerUser;
  225. this.m_bFirstCard = false;
  226. this.m_GameClientView.m_CardView.m_HandCard[2].SetCanTouch(true);
  227. }
  228. }
  229. return true;
  230. },
  231. //游戏场景
  232. OnEventSceneMessage: function (cbGameStatus, bLookonUser, pData, wDataSize) {
  233. if (GameDef.TMP_TEST) {
  234. this.__test();
  235. return true;
  236. }
  237. //this.m_GameClientView.m_BtFriend.active = (this.m_dwRoomID != 0 && this.m_wGameProgress == 0);
  238. this.m_cbGameStatus = cbGameStatus;
  239. switch (cbGameStatus) {
  240. case GameDef.GAME_SCENE_FREE: //空闲状态
  241. {
  242. var pStatusFree = GameDef.CMD_S_StatusFree();
  243. if (wDataSize != gCByte.Bytes2Str(pStatusFree, pData)) return false;
  244. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  245. if (this.GetClientUserItem(i) == null) continue;
  246. var OtherViewID = this.SwitchViewChairID(i);
  247. this.m_GameClientView.m_UserInfo[OtherViewID].SetScore(OtherViewID, pStatusFree.lSumGameScore[i])
  248. }
  249. return true;
  250. }
  251. case GameDef.GAME_SCENE_DOUBLE: //加倍状态
  252. {
  253. // function binaryData(ev) {
  254. // return JSON.parse(new TextDecoder("utf-8").decode(new Uint8Array(ev.data)))
  255. // }
  256. var pStatusFree = GameDef.CMD_S_StatusFree();
  257. if (wDataSize != gCByte.Bytes2Str(pStatusFree, pData)) return false;
  258. console.log("pStatusFree--", pStatusFree)
  259. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  260. this.m_GameClientView.SetTrustee(i, pStatusFree.bTrustee[i]);
  261. }
  262. var wMeChairID = this.GetMeChairID();
  263. this.m_bStustee = pStatusFree.bTrustee[wMeChairID];
  264. if (this.m_wGameProgress == 0) {
  265. var kernel = gClientKernel.get();
  266. if (this.m_dwCreater != 0 && this.m_dwCreater == kernel.mMeUserItem.GetUserID()) {
  267. this.m_BtExit.active = false;
  268. this.m_BtDissolve.active = true;
  269. }
  270. else {
  271. this.m_BtExit.active = true;
  272. this.m_BtDissolve.active = false;
  273. }
  274. }
  275. else {
  276. this.m_BtExit.active = false;
  277. this.m_BtDissolve.active = true;
  278. // 没开始不用计时
  279. if (this.m_bStustee) {
  280. this.checkTotalEnd(true);
  281. }
  282. // else
  283. // {
  284. // //计算时间
  285. // var wTimeCount=this.GetOperateTime() - pStatusFree.dwOperateTime;
  286. // this.SetGameClock(this.m_wCurrentUser,GameDef.IDI_OPERATE_CARD,wTimeCount);
  287. // }
  288. }
  289. //this.m_GameClientView.m_BtStart.active = !this.m_bStustee;
  290. this.m_GameClientView.m_CardView.SetDiscardTip(INVALID_CHAIR);
  291. // this.m_GameClientView.SetHuangZhuang(pStatusFree.wHuangZhuangCount);
  292. var kernel = gClientKernel.get();
  293. if (GameDef.GAME_SCENE_DOUBLE == cbGameStatus && !kernel.IsLookonMode()) {
  294. this.m_GameClientView.m_BtStart.active = false;
  295. var cbDoubleT = pStatusFree.cbDouble[this.GetMeChairID()];
  296. if (cbDoubleT == 0) {
  297. this.m_GameClientView.SetGangOperator(1);
  298. }
  299. else {
  300. //计算时间
  301. var wTimeCount = this.GetOperateTime() - pStatusFree.dwOperateTime;
  302. this.SetGameClock(this.m_wCurrentUser, GameDef.IDI_OPERATE_CARD, wTimeCount);
  303. this.m_GameClientView.SetGangOperator(2);
  304. }
  305. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  306. var viewId = this.SwitchViewChairID(i);
  307. var cbDouble = pStatusFree.cbDouble[i];
  308. this.m_GameClientView.m_UserInfo[viewId].SetGang(cbDouble);
  309. }
  310. }
  311. return true;
  312. }
  313. case GameDef.GAME_SCENE_PLAY: //游戏状态
  314. {
  315. var BankViewID = this.SwitchViewChairID(0);
  316. this.m_GameClientView.m_BtFriend.active = false;
  317. //效验数据
  318. var pStatusPlay = GameDef.CMD_S_StatusPlay();
  319. pStatusPlay.weaveItem = this.m_WeaveItemArray;
  320. pStatusPlay.cbWeaveCount = this.m_cbWeaveCount;
  321. if (wDataSize != gCByte.Bytes2Str(pStatusPlay, pData)) return false;
  322. console.log("pStatusPlay--", pStatusPlay)
  323. var displayF = true;
  324. var displayC = true;
  325. if (GameDef.GAME_RULE_SP_16 & GameDef.m_dwGameRuleArr[0]) displayF = false;
  326. if (this.m_cbGameStatus & GameDef.GAME_SCENE_PLAY) displayC = false;
  327. this.m_wGameProgress = pStatusPlay.cbQuan + 1;
  328. this.m_GameClientView.UpdateRoomProgress();
  329. //风局
  330. this.m_GameClientView.Fengju(pStatusPlay.cbQuan, pStatusPlay.cbFeng, displayF);
  331. //骰子
  332. this.m_GameClientView.DiceNum(pStatusPlay.cbSick)
  333. //风位
  334. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  335. if (this.GetClientUserItem(i) == null) continue;
  336. var OtherViewID = this.SwitchViewChairID(i);
  337. this.m_GameClientView.m_UserInfo[OtherViewID].SetFeng(pStatusPlay.cbQuan, pStatusPlay.cbUserDNXB[i], displayF);
  338. }
  339. //花牌数据
  340. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  341. if (this.GetClientUserItem(i) == null) continue;
  342. var OtherViewID = this.SwitchViewChairID(i);
  343. this.m_GameClientView.m_UserInfo[OtherViewID].SetFlower(OtherViewID, pStatusPlay.cbFlowerCount[i], pStatusPlay.cbCardDataFlower[i], displayF, displayC);
  344. this.m_GameClientView.showGotFlowers(OtherViewID, displayC);
  345. }
  346. this.m_GameClientView.SetUserAction(INVALID_CHAIR, 0);
  347. this.m_GameClientView.m_CardView.ResetView();
  348. //设置刚状态
  349. var wViewChairID = new Array();
  350. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  351. wViewChairID[i] = this.SwitchViewChairID(i);
  352. this.m_bListen[i] = pStatusPlay.bListen[i];
  353. // cbDouble= pStatusPlay.cbDouble[i];
  354. this.m_GameClientView.SetTrustee(i, pStatusPlay.bTrustee[i]);
  355. this.m_GameClientView.m_UserInfo[wViewChairID[i]].SetTing(this.m_bListen[i]);
  356. var cbDouble = pStatusPlay.cbDouble[i];
  357. this.m_GameClientView.m_UserInfo[wViewChairID[i]].SetGang(cbDouble);
  358. }
  359. var wMeChairID = this.GetMeChairID();
  360. this.m_bStustee = pStatusPlay.bTrustee[wMeChairID];
  361. //会牌
  362. this.m_GameClientView.m_CardView.SetMakeMagicIndex(pStatusPlay.cbMakeMagicIndex);
  363. //this.m_HuiCardDate = this.m_GameLogic.GetNextCardIndex( pStatusPlay.cbMakeMagicIndex);
  364. // this.m_GameClientView.m_CardView.SetMagicIndex(this.m_HuiCardDate);
  365. //this.m_HuiCardDate = this.m_GameLogic.SwitchToCardData(this.m_HuiCardDate);
  366. this.m_DingHuiCardDate = this.m_GameLogic.SwitchToCardData(pStatusPlay.cbMakeMagicIndex);
  367. //this.m_GameClientView.SetHuiPai(this.m_DingHuiCardDate,this.m_HuiCardDate);
  368. //GameDef.m_cbMagicData = this.m_HuiCardDate;
  369. this.m_wBankerUser = pStatusPlay.wBankerUser;
  370. this.m_wCurrentUser = pStatusPlay.wCurrentUser;
  371. this.m_cbLeftCardCount = pStatusPlay.cbLeftCardCount;
  372. // this.m_GameClientView.SetHuangZhuang(pStatusPlay.wHuangZhuangCount);
  373. //玩家变量
  374. //for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  375. //用户名字
  376. // var kernel = gClientKernel.get();
  377. // var pIClientUserItem = kernel.GetTableUserItem(i);
  378. // if (pIClientUserItem == null) continue;
  379. // this.m_GameClientView.SetScoreInfo(this.SwitchViewChairID(i), pIClientUserItem.GetUserScore() + pStatusPlay.lGangScore[i]);
  380. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  381. if (this.GetClientUserItem(i) == null) continue;
  382. var OtherViewID = this.SwitchViewChairID(i);
  383. this.m_GameClientView.m_UserInfo[OtherViewID].SetScore(OtherViewID, pStatusPlay.lSumGameScore[i])
  384. }
  385. this.m_GameClientView.SetLeftCardCount(this.m_cbLeftCardCount);
  386. this.m_GameLogic.SwitchToCardIndex3(pStatusPlay.cbCardData, pStatusPlay.cbCardCount, this.m_cbCardIndex);
  387. //界面设置
  388. this.m_GameClientView.SetCellScore(pStatusPlay.lCellScore);
  389. this.m_GameClientView.SetBankerUser(wViewChairID[this.m_wBankerUser]);
  390. //组合扑克
  391. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  392. // var wOperateViewID = this.SwitchViewChairID(i);
  393. for (var j = 0; j < this.m_cbWeaveCount[i]; j++) {
  394. this.m_GameClientView.m_CardView.SetWeaveData(wViewChairID[i], j, this.m_WeaveItemArray[i][j].cbCardData, this.m_WeaveItemArray[i][j].cbCardCount);
  395. this.m_GameClientView.m_CardView.SetWeaveState(wViewChairID[i], j, this.m_WeaveItemArray[i][j]);
  396. }
  397. }
  398. //用户扑克
  399. if (this.m_wCurrentUser == wMeChairID &&
  400. this.m_cbCardIndex[this.m_GameLogic.SwitchToCardIndex(pStatusPlay.cbSendCardData)] > 0) {
  401. this.m_GameClientView.m_CardView.SetSelfCardIndex(this.m_cbCardIndex, pStatusPlay.cbSendCardData, this.m_bListen[wMeChairID], pStatusPlay.cbCantOutCard);
  402. } else {
  403. this.m_GameClientView.m_CardView.SetSelfCardIndex(this.m_cbCardIndex, 0, this.m_bListen[wMeChairID], pStatusPlay.cbCantOutCard);
  404. }
  405. //扑克设置
  406. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  407. if (this.GetClientUserItem(i) == null) continue;
  408. //用户扑克
  409. var cbCardCount = GameDef.MAX_COUNT - this.m_cbWeaveCount[i] * 3 - 1;
  410. if (i != wMeChairID) {
  411. if (pStatusPlay.wCurrentUser == i) {
  412. cbCardCount++;
  413. }
  414. var wUserCardIndex = wViewChairID[i];
  415. this.m_GameClientView.m_CardView.SetCardData(wUserCardIndex, null, cbCardCount);
  416. }
  417. //丢弃扑克
  418. this.m_GameClientView.m_CardView.SetDiscardCardDate(wViewChairID[i], pStatusPlay.cbDiscardCard[i], pStatusPlay.cbDiscardCount[i]);
  419. }
  420. //丢弃效果
  421. if (pStatusPlay.wOutCardUser != INVALID_CHAIR) {
  422. this.m_GameClientView.m_CardView.AddDiscard(wViewChairID[pStatusPlay.wOutCardUser], pStatusPlay.cbOutCardData);
  423. this.m_GameClientView.m_CardView.SetDiscardTip(this.SwitchViewChairID(pStatusPlay.wOutCardUser));
  424. }
  425. //控制设置
  426. this.m_GameClientView.m_CardView.SetPositively(true);
  427. //操作界面
  428. if (pStatusPlay.wActionMask != GameDef.WIK_NULL) {
  429. //获取变量
  430. this.m_wActionMask = pStatusPlay.wActionMask;
  431. }
  432. this.m_GameClientView.SetCurrentUser(this.m_wCurrentUser);
  433. //设置时间
  434. if (this.m_wCurrentUser != INVALID_CHAIR) {
  435. //计算时间
  436. var wTimeCount = this.GetOperateTime() - pStatusPlay.dwOperateTime;
  437. //设置时间
  438. if (pStatusPlay.bLeave[this.m_wCurrentUser]) {
  439. this.m_GameClientView.SetUserTimer(this.SwitchViewChairID(this.m_wCurrentUser), 0);
  440. } else {
  441. this.SetGameClock(this.m_wCurrentUser, GameDef.IDI_OPERATE_CARD, wTimeCount);
  442. }
  443. }
  444. this.m_GameClientView.m_CardView.m_HandCard[2].SetCanTouch(pStatusPlay.bCanOutCard);
  445. this.m_BtExit.active = false;
  446. this.m_BtDissolve.active = true;
  447. return true;
  448. // }
  449. }
  450. return false;
  451. }
  452. },
  453. SetGameClock: function (wChairID, nTimerID, nElapse) {
  454. this.m_GameClientView.SetUserTimer(wChairID, nElapse, 1);
  455. if (this.m_ReplayMode) return
  456. g_TimerEngine.SetGameTimer(wChairID, nTimerID, nElapse * 1000, null, this, 'OnTimerMessage');
  457. },
  458. //删除定时器
  459. KillGameClock: function (nTimerID) {
  460. this.m_GameClientView.SetUserTimer(INVALID_CHAIR, 0);
  461. g_TimerEngine.KillGameTimer();
  462. return true;
  463. },
  464. //时间消息
  465. OnTimerMessage: function (wChairID, CountDown, nTimerID, Progress) {
  466. var nElapse = parseInt(CountDown / 1000) + 1;
  467. if (CountDown == 0) nElapse = 0;
  468. this.m_GameClientView.SetUserTimer(wChairID, nElapse);
  469. return true;
  470. },
  471. StusteeOperateCard: function (wChairID) {
  472. if (this.m_bStustee == false) {
  473. this.ListenAutoOutCard(wChairID);
  474. return false;
  475. }
  476. // if (this.m_bStustee){
  477. // if(this.m_wActionMask & GameDef.WIK_CHI_HU){
  478. // this.OnCardOperate(GameDef.WIK_CHI_HU, 0);
  479. // return true;
  480. // }
  481. // }
  482. //获取位置
  483. var wMeChairID = this.GetMeChairID();
  484. //动作处理
  485. if (wChairID == wMeChairID) {
  486. // //玩家未听牌,且未托管,则累加超时次数
  487. // if( this.m_bStustee==false && ++this.m_wTimeOutCount>=3 )
  488. // {
  489. // this.m_wTimeOutCount = 0;
  490. // this.OnStusteeControl(0,TRUE);
  491. // }
  492. if (this.m_wCurrentUser == wMeChairID) {
  493. //获取扑克
  494. var wViewID = this.SwitchViewChairID(wChairID);
  495. var cbCardData = this.m_GameClientView.m_CardView.GetHandCurrentCard(wViewID);
  496. //出牌效验
  497. if (this.VerdictOutCard(cbCardData) == false) {
  498. for (var i = 0; i < 42; i++)//GameDef.MAX_INDEX
  499. {
  500. //出牌效验
  501. if (this.m_cbCardIndex[i] == 0) continue;
  502. if (this.VerdictOutCard(this.m_GameLogic.SwitchToCardData(i)) == false)
  503. continue;
  504. //设置变量
  505. cbCardData = this.m_GameLogic.SwitchToCardData(i);
  506. }
  507. }
  508. //出牌动作
  509. var sequence = cc.sequence(
  510. cc.callFunc(function () {
  511. // this.m_GameClientView.m_CardView.m_HandCard[wViewID].SetCanTouch(false);
  512. if (this.m_wCurrentUser != wChairID) {
  513. this.m_GameClientView.m_CardView.m_HandCard[wViewID].SetCanTouch(false);
  514. return;
  515. }
  516. this.m_GameClientView.m_CardView.m_HandCard[wViewID].SetCanTouch(true);
  517. }, this),
  518. cc.delayTime(1),
  519. cc.callFunc(function () {
  520. this.m_GameClientView.m_CardView.m_HandCard[wViewID].SetOutCard(cbCardData);
  521. // this.OnOutCard(0, 0, cbCardData);
  522. }, this
  523. ));
  524. this.node.runAction(sequence);
  525. } else {
  526. this.OnCardOperate(0, 0);
  527. if (this.m_cbGameStatus == GameDef.GAME_SCENE_PLAY) {
  528. //过
  529. var sequence = cc.sequence(
  530. cc.delayTime(1),
  531. cc.callFunc(function () {
  532. this.OnCardOperate(0, 0);
  533. }, this
  534. ));
  535. this.node.runAction(sequence);
  536. }
  537. else if (this.m_cbGameStatus == GameDef.GAME_SCENE_DOUBLE) {
  538. //不下
  539. this.OnDoubleOperate(1);
  540. this.m_GameClientView.SetGangOperator(2);
  541. }
  542. }
  543. }
  544. return true;
  545. },
  546. ListenAutoOutCard: function (wChairID) {
  547. if (this.m_bStustee == true) return; //托管不走这
  548. var wMeChairID = this.GetMeChairID();
  549. if (wMeChairID != wChairID) return;
  550. if (this.m_wCurrentUser != wMeChairID) return;
  551. if (this.m_bListen[wChairID] == false) return;
  552. //可以杠
  553. if (this.m_wActionMask & (GameDef.WIK_GANG | GameDef.WIK_CHI_HU)) {
  554. return;
  555. }
  556. //获取扑克
  557. var wViewID = this.SwitchViewChairID(wChairID);
  558. var cbCardData = this.m_GameClientView.m_CardView.GetHandCurrentCard(wViewID);
  559. //出牌效验
  560. if (this.VerdictOutCard(cbCardData) == false) {
  561. for (var i = 0; i < 42; i++)//GameDef.MAX_INDEX
  562. {
  563. //出牌效验
  564. if (this.m_cbCardIndex[i] == 0) continue;
  565. if (this.VerdictOutCard(this.m_GameLogic.SwitchToCardData(i)) == false)
  566. continue;
  567. //设置变量
  568. cbCardData = this.m_GameLogic.SwitchToCardData(i);
  569. }
  570. }
  571. //出牌动作
  572. var sequence = cc.sequence(
  573. cc.callFunc(function () {
  574. this.m_GameClientView.m_CardView.m_HandCard[wViewID].SetCanTouch(false);
  575. }, this),
  576. cc.delayTime(1),
  577. cc.callFunc(function () {
  578. this.m_GameClientView.m_CardView.m_HandCard[wViewID].SetOutCard(cbCardData);
  579. this.OnOutCard(0, 0, cbCardData);
  580. }, this
  581. ));
  582. this.node.runAction(sequence);
  583. },
  584. //出牌判断
  585. VerdictOutCard: function (cbCardData) {
  586. return this.m_GameLogic.IsValidCard(cbCardData);
  587. },
  588. //游戏开始
  589. OnSubGameStart: function (pBuffer, wDataSize) {
  590. this.m_pGameStart = GameDef.CMD_S_GameStart();
  591. //效验
  592. if (wDataSize != gCByte.Bytes2Str(this.m_pGameStart, pBuffer)) return false;
  593. this.CleanView();
  594. if (this.m_EndLittleView) {
  595. this.m_EndLittleView.HideView();
  596. }
  597. this.m_GameClientView.SetGangOperator(0);
  598. this.m_cbGameStatus = GameDef.GAME_SCENE_PLAY;
  599. var pGameStart = this.m_pGameStart;
  600. console.log("pGameStart--", pGameStart);
  601. this.m_GameClientView.m_BtFriend.active = false;
  602. this.m_wGameProgress = this.m_pGameStart.cbQuan + 1;
  603. this.m_GameClientView.UpdateRoomProgress();
  604. //郑骰子
  605. this.m_GameClientView.OnRollDice(this.m_pGameStart.cbSick);
  606. setTimeout(() => {
  607. this.starts();
  608. }, 1500);
  609. this.m_bEnd = false;
  610. return true;
  611. },
  612. starts: function () {
  613. var display = true;
  614. if (GameDef.m_dwGameRuleArr[0] & GameDef.GAME_RULE_SP_16) display = false;
  615. //骰子
  616. this.m_GameClientView.DiceNum(this.m_pGameStart.cbSick);
  617. //风局
  618. this.m_GameClientView.Fengju(this.m_pGameStart.cbQuan, this.m_pGameStart.cbFeng, display);
  619. //风位
  620. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  621. if (this.GetClientUserItem(i) == null) continue;
  622. var OtherViewID = this.SwitchViewChairID(i);
  623. this.m_GameClientView.m_UserInfo[OtherViewID].SetFeng(this.m_pGameStart.cbQuan, this.m_pGameStart.cbUserDNXB[i], display);
  624. }
  625. //初始花牌显示
  626. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  627. if (this.GetClientUserItem(i) == null) continue;
  628. var OtherViewID = this.SwitchViewChairID(i);
  629. this.m_GameClientView.m_UserInfo[OtherViewID].ClearFlower(display);
  630. }
  631. //会牌
  632. this.m_GameClientView.m_CardView.SetMakeMagicIndex(this.m_pGameStart.cbMakeMagicIndex);
  633. //this.m_HuiCardDate = this.m_GameLogic.GetNextCardIndex( pGameStart.cbMakeMagicIndex );
  634. // this.m_GameClientView.m_CardView.SetMagicIndex(this.m_HuiCardDate);
  635. if (!this.m_bRollBack)
  636. this.m_GameClientView.SetMakeMagicIndex(this.m_pGameStart.cbMakeMagicIndex);
  637. //this.m_HuiCardDate = this.m_GameLogic.SwitchToCardData(this.m_HuiCardDate);
  638. // GameDef.m_cbMagicData = this.m_HuiCardDate;
  639. var BankViewID = this.SwitchViewChairID(this.m_pGameStart.wBankerUser);
  640. this.m_GameClientView.m_CardView.SetPositively(false);
  641. var wMeChairID = this.GetMeChairID();
  642. this.m_bStustee = this.m_pGameStart.bTrustee[wMeChairID];
  643. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  644. if (this.GetClientUserItem(i) == null) continue;
  645. var viewId = this.SwitchViewChairID(i);
  646. this.m_GameClientView.m_UserInfo[viewId].SetTing(false);
  647. var cbDouble = this.m_pGameStart.cbDouble[i];
  648. this.m_GameClientView.m_UserInfo[viewId].SetGang(cbDouble);
  649. this.m_GameClientView.SetTrustee(i, this.m_pGameStart.bTrustee[i]);
  650. }
  651. // this.m_GameClientView.SetHuangZhuang(pGameStart.wHuangZhuangCount);
  652. if (!this.m_bRollBack)
  653. cc.gSoundRes.PlayGameSound("GAME_START");
  654. //保存数据
  655. this.m_wBankerUser = this.m_pGameStart.wBankerUser;
  656. this.m_wCurrentUser = this.m_pGameStart.wCurrentUser;
  657. this.m_cbLeftCardCount = this.m_pGameStart.cbLastCardCount;
  658. this.m_wActionMask = this.m_pGameStart.wUserAction;
  659. this.m_GameClientView.SetLeftCardCount(this.m_cbLeftCardCount);
  660. //设置扑克
  661. var cbCardCount = (wMeChairID == this.m_wBankerUser) ? GameDef.MAX_COUNT : (GameDef.MAX_COUNT - 1);
  662. this.m_GameLogic.SwitchToCardIndex3(this.m_pGameStart.cbCardData, cbCardCount, this.m_cbCardIndex);
  663. //设置界面
  664. this.m_GameClientView.SetBankerUser(this.SwitchViewChairID(this.m_wBankerUser));
  665. this.m_GameClientView.m_CardView.SetPositively(true);
  666. this.m_GameClientView.m_BtStart.active = false;
  667. this.m_BtExit.active = false;
  668. this.m_BtDissolve.active = true;
  669. //扑克设置
  670. for (var i = 0; i < GameDef.GAME_PLAYER; ++i) {
  671. //听
  672. this.m_bListen[i] = false;
  673. //变量定义
  674. var wViewChairID = this.SwitchViewChairID(i);
  675. if (this.m_GameClientView.m_pIClientUserItem[wViewChairID] == null) continue;
  676. //用户扑克
  677. if (wViewChairID != GameDef.MYSELF_VIEW_ID) {
  678. this.m_GameClientView.m_CardView.SetCardData(wViewChairID, null, GameDef.MAX_COUNT - 1, null);
  679. } else {
  680. var cbCardData = new Array();
  681. this.m_GameLogic.SwitchToCardData2(this.m_cbCardIndex, cbCardData);
  682. var cbBankerCard = (i == this.m_wBankerUser ? cbCardData[GameDef.MAX_COUNT - 1] : null);
  683. this.m_GameClientView.m_CardView.SetSelfCardData(cbCardData, GameDef.MAX_COUNT - 1, cbBankerCard);
  684. }
  685. this.m_GameClientView.m_CardView.m_HandCard[wViewChairID].SetCanTouch(false);
  686. }
  687. //出牌提示
  688. // if (this.m_wCurrentUser != INVALID_CHAIR) {
  689. // this.m_GameClientView.SetCurrentUser(this.m_wCurrentUser);
  690. // this.SetGameClock(this.m_wCurrentUser, GameDef.IDI_OPERATE_CARD, this.GetOperateTime());
  691. // }
  692. },
  693. //补
  694. OnSubReplaceCard: function (pData, wDataSize) {
  695. var pSendCard = GameDef.CMD_S_ReplaceCard();
  696. //效验
  697. if (wDataSize != gCByte.Bytes2Str(pSendCard, pData)) return false;
  698. var wCurrentUser = pSendCard.wReplaceUser;
  699. console.log("补OnSubReplaceCard--", pSendCard)
  700. var displayF = true;
  701. var displayC = true;
  702. if (GameDef.m_dwGameRuleArr[0] & GameDef.GAME_RULE_SP_16) displayF = false;
  703. // if(this.m_cbGameStatus & GameDef.GAME_SCENE_PLAY)displayC = true;
  704. if (this.GetClientUserItem(wCurrentUser) != null) {
  705. var OtherViewID = this.SwitchViewChairID(wCurrentUser);
  706. this.PlayActionSound(wCurrentUser, "BUHUA");
  707. this.m_GameClientView.m_UserInfo[OtherViewID].SetFlower(OtherViewID, pSendCard.cbFlowerCount[wCurrentUser], pSendCard.cbCardDataFlower[wCurrentUser], displayF, displayC);
  708. this.m_GameClientView.showGotFlowers(OtherViewID, displayC);
  709. }
  710. return true;
  711. },
  712. //发牌
  713. OnSubSendCard: function (pData, wDataSize) {
  714. var pSendCard = GameDef.CMD_S_SendCard();
  715. //效验
  716. if (wDataSize != gCByte.Bytes2Str(pSendCard, pData)) return false;
  717. console.log("发牌--", pSendCard, pSendCard.wActionMask)
  718. //清空听牌提示
  719. this.m_GameClientView.m_CardView.ShowTingData();
  720. this.m_GameClientView.m_CardView.ShowTingTip(0);
  721. this.m_bFirstCard = pSendCard.bFirstCard;
  722. var wMeChairID = this.GetMeChairID();
  723. var wViewChairID = this.SwitchViewChairID(pSendCard.wSendCardUser);
  724. var wChairId = pSendCard.wSendCardUser;
  725. var cbSendCardData = pSendCard.cbCardData;
  726. this.m_wCurrentUser = pSendCard.wCurrentUser;
  727. this.m_cbLeftCardCount = pSendCard.cbLeftCardCount;
  728. this.m_GameClientView.SetLeftCardCount(this.m_cbLeftCardCount);
  729. //取牌界面
  730. if (wViewChairID != GameDef.MYSELF_VIEW_ID) {
  731. if (this.m_ReplayMode) {
  732. this.m_GameClientView.m_CardView.SetCurrentCard(wViewChairID, cbSendCardData, this.m_bListen[wChairId]);
  733. } else {
  734. this.m_GameClientView.m_CardView.SetCurrentCard(wViewChairID, 0, this.m_bListen[wChairId]);
  735. }
  736. } else {
  737. this.m_GameClientView.m_CardView.SetCurrentCard(wViewChairID, cbSendCardData, this.m_bListen[wChairId]);
  738. //插入扑克
  739. this.m_cbCardIndex[this.m_GameLogic.SwitchToCardIndex(cbSendCardData)]++;
  740. }
  741. //当前用户
  742. if (this.m_wCurrentUser == wMeChairID) {
  743. this.m_wActionMask = pSendCard.wActionMask;
  744. this.StusteeOperateCard(this.m_wCurrentUser);
  745. var wViewID = this.SwitchViewChairID(wMeChairID);
  746. this.m_GameClientView.m_CardView.m_HandCard[wViewID].SetCanTouch(pSendCard.bCanOut);
  747. }
  748. this.m_GameClientView.SetCurrentUser(this.m_wCurrentUser);
  749. this.SetGameClock(this.m_wCurrentUser, GameDef.IDI_OPERATE_CARD, this.GetOperateTime());
  750. cc.gSoundRes.PlayGameSound("SEND_CARD");
  751. console.log("cbSendCardData--", cbSendCardData)
  752. if (this.m_wCurrentUser == wMeChairID && cbSendCardData > 55) {
  753. // this.OnReplaceCard(cbSendCardData)
  754. }
  755. return true;
  756. },
  757. //出牌
  758. OnSubOutCard: function (pData, wDataSize) {
  759. // 创建一个CMD_S_OutCard对象,用于存储出牌信息
  760. var pOutCard = GameDef.CMD_S_OutCard();
  761. // 效验数据大小是否与出牌数据结构一致,不一致则返回false
  762. if (wDataSize != gCByte.Bytes2Str(pOutCard, pData)) return false;
  763. this.m_GameClientView.m_CardView.SetControlInfo(false);//关闭操作面板?
  764. // 将出牌用户的椅子ID转换为视角ID
  765. var wOutUserViewId = this.SwitchViewChairID(pOutCard.wOutCardUser);
  766. // 更新出牌数据
  767. this.m_cbOutCardData = pOutCard.cbOutCardData;
  768. // 清空听牌提示
  769. this.m_GameClientView.m_CardView.ShowTingData();
  770. // 隐藏听牌提示标志
  771. this.m_GameClientView.m_CardView.ShowTingTip(0);
  772. // 删除游戏计时器
  773. this.KillGameClock();
  774. // 播放出牌动作声音
  775. this.PlayActionSound(pOutCard.wOutCardUser, this.GetCardStr(this.m_cbOutCardData));
  776. // 设置扑克
  777. if (wOutUserViewId == GameDef.MYSELF_VIEW_ID) {
  778. // 从玩家的手牌中移除出的牌,失败则返回false
  779. if (!this.m_GameLogic.RemoveCard2(this.m_cbCardIndex, this.m_cbOutCardData)) return false;
  780. // 创建一个新的数组来存储手牌数据
  781. var cbHandCardData = new Array();
  782. // 获取更新后手牌的数量
  783. var cbCardCount = this.m_GameLogic.SwitchToCardData2(this.m_cbCardIndex, cbHandCardData);
  784. // 获取客户端内核实例
  785. var kernel = gClientKernel.get();
  786. // 如果是回放模式
  787. if (this.m_ReplayMode) {
  788. // 在回放中添加出的牌到弃牌堆
  789. this.m_GameClientView.m_CardView.AddDiscard(wOutUserViewId, this.m_cbOutCardData, true);
  790. // 更新手牌显示
  791. this.m_GameClientView.m_CardView.SetCardData(wOutUserViewId, cbHandCardData, cbCardCount);
  792. } else if (kernel.IsLookonMode()) {
  793. // 找到出牌在手牌中的索引位置
  794. var CardCtrl = this.m_GameClientView.m_CardView.m_HandCard[wOutUserViewId];
  795. var OutIndex = 0;
  796. for (var i = 0; i < CardCtrl.m_CardItemArray.length; i++) {
  797. if (CardCtrl.m_CardItemArray[i].node.active == true && this.m_cbOutCardData == CardCtrl.m_CardItemArray[i].GetCardData()) {
  798. OutIndex = i;
  799. break;
  800. }
  801. }
  802. // 使用requestAnimationFrame来播放出牌动画
  803. requestAnimationFrame(() => {
  804. this.m_GameClientView.m_CardView.PlayDiscard(wOutUserViewId, OutIndex, this.m_cbOutCardData, cbHandCardData, cbCardCount);
  805. });
  806. } else {
  807. // 获取玩家选择的手牌数据和索引
  808. var selCardData = this.m_GameClientView.m_CardView.m_HandCard[wOutUserViewId].GetDoubleCardData();
  809. var OutIndex = this.m_GameClientView.m_CardView.m_HandCard[wOutUserViewId].GetDoubleCardIndex();
  810. selCardData = this.m_cbOutCardData
  811. if (selCardData == 0 || this.m_bStustee == true) {
  812. selCardData = this.m_cbOutCardData
  813. this.m_GameClientView.m_CardView.m_HandCard[wOutUserViewId].SetOutCard(this.m_cbOutCardData)
  814. }
  815. //如果选择的牌与出的牌相同,则播放出牌动画
  816. if (selCardData == this.m_cbOutCardData) {
  817. requestAnimationFrame(() => {
  818. this.m_GameClientView.m_CardView.PlayDiscard(wOutUserViewId, OutIndex, this.m_cbOutCardData, cbHandCardData, cbCardCount);
  819. });
  820. }
  821. // if (this.m_bStustee == true) {
  822. // if (selCardData == 0) {
  823. // selCardData = this.m_cbOutCardData
  824. // this.m_GameClientView.m_CardView.m_HandCard[wOutUserViewId].SetOutCard(this.m_cbOutCardData)
  825. // }
  826. // requestAnimationFrame(() => {
  827. // this.m_GameClientView.m_CardView.PlayDiscard(wOutUserViewId, OutIndex, this.m_cbOutCardData, cbHandCardData, cbCardCount);
  828. // });
  829. // } else {
  830. // //如果选择的牌与出的牌相同,则播放出牌动画
  831. // if (selCardData == this.m_cbOutCardData) {
  832. // requestAnimationFrame(() => {
  833. // this.m_GameClientView.m_CardView.PlayDiscard(wOutUserViewId, OutIndex, this.m_cbOutCardData, cbHandCardData, cbCardCount);
  834. // });
  835. // }
  836. // }
  837. }
  838. } else {
  839. if (this.m_ReplayMode) {
  840. // 获取对手的手牌数据和数量
  841. var cbHandCardData = this.m_GameClientView.m_CardView.m_HandCard[wOutUserViewId].m_cbCardData;
  842. var cbCardCount = this.m_GameClientView.m_CardView.m_HandCard[wOutUserViewId].m_wCardCount;
  843. // 创建一个数组来存储移除的牌
  844. var cbRemoveCard = new Array();
  845. cbRemoveCard[0] = this.m_cbOutCardData;
  846. // 从对手的手牌中移除出的牌,失败则返回false
  847. if (!this.m_GameLogic.RemoveCard4(cbHandCardData, cbCardCount, cbRemoveCard, 1)) {
  848. return false;
  849. }
  850. // 对手手牌重新排序
  851. this.m_GameLogic.SortCardList(cbHandCardData, cbCardCount - 1);
  852. // 更新对手手牌显示
  853. this.m_GameClientView.m_CardView.SetCardData(wOutUserViewId, cbHandCardData, cbCardCount - 1);
  854. // 在回放中添加出的牌到弃牌堆
  855. this.m_GameClientView.m_CardView.AddDiscard(wOutUserViewId, this.m_cbOutCardData, true);
  856. } else {
  857. // 设置当前玩家的出牌状态
  858. this.m_GameClientView.m_CardView.SetCurrentCard(wOutUserViewId, null, this.m_bListen[pOutCard.wOutCardUser]);
  859. // 播放对手出牌动画
  860. requestAnimationFrame(() => {
  861. this.m_GameClientView.m_CardView.PlayDiscard(wOutUserViewId, OutIndex, this.m_cbOutCardData);
  862. });
  863. }
  864. }
  865. // 如果出牌用户不是当前玩家
  866. if (pOutCard.wOutCardUser != this.GetMeChairID()) {
  867. // 设置当前操作用户为无效
  868. this.m_wCurrentUser = INVALID_CHAIR;
  869. // 清空操作掩码
  870. this.m_wActionMask = 0;
  871. // 设置界面显示的当前操作用户为无效
  872. this.m_GameClientView.SetCurrentUser(INVALID_CHAIR);
  873. // 设置用户操作界面为无效
  874. this.m_GameClientView.SetUserAction(INVALID_CHAIR, 0);
  875. }
  876. // 出牌处理完成,返回true
  877. return true;
  878. },
  879. // //出牌
  880. // OnSubOutCard: function (pData, wDataSize) {
  881. // var pOutCard = GameDef.CMD_S_OutCard();
  882. // //效验
  883. // if (wDataSize != gCByte.Bytes2Str(pOutCard, pData)) return false;
  884. // var wOutUserViewId = this.SwitchViewChairID(pOutCard.wOutCardUser);
  885. // this.m_cbOutCardData = pOutCard.cbOutCardData;
  886. // //清空听牌提示
  887. // this.m_GameClientView.m_CardView.ShowTingData();
  888. // this.m_GameClientView.m_CardView.ShowTingTip(0);
  889. // //删除定时器
  890. // this.KillGameClock();
  891. // //播放声音
  892. // this.PlayActionSound(pOutCard.wOutCardUser, this.GetCardStr(this.m_cbOutCardData));
  893. // //设置扑克
  894. // if (wOutUserViewId == GameDef.MYSELF_VIEW_ID) {
  895. // //删除扑克
  896. // if (!this.m_GameLogic.RemoveCard2(this.m_cbCardIndex, this.m_cbOutCardData)) return false;
  897. // var cbHandCardData = new Array();//[GameDef.MAX_COUNT];
  898. // var cbCardCount = this.m_GameLogic.SwitchToCardData2(this.m_cbCardIndex, cbHandCardData);
  899. // var kernel = gClientKernel.get();
  900. // if (this.m_ReplayMode) {
  901. // this.m_GameClientView.m_CardView.AddDiscard(wOutUserViewId, this.m_cbOutCardData, true);
  902. // this.m_GameClientView.m_CardView.SetCardData(wOutUserViewId, cbHandCardData, cbCardCount);
  903. // }
  904. // else if (kernel.IsLookonMode()) {
  905. // var CardCtrl = this.m_GameClientView.m_CardView.m_HandCard[wOutUserViewId];
  906. // var OutIndex = 0;
  907. // for (var i = 0; i < CardCtrl.m_CardItemArray.length; i++) {
  908. // if (CardCtrl.m_CardItemArray[i].node.active == true && this.m_cbOutCardData == CardCtrl.m_CardItemArray[i].GetCardData()) {
  909. // OutIndex = i;
  910. // break;
  911. // }
  912. // }
  913. // this.m_GameClientView.m_CardView.PlayDiscard(wOutUserViewId, OutIndex, this.m_cbOutCardData, cbHandCardData, cbCardCount);
  914. // }
  915. // else {
  916. // var selCardData = this.m_GameClientView.m_CardView.m_HandCard[wOutUserViewId].GetDoubleCardData();
  917. // var OutIndex = this.m_GameClientView.m_CardView.m_HandCard[wOutUserViewId].GetDoubleCardIndex();
  918. // if (selCardData == this.m_cbOutCardData) {
  919. // this.m_GameClientView.m_CardView.PlayDiscard(wOutUserViewId, OutIndex, this.m_cbOutCardData, cbHandCardData, cbCardCount);
  920. // }
  921. // }
  922. // } else {
  923. // if (this.m_ReplayMode) {
  924. // var cbHandCardData = this.m_GameClientView.m_CardView.m_HandCard[wOutUserViewId].m_cbCardData;//[GameDef.MAX_COUNT];
  925. // var cbCardCount = this.m_GameClientView.m_CardView.m_HandCard[wOutUserViewId].m_wCardCount;
  926. // var cbRemoveCard = new Array();
  927. // cbRemoveCard[0] = this.m_cbOutCardData;
  928. // //删除扑克
  929. // if (!this.m_GameLogic.RemoveCard4(cbHandCardData, cbCardCount, cbRemoveCard, 1)) {
  930. // return false;
  931. // }
  932. // this.m_GameLogic.SortCardList(cbHandCardData, cbCardCount - 1);
  933. // this.m_GameClientView.m_CardView.SetCardData(wOutUserViewId, cbHandCardData, cbCardCount - 1);
  934. // this.m_GameClientView.m_CardView.AddDiscard(wOutUserViewId, this.m_cbOutCardData, true);
  935. // } else {
  936. // this.m_GameClientView.m_CardView.SetCurrentCard(wOutUserViewId, null, this.m_bListen[pOutCard.wOutCardUser]);
  937. // this.m_GameClientView.m_CardView.PlayDiscard(wOutUserViewId, OutIndex, this.m_cbOutCardData);
  938. // }
  939. // }
  940. // if (pOutCard.wOutCardUser != this.GetMeChairID()) {
  941. // //设置变量
  942. // this.m_wCurrentUser = INVALID_CHAIR;
  943. // this.m_wActionMask = 0;
  944. // //设置界面
  945. // this.m_GameClientView.SetCurrentUser(INVALID_CHAIR);
  946. // this.m_GameClientView.SetUserAction(INVALID_CHAIR, 0);
  947. // }
  948. // return true;
  949. // },
  950. huAuto: function(){
  951. var OperateCard = GameDef.CMD_C_OperateCard();
  952. OperateCard.wOperateCode = GameDef.WIK_CHI_HU;
  953. this.SendGameData(GameDef.SUB_C_OPERATE_CARD, OperateCard);
  954. },
  955. //操作提示
  956. OnSubOperateNotify: function (pData, wDataSize) {
  957. var pOperateNotify = GameDef.CMD_S_OperateNotify();
  958. var size = gCByte.Bytes2Str(pOperateNotify, pData);
  959. var pObj = new Object()
  960. pObj.pItem = new Array(pOperateNotify.wCount);
  961. for (var i = 0; i < pOperateNotify.wCount; i++) {
  962. pObj.pItem[i] = GameDef.CMD_WeaveItem();
  963. }
  964. //效验
  965. if (wDataSize != gCByte.Bytes2Str(pObj, pData, size) + size) return false;
  966. //回放、观战不显示选飘界面
  967. var kernel = gClientKernel.get();
  968. if (this.m_ReplayMode || kernel.IsLookonMode()) return true;
  969. console.log("操作提示--", pOperateNotify, pObj)
  970. //用户界面
  971. if (pOperateNotify.wActionMask != GameDef.WIK_NULL) {
  972. if (pOperateNotify.wActionMask & GameDef.WIK_CHI_HU) {
  973. console.log("操作提示-胡")
  974. this.scheduleOnce(() => {
  975. this.huAuto();
  976. // var OperateCard = GameDef.CMD_C_OperateCard();
  977. // OperateCard.wOperateCode = GameDef.WIK_CHI_HU;
  978. // OperateCard.cbOperateCard[0] = pOperateNotify.cbActionCard;
  979. // OperateCard.cbOperateCount = 1;
  980. // OperateCard.cbIndex = 0;
  981. // this.SendGameData(GameDef.SUB_C_OPERATE_CARD, OperateCard);
  982. }, 0.3);
  983. }
  984. // if (pOperateNotify.wActionMask & GameDef.WIK_GANG) {
  985. // console.log("操作提示-杠")
  986. // }
  987. // if (pOperateNotify.wActionMask & GameDef.WIK_PENG) {
  988. // console.log("操作提示-碰")
  989. // }
  990. // if (pOperateNotify.wActionMask & GameDef.WIK_LEFT) {
  991. // console.log("操作提示-左吃")
  992. // }
  993. // if (pOperateNotify.wActionMask & GameDef.WIK_CENTER) {
  994. // console.log("操作提示-中吃")
  995. // }
  996. // if (pOperateNotify.wActionMask & GameDef.WIK_RIGHT) {
  997. // console.log("操作提示-右吃")
  998. // }
  999. //this.m_GameClientView.m_CardView.m_HandCard[2].SetCanTouch(false);
  1000. //获取变量
  1001. var wMeChairID = this.GetMeChairID();
  1002. this.m_wActionMask = pOperateNotify.wActionMask;
  1003. //设置界面
  1004. cc.error("OnSubOperateNotify ", pObj.pItem);
  1005. this.m_GameClientView.m_CardView.SetControlInfo(true, pObj.pItem, pObj.pItem.length);
  1006. //设置时间
  1007. this.m_GameClientView.SetCurrentUser(pOperateNotify.wResumeUser);
  1008. this.SetGameClock(wMeChairID, GameDef.IDI_OPERATE_CARD, this.GetOperateTime());
  1009. this.StusteeOperateCard(wMeChairID);
  1010. }
  1011. return true;
  1012. },
  1013. OnSubOperateTimer: function (pData, wDataSize) {
  1014. this.SetGameClock(INVALID_CHAIR, GameDef.IDI_OPERATE_CARD, this.GetOperateTime());
  1015. return true;
  1016. },
  1017. //操作提示
  1018. OnSubOperateResult: function (pData, wDataSize) {
  1019. var pOperateResult = GameDef.CMD_S_OperateResult();
  1020. //效验
  1021. if (wDataSize != gCByte.Bytes2Str(pOperateResult, pData)) return false;
  1022. console.log("pOperateResult--", pOperateResult)
  1023. var wOperateViewID = this.SwitchViewChairID(pOperateResult.wOperateUser);
  1024. if (pOperateResult.wOperateUser != pOperateResult.wProvideUser && pOperateResult.bQiangGang == false) {
  1025. var PrivideViewID = this.SwitchViewChairID(pOperateResult.wProvideUser);
  1026. this.m_GameClientView.m_CardView.StopDiscard(PrivideViewID, pOperateResult.cbCenterCard);
  1027. }
  1028. var wOperateUser = pOperateResult.wOperateUser;
  1029. this.m_GameClientView.m_CardView.SetControlInfo(false);
  1030. this.m_GameClientView.SetUserAction(wOperateViewID, pOperateResult.wOperateCode);
  1031. //环境设置
  1032. if (pOperateResult.wOperateCode & (GameDef.WIK_GANG)) {
  1033. this.PlayActionSound(wOperateUser, "GANG");
  1034. // if (pOperateResult.dwGangScore > 0) {
  1035. // if (pOperateResult.wProvideUser == wOperateUser) {
  1036. // //暗杠,补杠
  1037. // var AddScore = 0;
  1038. // for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  1039. // if (this.GetClientUserItem(i) == null) continue;
  1040. // if (i == wOperateUser) continue;
  1041. // var OtherViewID = this.SwitchViewChairID(i);
  1042. // this.m_GameClientView.m_UserInfo[OtherViewID].SetScore(OtherViewID, -pOperateResult.dwGangScore);// -
  1043. // AddScore += pOperateResult.dwGangScore;
  1044. // }
  1045. // // this.m_GameClientView.m_UserInfo[wOperateViewID].SetScore(OtherViewID, AddScore);//+ AddScore
  1046. // }
  1047. // else {
  1048. // //叉杠
  1049. // var PrivideViewID = this.SwitchViewChairID(pOperateResult.wProvideUser);
  1050. // this.m_GameClientView.m_UserInfo[PrivideViewID].SetScore(PrivideViewID, -pOperateResult.dwGangScore);;//-
  1051. // this.m_GameClientView.m_UserInfo[wOperateViewID].SetScore(wOperateViewID, pOperateResult.dwGangScore);;//+
  1052. // }
  1053. // }
  1054. }
  1055. else if (pOperateResult.wOperateCode & (GameDef.WIK_LEFT | GameDef.WIK_CENTER | GameDef.WIK_RIGHT))
  1056. this.PlayActionSound(wOperateUser, "CHI");
  1057. else if (pOperateResult.wOperateCode & GameDef.WIK_PENG)
  1058. this.PlayActionSound(wOperateUser, "PENG");
  1059. else if (pOperateResult.wOperateCode & GameDef.WIK_CHI_HU)
  1060. this.PlayActionSound(wOperateUser, "HU");
  1061. else if (pOperateResult.wOperateCode & GameDef.WIK_LISTEN) {
  1062. this.PlayActionSound(wOperateUser, "TING");
  1063. this.m_bListen[wOperateUser] = true;
  1064. var viewID = this.SwitchViewChairID(wOperateUser);
  1065. this.m_GameClientView.m_UserInfo[viewID].SetTing(true);
  1066. }
  1067. else if (pOperateResult.wOperateCode & GameDef.WIK_GANG_FENG) {
  1068. this.PlayActionSound(wOperateUser, "FENG");
  1069. }
  1070. else if (pOperateResult.wOperateCode & GameDef.WIK_DNJ) {
  1071. this.PlayActionSound(wOperateUser, "DNJ");
  1072. }
  1073. else if (pOperateResult.wOperateCode & GameDef.WIK_CAI_ZFB) {
  1074. this.PlayActionSound(wOperateUser, "ZFB");
  1075. }
  1076. //设置时间
  1077. if (pOperateResult.bBeiQiangGang) {
  1078. this.m_wCurrentUser = INVALID_CHAIR;
  1079. }
  1080. else {
  1081. this.m_wCurrentUser = wOperateUser;
  1082. }
  1083. var wMeChairID = this.GetMeChairID();
  1084. if (wOperateUser == wMeChairID) {
  1085. var wViewID = this.SwitchViewChairID(wMeChairID);
  1086. this.m_GameClientView.m_CardView.m_HandCard[wViewID].SetCanTouch(true);
  1087. }
  1088. this.m_GameClientView.SetCurrentUser(wOperateUser);
  1089. this.SetGameClock(wOperateUser, GameDef.IDI_OPERATE_CARD, this.GetOperateTime());
  1090. return true;
  1091. },
  1092. OnSubGameEnd: function (pData, wDataSize) {
  1093. this.m_GameEnd = GameDef.CMD_S_GameEnd();
  1094. if (wDataSize != gCByte.Bytes2Str(this.m_GameEnd, pData)) return false;
  1095. GameDef.cbLianZhuangCount = this.m_GameEnd.cbLianZhuangCount;
  1096. console.log("連莊cbLianZhuangCount", GameDef.cbLianZhuangCount);
  1097. this.m_cbGameStatus = GameDef.GAME_SCENE_FREE;
  1098. console.log("this.m_GameEnd--", this.m_GameEnd);
  1099. this.m_bCanShowBigEnd = false;
  1100. //清空听牌提示
  1101. this.m_GameClientView.m_CardView.ShowTingData();
  1102. this.m_GameClientView.m_CardView.ShowTingTip(0);
  1103. //删除定时器
  1104. this.KillGameClock();
  1105. GameDef.dwChiHuRightAdd = this.m_GameEnd.dwChiHuRightAdd;
  1106. this.m_wGameProgress = this.m_GameEnd.cbQuan + 1;
  1107. // this.m_GameClientView.UpdateRoomProgress();
  1108. this.MyChairID = this.GetMeChairID()
  1109. let isZimo = false;
  1110. //赢家
  1111. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  1112. if (this.GetClientUserItem(i) == null) continue;
  1113. if (this.m_GameEnd.dwChiHuKind[i] == GameDef.WIK_CHI_HU) {
  1114. var viewID = this.SwitchViewChairID(i);
  1115. if (this.m_GameEnd.dwChiHuRight[i] & GameDef.CHR_ZI_MO) {
  1116. //自摸
  1117. this.m_GameClientView.SetUserAction(viewID, GameDef.WIK_CHI_HU, GameDef.CHR_ZI_MO);
  1118. isZimo = true;
  1119. } else {
  1120. //胡牌
  1121. this.m_GameClientView.SetUserAction(viewID, GameDef.WIK_CHI_HU);
  1122. }
  1123. }
  1124. }
  1125. //输家
  1126. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  1127. if (this.m_GameEnd.lGameScore[i] >= 0) {
  1128. continue;
  1129. }
  1130. if (this.GetClientUserItem(i) == null) continue;
  1131. var viewID = this.SwitchViewChairID(i);
  1132. this.m_GameClientView.SetUserAction(viewID, GameDef.WIK_FANG_PAO, isZimo ? GameDef.CHR_ZI_MO : 0);
  1133. }
  1134. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  1135. if (this.GetClientUserItem(i) == null) continue;
  1136. var OtherViewID = this.SwitchViewChairID(i);
  1137. this.m_GameClientView.m_UserInfo[OtherViewID].SetScore(OtherViewID, this.m_GameEnd.lSumGameScore[i])
  1138. }
  1139. //设置控件
  1140. this.m_GameClientView.m_CardView.SetControlInfo(false);
  1141. this.m_GameClientView.m_CardView.SetPositively(false);
  1142. this.m_GameClientView.SetCurrentUser(INVALID_CHAIR);
  1143. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  1144. if (this.GetClientUserItem(i) == null) continue;
  1145. for (var j = 0; j < this.m_GameEnd.cbWeaveCount[i]; ++j) {
  1146. var cbCenterCard = this.m_GameEnd.weaveItem[i][j].cbCenterCard;
  1147. var wWeaveKind = this.m_GameEnd.weaveItem[i][j].wWeaveKind;
  1148. var cbCardData = this.m_GameEnd.weaveItem[i][j].cbCardData;
  1149. var cbWeaveCardCount = this.m_GameEnd.weaveItem[i][j].cbCardCount;
  1150. var cbPublicCard = this.m_GameEnd.weaveItem[i][j].cbPublicCard;
  1151. var viewID = this.SwitchViewChairID(i);
  1152. this.m_GameClientView.m_CardView.SetWeaveData(viewID, j, cbCardData, cbWeaveCardCount, cbPublicCard);
  1153. this.m_GameClientView.m_CardView.SetWeaveState(viewID, j, this.m_GameEnd.weaveItem[i][j]);
  1154. if (cbWeaveCardCount == 4 && !cbPublicCard) {
  1155. this.m_GameClientView.m_CardView.SetWeaveState(viewID, j, GameDef.GAME_THREE_BACK_SELF);
  1156. }
  1157. }
  1158. }
  1159. //设置扑克
  1160. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  1161. if (this.GetClientUserItem(i) == null) continue;
  1162. var cbCardData = this.m_GameEnd.cbCardData;
  1163. var wCardCount = this.m_GameEnd.cbCardCount[i];
  1164. var viewID = this.SwitchViewChairID(i);
  1165. if ((wCardCount + 1) % 3 == 0) {
  1166. var tmpCardData = new Array();
  1167. for (var j = 0; j < wCardCount; j++) {
  1168. tmpCardData[j] = cbCardData[i][j];
  1169. }
  1170. var cbRemoveCard = new Array();
  1171. if (this.m_GameEnd.cbProvideCard != 0) {
  1172. cbRemoveCard[0] = this.m_GameEnd.cbProvideCard;
  1173. } else {
  1174. cbRemoveCard[0] = tmpCardData[wCardCount - 1];
  1175. }
  1176. if (this.m_GameEnd.cbLastCardData[i]) {
  1177. cbRemoveCard[0] = this.m_GameEnd.cbLastCardData[i];
  1178. }
  1179. if (this.m_GameLogic.RemoveCard4(tmpCardData, wCardCount, cbRemoveCard, 1)) {
  1180. this.m_GameClientView.m_CardView.SetCardData(viewID, tmpCardData, wCardCount - 1);
  1181. this.m_GameClientView.m_CardView.SetCurrentCard(viewID, cbRemoveCard[0]);
  1182. }
  1183. } else {
  1184. this.m_GameClientView.m_CardView.SetCardData(viewID, cbCardData[i], wCardCount);
  1185. }
  1186. this.m_GameClientView.m_CardView.SetCardItemState(viewID, GameDef.HAND_STATE_SHOW);
  1187. }
  1188. //播放声音
  1189. if (this.m_GameEnd.wProvideUser != INVALID_CHAIR) {
  1190. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  1191. if (this.m_GameEnd.dwChiHuKind[i] != GameDef.WIK_NULL) {
  1192. if (this.m_GameEnd.dwChiHuRight[i] & GameDef.CHR_ZI_MO) {
  1193. this.PlayActionSound(i, "ZIMO");
  1194. }
  1195. else {
  1196. this.PlayActionSound(i, "HU");
  1197. }
  1198. }
  1199. }
  1200. } else {
  1201. cc.gSoundRes.PlayGameSound("GAME_END");
  1202. }
  1203. var WaitTime = 3;
  1204. // if(this.m_GameEnd.cbBirdCardCount > 0)
  1205. // {
  1206. // this.m_GameClientView.ShowBird(this.m_GameEnd.cbBirdCard, this.m_GameEnd.cbBirdCardCount);
  1207. // WaitTime = 4;
  1208. // }
  1209. //设置定时
  1210. this.schedule(this.OnTimeIDI_PERFORM_END, WaitTime);
  1211. // this.OnTimeIDI_PERFORM_END();
  1212. return true;
  1213. },
  1214. //用户托管
  1215. OnSubTrustee: function (pData, wDataSize) {
  1216. var pTrustee = GameDef.CMD_S_Trustee();
  1217. if (wDataSize != gCByte.Bytes2Str(pTrustee, pData)) return false;
  1218. this.m_GameClientView.SetTrustee(pTrustee.wChairID, pTrustee.bTrustee);
  1219. var wMeChairID = this.GetMeChairID();
  1220. if (wMeChairID == pTrustee.wChairID) {
  1221. this.m_bStustee = pTrustee.bTrustee;
  1222. if (pTrustee.bTrustee) {
  1223. if (this.m_bEnd) {
  1224. if (this.m_EndLittleView) {
  1225. this.m_EndLittleView.HideView();
  1226. }
  1227. this.checkTotalEnd(true);
  1228. }
  1229. else {
  1230. this.StusteeOperateCard(pTrustee.wChairID);
  1231. }
  1232. }
  1233. }
  1234. console.log("是否托管---", this.m_bStustee)
  1235. return true;
  1236. },
  1237. OnSubLeave: function (pData, wDataSize) {
  1238. var pLeave = GameDef.CMD_S_Leave();
  1239. if (wDataSize != gCByte.Bytes2Str(pLeave, pData)) return false;
  1240. this.m_GameClientView.SetUserTimer(this.SwitchViewChairID(this.m_wCurrentUser), 0);
  1241. // for(var i = 0; i < GameDef.GAME_PLAYER; ++ i)
  1242. // this.m_GameClientView.SetLeave(this.SwitchViewChairID(i), pLeave.bLeave[i]);
  1243. return true;
  1244. },
  1245. OnSubPlayerDouble: function (pData, wDataSize) {
  1246. var pDouble = GameDef.CMD_S_Double();
  1247. if (wDataSize != gCByte.Bytes2Str(pDouble, pData)) return false;
  1248. var viewID = this.SwitchViewChairID(pDouble.wCallUser);
  1249. this.m_GameClientView.m_UserInfo[viewID].SetGang(pDouble.cbDouble);
  1250. return true;
  1251. },
  1252. UpdateHandActionCard: function () {
  1253. },
  1254. OnTing: function (pData, wDataSize) {
  1255. var pTing = new Object();
  1256. pTing.wCount = 0;
  1257. var size = gCByte.Bytes2Str(pTing, pData);
  1258. var pObj = new Object()
  1259. pObj.pItem = new Array(pTing.wCount);
  1260. for (var i = 0; i < pTing.wCount; i++) {
  1261. pObj.pItem[i] = GameDef.CMD_TingTip();
  1262. }
  1263. console.log("听--", pObj)
  1264. //效验
  1265. if (wDataSize != gCByte.Bytes2Str(pObj, pData, size) + size) return false;
  1266. var wMeChairID = this.GetMeChairID();
  1267. this.m_GameClientView.m_CardView.ShowTingData(pObj.pItem, this.m_bListen[wMeChairID]);
  1268. return true;
  1269. },
  1270. OnUpdateCardData: function (pData, wDataSize) {
  1271. var pHandCardData = GameDef.CMD_S_HandCardData();
  1272. if (wDataSize != gCByte.Bytes2Str(pHandCardData, pData)) return false;
  1273. console.log("刷新pHandCardData--", pHandCardData);
  1274. var wMeChairID = this.GetMeChairID();
  1275. if (pHandCardData.wChairID == wMeChairID) {
  1276. this.m_cbCardIndex = new Array();
  1277. this.m_GameLogic.SwitchToCardIndex3(pHandCardData.cbCardData, pHandCardData.wCardCount, this.m_cbCardIndex);
  1278. this.m_GameClientView.m_CardView.SetSelfCardIndex(this.m_cbCardIndex, pHandCardData.cbSendCardData, this.m_bListen[wMeChairID], pHandCardData.cbCantOutCard);
  1279. } else {
  1280. var viewID = this.SwitchViewChairID(pHandCardData.wChairID);
  1281. if (this.m_ReplayMode) {
  1282. if (pHandCardData.cbCardData[0] != 0) {
  1283. if ((pHandCardData.wCardCount + 1) % 3 == 0) {
  1284. var curCardData = pHandCardData.cbSendCardData;
  1285. if (curCardData == 0) curCardData = pHandCardData.cbCardData[0]
  1286. this.m_GameClientView.m_CardView.SetCardData(viewID, pHandCardData.cbCardData, pHandCardData.wCardCount, curCardData);
  1287. } else {
  1288. this.m_GameClientView.m_CardView.SetCardData(viewID, pHandCardData.cbCardData, pHandCardData.wCardCount);
  1289. }
  1290. }
  1291. } else {
  1292. // if((pHandCardData.wCardCount+1)%3==0){
  1293. // this.m_GameClientView.m_CardView.SetCardData(viewID,null,pHandCardData.wCardCount-1,0);
  1294. // }else{
  1295. // this.m_GameClientView.m_CardView.SetCardData(viewID,null,pHandCardData.wCardCount);
  1296. // }
  1297. this.m_GameClientView.m_CardView.SetCardData(viewID, null, pHandCardData.wCardCount);
  1298. }
  1299. }
  1300. var i = pHandCardData.wChairID;
  1301. this.m_cbWeaveCount[i] = pHandCardData.dwWeaveCount;
  1302. for (var j = 0; j < GameDef.MAX_WEAVE; ++j) {
  1303. this.m_WeaveItemArray[i][j].wWeaveKind = pHandCardData.WeaveItem[j].wWeaveKind;
  1304. this.m_WeaveItemArray[i][j].cbCenterCard = pHandCardData.WeaveItem[j].cbCenterCard;
  1305. this.m_WeaveItemArray[i][j].cbPublicCard = pHandCardData.WeaveItem[j].cbPublicCard;
  1306. this.m_WeaveItemArray[i][j].wProvideUser = pHandCardData.WeaveItem[j].wProvideUser;
  1307. this.m_WeaveItemArray[i][j].cbCardCount = pHandCardData.WeaveItem[j].cbCardCount;
  1308. for (var k = 0; k < 4; ++k) {
  1309. this.m_WeaveItemArray[i][j].cbCardData[k] = pHandCardData.WeaveItem[j].cbCardData[k];
  1310. this.m_WeaveItemArray[i][j].cbExtraCount[k] = pHandCardData.WeaveItem[j].cbExtraCount[k];
  1311. }
  1312. }
  1313. var ViewID = this.SwitchViewChairID(i);
  1314. for (var j = 0; j < this.m_cbWeaveCount[i]; j++) {
  1315. this.m_GameClientView.m_CardView.SetWeaveData(ViewID, j, this.m_WeaveItemArray[i][j].cbCardData, this.m_WeaveItemArray[i][j].cbCardCount);
  1316. this.m_GameClientView.m_CardView.SetWeaveState(ViewID, j, this.m_WeaveItemArray[i][j]);
  1317. }
  1318. return true;
  1319. },
  1320. //开始选刚
  1321. OnSubStartDouble: function (pData, wDataSize) {
  1322. var pGameDouble = GameDef.CMD_S_Game_Double();
  1323. if (wDataSize != gCByte.Bytes2Str(pGameDouble, pData)) return false;
  1324. this.m_bStustee = false;
  1325. this.m_wBankerUser = pGameDouble.wBankerUser;
  1326. var bankerViewID = this.SwitchViewChairID(this.m_wBankerUser);
  1327. this.m_GameClientView.SetBankerUser(bankerViewID);
  1328. this.m_cbGameStatus = GameDef.GAME_SCENE_DOUBLE;
  1329. this.SetGameClock(INVALID_CHAIR, GameDef.IDI_OPERATE_CARD, this.GetOperateTime());
  1330. this.m_GameClientView.m_BtStart.active = false;
  1331. this.m_GameClientView.m_BtFriend.active = false;
  1332. this.m_BtExit.active = false;
  1333. this.m_BtDissolve.active = true;
  1334. //回放、观战不显示选飘界面
  1335. var kernel = gClientKernel.get();
  1336. if (this.m_ReplayMode || kernel.IsLookonMode()) return true;
  1337. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  1338. if (this.GetClientUserItem(i) == null) continue;
  1339. var viewId = this.SwitchViewChairID(i);
  1340. this.m_GameClientView.m_UserInfo[viewId].SetTing(false);
  1341. this.m_GameClientView.m_UserInfo[viewId].SetGang(0);
  1342. this.m_GameClientView.SetTrustee(i, false);
  1343. }
  1344. this.m_GameClientView.SetGangOperator(1);
  1345. return true;
  1346. },
  1347. OnMessageStart: function () {
  1348. //this.ShowHead(true);
  1349. this.KillGameClock();
  1350. //隐藏按钮
  1351. this.m_GameClientView.m_BtStart.active = false;
  1352. //this.m_GameClientView.m_BtFriend.active = false;
  1353. this.m_GameClientView.m_CardView.SetControlInfo(false);
  1354. this.m_GameClientView.SetCurrentUser(INVALID_CHAIR);
  1355. //设置界面
  1356. this.m_GameClientView.m_CardView.SetDiscardTip(INVALID_CHAIR);
  1357. this.m_GameClientView.SetBankerUser(INVALID_CHAIR);
  1358. this.m_GameClientView.SetUserAction(INVALID_CHAIR, 0);
  1359. //关闭显示花,风位
  1360. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  1361. if (this.GetClientUserItem(i) == null) continue;
  1362. var OtherViewID = this.SwitchViewChairID(i);
  1363. this.m_GameClientView.m_UserInfo[OtherViewID].SetShowFenganFlower();
  1364. }
  1365. //隐藏骰子
  1366. this.m_GameClientView.ShowDice(false);
  1367. this.m_GameClientView.m_CardView.ResetView();
  1368. //扑克设置
  1369. //游戏变量
  1370. this.m_wCurrentUser = INVALID_CHAIR;
  1371. this.m_wActionMask = 0;
  1372. for (var i = 0; i < GameDef.GAME_PLAYER; ++i) {
  1373. this.m_cbWeaveCount[i] = 0;
  1374. for (var j = 0; j < GameDef.MAX_WEAVE; ++j) {
  1375. this.m_WeaveItemArray[i][j] = GameDef.tagWeaveItem();
  1376. }
  1377. }
  1378. //扑克变量
  1379. this.m_cbLeftCardCount = 0;
  1380. for (var i = 0; i < 42; ++i)//GameDef.MAX_INDEX
  1381. {
  1382. this.m_cbCardIndex[i] = 0;
  1383. }
  1384. //if (this.m_dwRulesArr[0] & GameDef.GAME_RULE_SP_7)
  1385. //{
  1386. // this.m_GameClientView.SetLeftCardCount(112);
  1387. //}
  1388. //else
  1389. //{
  1390. // this.m_GameClientView.SetLeftCardCount(108);
  1391. //}
  1392. this.m_GameClientView.SetLeftCardCount(GameDef.MAX_REPERTORY);
  1393. //设置用户动作
  1394. this.m_GameClientView.SetUserAction(INVALID_CHAIR, 0);
  1395. var kernel = gClientKernel.get();
  1396. if (kernel.IsLookonMode() == false) {
  1397. //发送准备
  1398. this.SendUserReady(null, 0);
  1399. }
  1400. },
  1401. CleanView: function (bOffLineBack) {
  1402. this.Init();
  1403. this.waitOperate = false;
  1404. this.m_GameClientView.m_CardView.SetControlInfo(false);
  1405. this.m_GameClientView.SetCurrentUser(INVALID_CHAIR);
  1406. //设置界面
  1407. this.m_GameClientView.m_CardView.SetDiscardTip(INVALID_CHAIR);
  1408. this.m_GameClientView.SetBankerUser(INVALID_CHAIR);
  1409. this.m_GameClientView.SetUserAction(INVALID_CHAIR, 0);
  1410. //扑克设置
  1411. this.m_GameClientView.m_CardView.ResetView();
  1412. //游戏变量
  1413. this.m_wCurrentUser = INVALID_CHAIR;
  1414. this.m_wActionMask = 0;
  1415. this.m_wTimeOutCount = 0;
  1416. for (var i = 0; i < GameDef.GAME_PLAYER; ++i) {
  1417. this.m_cbWeaveCount[i] = 0;
  1418. for (var j = 0; j < GameDef.MAX_WEAVE; ++j) {
  1419. this.m_WeaveItemArray[i][j] = GameDef.tagWeaveItem();
  1420. }
  1421. }
  1422. //扑克变量
  1423. this.m_cbLeftCardCount = 0;
  1424. for (var i = 0; i < 42; ++i)//GameDef.MAX_INDEX
  1425. {
  1426. this.m_cbCardIndex[i] = 0;
  1427. }
  1428. if (this.m_dwRulesArr[0] & GameDef.GAME_RULE_SP_7) {
  1429. this.m_GameClientView.SetLeftCardCount(112);
  1430. }
  1431. else {
  1432. this.m_GameClientView.SetLeftCardCount(108);
  1433. }
  1434. this.m_GameClientView.SetLeftCardCount(GameDef.MAX_REPERTORY);
  1435. //设置用户动作
  1436. this.m_GameClientView.SetUserAction(INVALID_CHAIR, 0);
  1437. },
  1438. //补牌
  1439. OnReplaceCard: function (cbCardData) {
  1440. //构造数据
  1441. this.m_GameClientView.m_CardView.SetControlInfo(false);
  1442. var ReplaceCard = GameDef.CMD_C_ReplaceCard4();
  1443. ReplaceCard.cbCardData[0] = cbCardData;
  1444. ReplaceCard.cbCardCount = 1;
  1445. console.log("补花", cbCardData, ReplaceCard)
  1446. //发送数据
  1447. // if (this.m_ReplayMode) return 0;
  1448. this.SendGameData(GameDef.SUB_C_REPLACE_CARD, ReplaceCard);
  1449. return 0;
  1450. },
  1451. //出牌消息
  1452. OnOutCard: function (HandState, CardIndex, cbCardData, bAdd) {
  1453. //出牌判断
  1454. if (this.m_wCurrentUser != this.GetMeChairID()) return 0;
  1455. // 检查 cbOutCardData 是否大于 55
  1456. // if (cbCardData > 55) return 0;
  1457. //设置变量
  1458. this.m_wCurrentUser = INVALID_CHAIR;
  1459. this.m_wActionMask = 0;
  1460. var cbOutCardData = cbCardData;
  1461. //设置界面
  1462. this.m_GameClientView.m_CardView.SetControlInfo(false);
  1463. //定义变量
  1464. var wMeChairId = this.GetMeChairID();
  1465. var wOutCardUser = this.GetMeChairID();
  1466. var wViewOutCardUser = this.SwitchViewChairID(wOutCardUser);
  1467. // this.PlayActionSound(wMeChairId,this.GetCardStr(cbOutCardData),true);
  1468. //环境设置
  1469. this.KillGameClock();
  1470. //设置变量
  1471. this.m_wCurrentUser = INVALID_CHAIR;
  1472. this.m_wActionMask = 0;
  1473. //设置界面
  1474. this.m_GameClientView.SetCurrentUser(INVALID_CHAIR);
  1475. this.m_GameClientView.SetUserAction(INVALID_CHAIR, 0);
  1476. //构造数据
  1477. var OutCard = GameDef.CMD_C_OutCard();
  1478. OutCard.cbCardData = cbOutCardData;
  1479. OutCard.bAddGang = bAdd == true ? true : false;
  1480. //发送数据
  1481. this.SendGameData(GameDef.SUB_C_OUT_CARD, OutCard);
  1482. return 0;
  1483. },
  1484. //扑克操作
  1485. OnCardOperate: function (wOperateCode, cbOperateCard, cbCardCount, cbIndex) {
  1486. //变量定义
  1487. if (this.m_bFirstCard == false && wOperateCode == 0 && this.m_wCurrentUser == this.GetMeChairID()) {
  1488. this.m_GameClientView.m_CardView.SetControlInfo(false);
  1489. var wViewID = this.SwitchViewChairID(this.GetMeChairID());
  1490. this.m_GameClientView.m_CardView.m_HandCard[wViewID].SetCanTouch(true);
  1491. if (this.m_bStustee == false) {
  1492. this.ListenAutoOutCard(this.m_wCurrentUser);
  1493. }
  1494. return;
  1495. }
  1496. //补扭走打牌逻辑
  1497. if (wOperateCode & (GameDef.WIK_ADD_ZFB | GameDef.WIK_ADD_DNJ | GameDef.WIK_ADD_FENG)) {
  1498. this.m_GameClientView.m_CardView.m_HandCard[2].SetOutCard(cbOperateCard[0]);
  1499. this.OnOutCard(0, 0, cbOperateCard[0], true);
  1500. return;
  1501. }
  1502. //删除时间
  1503. this.KillGameClock();
  1504. this.m_wCurrentUser = INVALID_CHAIR;
  1505. this.m_wActionMask = 0;
  1506. //构造数据
  1507. var OperateCard = GameDef.CMD_C_OperateCard();
  1508. OperateCard.wOperateCode = wOperateCode;
  1509. OperateCard.cbOperateCard[0] = cbOperateCard[0];
  1510. OperateCard.cbOperateCard[1] = cbOperateCard[1];
  1511. OperateCard.cbOperateCard[2] = cbOperateCard[2];
  1512. OperateCard.cbOperateCard[3] = cbOperateCard[3];
  1513. OperateCard.cbOperateCount = cbCardCount;
  1514. OperateCard.cbIndex = cbIndex;
  1515. console.log("发送胡牌操作",OperateCard)
  1516. //发送数据
  1517. this.SendGameData(GameDef.SUB_C_OPERATE_CARD, OperateCard);
  1518. this.m_GameClientView.m_CardView.m_HandCard[2].SetCanTouch(false);
  1519. this.m_GameClientView.m_CardView.SetControlInfo(false);
  1520. return 0;
  1521. },
  1522. //扑克操作
  1523. OnDoubleOperate: function (cbDouble) {
  1524. this.KillGameClock();
  1525. var Double = GameDef.CMD_C_Double();
  1526. Double.cbDouble = cbDouble;
  1527. //发送数据
  1528. this.SendGameData(GameDef.SUB_C_USER_DOUBLE, Double);
  1529. return 0;
  1530. },
  1531. OnCancelTrustee: function (bTrustee) {
  1532. var Trustee = GameDef.CMD_C_Trustee();
  1533. Trustee.bTrustee = bTrustee;
  1534. //发送数据
  1535. this.SendGameData(GameDef.SUB_C_TRUSTEE, Trustee);
  1536. },
  1537. // //扑克操作
  1538. // OnStusteeControl:function(wParam, lParam){
  1539. // //设置变量
  1540. // this.m_wTimeOutCount=0;
  1541. // if(this.m_bStustee&&lParam==true)return 0;
  1542. // if(!this.m_bStustee&&lParam==0)return 0;
  1543. // //设置状态
  1544. // this.m_bStustee = this.m_bStustee?false:true;
  1545. // //构造数据
  1546. // var Trustee = GameDef.CMD_C_Trustee();
  1547. // Trustee.bTrustee = this.m_bStustee;
  1548. // //发送数据
  1549. // this.SendGameData(GameDef.SUB_C_TRUSTEE, Trustee);
  1550. // return 0;
  1551. // },
  1552. // //离开控制
  1553. // OnLeaveControl: function(event, customData){
  1554. // if(customData != 0){
  1555. // this.m_LeaveControl.ShowView(true);
  1556. // this.m_bLeave = true;
  1557. // }else{
  1558. // this.m_LeaveControl.ShowView(false);
  1559. // this.m_bLeave = false;
  1560. // this.SetGameClock(this.GetMeChairID(),GameDef.IDI_OPERATE_CARD,GameDef.TIME_OPERATE_CARD);
  1561. // }
  1562. // //构造数据
  1563. // var Leave = GameDef.CMD_C_Leave();
  1564. // Leave.bLeave = this.m_bLeave;
  1565. // //发送数据
  1566. // this.SendGameData(GameDef.SUB_C_LEAVE, Leave);
  1567. // return 0;
  1568. // },
  1569. OnNextReady: function () {
  1570. this.KillGameClock();
  1571. //游戏变量
  1572. this.m_lCellScore = 0;
  1573. //设置当前玩家
  1574. this.m_wCurrentUser = INVALID_CHAIR;
  1575. //隐藏按钮
  1576. this.m_GameClientView.m_BtStart.active = false;
  1577. //设置游戏状态
  1578. this.m_GameClientView.SetPlayStatus(INVALID_CHAIR, 0);
  1579. this.m_GameClientView.m_CardView.SetControlInfo(false);
  1580. this.m_GameClientView.SetCurrentUser(INVALID_CHAIR);
  1581. //设置界面
  1582. this.m_GameClientView.m_CardView.SetDiscardTip(INVALID_CHAIR);
  1583. this.m_GameClientView.SetBankerUser(INVALID_CHAIR);
  1584. this.m_GameClientView.SetUserAction(INVALID_CHAIR, 0);
  1585. //扑克设置
  1586. this.m_GameClientView.m_CardView.ResetView();
  1587. //游戏变量
  1588. this.m_wCurrentUser = INVALID_CHAIR;
  1589. this.m_wActionMask = 0;
  1590. for (var i = 0; i < GameDef.GAME_PLAYER; ++i) {
  1591. this.m_cbWeaveCount[i] = 0;
  1592. for (var j = 0; j < GameDef.MAX_WEAVE; ++j) {
  1593. this.m_WeaveItemArray[i][j] = GameDef.tagWeaveItem();
  1594. }
  1595. }
  1596. //扑克变量
  1597. this.m_cbLeftCardCount = 0;
  1598. for (var i = 0; i < 42; ++i) {//GameDef.MAX_INDEX
  1599. this.m_cbCardIndex[i] = 0;
  1600. }
  1601. if (this.m_dwRulesArr[0] & GameDef.GAME_RULE_SP_7) {
  1602. this.m_GameClientView.SetLeftCardCount(112);
  1603. }
  1604. else {
  1605. this.m_GameClientView.SetLeftCardCount(108);
  1606. }
  1607. this.m_GameClientView.SetLeftCardCount(GameDef.MAX_REPERTORY);
  1608. //设置用户动作
  1609. this.m_GameClientView.SetUserAction(INVALID_CHAIR, 0);
  1610. this.SendGameData(GameDef.SUB_C_NEXT_READY, null);
  1611. },
  1612. //执行结束
  1613. OnTimeIDI_PERFORM_END: function () {
  1614. this.unschedule(this.OnTimeIDI_PERFORM_END);
  1615. this.m_bEnd = true;
  1616. //成绩界面
  1617. this.ShowGamePrefab("LittleResultBG", GameDef.KIND_ID, this.node, function (Js) {
  1618. this.m_EndLittleView = Js;
  1619. //this.m_EndLittleView.SetTrustee(this.m_bStustee);
  1620. }.bind(this));
  1621. //this.ShowPrefabDLG('LittleResultBG_21201');
  1622. },
  1623. checkTotalEnd: function (bNext) {
  1624. this.m_bEnd = false;
  1625. if (this.m_RoomEnd) {
  1626. if (this.m_wGameProgress > 0 || this.m_ReplayMode) {
  1627. this.showRealEndView();
  1628. } else {
  1629. this.ShowAlert("該房間已被解散!", Alert_Yes, function (Res) {
  1630. this.m_pTableScene.ExitGame();
  1631. }.bind(this));
  1632. }
  1633. } else {
  1634. var kernel = gClientKernel.get();
  1635. if (!kernel.IsLookonMode() && bNext) this.OnMessageStart();
  1636. }
  1637. this.m_bCanShowBigEnd = true;
  1638. },
  1639. //发送准备
  1640. SendUserReady: function (pBuffer, wDataSize) {
  1641. var kernel = gClientKernel.get();
  1642. if (kernel == 0 || kernel == null || kernel.IsLookonMode()) return;
  1643. kernel.SendSocketData(MDM_GF_FRAME, SUB_GF_USER_READY, pBuffer, wDataSize);
  1644. },
  1645. //出牌声音字符串
  1646. GetCardStr: function (cbCardData) {
  1647. var str = "";
  1648. var color = cbCardData & 0xf0;
  1649. var value = cbCardData & 0x0f;
  1650. if (color == 0)
  1651. str = "W_";
  1652. if (color == 0x10)
  1653. str = "S_";
  1654. if (color == 0x20)
  1655. str = "T_";
  1656. if (color == 0x30)
  1657. str = "F_";
  1658. str = str + value.toString();
  1659. return str;
  1660. },
  1661. //播放操作声音
  1662. PlayActionSound: function (wChairId, byAction, chuyin) {
  1663. if (this.m_bRollBack) return;
  1664. //椅子效验
  1665. var kernel = gClientKernel.get();
  1666. var pIClientUserItem = kernel.GetTableUserItem(wChairId);
  1667. if (pIClientUserItem == null) return;
  1668. console.log(pIClientUserItem)
  1669. console.log(wChairId, byAction, chuyin)
  1670. if (pIClientUserItem.GetGender() == 1) {
  1671. cc.gSoundRes.PlayGameSound("M_" + byAction + "L" + wChairId);
  1672. }
  1673. else {
  1674. cc.gSoundRes.PlayGameSound("W_" + byAction + "L" + wChairId);
  1675. // cc.gSoundRes.PlayGameSound("W_" + byAction);
  1676. }
  1677. if (chuyin) {
  1678. cc.gSoundRes.PlayGameSound("CHUPAI");
  1679. }
  1680. },
  1681. OnExitGame: function () {
  1682. //退出游戏
  1683. this.m_TableViewFrame.ExitGame();
  1684. },
  1685. ExitGame: function () {
  1686. this.OnExitGame();
  1687. },
  1688. //////////////////////////////////////////////////////////////////////////
  1689. //获取用户
  1690. GetClientUserItem: function (wChairID) {
  1691. var kernel = gClientKernel.get();
  1692. if (kernel == 0 || kernel == null || kernel == undefined) return null;
  1693. return kernel.GetTableUserItem(wChairID);
  1694. },
  1695. GetGameStatus: function () {
  1696. var kernel = gClientKernel.get();
  1697. if (!kernel) return GAME_SCENE_FREE;
  1698. return kernel.GetGameStatus();
  1699. },
  1700. IsValidChairID: function (wChairID) {
  1701. if (wChairID >= 0 && wChairID < GameDef.GAME_PLAYER) return true;
  1702. return false;
  1703. },
  1704. // 获取座位
  1705. GetUserChairID: function (dwUserID) {
  1706. for (var i = 0; i < GameDef.GAME_PLAYER; ++i) {
  1707. var pIClientUserItem = this.GetClientUserItem(i);
  1708. if (!pIClientUserItem) continue;
  1709. if (pIClientUserItem.GetUserID() == dwUserID) return i;
  1710. }
  1711. return INVALID_CHAIR;
  1712. },
  1713. SetViewRoomInfo: function (dwServerRules, dwRulesArr) {
  1714. if (this.m_GameClientView)
  1715. this.m_GameClientView.SetViewRoomInfo(dwRulesArr, dwServerRules);
  1716. GameDef.setRule(dwServerRules, dwRulesArr);
  1717. this.updateUserCount();
  1718. this.m_GameClientView.m_CardView.m_CenterViewCtrl.updateNorth();
  1719. //this.m_GameClientView.m_Trustee.string = GameDef.GetTrusteeString(this.m_dwRules);
  1720. },
  1721. OnEventRoomEnd: function (data, datasize) {
  1722. this.m_RoomEnd = GameDef.CMD_S_GameCustomInfo();
  1723. if (datasize != gCByte.Bytes2Str(this.m_RoomEnd, data)) return false;
  1724. console.log("总结束", this.m_RoomEnd)
  1725. this.m_RoomEnd.UserID = new Array();
  1726. //用户成绩
  1727. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  1728. //变量定义
  1729. var pIClientUserItem = this.GetClientUserItem(i);
  1730. if (pIClientUserItem == null) continue;
  1731. this.m_RoomEnd.UserID[i] = pIClientUserItem.GetUserID();
  1732. }
  1733. if (this.m_wGameProgress > 0 || this.m_ReplayMode) {
  1734. this.m_GameClientView.m_BtStart.active = false;
  1735. this.KillGameClock();
  1736. if (this.m_bCanShowBigEnd) {
  1737. this.showRealEndView();
  1738. }
  1739. } else {
  1740. var self = this;
  1741. this.ShowAlert("該房間已被解散!", Alert_Yes, function (Res) {
  1742. self.m_pTableScene.ExitGame();
  1743. });
  1744. }
  1745. return true;
  1746. },
  1747. showRealEndView() {
  1748. this.RealShowEndView();
  1749. GameDef.m_AllCardItem = [];
  1750. },
  1751. //点击安全监测
  1752. OnBtClickedSafe: function () {
  1753. cc.gSoundRes.PlaySound('Button');
  1754. this.ShowGamePrefab('SafeCheck_21201');
  1755. },
  1756. ChangeCardBack: function (index) {
  1757. this.m_CardBack = index;
  1758. if (this.m_GameClientView.m_CardView == null) {
  1759. this.m_GameClientView.Init();
  1760. }
  1761. this.m_GameClientView.m_CardView.ChangeCardBack(this.node, index);
  1762. this.m_GameClientView.ChangeCardBack(index);
  1763. },
  1764. //震动会牌
  1765. ShockHuiPai: function () {
  1766. if (this.m_bRollBack) return;
  1767. this.m_GameClientView.ShockHuiPai();
  1768. },
  1769. updateUserCount: function () {
  1770. this.m_GameClientView.m_CardView.UpdateUserCount();
  1771. this.m_GameClientView.updateUserCount();
  1772. },
  1773. //邀请好友分享
  1774. OnFriend: function () {
  1775. if (cc.sys.isNative) {
  1776. this.ShowPrefabDLG("SharePre");
  1777. } else {
  1778. // this.m_GameClientView.m_FriendBg.node.active = true;
  1779. }
  1780. },
  1781. OnClearScene: function () {
  1782. if (this.m_EndLittleView) this.m_EndLittleView.HideView();
  1783. var CardBack = cc.sys.localStorage.getItem(window.Key_CardColor);
  1784. if (CardBack) {
  1785. this.ChangeCardBack(CardBack);
  1786. } else {
  1787. this.ChangeCardBack(0);
  1788. }
  1789. this.CleanView();
  1790. },
  1791. GetOperateTime: function () {
  1792. if (this.m_dwRulesArr[0] & GameDef.GAME_RULE_TUOGUAN_15) {
  1793. return GameDef.TIME_OPERATE_CARD_15;
  1794. }
  1795. else if (this.m_dwRulesArr[0] & GameDef.GAME_RULE_TUOGUAN_30) {
  1796. return GameDef.TIME_OPERATE_CARD_30;
  1797. }
  1798. else if (this.m_dwRulesArr[0] & GameDef.GAME_RULE_TUOGUAN_60) {
  1799. return GameDef.TIME_OPERATE_CARD_60;
  1800. }
  1801. else if (this.m_dwRulesArr[0] & GameDef.GAME_RULE_TUOGUAN_NONE) {
  1802. return GameDef.TIME_OPERATE_CARD;
  1803. }
  1804. },
  1805. //测试
  1806. __test: function () {
  1807. this.m_GameClientView.m_CardView.setUserCount(4);
  1808. this.m_GameClientView.m_CardView.SetClientEngine(this);
  1809. this.m_CardData = new Array();
  1810. this.m_CardData =
  1811. [
  1812. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, //万子
  1813. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, //万子
  1814. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, //万子
  1815. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, //万子
  1816. 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, //索子
  1817. 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, //索子
  1818. 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, //索子
  1819. 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, //索子
  1820. 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, //同子
  1821. 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, //同子
  1822. 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, //同子
  1823. 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, //同子
  1824. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, //番子
  1825. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, //番子
  1826. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, //番子
  1827. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, //番子
  1828. ];
  1829. this.m_GameClientView.m_CardView.SetCardData(0, this.m_CardData, 10);
  1830. this.m_GameClientView.m_CardView.SetCardData(1, this.m_CardData, 10);
  1831. this.m_GameClientView.m_CardView.SetCardData(2, this.m_CardData, 10);
  1832. this.m_GameClientView.m_CardView.SetPositively(true);
  1833. var weaveCard = new Array();
  1834. weaveCard[0] = 0x21;
  1835. weaveCard[1] = 0x21;
  1836. weaveCard[2] = 0x21;
  1837. weaveCard[3] = 0x21;
  1838. this.m_GameClientView.m_CardView.SetWeaveData(0, 0, weaveCard, 4);
  1839. // this.m_GameClientView.m_CardView.SetWeaveData(1,0,weaveCard,4);
  1840. this.m_GameClientView.m_CardView.SetWeaveData(2, 0, weaveCard, 4);
  1841. // this.m_GameClientView.m_CardView.SetWeaveData(3,0,weaveCard,4);
  1842. // this.m_GameClientView.m_CardView.SetCardData(3,cardData,13,0x02);
  1843. this.DiscardDate = 0x22;
  1844. this.m_GameClientView.m_CardView.SetDiscardCardDate(0, this.m_CardData, 33);
  1845. this.m_GameClientView.m_CardView.SetDiscardCardDate(1, this.m_CardData, 33);
  1846. this.m_GameClientView.m_CardView.SetDiscardCardDate(2, this.m_CardData, 33);
  1847. this.m_GameClientView.m_CardView.SetDiscardCardDate(3, this.m_CardData, 33);
  1848. // this.m_GameClientView.m_CardView.PlayDiscard(0,13);
  1849. },
  1850. });