TrucoGameSence.js 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098
  1. import GameManagerBase from 'GameManagerBase';
  2. import { CServerItem } from 'CServerItem';
  3. import ScenceManager from 'HNScenceManager';
  4. /**
  5. * Author:alin,modify:alin
  6. * 大吃小gamescene
  7. */
  8. var GameBase = require("GameBase");
  9. var ProtocolGameServer = require("ProtocolGameServer");
  10. var GameProtocol = require("TrucoGameProtocol");
  11. var AnalyzeXieYi = require("AnalyzeTrucoXieYi");
  12. var MakeXieYi = require("MakeTrucoXieYi");
  13. var Global = require("Global");
  14. var topTipMsg = require("topTipMsg");
  15. var UIHelper = require("UIHelper");
  16. var Define = require("Define")
  17. var popScence = require("popScence");
  18. var LanguageKey = require("LanguageKey");
  19. var SoundFun = require("TrucoSoundFun");
  20. var HomeSoundFun = require("homeSoundFunc");
  21. var CGPIndividualMission = require("CGPIndividualMission");
  22. var BaseDefine = require("BaseDefine");
  23. //游戏状态
  24. var GameState = cc.Enum( //0,1,2,3,空闲,赢,输,放弃
  25. {
  26. FREE: 0, //空闲
  27. PLAYING: 1, //游戏中
  28. ROUNDSTART: 2, //小局开始
  29. OUTCARD: 3, //出牌过程
  30. COMPARECARD: 4, //比牌
  31. ENDING: 5, //结算中
  32. END: 6, //结束
  33. }
  34. )
  35. cc.Class({
  36. extends: GameBase,
  37. editor: {
  38. menu: 'Game/Truco/GameSence'
  39. },
  40. properties: {
  41. playerNode: cc.Node,//玩家节点
  42. cardNode: cc.Node,//手牌节点
  43. handCardGroupNode: cc.Node,//牌组节点
  44. shuffleAniNode: cc.Node,
  45. leftNode:cc.Node,
  46. gameRuleNode:cc.Node,
  47. AniNode:cc.Node,
  48. startNode: cc.Node,
  49. cardAtlas: cc.SpriteAtlas,
  50. _players: [],
  51. _seatPlayer: [],//主界面显示的6个玩家
  52. _handCards: [],//13张手牌节点数组
  53. _selectCard:null,
  54. _readyOutCard:null,//准备要打出的牌
  55. _selectCards:[],//弹起的牌
  56. _cardPreFabs:null, //牌预制
  57. _CurrentUser:-1,//当前玩家
  58. _MagicCardData:0,//百变牌
  59. _myTeam: -1,
  60. _isPlaying:false,//
  61. _isPlayingAni:false,
  62. _isTouchSend:false,//通过移动牌打出的
  63. _canGetCard:false,//可以抓牌
  64. _canOutCard:false,//可以出牌
  65. _willExit_LackOfGold:false,
  66. _willExit_LongTimeNoOperation:false,
  67. _delayEvalCallback: null,
  68. _delayEvalTimes: -1,
  69. },
  70. onLoad: function () {
  71. this.registerTouchEventHandle();
  72. this._cardPreFabs = this.cardNode.getChildByName("card");
  73. this._cardPreFabs.setPosition(cc.v2(0,0));
  74. this._cardPreFabs.setScale(1);
  75. this._gameInfoJS = this.node.getChildByName("RoomInfo").getComponent("TrucoGameInfo");
  76. this._willExit_LackOfGold = false;
  77. this._willExit_LongTimeNoOperation = false;
  78. this.gameStartTimer = 0;
  79. this._gameEnd = false;
  80. this._gameState = GameState.FREE;
  81. this.AniNode.getChildByName("trucoNode").active = false;
  82. this._handCards = [];
  83. for(let i = 0; i < GameProtocol.HAND_CARD_COUNT; ++i) {
  84. this._handCards[i] = this.handCardGroupNode.getChildByName("card"+i);
  85. }
  86. this._msgCallback = [];
  87. this.msgDelayTime = {
  88. 105: 1, //truco选择
  89. 106: 2.8, //小局开始
  90. 107: 2, //比牌
  91. 112: 0.8, //出牌
  92. 117: 1, //出牌
  93. }
  94. },
  95. start() {
  96. SoundFun.playBackMusic(SoundFun.GAME_BACKGRUAND);
  97. this.goToRealRoom = 0;
  98. this.dayCount = 1;
  99. this.limitCount = 1;
  100. this.playerCount = 0;
  101. },
  102. //注册触摸事件
  103. registerTouchEventHandle: function () {
  104. this.cardCanMoveAni = true;
  105. this.touchStatus = false;
  106. this.moved = false;
  107. let funcJS = this.node.getComponent("TrucoFuncBtnMgr");
  108. // return;
  109. this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
  110. // funcJS.hideSelfBQ();
  111. this.hideAllMene();
  112. if(!this._isPlaying){return;}
  113. if(this.touchStatus){return;}
  114. if(this._isPlayingAni){return;}
  115. if(this.playingGetCardAni) {return;}
  116. this.moved = false;
  117. var player = this.getSelfLocalPlayer();
  118. if (player == null) {
  119. return;
  120. }
  121. // Global.print("TOUCH_START::4");
  122. this._selectCard = this.GetTouchCard(event.getLocation());
  123. if (this._selectCard == null) {
  124. return;
  125. }
  126. this.touchStatus = true;
  127. }, this),
  128. this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
  129. //Global.print("TOUCH_MOVE::");
  130. if(!this._isPlaying){return;}
  131. if(!this.touchStatus){return;}
  132. if(this._isPlayingAni){return;}
  133. if(this.playingGetCardAni) {return;}
  134. var delta = event.getDelta();
  135. if(Math.abs(delta.x)<= 2 && Math.abs(delta.y) <= 2){
  136. return;
  137. }
  138. var pos = event.getLocation();
  139. if(this._selectCard){
  140. this.moved = true;
  141. this.setMovePosition(this._selectCard,pos);
  142. };
  143. }, this),
  144. this.node.on(cc.Node.EventType.TOUCH_END, function (event) {
  145. //Global.print("TOUCH_END::");
  146. if(!this._isPlaying){return;}
  147. if(!this.touchStatus){return;}
  148. if(this._isPlayingAni){return;}
  149. if(this.playingGetCardAni) {return;}
  150. // var pos = event.getLocation();
  151. if(this._selectCard && this.moved){
  152. if(this.isOutErea(this._selectCard) && this._canOutCard){//出牌
  153. this.outCard();
  154. }else{//其他区域自动复位
  155. this.resetHandCards();
  156. }
  157. }
  158. this.touchStatus = false;
  159. }, this),
  160. this.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
  161. //Global.print("TOUCH_CANCEL::");
  162. if(!this._isPlaying){return;}
  163. if(!this.touchStatus){return;}
  164. if(this._isPlayingAni){return;}
  165. if(this.playingGetCardAni) {return;}
  166. this.moved = false;
  167. if(this._selectCard){
  168. this.resetHandCards();
  169. }
  170. this._selectCard = null;
  171. this.touchStatus = false;
  172. }, this)
  173. },
  174. GetTouchCard:function(kTouchPos){
  175. var kWorldPos = this.handCardGroupNode.convertToNodeSpaceAR(kTouchPos);
  176. for (var idx = this.handCardGroupNode.childrenCount-1; idx >= 0; idx--) {
  177. var cardNode = this._handCards[idx];
  178. if(!cardNode.active) {
  179. continue;
  180. }
  181. var cardSize = cardNode.getBoundingBox().size;
  182. var cardPos = cardNode.getPosition();
  183. var rect = cc.rect(cardPos.x-cardSize.width/2,cardPos.y-cardSize.height/2,cardSize.width,cardSize.height);
  184. if (rect.contains(kWorldPos)){
  185. return cardNode;
  186. }
  187. }
  188. return null;
  189. },
  190. setMovePosition:function(cardNode,kTouchPos){
  191. if(!cardNode){
  192. return;
  193. }
  194. var kWorldPos = this.handCardGroupNode.convertToNodeSpaceAR(kTouchPos);
  195. // Global.print("cardNode"+kWorldPos.x)
  196. cardNode.setPosition(kWorldPos);
  197. },
  198. resetHandCards() {
  199. var selfPlayer = this.getSelfLocalPlayer();
  200. if(!selfPlayer) {
  201. return;
  202. }
  203. selfPlayer.resetHandCardPos();
  204. },
  205. isOutErea:function(cardNode){
  206. return cardNode.y > -200;
  207. },
  208. outCard:function() {
  209. var selfPlayer = this.getSelfLocalPlayer();
  210. if(!selfPlayer) {
  211. return;
  212. }
  213. if(this._selectCard) {
  214. let cardid = this._selectCard.getComponent("TrucoCard").cardId();
  215. Global.print("outCard::"+this._selectCard.getComponent("TrucoCard").cardId())
  216. Global.print(this._selectCard)
  217. if(cardid <= 0) {
  218. Global.print("0牌")
  219. Global.print(this._selectCard.cardValue)
  220. cardid = this._selectCard.cardValue//selfPlayer.getHandCardValue(parseInt(this._selectCard.name))
  221. }
  222. Global.print(cardid)
  223. this.SendGameSocketData(GameProtocol.SUB_C_OUT_CARD,{
  224. cbOutCardData: cardid//this._selectCard.getComponent("TrucoCard").cardId(),
  225. })
  226. }else{
  227. topTipMsg.showTopTipMsg("Truco.no_select_card");
  228. }
  229. },
  230. /*************************网络协议相关*****************************/
  231. //场景消息
  232. onEventSceneMessage: function (gameStatus, lookonUser, data) {
  233. Global.print("RUMMYGameSence onEventSceneMessage 场景消息 ");
  234. var arr = new DataView(data.slice(0, 8));
  235. var dataView = new DataView(data.slice(8));
  236. var msgHead = { m: arr.getUint16(4, true), s: arr.getUint16(6, true), d: null };
  237. arr = null;
  238. switch (gameStatus) {
  239. case GameProtocol.GAME_STATUS_FREE: {
  240. var msg = AnalyzeXieYi.analyze_StatusFree(dataView);
  241. Global.print("onFreeScence......")
  242. this.onFreeScence(msg);
  243. }
  244. break;
  245. case GameProtocol.GAME_STATUS_PLAY: {
  246. var msg = AnalyzeXieYi.analyze_StatusPlay(dataView);
  247. this.onPlayScence(msg);
  248. }
  249. break;
  250. default: {
  251. Global.print("RUMMYGameSence onEventSceneMessage error ");
  252. }
  253. break;
  254. };
  255. },
  256. //游戏消息
  257. onEventGameMessage: function (data) {
  258. //Global.print("RUMMYGameSence onEventGameMessage 游戏消息 ");
  259. var arr = new DataView(data.slice(0, 8));
  260. var dataView = new DataView(data.slice(8));
  261. var msgHead = { m: arr.getUint16(4, true), s: arr.getUint16(6, true), d: null };
  262. arr = null;
  263. var msg = AnalyzeXieYi.analyzeData(msgHead.m, msgHead.s, dataView);
  264. switch (msgHead.s) {
  265. case GameProtocol.SUB_S_GAME_FREE: {
  266. Global.print("游戏空闲");
  267. }
  268. break;
  269. case GameProtocol.SUB_S_GAME_START: {
  270. Global.print("游戏开始");
  271. this.OnGameStart(msg);
  272. }
  273. break;
  274. case GameProtocol.SUB_S_GAME_END: {
  275. Global.print("游戏结束");
  276. this.preSetEndPlayerInfo(msg);
  277. this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnGameEnd(msg);}});
  278. return;
  279. if(this._isOutCarding || this._compareCarding) {
  280. this._gameResultData = msg;
  281. return;
  282. }
  283. this.OnGameEnd(msg);
  284. }
  285. break;
  286. case GameProtocol.SUB_S_GAME_CONTINUE: {
  287. Global.print("游戏继续");
  288. this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnGameContinue(msg);}});
  289. return;
  290. let nowTime = new Date().getTime();
  291. if(this._trucoChooseTimes && nowTime - this._trucoChooseTimes < 2000) {
  292. setTimeout(()=>{
  293. this.OnGameContinue(msg);
  294. }, this._trucoChooseTimes+2000-nowTime)
  295. return;
  296. }
  297. this.OnGameContinue(msg);
  298. }
  299. break;
  300. case GameProtocol.SUB_S_TRUCO: {
  301. Global.print("游戏TRUCO");
  302. this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnTruco(msg);}});
  303. return;
  304. this.OnTruco(msg);
  305. }
  306. break;
  307. case GameProtocol.SUB_S_TRUCO_CHOOSE: {
  308. Global.print("游戏TRUCO选择");
  309. this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnTrucoChoose(msg);}});
  310. return;
  311. this.OnTrucoChoose(msg);
  312. }
  313. break;
  314. case GameProtocol.SUB_S_TRUCO_SET:{
  315. Global.print("TRUCO设置");
  316. this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnTrucoSet(msg);}});
  317. return;
  318. if(this._needDelaySet) {
  319. this._trucoSetData = msg;
  320. }else{
  321. this.OnTrucoSet(msg);
  322. }
  323. }
  324. break;
  325. case GameProtocol.SUB_S_COMPARE_CARD: {
  326. Global.print("游戏比牌结果");
  327. this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnCompareCard(msg);}});
  328. return;
  329. if(this._isOutCarding) {
  330. this._compareData = msg;
  331. return;
  332. }
  333. this.OnCompareCard(msg);
  334. }
  335. break;
  336. case GameProtocol.SUB_S_ROUND_START: {
  337. Global.print("小局开始");
  338. this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnRoundStart(msg);}});
  339. return;
  340. if(this._isOutCarding || this._compareCarding) {
  341. this._roundStartData = msg;
  342. return;
  343. }
  344. let nowTime = new Date().getTime();
  345. if(this._trucoChooseTimes && nowTime - this._trucoChooseTimes < 2000) {
  346. setTimeout(()=>{
  347. this.OnRoundStart(msg);
  348. }, this._trucoChooseTimes+2000-nowTime)
  349. return;
  350. }
  351. this.OnRoundStart(msg);
  352. }
  353. break;
  354. case GameProtocol.SUB_S_OPERATE_FAIL: {
  355. Global.print("操作失败");
  356. this.OnGameOperareOutCard(msg);
  357. }
  358. break;
  359. case GameProtocol.SUB_S_OUT_CARD: {
  360. Global.print("玩家出牌");
  361. this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnGameOutCard(msg);}});
  362. return;
  363. this.OnGameOutCard(msg);
  364. }
  365. break;
  366. case GameProtocol.SUB_S_WAIT_START:{
  367. Global.print("等待开始");
  368. this.OnWaitStart(msg);
  369. }
  370. break;
  371. case GameProtocol.SUB_S_GAME_INFO:{
  372. Global.print("控制信息");
  373. this.OnGameInfo(msg);
  374. }
  375. break;
  376. case GameProtocol.SUB_S_TRUSTEE_STATUS:{
  377. this.OnPlayerTrustee(msg);
  378. break;
  379. }
  380. case GameProtocol.SUB_S_FORCE_LEAVE_CHOOSE:{
  381. this.node.getComponent("TrucoFuncBtnMgr").showForceExit();
  382. break;
  383. }
  384. case GameProtocol.SUB_S_CELL_SCORE:{
  385. Global.print("底分倍数");
  386. this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnCellScore(msg);}});
  387. return;
  388. this.OnCellScore(msg);
  389. break;
  390. }
  391. case GameProtocol.SUB_S_FINAL_ROUND:{
  392. Global.print("OnFinalRound");
  393. this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnFinalRound(msg);}});
  394. break;
  395. }
  396. case GameProtocol.SUB_S_FINAL_CHOOSE:{
  397. Global.print("OnFinalChoose");
  398. this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnFinalChoose(msg);}});
  399. break;
  400. }
  401. default: {
  402. Global.print("RUMMYGameSence onEventGameMessage error ");
  403. }
  404. break;
  405. }
  406. },
  407. getSceneState: function () {
  408. return this._isPlaying;
  409. },
  410. OnGameInfo(msg) {
  411. if(!BaseDefine.LOCALTEST)
  412. return;
  413. Global.print(JSON.stringify(msg));
  414. let layer_player = this.node.getChildByName("layer_control");
  415. layer_player.active = true;
  416. let labelNode = layer_player.getChildByName("label_item");
  417. let playerNode = layer_player.getChildByName("parent");
  418. let ControlInfo = msg.tagControlInfo;
  419. let type = ControlInfo.cbControlType;
  420. let info1 = "控制类型__" + ["无控制", "1后台单控赢", "2后台单控输", "3库存控制赢", "4库存控制输", "5自动控制赢", "6自动控制输"][type];
  421. let info2 = "控制结果__" + ["无控制", "1控制赢", "2控制输"][ControlInfo.cbControlReslut];
  422. let str = info1 + "\r\n" + info2 + "\r\n";
  423. let info3 = "控制玩家__" + ControlInfo.wControlUser; //控制玩家
  424. let info4 = ControlInfo.wControlWinUser; //控制赢玩家
  425. let info5 = ControlInfo.wControlLoseUser; //控制输玩家
  426. let info6 = ControlInfo.nControlRadian; //控制概率[]
  427. let info7 = "随机值__" + ControlInfo.nRnd; //随机值
  428. let info8 = ControlInfo.nControlValue; //单控值 0~20[]
  429. // labelNode.getChildByName("label2").getComponent(cc.Label).string = info2;
  430. // labelNode.getChildByName("label3").getComponent(cc.Label).string = info3;
  431. // labelNode.getChildByName("label4").getComponent(cc.Label).string = info4;
  432. // labelNode.getChildByName("label5").getComponent(cc.Label).string = info5;
  433. // labelNode.getChildByName("label6").getComponent(cc.Label).string = info7;
  434. // labelNode.getChildByName("label7").getComponent(cc.Label).string = info1;
  435. let index = ControlInfo.lRet;
  436. //库存控制的返回 索引2代表当前库存, 索引3代表当前杀率 索引4代表系统赢概率 索引5代表系统输概率 索引6代表随机值
  437. let info9 = "控制结果" + ["0不控制", "1控制系统赢", "2控制系统输"][index[0]];
  438. let info10 = "是否需要控制" + ["0不需要", "1需要"][index[1]];
  439. let info11 = "库存剩余__" + index[2];
  440. let info12 = "杀率__" + index[3];
  441. let info13 = "系统赢概率__" + index[4];
  442. let info14 = "系统输概率__" + index[5];
  443. let info15 = "随机值__" + index[6];
  444. if (type == 0) {
  445. str += info7;
  446. } if (type == 1 || type == 2) {
  447. str += info3 + "\r\n" + info7;
  448. } else if (type == 3 || type == 4) {
  449. str += info3 + "\r\n" + info9 + "\r\n" + info10 + "\r\n" + info11 + "\r\n" + info12 + "\r\n" + info13 + "\r\n" + info14 + "\r\n" + info15;
  450. } else if (type == 5 || type == 6) {
  451. str += info3 + "\r\n" + info7;
  452. }
  453. labelNode.getChildByName("label1").getComponent(cc.Label).string = str;
  454. for(let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
  455. let index = this.getPlayerIndex(i);
  456. let label = playerNode.getChildByName("label"+index);
  457. if(label) {
  458. let player = this.getLocalPlayerByIndex(i);
  459. if(player && player.getUserItem()) {
  460. let ssstr = "";
  461. if (info4 == i) {
  462. ssstr += "控赢\r\n";
  463. }
  464. if(info5 == i) {
  465. ssstr += "控输\r\n";
  466. }
  467. ssstr += "控制概率__"+info6[i]+"\r\n";
  468. ssstr += "单控值__"+info8[i];
  469. label.getComponent(cc.Label).string = ssstr;
  470. }
  471. }
  472. }
  473. },
  474. //断线续连
  475. onFreeScence: function (data) {
  476. Global.print("onFreeScence "+JSON.stringify(data))
  477. // this.node.getChildByName("RoomInfo").getChildByName("bg1").getChildByName("bet").getComponent(cc.Label).string = Global.formatString2Score(data.lCellScore);
  478. var selfPlayer = this.getSelfPlayer();
  479. if (!selfPlayer) {
  480. return;
  481. }
  482. this.initPlayers(GameProtocol.GAME_PLAYER);
  483. this.resetView();
  484. this._bFirstIn = true;
  485. this._isPlaying = false;
  486. this._baseScore = data.lCellScore;
  487. this._gameInfoJS.setBaseCellScore(data.lCellScore);
  488. this.startNode.getChildByName("startTime").active = true;
  489. this.resetFreeStatus();
  490. },
  491. //游戏场景重连
  492. onPlayScence: function (data) {
  493. Global.print("RUMMY 游戏重连 " + JSON.stringify(data));
  494. // this._gameInfoJS
  495. var selflayer = this.getSelfPlayer();
  496. if (!selflayer) {
  497. return;
  498. }
  499. this.initPlayers(GameProtocol.GAME_PLAYER);
  500. this.resetView();
  501. this._bFirstIn = false;
  502. this._gameState = GameState.OUTCARD;
  503. this._isPlaying = true;
  504. this._CurrentUser = data.wCurrentUser;
  505. this._MagicCardData = data.cbMagicCardValue;
  506. this._outCard = data.cbOpenCardData;
  507. this._trucoSide = data.cbTruco;
  508. this._trucoScore = data.cbTrucoScore;
  509. this._nowScore = data.cbNowScore;
  510. this._myTeam = data.cbTeam;
  511. this._baseScore = data.lCellScore;
  512. this._gameInfoJS.setTeam(this._myTeam);
  513. this._gameInfoJS.setBaseCellScore(data.lCellScore);
  514. this._gameInfoJS.setMagicCardValue(data.cbMagicCardValue);
  515. this._gameInfoJS.upNowScore(data.cbNowScore);
  516. this._gameInfoJS.initRoundState(data.cbRoundResult, data.cbPlayCount);
  517. this._gameInfoJS.upRoundScore(data.cTotalScore);
  518. this._gameInfoJS.upBetScore(data.nCellMulti);
  519. this.leftNode.active = true;
  520. let magicCard = this.leftNode.getChildByName("cardl");
  521. magicCard.getComponent("TrucoCard").setId(data.cbMagicShowCardData, 0);
  522. magicCard.scale = 0.42;
  523. magicCard.angle = 18;
  524. magicCard.position = cc.v2(-74, 0);
  525. let selfPlayer = this.getSelfLocalPlayer();
  526. let handCard = data.cbCardData;
  527. selfPlayer.changeMingCard(data.cbFinalRound != 2);
  528. // selfPlayer.changeMingCard(true);
  529. for (let i = 0; i < GameProtocol.GAME_PLAYER; i++) {
  530. var index = this.getPlayerIndex(i);
  531. var player = this.getLocalPlayerByIndex(index);
  532. if (player) {
  533. player.setMagicCardValue(this._MagicCardData);
  534. player.setHandCards(handCard, data.cbCardCount[i], true);
  535. player.showOutCard(data.cbCardOut[i], this._MagicCardData);
  536. player.changeTrusteeState(data.cbUserTrustee[i]);
  537. }
  538. }
  539. this.node.getChildByName("TrusteeNode").active = data.cbUserTrustee[selfPlayer.getChairID()] == 1;
  540. this.upForceExitBtnState(data.cbForceLeaveChoose[selfPlayer.getChairID()] == 0);
  541. this.showPePlayer(data.wFirstUser);
  542. //正在truco
  543. if(data.cbTruco > 0) {
  544. //当前拍了的队伍
  545. // let bSameTeam = (selfPlayer.getChairID()-data.wCurrentUser+4)%2 == 0;
  546. let trucoPlayer = this.getLocalPlayerByChairId(data.wTrucoChair);
  547. if(trucoPlayer) {
  548. let trucoAni = this.AniNode.getChildByName("trucoNode");
  549. trucoAni.active = true;
  550. let ani = trucoAni.getChildByName("trucoAni").getComponent(sp.Skeleton);
  551. ani.clearTracks();
  552. ani.setAnimation(0, "a1", false);
  553. trucoPlayer.playTruco(this._trucoScore);
  554. }
  555. for(let i = 0; i < 2; ++i) {
  556. let chairID = (data.wTrucoChair+1+i*2)%GameProtocol.GAME_PLAYER;
  557. let sPlayer = this.getLocalPlayerByChairId(chairID);
  558. if(sPlayer) {
  559. if(data.cbTrucoStatus[chairID] > 0) {
  560. sPlayer.showTrucoChoose(data.cbTrucoStatus[chairID]);
  561. }else{
  562. if(sPlayer == selfPlayer) {
  563. this.showTrucoBtns();
  564. }
  565. sPlayer.playTimeAction(data.cbTimeCount);
  566. }
  567. }
  568. }
  569. }else{
  570. this.SetCurrentUser(this._CurrentUser,data.cbTimeCount);
  571. }
  572. if(data.cbFinalRound > 0) {
  573. if(data.cbFinalRound == 2) {
  574. // selfPlayer.changeMingCard(false);
  575. for (let i = 0; i < GameProtocol.GAME_PLAYER; i++) {
  576. var index = this.getPlayerIndex(i);
  577. var player = this.getLocalPlayerByIndex(index);
  578. if (player && data.cbFinalStatus[i] > 0) {
  579. player.showTrucoChoose(data.cbFinalStatus[i]);
  580. }
  581. }
  582. }else{
  583. let ppID = (selfPlayer.getChairID()+this._myTeam-data.cbFinalTeam+GameProtocol.GAME_PLAYER)%GameProtocol.GAME_PLAYER;
  584. for (let i = 0; i < GameProtocol.SIDE_NUM; i++) {
  585. let pid = (ppID + i * 2)%GameProtocol.GAME_PLAYER;
  586. var index = this.getPlayerIndex(pid);
  587. var player = this.getLocalPlayerByIndex(index);
  588. if (player && data.cbFinalStatus[pid] > 0) {
  589. player.showTrucoChoose(data.cbFinalStatus[pid]);
  590. }
  591. }
  592. }
  593. }
  594. },
  595. upForceExitBtnState(bShow) {
  596. this.node.getChildByName("FuncBtnNode").getChildByName("btn_Exit").active = bShow;
  597. },
  598. //游戏结束 隐藏牌面
  599. hideCardsNode() {
  600. var EventNode = this.node.getChildByName("Cards").getChildByName("EventNode");
  601. EventNode.active = false;
  602. for (let i = 0; i < this._players.length; i++) {
  603. var player = this._players[i];
  604. if (player) {
  605. player.cardsNode.active = false;
  606. }
  607. }
  608. },
  609. hideBtns() {
  610. var funcBtnNode = this.node.getChildByName("FuncBtnNode");
  611. funcBtnNode.getChildByName("btn_Truco").active = false;
  612. funcBtnNode.getChildByName("btn_Ace").active = false;
  613. funcBtnNode.getChildByName("btn_Cor").active = false;
  614. // funcBtnNode.getChildByName("btn_Listener").active = false;
  615. // funcBtnNode.getChildByName("btn_Finish").active = false;
  616. // funcBtnNode.getChildByName("btn_Descartar").active = false;
  617. },
  618. //每局游戏结束后重置UI
  619. resetView: function () {
  620. this.node.getChildByName("GameEnd").active = false;
  621. this.leftNode.active = false;
  622. this.AniNode.getChildByName("trucoNode").active = false;
  623. this.startNode.getChildByName("startTime").active = false;
  624. //按钮
  625. this.hideBtns();
  626. //对局
  627. this._gameInfoJS.reset();
  628. this._msgCallback.splice(0);
  629. this.upForceExitBtnState(false);
  630. this._isPlaying = false;
  631. this._gameEnd = false;
  632. this._roundStarting = false;
  633. this._needDelaySet = false;
  634. this._gameState = GameState.FREE;
  635. for (let i = 0; i < this._players.length; i++) {
  636. var player = this._players[i];
  637. if(!player) {
  638. // player.node.active = false;
  639. continue;
  640. }
  641. player.node.active = player.getUserItem();
  642. player.hideHandCard();
  643. player.setNameLabelActive(true);
  644. player.changeTrusteeState(false);
  645. player.setVIPActive(true);
  646. player.upPlayerHead();
  647. player.hideTimeNode();
  648. }
  649. },
  650. resetRound() {
  651. for (let i = 0; i < this._players.length; i++) {
  652. var player = this._players[i];
  653. if(!player) {
  654. continue;
  655. }
  656. player.node.active = player.getUserItem();
  657. player.hideHandCard();
  658. player.hideTimeNode();
  659. player.hideTruco();
  660. player.hideTrucoChoose();
  661. player.showPe(false);
  662. }
  663. this._gameInfoJS.roundStart();
  664. this.leftNode.active = false;
  665. this.leftNode.getChildByName("cardNode").active = false;
  666. this.node.getChildByName("CoinNode").active = false;
  667. this._nowScore = 1;
  668. this._trucoScore = 0;
  669. this._trucoSide = -1;
  670. },
  671. hideAllMene() {
  672. for (let i = 0; i < this._players.length; i++) {
  673. var player = this._players[i];
  674. if(!player) {
  675. continue;
  676. }
  677. player.hideInfoNode();
  678. }
  679. },
  680. hideAllTimes() {
  681. for (let i = 0; i < this._players.length; i++) {
  682. var player = this._players[i];
  683. if(!player) {
  684. continue;
  685. }
  686. player.hideTimeNode();
  687. }
  688. },
  689. hideAllTrucos() {
  690. for (let i = 0; i < this._players.length; i++) {
  691. var player = this._players[i];
  692. if(!player) {
  693. continue;
  694. }
  695. player.hideTruco();
  696. }
  697. },
  698. hideAllTrucoChoose() {
  699. for (let i = 0; i < this._players.length; i++) {
  700. var player = this._players[i];
  701. if(!player) {
  702. continue;
  703. }
  704. player.hideTrucoChoose();
  705. }
  706. },
  707. resetFreeStatus:function(){//匹配状态中
  708. for (let i = 0; i < this._players.length; i++) {
  709. const player = this._players[i];
  710. if(!player || player.getChairID() == this.getSelfPlayer().getChairID()){
  711. continue;
  712. }
  713. player.setNameLabelActive(false);
  714. player.setVIPActive(false);
  715. }
  716. },
  717. resetGameStatus:function(){//游戏状态中
  718. this.node.getChildByName("TipNode").getChildByName("tip_wait").active = false;
  719. this.node.getChildByName("TipNode").getChildByName("tip_wait1").active = false;
  720. this.node.getChildByName("TipNode").getChildByName("tip_start").active = false;
  721. for (let i = 0; i < this._players.length; i++) {
  722. const player = this._players[i];
  723. if(!player || !player.getUserItem()){
  724. continue;
  725. }
  726. player.node.active = true;
  727. player.setNameLabelActive(true);
  728. player.setVIPActive(true);
  729. player.upPlayerHead();
  730. }
  731. },
  732. updateLeftCards() {
  733. let resIdx = parseInt(this._leftCardCount / 5);
  734. let notLast = this._leftCardCount > 0;
  735. for(let i = 0; i < 20; ++i) {
  736. this.leftCardsArr[i].active = (i <= resIdx) && notLast;
  737. }
  738. },
  739. reduceOneCard() {
  740. this._leftCardCount--;
  741. if(this._leftCardCount % 5 == 4 || this._leftCardCount == 0) {
  742. this.updateLeftCards();
  743. }
  744. },
  745. autoReady:function() {
  746. },
  747. cardNum(cardid) {
  748. return (cardid & 0x0F);
  749. },
  750. //cbCardState 1拿牌 2丢牌
  751. SetCurrentUser:function(_CurrentUser, cbUserTime){
  752. var selfPlayer = this.getSelfPlayer();
  753. if (!selfPlayer) {
  754. return;
  755. }
  756. // return;
  757. this._CurrentUser = _CurrentUser;
  758. var index = this.getPlayerIndex(_CurrentUser);
  759. for (let i = 0; i < this._players.length; i++) {
  760. const player = this._players[i];
  761. if(!player){
  762. continue;
  763. }
  764. if (player.getIndex() == index) {
  765. //全部减掉3秒
  766. player.playTimeAction(cbUserTime);
  767. }else{
  768. player.hideTimeNode();
  769. }
  770. }
  771. this._canGetCard = false;
  772. this._canOutCard = false;
  773. if(this._CurrentUser == selfPlayer.getChairID()){
  774. this._canOutCard = true;
  775. this.showTrucoBtns(false);
  776. if(this._trucoSetData) {
  777. this.OnTrucoSet(this._trucoSetData);
  778. }
  779. cc.vv.reflection.shake(100);
  780. }else{
  781. Global.print("不是我")
  782. }
  783. },
  784. upTrusteeMask(width) {
  785. this.node.getChildByName("TrusteeNode").getChildByName("mask").width = width;
  786. },
  787. OnPlayerTrustee(data) {
  788. Global.print("托管"+JSON.stringify(data))
  789. var index = this.getPlayerIndex(data.wChairID);
  790. var tPlayer = this.getLocalPlayerByIndex(index);
  791. if(tPlayer) {
  792. tPlayer.changeTrusteeState(data.cbStatus);
  793. if(tPlayer == this.getSelfLocalPlayer()) {
  794. this.node.getChildByName("TrusteeNode").active = data.cbStatus == 1;
  795. // if(data.cbStatus == 0) {
  796. // topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.cancel_hosting"));
  797. // }
  798. }
  799. }
  800. },
  801. showPePlayer(firstUserID) {
  802. let chairid = (firstUserID + 3) % GameProtocol.GAME_PLAYER;
  803. let player = this.getLocalPlayerByChairId(chairid);
  804. if(player) {
  805. player.showPe(true);
  806. }
  807. },
  808. OnWaitStart(data) {
  809. let aniNode = this.startNode.getChildByName("startTime").getChildByName("aniNode");
  810. aniNode.getChildByName("ani").active = false;
  811. aniNode.getChildByName("ani2").active = true;
  812. },
  813. OnGameStart: function (data) {
  814. this.resetView();
  815. Global.print("Truco 游戏开始 " + JSON.stringify(data));
  816. SoundFun.playEffectEX(SoundFun.GAME_START);
  817. this._gameState = GameState.PLAYING;
  818. var selfPlayer = this.getSelfLocalPlayer();
  819. if (!selfPlayer) {
  820. return;
  821. }
  822. this._isPlaying = true;
  823. this._myTeam = data.cbTeam;
  824. this._gameInfoJS.setTeam(this._myTeam);
  825. this._gameInfoJS.upBetScore(1);
  826. this.upForceExitBtnState(true);
  827. },
  828. preSetEndPlayerInfo(data) {
  829. Global.print("Truco 游戏结束 预设玩家信息 " + JSON.stringify(data));
  830. var selfPlayer = this.getSelfLocalPlayer();
  831. if (!selfPlayer) {
  832. return;
  833. }
  834. let bWin = data.cbWinSide == this._myTeam;
  835. let playerNode = this.node.getChildByName("GameEnd").getChildByName("RootNode").getChildByName("playerNode");
  836. playerNode.getChildByName("loseBG").active = !bWin;
  837. playerNode.getChildByName("winBG").active = bWin;
  838. let startChairID = selfPlayer.getChairID();
  839. for(let i = 0; i < 2; ++i) {
  840. let playerN = playerNode.getChildByName("player"+i);
  841. let iChairID = (startChairID+i*2)%GameProtocol.GAME_PLAYER;
  842. let player = this.getLocalPlayerByChairId(iChairID);
  843. if(playerN && player) {
  844. playerN.getChildByName("headNode").getChildByName("head").getComponent(cc.Sprite).spriteFrame = player.getHeadSpriteFrame();
  845. playerN.getChildByName("Name").getComponent(cc.Label).string = player.getnickName();
  846. let winS = playerN.getChildByName("winScore");
  847. let loseS = playerN.getChildByName("loseScore");
  848. winS.active = bWin;
  849. loseS.active = !bWin;
  850. winS.getComponent(cc.Label).string = '+'+Global.formatString2Score(data.lUserScore[iChairID]);
  851. loseS.getComponent(cc.Label).string = Global.formatString2Score(data.lUserScore[iChairID]);
  852. }
  853. }
  854. },
  855. OnGameEnd(data) {
  856. Global.print("Truco 游戏结束 " + JSON.stringify(data));
  857. this.gameEndData = data;
  858. this._gameState = GameState.ENDING;
  859. this._isPlaying = false;
  860. this._bFirstIn = false;
  861. this.node.getChildByName("TrusteeNode").active = false;
  862. this._gameEnd = true;
  863. var selfPlayer = this.getSelfLocalPlayer();
  864. if (!selfPlayer) {
  865. return false;
  866. }
  867. this.hideBtns();
  868. this._gameInfoJS.upRoundScore(data.cTotalScore);
  869. let bWin = data.cbWinSide == this._myTeam;
  870. let GameEnd = this.node.getChildByName("GameEnd");
  871. GameEnd.active = true;
  872. let rootNode = GameEnd.getChildByName("RootNode");
  873. let ani = rootNode.getChildByName("ani").getComponent(sp.Skeleton);
  874. ani.clearTracks();
  875. if(bWin) {
  876. ani.setAnimation(0, "a1", false);
  877. ani.addAnimation(0, "a2", true);
  878. SoundFun.playEffectEX(SoundFun.GAME_WIN);
  879. }else{
  880. ani.setAnimation(0, "a3", false);
  881. ani.addAnimation(0, "a4", true);
  882. SoundFun.playEffectEX(SoundFun.GAME_LOSE);
  883. }
  884. rootNode.getChildByName("playerNode").getComponent(cc.Animation).play("showEndLayer");
  885. cc.tween(GameEnd)
  886. .delay(5)
  887. .call(()=>{
  888. GameEnd.active = false;
  889. this.resetView();
  890. this.startNode.getChildByName("startTime").active = true;
  891. })
  892. .start()
  893. },
  894. OnGameContinue(data) {
  895. Global.print("Truco OnGameContinue " + JSON.stringify(data));
  896. var selfPlayer = this.getSelfLocalPlayer();
  897. if (!selfPlayer) {
  898. return false;
  899. }
  900. this.hideBtns();
  901. this._gameInfoJS.upNowScore(this._trucoScore?this._trucoScore:1);
  902. for (let i = 0; i < this._players.length; i++) {
  903. var player = this._players[i];
  904. if(!player) {
  905. continue;
  906. }
  907. player.hideTimeNode();
  908. player.hideTruco();
  909. player.hideTrucoChoose();
  910. }
  911. this.SetCurrentUser(data.wCurrentUser, data.cbTimeCount);
  912. },
  913. OnTruco(data) {
  914. Global.print("Truco OnTruco " + JSON.stringify(data));
  915. var selfPlayer = this.getSelfLocalPlayer();
  916. if (!selfPlayer) {
  917. return false;
  918. }
  919. var trucoPlayer = this.getLocalPlayerByChairId(data.wTrucoUser);
  920. if(!trucoPlayer) {
  921. return;
  922. }
  923. this._trucoScore = data.cbTrucoScore;
  924. this._trucoSide = data.cbTrucoSide;
  925. SoundFun.playEffectEX("truco"+this._trucoScore);
  926. this.hideAllTimes();
  927. this.hideAllTrucos();
  928. this.hideAllTrucoChoose();
  929. this.hideBtns();
  930. this.AniNode.active = true;
  931. let trucoAni = this.AniNode.getChildByName("trucoNode");
  932. trucoAni.active = true;
  933. let ani = trucoAni.getChildByName("trucoAni").getComponent(sp.Skeleton);
  934. ani.clearTracks();
  935. ani.setAnimation(0, "a1", false);
  936. trucoPlayer.playTruco(this._trucoScore);
  937. trucoPlayer.hideTimeNode();
  938. if(this._myTeam != this._trucoSide) {
  939. this.showTrucoBtns();
  940. }
  941. let side1 = this.getLocalPlayerByChairId((data.wTrucoUser+1)%GameProtocol.GAME_PLAYER);
  942. if(side1) {
  943. side1.playTimeAction(data.cbTimeCount);
  944. }
  945. let side2 = this.getLocalPlayerByChairId((data.wTrucoUser+3)%GameProtocol.GAME_PLAYER);
  946. if(side2) {
  947. side2.playTimeAction(data.cbTimeCount);
  948. }
  949. },
  950. showTrucoBtns(nFirst = true) {
  951. var funcBtnNode = this.node.getChildByName("FuncBtnNode")
  952. funcBtnNode.getChildByName("btn_Ace").active = nFirst;
  953. funcBtnNode.getChildByName("btn_Cor").active = nFirst;
  954. // funcBtnNode.getChildByName("btn_Truco").active = true;
  955. // funcBtnNode.getChildByName("btn_Truco").getChildByName("Label").getComponent(cc.Label).string = '+'+(this._trucoScore+3);
  956. },
  957. OnTrucoChoose(data) {
  958. Global.print("Truco OnTrucoChoose " + JSON.stringify(data));
  959. var selfPlayer = this.getSelfLocalPlayer();
  960. if (!selfPlayer) {
  961. return false;
  962. }
  963. var trucoPlayer = this.getLocalPlayerByChairId(data.wTrucoUser);
  964. if(!trucoPlayer) {
  965. return;
  966. }
  967. if(selfPlayer == trucoPlayer || (data.cbTrucoChoose == 1 && (selfPlayer.getChairID()+2)%GameProtocol.GAME_PLAYER == data.wTrucoUser)) {
  968. this.hideBtns();
  969. }
  970. if(data.cbTrucoChoose == 1) {
  971. SoundFun.playEffectEX(SoundFun.TRUCO_TY);
  972. }else{
  973. SoundFun.playEffectEX(SoundFun.TRUCO_FQ);
  974. }
  975. trucoPlayer.hideTimeNode();
  976. trucoPlayer.showTrucoChoose(data.cbTrucoChoose);
  977. this._trucoChooseTimes = new Date().getTime();
  978. this._needDelaySet = data.cbTrucoChoose == 2;
  979. if(this._msgCallback.length > 1 && this._msgCallback[0].id == GameProtocol.SUB_S_TRUCO_CHOOSE) {
  980. this._delayEvalTimes = 0;
  981. }
  982. },
  983. OnTrucoSet(data) {
  984. Global.print("Truco OnTrucoSet " + JSON.stringify(data));
  985. var selfPlayer = this.getSelfLocalPlayer();
  986. if (!selfPlayer) {
  987. return false;
  988. }
  989. var funcBtnNode = this.node.getChildByName("FuncBtnNode")
  990. funcBtnNode.getChildByName("btn_Truco").active = true;
  991. funcBtnNode.getChildByName("btn_Truco").getChildByName("Label").getComponent(cc.Label).string = '+'+(data.cbTrucoScore);
  992. this._trucoSetData = null;
  993. this._needDelaySet = false;
  994. },
  995. OnCompareCard(data) {
  996. Global.print("Truco OnCompareCard " + JSON.stringify(data));
  997. this._compareCarding = true;
  998. this._needDelaySet = true;
  999. this._gameState = GameState.COMPARECARD;
  1000. let winPlayer = this.getLocalPlayerByChairId(data.wWinChairID);
  1001. if(!winPlayer) {
  1002. return;
  1003. }
  1004. winPlayer.playLightCardAni();
  1005. let winCard = this.cardNum(winPlayer.getOutCard());
  1006. if(winCard == this._MagicCardData) {
  1007. SoundFun.playEffectEX(SoundFun.WINKING);
  1008. }
  1009. var setUser = ()=>{
  1010. // this.SetCurrentUser(data.wWinChairID, data.cbTimeCount);
  1011. this._compareCarding = false;
  1012. if(data.cbRoundEnd) {
  1013. // this._gameInfoJS.upRoundScore(data.cbRoundScore);
  1014. if(this._gameResultData) {
  1015. this.OnGameEnd(JSON.parse(JSON.stringify(this._gameResultData)));
  1016. this._gameResultData = null;
  1017. }else if(this._roundStartData) {
  1018. this.OnRoundStart(JSON.parse(JSON.stringify(this._roundStartData)));
  1019. this._roundStartData = null;
  1020. }
  1021. }else{
  1022. this.SetCurrentUser(data.wWinChairID, data.cbTimeCount);
  1023. }
  1024. }
  1025. var upWinState = ()=>{
  1026. this._gameInfoJS.initRoundState(data.cbRoundResult, data.cbPlayCount);
  1027. SoundFun.playEffectEX(SoundFun.MOVECARD);
  1028. for(let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
  1029. let index = this.getPlayerIndex(i);
  1030. let player = this.getLocalPlayerByIndex(index);
  1031. if(player) {
  1032. player.outCardMoveToTrush();
  1033. }
  1034. }
  1035. setTimeout(()=>{
  1036. setUser();
  1037. }, 500)
  1038. }
  1039. if(data.cbWinSide == 0) {
  1040. for(let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
  1041. let index = this.getPlayerIndex(i);
  1042. let player = this.getLocalPlayerByIndex(index);
  1043. if(player && player.getChairID() != data.wWinChairID) {
  1044. if(this.cardNum(player.getOutCard()) == winCard) {
  1045. player.playLightCardAni()
  1046. }
  1047. }
  1048. }
  1049. }else{
  1050. let player = this.getLocalPlayerByChairId((data.wWinChairID+2)%GameProtocol.GAME_PLAYER);
  1051. if(player && this.cardNum(player.getOutCard()) == winCard && winCard != this._MagicCardData) {
  1052. player.playLightCardAni()
  1053. }
  1054. }
  1055. cc.tween(this.node)
  1056. .delay(1.5)
  1057. .call(()=>{
  1058. upWinState();
  1059. })
  1060. .start()
  1061. },
  1062. OnRoundStart(data) {
  1063. Global.print("Truco 小局开始 " + JSON.stringify(data));
  1064. var selfPlayer = this.getSelfLocalPlayer();
  1065. if (!selfPlayer) {
  1066. return;
  1067. }
  1068. this.resetRound();
  1069. this._isPlaying = true;
  1070. this._bLastRound = false;
  1071. this._roundStarting = true;
  1072. this._needDelaySet = true;
  1073. this._gameState = GameState.ROUNDSTART;
  1074. this._gameInfoJS.setMagicCardValue(0);
  1075. this._gameInfoJS.upNowScore(0);
  1076. this._gameInfoJS.upRoundScore(data.cTotalScore);
  1077. this.leftNode.active = true;
  1078. let magicCard = this.leftNode.getChildByName("cardl");
  1079. magicCard.getComponent("TrucoCard").setId(0, 0);
  1080. magicCard.scale = 0.42;
  1081. magicCard.angle = 0;
  1082. magicCard.position = cc.v2(0, 0);
  1083. magicCard.active = false;
  1084. this._MagicCardData = data.cbMagicCardValue;
  1085. let handCard = data.cbCardData;
  1086. selfPlayer.changeMingCard(true);
  1087. selfPlayer.setHandCards(handCard, handCard.length);
  1088. let bEnd = data.cTotalScore[0] == data.cTotalScore[1] && data.cTotalScore[0] == 11;
  1089. this.showPePlayer(data.wCurrentUser);
  1090. this.shuffleAniNode.active = true;
  1091. let ani = this.shuffleAniNode.getComponent(sp.Skeleton);
  1092. ani.clearTracks();
  1093. ani.setAnimation(0, "a1", false);
  1094. var next = ()=>{
  1095. if(data.cbFinalRound == 1) {
  1096. let ppID = (selfPlayer.getChairID()+this._myTeam-data.cbFinalTeam+GameProtocol.GAME_PLAYER)%GameProtocol.GAME_PLAYER;
  1097. for (let i = 0; i < GameProtocol.SIDE_NUM; i++) {
  1098. let pid = (ppID + i * 2)%GameProtocol.GAME_PLAYER;
  1099. var index = this.getPlayerIndex(pid);
  1100. var player = this.getLocalPlayerByIndex(index);
  1101. if (player) {
  1102. player.playTimeAction(data.cbTimeCount);
  1103. }
  1104. }
  1105. }else{
  1106. this.SetCurrentUser(data.wCurrentUser, data.cbTimeCount);
  1107. }
  1108. }
  1109. var openMagicCard = ()=>{
  1110. magicCard.active = true;
  1111. magicCard.getComponent("TrucoCard").setId(data.cbMagicShowCardData, 0);
  1112. cc.tween(magicCard)
  1113. .to(0.3, {angle: 18, x: -74})
  1114. .call(()=>{
  1115. // next();
  1116. this.SetCurrentUser(data.wCurrentUser, data.cbTimeCount);
  1117. this._gameInfoJS.setMagicCardValue(data.cbMagicCardValue);
  1118. this._gameInfoJS.upNowScore(1);
  1119. this._roundStarting = false;
  1120. this._gameState = GameState.OUTCARD;
  1121. this._needDelaySet = false;
  1122. })
  1123. .start()
  1124. }
  1125. var openCard = ()=>{
  1126. for(let i = 0; i < selfPlayer.cardsNode.childrenCount; ++i) {
  1127. let card = selfPlayer.cardsNode.children[i];
  1128. if(card){
  1129. let scale = card.scale;
  1130. cc.tween(card)
  1131. .delay(0.1*i)
  1132. .to(0.1, {scaleX: 0})
  1133. .call(()=>{
  1134. // let cardId = handCard[i];
  1135. card.getComponent("TrucoCard").setId(handCard[i], this._MagicCardData);
  1136. })
  1137. .to(0.1, {scaleX: scale})
  1138. .start()
  1139. }
  1140. }
  1141. cc.tween(this.node)
  1142. .delay(0.5)
  1143. .call(()=>{
  1144. openMagicCard();
  1145. })
  1146. .start()
  1147. }
  1148. let cardIdx = 0;
  1149. var sendCard = ()=>{
  1150. if(cardIdx >= 3) {
  1151. this.unschedule(sendCard);
  1152. setTimeout(()=>{
  1153. if(bEnd) {
  1154. selfPlayer.changeMingCard(false);
  1155. selfPlayer.resetHandCardPos();
  1156. openMagicCard();
  1157. }else
  1158. openCard();
  1159. }, 300)
  1160. }
  1161. SoundFun.playEffectEX(SoundFun.SENDCARD);
  1162. for(let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
  1163. let index = this.getPlayerIndex(i);
  1164. let player = this.getLocalPlayerByIndex(index);
  1165. if(player) {
  1166. player.oneCardMove(cardIdx);
  1167. player.setMagicCardValue(this._MagicCardData);
  1168. }
  1169. }
  1170. cardIdx++;
  1171. }
  1172. cc.tween(this.node)
  1173. .delay(1.4)
  1174. .call(()=>{
  1175. // sendCard();
  1176. this.leftNode.getChildByName("cardNode").active = true;
  1177. this.schedule(sendCard, 1/60);
  1178. })
  1179. .start()
  1180. },
  1181. OnGameOperareOutCard(data) {
  1182. Global.print("RUMMY 操作失败 " + JSON.stringify(data));
  1183. this._gameEnd = false;
  1184. this._isPlayingAni = false;
  1185. var cbFailCode = data.cbFailCode;
  1186. this.resetHandCards();
  1187. return;
  1188. if(cbFailCode == 100){//长时间没操作踢出房间
  1189. Global.print("长时间没操作踢出房间");
  1190. this._willExit_LongTimeNoOperation = true;
  1191. return;
  1192. }
  1193. /*
  1194. 出牌失败:
  1195. 0 状态不是游戏状态!
  1196. 1 还没轮到您操作!
  1197. 2 出牌之前请先抓牌!
  1198. 3 出牌数据异常!
  1199. 4 手牌没有出的这张牌!!
  1200. 5 组合数超出最大范围
  1201. 6 有错误组合,牌数量错误
  1202. 7 有错误组合,牌数据异常
  1203. 8 有错误组合,手牌没有这张牌
  1204. 9 牌总数错误
  1205. ==============================
  1206. 操作错误:
  1207. 20 状态不是游戏状态!
  1208. ==============================
  1209. 获取牌组错误:
  1210. 30 状态不是游戏状态!
  1211. ==============================
  1212. 放弃错误:
  1213. 40 状态不是游戏状态!
  1214. 41 还没轮到您操作!
  1215. 42 您本回合已经抓过牌,不能申请放弃!
  1216. */
  1217. //出牌失败:
  1218. if(cbFailCode == 0){
  1219. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_dqbsyxzt);
  1220. }else if(cbFailCode == 1){
  1221. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_hmldncz);
  1222. }else if(cbFailCode == 2){
  1223. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_cpzqqxzp);
  1224. }else if(cbFailCode == 3){
  1225. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_cpsjyc);
  1226. }else if(cbFailCode == 4){
  1227. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_spzmycdzzp);
  1228. }else if(cbFailCode == 5){
  1229. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_zhscczdfw);
  1230. }else if(cbFailCode == 6){
  1231. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_ycwzhpcw);
  1232. }else if(cbFailCode == 7){
  1233. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_ycwzhpyc);
  1234. }else if(cbFailCode == 8){
  1235. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_ycwzhmyzzp);
  1236. }else if(cbFailCode == 9){
  1237. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_pzscw);
  1238. }
  1239. //获取记录失败:
  1240. else if(cbFailCode == 20){
  1241. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_dqbsyxzt);
  1242. }
  1243. //获取牌组失败:
  1244. else if(cbFailCode == 30){
  1245. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_dqbsyxzt);
  1246. }
  1247. //放弃失败:
  1248. else if(cbFailCode == 40){
  1249. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_dqbsyxzt);
  1250. }else if(cbFailCode == 41){
  1251. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_hmldncz);
  1252. }else if(cbFailCode == 42){
  1253. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_yjzgpbnfq);
  1254. }
  1255. //抓牌失败:
  1256. else if(cbFailCode == 40){
  1257. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_dqbsyxzt);
  1258. }else if(cbFailCode == 41){
  1259. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_hmldncz);
  1260. }else if(cbFailCode == 42){
  1261. topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_yjzgp);
  1262. }
  1263. this._readyOutCard = null;
  1264. },
  1265. OnGameOutCard(data) {
  1266. Global.print("TRUCO 玩家出牌 " + JSON.stringify(data));
  1267. this._gameEnd = false;
  1268. this._isOutCarding = true;
  1269. this._canOutCard = false;
  1270. this._needDelaySet = false;
  1271. this._gameState = GameState.OUTCARD;
  1272. var selfPlayer = this.getSelfLocalPlayer();
  1273. if (!selfPlayer) {
  1274. return false;
  1275. }
  1276. if(data.wCurrentUser < 0) { //本轮出牌完毕
  1277. this._needDelaySet = true;
  1278. this._gameState = GameState.COMPARECARD;
  1279. }
  1280. this.hideBtns();
  1281. this._outCard = data.cbOutCardData;
  1282. let nowTime = new Date().getTime();
  1283. var setUser = ()=>{
  1284. this._isOutCarding = false;
  1285. //-1 表示小轮结束,需要比牌
  1286. if(data.wCurrentUser >= 0)
  1287. this.SetCurrentUser(data.wCurrentUser, data.cbTimeCount);
  1288. else if(this._compareData){
  1289. this.OnCompareCard(this._compareData);
  1290. }
  1291. }
  1292. if(this.cardNum(this._outCard) == this._MagicCardData) {
  1293. SoundFun.playEffectEX(SoundFun.OUTKING);
  1294. }else{
  1295. SoundFun.playEffectEX(SoundFun.CARD);
  1296. }
  1297. var index = this.getPlayerIndex(data.wOutCardUser);
  1298. var player = this.getLocalPlayerByIndex(index);
  1299. if(player){
  1300. player.hideTimeNode();
  1301. player.outOneCard(this._outCard, this._MagicCardData);
  1302. }
  1303. setTimeout(()=>{
  1304. setUser();
  1305. }, 800)
  1306. },
  1307. OnCellScore(data) {
  1308. Global.print("TRUCO OnCellScore " + JSON.stringify(data));
  1309. var selfPlayer = this.getSelfLocalPlayer();
  1310. if (!selfPlayer) {
  1311. return false;
  1312. }
  1313. SoundFun.playEffectEX(SoundFun.ADDBET);
  1314. let startPos = [cc.v2(-367,-340), cc.v2(-561,0), cc.v2(-77,300), cc.v2(575,0)];
  1315. let endPos = cc.v2(-642,324);
  1316. endPos.x -= cc.winSize.width/2-812;
  1317. let coinNode = this.node.getChildByName("CoinNode");
  1318. coinNode.active = true;
  1319. for(let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
  1320. let coin = coinNode.getChildByName("coin"+i);
  1321. if(coin) {
  1322. coin.position = startPos[i];
  1323. coin.active = true;
  1324. cc.tween(coin)
  1325. .to(0.3, {position: endPos})
  1326. .call(()=>{
  1327. coin.active = false;
  1328. })
  1329. .start()
  1330. }
  1331. }
  1332. cc.tween(coinNode)
  1333. .delay(0.3)
  1334. .call(()=>{
  1335. this._gameInfoJS.upBetScore(data.nMulti);
  1336. })
  1337. .start()
  1338. },
  1339. OnFinalRound(data) {
  1340. Global.print("TRUCO OnFinalRound " + JSON.stringify(data));
  1341. var selfPlayer = this.getSelfLocalPlayer();
  1342. if (!selfPlayer) {
  1343. return false;
  1344. }
  1345. this._bLastRound = true;
  1346. let dPlayer = this.getLocalPlayerByIndex(2);
  1347. if(!dPlayer) {return;}
  1348. if(data.cbFinalRound == 2) {
  1349. selfPlayer.changeMingCard(false);
  1350. dPlayer.changeMingCard(false);
  1351. dPlayer.setHandCards(data.cbTeamCardData, data.cbTeamCardData.length, true);
  1352. // dPlayer.playTimeAction(data.cbTimeCount);
  1353. }
  1354. if(data.cbFinalRound == 1) {
  1355. this.hideAllTimes();
  1356. if(data.cbFinalTeam == this._myTeam) {
  1357. this.showTrucoBtns(true);
  1358. selfPlayer.playTimeAction(data.cbTimeCount);
  1359. dPlayer.changeMingCard(true);
  1360. dPlayer.setHandCards(data.cbTeamCardData, data.cbTeamCardData.length, true);
  1361. dPlayer.playTimeAction(data.cbTimeCount);
  1362. }else{ //展示对方两家的时间倒计时
  1363. let ppID = (selfPlayer.getChairID()+this._myTeam-data.cbFinalTeam+GameProtocol.GAME_PLAYER)%GameProtocol.GAME_PLAYER;
  1364. for (let i = 0; i < GameProtocol.SIDE_NUM; i++) {
  1365. let pid = (ppID + i * 2)%GameProtocol.GAME_PLAYER;
  1366. var index = this.getPlayerIndex(pid);
  1367. var player = this.getLocalPlayerByIndex(index);
  1368. if (player) {
  1369. player.playTimeAction(data.cbTimeCount);
  1370. }
  1371. }
  1372. }
  1373. }
  1374. // let dPlayer = this.getLocalPlayerByIndex(2);
  1375. // if(dPlayer) {
  1376. // dPlayer.changeMingCard(true);
  1377. // dPlayer.setHandCards(data.cbTeamCardData, data.cbTeamCardData.length, true);
  1378. // }
  1379. },
  1380. OnFinalChoose(data) {
  1381. Global.print("TRUCO OnFinalChoose " + JSON.stringify(data));
  1382. var selfPlayer = this.getSelfLocalPlayer();
  1383. if (!selfPlayer) {
  1384. return false;
  1385. }
  1386. let dPlayer = this.getLocalPlayerByChairId(data.wFinalUser);
  1387. if(dPlayer) {
  1388. dPlayer.showTrucoChoose(data.cbFinalChoose);
  1389. dPlayer.hideTimeNode();
  1390. }
  1391. if(selfPlayer == dPlayer) {
  1392. this.showTrucoBtns(false);
  1393. }
  1394. if(data.cbFinalChoose == 1) {
  1395. SoundFun.playEffectEX(SoundFun.TRUCO_TY);
  1396. // this._gameInfoJS.upNowScore(3);
  1397. this._trucoScore = 3;
  1398. }else{
  1399. SoundFun.playEffectEX(SoundFun.TRUCO_FQ);
  1400. }
  1401. },
  1402. onClickTruco() {
  1403. var selfPlayer = this.getSelfLocalPlayer();
  1404. if (!selfPlayer) {
  1405. return false;
  1406. }
  1407. var data = {};
  1408. this.SendGameSocketData(GameProtocol.SUB_C_TRUCO,data);
  1409. },
  1410. onClickTrucoChoose:function(type){
  1411. var selfPlayer = this.getSelfLocalPlayer();
  1412. if (!selfPlayer) {
  1413. return false;
  1414. }
  1415. var data = {cbChoose: type};
  1416. if(this._bLastRound) {
  1417. this.SendGameSocketData(GameProtocol.SUB_C_FINAL_CHOOSE,data);
  1418. return;
  1419. }
  1420. this.SendGameSocketData(GameProtocol.SUB_C_TRUCO_CHOOSE,data);
  1421. },
  1422. isTurnSelf:function(){
  1423. var selfPlayer = this.getSelfPlayer();
  1424. if (!selfPlayer) {
  1425. return false;
  1426. }
  1427. if (this._CurrentUser == selfPlayer.getChairID()) {
  1428. return true;
  1429. }
  1430. return false;
  1431. },
  1432. reqUserInfo:function(userID){
  1433. if (!this.m_kReqPlayerInfo) {
  1434. this.m_kReqPlayerInfo = new CGPIndividualMission({ URL: cc.vv.config.Address, Port: cc.vv.config.Port });
  1435. this.m_kReqPlayerInfo.setMissionSink(this);
  1436. }
  1437. this.m_kReqPlayerInfo.queryIndividual(userID);
  1438. },
  1439. updateUserInfo: function (kNetInfo) {
  1440. Global.print("Rummy onGPAccountInfoHttpIP! kNetInfo.UserID = " + JSON.stringify(kNetInfo));
  1441. },
  1442. //初始化玩家信息
  1443. initPlayers: function (playerCnt) {
  1444. // console.log('playerCnt', playerCnt);
  1445. if (this._players.length > 0) {
  1446. return;
  1447. }
  1448. this._localPlayer = this.playerNode.getChildByName("Player0");
  1449. var selfPlayer = this.getSelfPlayer();
  1450. if (!selfPlayer) {
  1451. return;
  1452. }
  1453. for (let i = 0; i < GameProtocol.GAME_PLAYER; i++) {
  1454. var playerjs = this.playerNode.getChildByName("Player" + i).getComponent("TrucoPlayer");
  1455. if (playerjs && playerjs.node) {
  1456. playerjs.node.active = true;
  1457. }
  1458. }
  1459. for (let i = 0; i < playerCnt/*GameProtocol.GAME_PLAYER*/; i++) {
  1460. var index = this.getPlayerIndex(i);
  1461. var playerjs = this.playerNode.getChildByName("Player" + index).getComponent("TrucoPlayer");
  1462. if (!playerjs) {
  1463. continue;
  1464. }
  1465. var gamePlayer = this.getPlayerByChairID(i);
  1466. if (gamePlayer) {
  1467. playerjs.setUserItem(gamePlayer.getUserItem());
  1468. playerjs.playerEnter();
  1469. playerjs.upPlayerInfo();
  1470. playerjs.upPlayerState();
  1471. }
  1472. this._players.push(playerjs);
  1473. }
  1474. },
  1475. //得到玩家的index标识 (0:下,1:左,2:上,3:右)
  1476. getPlayerIndex: function (seatId) {
  1477. var selfPlayer = this.getSelfPlayer();
  1478. if (!selfPlayer) {
  1479. return;
  1480. }
  1481. if (seatId == selfPlayer.getChairID()) {
  1482. return 0;
  1483. }
  1484. // switch(seatId){
  1485. // case 1:
  1486. // return 3;
  1487. // break;
  1488. // case 2:
  1489. // return 2;
  1490. // break;
  1491. // case 3:
  1492. // return 1;
  1493. // break;
  1494. // }
  1495. var index = (GameProtocol.GAME_PLAYER + seatId - selfPlayer.getChairID()) % GameProtocol.GAME_PLAYER;
  1496. return index;
  1497. },
  1498. onUserEnter(clientUserItem) {
  1499. var selfPlayer = this.getSelfLocalPlayer();
  1500. if (!selfPlayer) {
  1501. return;
  1502. }else{
  1503. if(this._offlineNode){
  1504. this._offlineNode.getComponent("OfflineNodeJS").showWait();
  1505. this._isOffLine = false;
  1506. }
  1507. }
  1508. var index = this.getPlayerIndex(clientUserItem.GetChairID());
  1509. var player = this.getLocalPlayerByIndex(index);
  1510. if (player) {
  1511. player.setUserItem(clientUserItem);
  1512. player.playerEnter();
  1513. player.upPlayerInfo();
  1514. player.upPlayerHead();
  1515. player.upPlayerState();
  1516. }
  1517. },
  1518. onUserLeave(clientUserItem) {
  1519. if (Global.IsEmpty(clientUserItem)) {
  1520. return;
  1521. }
  1522. if (!this.getSelfPlayer()) {
  1523. if(this._gameEnd) {
  1524. return;
  1525. }
  1526. Global.print("onUserLeave 自己已经离开当前房间");
  1527. Global.print("onUserLeave :" + this._isPlaying);
  1528. this.stopCountdown();
  1529. this.unschedule(this.updataMobileTime);
  1530. if(CServerItem.get().IsService()){// 区别断网
  1531. Global.print("onUserLeave exitGame");
  1532. ScenceManager.Instance().gameBackScence();
  1533. GameManagerBase.Instance().setInGameServerID(-1);
  1534. this.exitGame();
  1535. }else
  1536. {
  1537. if(this._isPlaying){
  1538. var self = this;
  1539. cc.resources.load("GamePrefabs/homescence/OfflineNode", cc.Prefab, function (err, prefab) {
  1540. if (!self._offlineNode) {
  1541. self._offlineNode = cc.instantiate(prefab);
  1542. self._offlineNode.parent = self.node;
  1543. }
  1544. self._offlineNode.getComponent("OfflineNodeJS").showWait();
  1545. });
  1546. /*var Ok = function(){};
  1547. popScence.initPopScence(LanguageKey.Rummy.TopTip_ConnectionFailure, this, Ok);*/
  1548. var playerViewJS = this.node.getChildByName("Players").getChildByName("Player0").getComponent("TrucoPlayer");
  1549. playerViewJS.setOffline(true);
  1550. if(!this._isOffLine) {
  1551. // cc.userOperate.sendRecord("Rummy2R-Number of disconnections");
  1552. this._isOffLine = true;
  1553. }
  1554. }
  1555. }
  1556. return;
  1557. }
  1558. var player = this.getLocalPlayerByChairId(clientUserItem.GetChairID());
  1559. if (player) {
  1560. player.playerLeave();
  1561. player.setUserItem(null);
  1562. }
  1563. },
  1564. upPlayerInfo(clientUserItem) {
  1565. var player = this.getLocalPlayerByChairId(clientUserItem.GetChairID());
  1566. if (player) {
  1567. player.setUserItem(clientUserItem);
  1568. player.upPlayerInfo();
  1569. }
  1570. },
  1571. upSelfPlayerInfo: function () {
  1572. var selfPlayer = this.getSelfLocalPlayer();
  1573. if (!selfPlayer) {
  1574. return;
  1575. }
  1576. var clientUserItem = selfPlayer.getUserItem(false);
  1577. if (!clientUserItem) {
  1578. return;
  1579. }
  1580. var userInfo = clientUserItem.GetUserInfo();
  1581. userInfo.szUnderWrite = cc.vv.globalUserInfo.getAutoGraph();
  1582. selfPlayer.upPlayerInfo();
  1583. return;
  1584. },
  1585. upPlayerHead(clientUserItem) {
  1586. var player = this.getLocalPlayerByChairId(clientUserItem.GetChairID());
  1587. if (player) {
  1588. player.setUserItem(clientUserItem);
  1589. player.upPlayerHead();
  1590. }
  1591. },
  1592. upPlayerState(clientUserItem) {
  1593. var player = this.getLocalPlayerByChairId(clientUserItem.GetChairID());
  1594. if (player) {
  1595. player.setUserItem(clientUserItem);
  1596. player.upPlayerState();
  1597. var status = player.getUserStatus();
  1598. if(this.isSelf(player)){
  1599. }
  1600. }
  1601. },
  1602. getLocalPlayerByChairId: function (chairId) {
  1603. for (let index = 0; index < this._players.length; index++) {
  1604. const element = this._players[index];
  1605. if (element.getChairID() == chairId) {
  1606. return element;
  1607. }
  1608. }
  1609. return null;
  1610. },
  1611. getLocalPlayerByIndex: function (index) {
  1612. for (let i = 0; i < this._players.length; i++) {
  1613. const element = this._players[i];
  1614. if (element.getIndex() == index) {
  1615. return element;
  1616. }
  1617. }
  1618. return null;
  1619. },
  1620. //得到DSMJGamePlayer (是GamePlayer的派生类)
  1621. getSelfLocalPlayer: function () {
  1622. if(this._willExit_LackOfGold) {
  1623. return this._players[0];
  1624. }
  1625. for (let index = 0; index < this._players.length; index++) {
  1626. const element = this._players[index];
  1627. if (this.isSelf(element)) {
  1628. return element;
  1629. }
  1630. }
  1631. return null;
  1632. },
  1633. getLocalPlayerByUserID: function(userID)
  1634. {
  1635. for (let index = 0; index < this._players.length; index++) {
  1636. const element = this._players[index];
  1637. if (element.getUserID() == userID) {
  1638. return element;
  1639. }
  1640. }
  1641. return null;
  1642. },
  1643. showHeadInfo(player) {
  1644. // GameHeadInfo
  1645. if (player != null) {
  1646. var selfPlayer = this.getSelfLocalPlayer();
  1647. if (!selfPlayer || !player.getUserItem() || this.isSelf(player)) {
  1648. return;
  1649. }
  1650. var self = this;
  1651. UIHelper.loadRes("resourcesPrefab/GameHeadInfo", cc.Prefab, function (prefab) {
  1652. if (!self._GameHeadInfo) {
  1653. self._GameHeadInfo = cc.instantiate(prefab);
  1654. self._GameHeadInfo.parent = self.node;
  1655. var GameHeadInfoJS = self._GameHeadInfo.getComponent("GameHeadInfo");
  1656. if (!GameHeadInfoJS) {
  1657. self._GameHeadInfo.addComponent("GameHeadInfo");
  1658. }
  1659. }
  1660. self._GameHeadInfo.getComponent("GameHeadInfo").show(player);
  1661. // let currentGame = Global.getLocalStorageVaule("GoldCurrentGame");
  1662. // let gameName = GameConstant.getGameNameByByKey(currentGame);
  1663. // if (gameName) {
  1664. // cc.userOperate.sendRecord(gameName + "-Click on the avatar");
  1665. // }
  1666. });
  1667. }
  1668. },
  1669. OnSocketSubProtectBack: function (bLookonUser, data) {//低保信息
  1670. if (bLookonUser) {
  1671. return;
  1672. }
  1673. var selfPlayer = this.getSelfPlayer();
  1674. if (!selfPlayer) {
  1675. return;
  1676. }
  1677. if (data.dwUserId != selfPlayer.getUserID()) {
  1678. var player = this.getLocalPlayerByChairId(this.getPlayerByUserID(data.dwUserId).getChairID());
  1679. player.setUserScore(data.nCurScore);
  1680. player.setScore(data.nCurScore);
  1681. return;
  1682. }
  1683. selfPlayer.setUserScore(data.nCurScore);
  1684. selfPlayer.setScore(data.nCurScore);
  1685. selfPlayer.upPlayerInfo();
  1686. return true;
  1687. },
  1688. onGameServerItem:function(gameServerItem) {
  1689. GameBase.prototype.onGameServerItem.apply(this, [gameServerItem]);
  1690. if (GameManagerBase.Instance().IsGoldGame()) {
  1691. }
  1692. },
  1693. //聊天协议
  1694. revTalk: function (data) {//
  1695. var databuf = ProtocolGameServer.CMD_GR_C_TableTalk.data();
  1696. var dataView = new DataView(data);
  1697. dataView.pos = 8;
  1698. databuf.Type = Global.GetUint8(dataView);
  1699. databuf.ChairID = Global.GetUint8(dataView);
  1700. databuf.String = Global.Read2CharUtf(dataView, 128);
  1701. databuf.TalkSize = Global.GetInt32(dataView);
  1702. databuf.TalkData = Global.Read2Char(dataView, data.byteLength - databuf.pos);
  1703. Global.print(databuf);
  1704. var player = this.getLocalPlayerByChairId(databuf.ChairID);
  1705. if (player != null) {
  1706. player.showTalkState(databuf);
  1707. }
  1708. },
  1709. revVoice: function (data) {
  1710. var databuf = ProtocolGameServer.CMD_GR_TabelVoice.data();
  1711. var dataView = new DataView(data);
  1712. dataView.pos = 8;
  1713. databuf.ChairID = Global.GetUint8(dataView);
  1714. databuf.SerVerID = Global.Read2String(dataView);
  1715. Global.print("收到语音消息::");
  1716. Global.print(databuf);
  1717. var player = this.getLocalPlayerByChairId(databuf.ChairID);
  1718. if (player != null) {
  1719. player.showVoice(databuf);
  1720. }
  1721. var curTime = new Date();
  1722. var filePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + curTime.getTime() + '.ptt');
  1723. this.node.getComponent("TrucoFuncBtnMgr").getAr().downloadRecordedFile(databuf.SerVerID, filePath);
  1724. },
  1725. hideVoice: function () {
  1726. for (let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
  1727. var player = this.getLocalPlayerByChairId(i);
  1728. if (player != null) {
  1729. player.hideVoice();
  1730. }
  1731. }
  1732. },
  1733. ////////////////////////////////////////////////////////////////////////////
  1734. //银行信息
  1735. OnSocketSubUserInsureInfo: function (pNetInfo) {
  1736. var selfPlayer = this.getSelfPlayer();
  1737. if (!selfPlayer) {
  1738. return;
  1739. }
  1740. this.showBank(pNetInfo);
  1741. },
  1742. OnSocketSubUserInsureSuccess: function (pNetInfo) {
  1743. var selfPlayer = this.getSelfPlayer();
  1744. if (!selfPlayer) {
  1745. return;
  1746. }
  1747. selfPlayer.setScore(pNetInfo.UserScore);
  1748. selfPlayer.setUserScore(pNetInfo.UserScore);
  1749. cc.vv.globalUserInfo.setUserScore(pNetInfo.UserScore);
  1750. cc.vv.globalUserInfo.setBankScore(pNetInfo.UserInsure);
  1751. if (this._bankNode) {
  1752. this._bankNode.active = false;
  1753. }
  1754. //TODO ENDTIP
  1755. if (pNetInfo.cbType == 0) { //银行正常操作
  1756. } else if (pNetInfo.cbType == 1) { //存钱继续
  1757. if (this._goldUnusual) {
  1758. this._goldUnusual.active = false;
  1759. }
  1760. GameManagerBase.Instance().connectGameServer(this._gameServerItem);
  1761. } else if (pNetInfo.cbType == 2) { //取钱继续
  1762. if (this._goldUnusual) {
  1763. this._goldUnusual.active = false;
  1764. }
  1765. GameManagerBase.Instance().connectGameServer(this._gameServerItem);
  1766. }
  1767. },
  1768. OnSocketSubUserInsureFailure: function (pNetInfo) {
  1769. var selfPlayer = this.getSelfPlayer();
  1770. if (!selfPlayer) {
  1771. return;
  1772. }
  1773. var str = Global.gbk2Utf8(pNetInfo.DescribeString);
  1774. //Global.print(str);
  1775. this._bankNode.active = false;
  1776. topTipMsg.showTopTipMsg(LanguageKey.Public.TopTip_yxzbnck);
  1777. //topTipMsg.showTopTipMsg("游戏中不能存款");
  1778. },
  1779. showBank: function (data) {
  1780. var self = this;
  1781. /*cc.resources.load("GamePrefabs/homescence/BankNode", cc.Prefab, function (err, prefab) {
  1782. if (!self._bankNode) {
  1783. self._bankNode = cc.instantiate(prefab);
  1784. self._bankNode.parent = self.node;
  1785. self._bankNode.addComponent("bankSence");
  1786. }
  1787. self._bankNode.getComponent("bankSence").showBankNode(data, true);
  1788. });*/
  1789. },
  1790. //初始化UI
  1791. initView: function () {
  1792. },
  1793. defaultPrivateState: function () {
  1794. },
  1795. //返回大厅
  1796. backHome: function () {
  1797. if (CServerItem.get()) {
  1798. CServerItem.get().PerformStandUpAction(1);
  1799. } else {
  1800. this.exitGame();
  1801. }
  1802. this.unschedule(this.nextRecordAction);
  1803. this.unschedule(this.updataMobileTime);
  1804. ScenceManager.Instance().gameBackScence();
  1805. GameManagerBase.Instance().setInGameServerID(-1);
  1806. },
  1807. //解散房间
  1808. dissmissRoom: function (bAgree) {
  1809. },
  1810. exitGameWhenPlaying: function () {
  1811. var self = this;
  1812. if (this.getSceneState()) {
  1813. // this.node.getChildByName("tipNode").active = true;
  1814. // this.node.getChildByName("tipNode").getComponent(cc.Animation).play("showTipNode");
  1815. topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.not_exit_game"));
  1816. } else {
  1817. if(cc.vv.config.ReviewApk) {
  1818. cc.game.end();
  1819. return;
  1820. }
  1821. this.backHome();
  1822. this.exitGame();
  1823. this._isPlaying = false;
  1824. }
  1825. },
  1826. makeXieYi: function (m, s, data) {
  1827. return MakeXieYi.makeGameData(m, s, data);
  1828. },
  1829. isRecord: function() {
  1830. return false;
  1831. },
  1832. _GameHeadInfoCB(msg) {
  1833. // this.showHeadInfo(this.getPlayerByUserID(msg.userID));
  1834. var self = this;
  1835. UIHelper.loadRes("resourcesPrefab/GameHeadInfo", cc.Prefab, function (prefab) {
  1836. if (!self._GameHeadInfo) {
  1837. self._GameHeadInfo = cc.instantiate(prefab);
  1838. self._GameHeadInfo.parent = self.node;
  1839. var GameHeadInfoJS = self._GameHeadInfo.getComponent("GameHeadInfo");
  1840. if (!GameHeadInfoJS) {
  1841. self._GameHeadInfo.addComponent("GameHeadInfo");
  1842. }
  1843. }
  1844. self._GameHeadInfo.getComponent("GameHeadInfo").playMemeAni(msg);
  1845. });
  1846. },
  1847. onSocketSubExchangeRoom(data) {
  1848. if (data.cbReason == 1 || data.cbReason == 2) {
  1849. var self = this;
  1850. var OK = function () {
  1851. self.backHome();
  1852. self.exitGame();
  1853. }
  1854. popScence.initPopScence("Not enough chips,you can't continue the game", this, OK);
  1855. }
  1856. },
  1857. LackOfGoldWillExitGame: function(type) {
  1858. this._willExit_LackOfGold = true;
  1859. this.willExit = ()=>{
  1860. if (type == "low") {
  1861. popScence.initPopScence(LanguageKey.t("pubWords.money_notenghou"), this, () => { this.backHome() });
  1862. } else {
  1863. popScence.initPopScence(LanguageKey.t("pubWords.money_somore"), this, () => { this.backHome() });
  1864. }
  1865. GameManagerBase.Instance().setInGameServerID(-1);
  1866. }
  1867. if(!this._gameEnd) {
  1868. this.willExit();
  1869. }
  1870. },
  1871. //唯一对局码
  1872. onSocketUpdateUniqueCode(data){
  1873. Global.print("RUMMY 唯一对局码 " + JSON.stringify(data));
  1874. this.node.getChildByName("RoomInfo").getChildByName("GameId").active = BaseDefine.LOCALTEST;
  1875. this.node.getChildByName("RoomInfo").getChildByName("GameId").getComponent(cc.Label).string = data.strUniqueCode;
  1876. },
  1877. update(dt) {
  1878. //TODO GOLDSCENE
  1879. if (CServerItem.get().GetServerAttribute().wServerType == Define.GAME_GENRE_GOLD) {
  1880. this._changeTableLimit -= dt;
  1881. }
  1882. this._delayEvalTimes -= dt;
  1883. if(this._delayEvalTimes <= 0) {
  1884. if(this._msgCallback.length > 0) {
  1885. let info = this._msgCallback.shift();
  1886. info.call(info.data);
  1887. if(this.msgDelayTime[info.id] > 0) {
  1888. this._delayEvalTimes = this.msgDelayTime[info.id];
  1889. }
  1890. }
  1891. }
  1892. },
  1893. runCountdown:function(LabelNode,time,callFunc){
  1894. this.stopCountdown();
  1895. this._countdown = time;
  1896. LabelNode.active = true;
  1897. //var skt = LabelNode.getComponent(sp.Skeleton);
  1898. LabelNode.getChildByName("Label").getComponent(cc.Label).string = this._countdown;
  1899. this.timeCallback = function(){
  1900. self._countdown = self._countdown-1;
  1901. LabelNode.getChildByName("Label").getComponent(cc.Label).string = self._countdown;
  1902. if(self._countdown < 0){
  1903. //skt.setAnimation(0,"a1",true);
  1904. LabelNode.active = false;
  1905. if(callFunc){
  1906. callFunc();
  1907. callFunc = null;
  1908. }
  1909. self.stopCountdown();
  1910. }else if(self._countdown <= 3){
  1911. //skt.setAnimation(0,"a2",true);
  1912. SoundFun.playEffectEX(SoundFun.EX_COUNTDOWN);
  1913. }
  1914. }
  1915. var self = this;
  1916. this.schedule(this.timeCallback,1);
  1917. },
  1918. stopCountdown:function(){
  1919. this.unschedule(this.timeCallback);
  1920. this.timeCallback = null;
  1921. },
  1922. getFuncBtnComponent: function(){
  1923. return this.node.getComponent("TrucoFuncBtnMgr");
  1924. },
  1925. sendTalkBiaoqing: function(memeIdx){
  1926. let ichair = this.getSelfPlayer().getChairID();
  1927. var data = ProtocolGameServer.CMD_GR_C_TableTalk.data();
  1928. data.ChairID = ichair;
  1929. data.Type = ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_BIAOQING;
  1930. data.String = memeIdx.toString();
  1931. this.sendTalkDefineSocketData(ProtocolGameServer.SUB_GR_TABLE_TALK,data);
  1932. },
  1933. sendInputTxt: function(txt){
  1934. let ichair = this.getSelfPlayer().getChairID();
  1935. var data = ProtocolGameServer.CMD_GR_C_TableTalk.data();
  1936. data.ChairID = ichair;
  1937. data.Type = ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_WORD;
  1938. data.String = txt;
  1939. this.sendTalkDefineSocketData(ProtocolGameServer.SUB_GR_TABLE_TALK,data);
  1940. },
  1941. });