GameClientEngine_21201.js 91 KB

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