1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098 |
- import GameManagerBase from 'GameManagerBase';
- import { CServerItem } from 'CServerItem';
- import ScenceManager from 'HNScenceManager';
- /**
- * Author:alin,modify:alin
- * 大吃小gamescene
- */
- var GameBase = require("GameBase");
- var ProtocolGameServer = require("ProtocolGameServer");
- var GameProtocol = require("TrucoGameProtocol");
- var AnalyzeXieYi = require("AnalyzeTrucoXieYi");
- var MakeXieYi = require("MakeTrucoXieYi");
- var Global = require("Global");
- var topTipMsg = require("topTipMsg");
- var UIHelper = require("UIHelper");
- var Define = require("Define")
- var popScence = require("popScence");
- var LanguageKey = require("LanguageKey");
- var SoundFun = require("TrucoSoundFun");
- var HomeSoundFun = require("homeSoundFunc");
- var CGPIndividualMission = require("CGPIndividualMission");
- var BaseDefine = require("BaseDefine");
- //游戏状态
- var GameState = cc.Enum( //0,1,2,3,空闲,赢,输,放弃
- {
- FREE: 0, //空闲
- PLAYING: 1, //游戏中
- ROUNDSTART: 2, //小局开始
- OUTCARD: 3, //出牌过程
- COMPARECARD: 4, //比牌
- ENDING: 5, //结算中
- END: 6, //结束
- }
- )
- cc.Class({
- extends: GameBase,
- editor: {
- menu: 'Game/Truco/GameSence'
- },
- properties: {
- playerNode: cc.Node,//玩家节点
- cardNode: cc.Node,//手牌节点
-
- handCardGroupNode: cc.Node,//牌组节点
- shuffleAniNode: cc.Node,
- leftNode:cc.Node,
- gameRuleNode:cc.Node,
- AniNode:cc.Node,
- startNode: cc.Node,
- cardAtlas: cc.SpriteAtlas,
- _players: [],
- _seatPlayer: [],//主界面显示的6个玩家
- _handCards: [],//13张手牌节点数组
- _selectCard:null,
- _readyOutCard:null,//准备要打出的牌
- _selectCards:[],//弹起的牌
- _cardPreFabs:null, //牌预制
- _CurrentUser:-1,//当前玩家
- _MagicCardData:0,//百变牌
- _myTeam: -1,
- _isPlaying:false,//
- _isPlayingAni:false,
- _isTouchSend:false,//通过移动牌打出的
- _canGetCard:false,//可以抓牌
- _canOutCard:false,//可以出牌
- _willExit_LackOfGold:false,
- _willExit_LongTimeNoOperation:false,
- _delayEvalCallback: null,
- _delayEvalTimes: -1,
- },
- onLoad: function () {
- this.registerTouchEventHandle();
- this._cardPreFabs = this.cardNode.getChildByName("card");
- this._cardPreFabs.setPosition(cc.v2(0,0));
- this._cardPreFabs.setScale(1);
- this._gameInfoJS = this.node.getChildByName("RoomInfo").getComponent("TrucoGameInfo");
- this._willExit_LackOfGold = false;
- this._willExit_LongTimeNoOperation = false;
- this.gameStartTimer = 0;
- this._gameEnd = false;
- this._gameState = GameState.FREE;
- this.AniNode.getChildByName("trucoNode").active = false;
- this._handCards = [];
- for(let i = 0; i < GameProtocol.HAND_CARD_COUNT; ++i) {
- this._handCards[i] = this.handCardGroupNode.getChildByName("card"+i);
- }
- this._msgCallback = [];
- this.msgDelayTime = {
- 105: 1, //truco选择
- 106: 2.8, //小局开始
- 107: 2, //比牌
- 112: 0.8, //出牌
- 117: 1, //出牌
- }
- },
- start() {
- SoundFun.playBackMusic(SoundFun.GAME_BACKGRUAND);
- this.goToRealRoom = 0;
- this.dayCount = 1;
- this.limitCount = 1;
- this.playerCount = 0;
- },
- //注册触摸事件
- registerTouchEventHandle: function () {
- this.cardCanMoveAni = true;
- this.touchStatus = false;
- this.moved = false;
- let funcJS = this.node.getComponent("TrucoFuncBtnMgr");
- // return;
- this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
- // funcJS.hideSelfBQ();
- this.hideAllMene();
- if(!this._isPlaying){return;}
- if(this.touchStatus){return;}
- if(this._isPlayingAni){return;}
- if(this.playingGetCardAni) {return;}
- this.moved = false;
- var player = this.getSelfLocalPlayer();
- if (player == null) {
- return;
- }
- // Global.print("TOUCH_START::4");
- this._selectCard = this.GetTouchCard(event.getLocation());
- if (this._selectCard == null) {
- return;
- }
- this.touchStatus = true;
- }, this),
- this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
- //Global.print("TOUCH_MOVE::");
- if(!this._isPlaying){return;}
- if(!this.touchStatus){return;}
- if(this._isPlayingAni){return;}
- if(this.playingGetCardAni) {return;}
- var delta = event.getDelta();
- if(Math.abs(delta.x)<= 2 && Math.abs(delta.y) <= 2){
- return;
- }
- var pos = event.getLocation();
- if(this._selectCard){
- this.moved = true;
- this.setMovePosition(this._selectCard,pos);
- };
- }, this),
- this.node.on(cc.Node.EventType.TOUCH_END, function (event) {
- //Global.print("TOUCH_END::");
- if(!this._isPlaying){return;}
- if(!this.touchStatus){return;}
- if(this._isPlayingAni){return;}
- if(this.playingGetCardAni) {return;}
- // var pos = event.getLocation();
- if(this._selectCard && this.moved){
- if(this.isOutErea(this._selectCard) && this._canOutCard){//出牌
- this.outCard();
- }else{//其他区域自动复位
- this.resetHandCards();
- }
- }
-
- this.touchStatus = false;
- }, this),
- this.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
- //Global.print("TOUCH_CANCEL::");
- if(!this._isPlaying){return;}
- if(!this.touchStatus){return;}
- if(this._isPlayingAni){return;}
- if(this.playingGetCardAni) {return;}
-
- this.moved = false;
- if(this._selectCard){
- this.resetHandCards();
- }
- this._selectCard = null;
- this.touchStatus = false;
- }, this)
- },
- GetTouchCard:function(kTouchPos){
- var kWorldPos = this.handCardGroupNode.convertToNodeSpaceAR(kTouchPos);
- for (var idx = this.handCardGroupNode.childrenCount-1; idx >= 0; idx--) {
- var cardNode = this._handCards[idx];
- if(!cardNode.active) {
- continue;
- }
- var cardSize = cardNode.getBoundingBox().size;
- var cardPos = cardNode.getPosition();
- var rect = cc.rect(cardPos.x-cardSize.width/2,cardPos.y-cardSize.height/2,cardSize.width,cardSize.height);
- if (rect.contains(kWorldPos)){
- return cardNode;
- }
- }
- return null;
- },
- setMovePosition:function(cardNode,kTouchPos){
- if(!cardNode){
- return;
- }
- var kWorldPos = this.handCardGroupNode.convertToNodeSpaceAR(kTouchPos);
- // Global.print("cardNode"+kWorldPos.x)
- cardNode.setPosition(kWorldPos);
-
- },
- resetHandCards() {
- var selfPlayer = this.getSelfLocalPlayer();
- if(!selfPlayer) {
- return;
- }
- selfPlayer.resetHandCardPos();
- },
- isOutErea:function(cardNode){
- return cardNode.y > -200;
- },
-
- outCard:function() {
- var selfPlayer = this.getSelfLocalPlayer();
- if(!selfPlayer) {
- return;
- }
-
- if(this._selectCard) {
- let cardid = this._selectCard.getComponent("TrucoCard").cardId();
- Global.print("outCard::"+this._selectCard.getComponent("TrucoCard").cardId())
- Global.print(this._selectCard)
- if(cardid <= 0) {
- Global.print("0牌")
- Global.print(this._selectCard.cardValue)
- cardid = this._selectCard.cardValue//selfPlayer.getHandCardValue(parseInt(this._selectCard.name))
- }
- Global.print(cardid)
- this.SendGameSocketData(GameProtocol.SUB_C_OUT_CARD,{
- cbOutCardData: cardid//this._selectCard.getComponent("TrucoCard").cardId(),
- })
- }else{
- topTipMsg.showTopTipMsg("Truco.no_select_card");
- }
- },
- /*************************网络协议相关*****************************/
- //场景消息
- onEventSceneMessage: function (gameStatus, lookonUser, data) {
- Global.print("RUMMYGameSence onEventSceneMessage 场景消息 ");
- var arr = new DataView(data.slice(0, 8));
- var dataView = new DataView(data.slice(8));
- var msgHead = { m: arr.getUint16(4, true), s: arr.getUint16(6, true), d: null };
- arr = null;
- switch (gameStatus) {
- case GameProtocol.GAME_STATUS_FREE: {
- var msg = AnalyzeXieYi.analyze_StatusFree(dataView);
- Global.print("onFreeScence......")
- this.onFreeScence(msg);
- }
- break;
- case GameProtocol.GAME_STATUS_PLAY: {
- var msg = AnalyzeXieYi.analyze_StatusPlay(dataView);
- this.onPlayScence(msg);
- }
- break;
- default: {
- Global.print("RUMMYGameSence onEventSceneMessage error ");
- }
- break;
- };
- },
- //游戏消息
- onEventGameMessage: function (data) {
- //Global.print("RUMMYGameSence onEventGameMessage 游戏消息 ");
- var arr = new DataView(data.slice(0, 8));
- var dataView = new DataView(data.slice(8));
- var msgHead = { m: arr.getUint16(4, true), s: arr.getUint16(6, true), d: null };
- arr = null;
- var msg = AnalyzeXieYi.analyzeData(msgHead.m, msgHead.s, dataView);
- switch (msgHead.s) {
- case GameProtocol.SUB_S_GAME_FREE: {
- Global.print("游戏空闲");
- }
- break;
- case GameProtocol.SUB_S_GAME_START: {
- Global.print("游戏开始");
- this.OnGameStart(msg);
- }
- break;
- case GameProtocol.SUB_S_GAME_END: {
- Global.print("游戏结束");
- this.preSetEndPlayerInfo(msg);
- this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnGameEnd(msg);}});
- return;
- if(this._isOutCarding || this._compareCarding) {
- this._gameResultData = msg;
- return;
- }
- this.OnGameEnd(msg);
- }
- break;
- case GameProtocol.SUB_S_GAME_CONTINUE: {
- Global.print("游戏继续");
- this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnGameContinue(msg);}});
- return;
- let nowTime = new Date().getTime();
- if(this._trucoChooseTimes && nowTime - this._trucoChooseTimes < 2000) {
- setTimeout(()=>{
- this.OnGameContinue(msg);
- }, this._trucoChooseTimes+2000-nowTime)
- return;
- }
- this.OnGameContinue(msg);
- }
- break;
- case GameProtocol.SUB_S_TRUCO: {
- Global.print("游戏TRUCO");
- this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnTruco(msg);}});
- return;
- this.OnTruco(msg);
- }
- break;
- case GameProtocol.SUB_S_TRUCO_CHOOSE: {
- Global.print("游戏TRUCO选择");
- this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnTrucoChoose(msg);}});
- return;
- this.OnTrucoChoose(msg);
- }
- break;
- case GameProtocol.SUB_S_TRUCO_SET:{
- Global.print("TRUCO设置");
- this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnTrucoSet(msg);}});
- return;
- if(this._needDelaySet) {
- this._trucoSetData = msg;
- }else{
- this.OnTrucoSet(msg);
- }
- }
- break;
- case GameProtocol.SUB_S_COMPARE_CARD: {
- Global.print("游戏比牌结果");
- this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnCompareCard(msg);}});
- return;
- if(this._isOutCarding) {
- this._compareData = msg;
- return;
- }
- this.OnCompareCard(msg);
- }
- break;
- case GameProtocol.SUB_S_ROUND_START: {
- Global.print("小局开始");
- this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnRoundStart(msg);}});
- return;
- if(this._isOutCarding || this._compareCarding) {
- this._roundStartData = msg;
- return;
- }
- let nowTime = new Date().getTime();
- if(this._trucoChooseTimes && nowTime - this._trucoChooseTimes < 2000) {
- setTimeout(()=>{
- this.OnRoundStart(msg);
- }, this._trucoChooseTimes+2000-nowTime)
- return;
- }
- this.OnRoundStart(msg);
- }
- break;
- case GameProtocol.SUB_S_OPERATE_FAIL: {
- Global.print("操作失败");
- this.OnGameOperareOutCard(msg);
- }
- break;
- case GameProtocol.SUB_S_OUT_CARD: {
- Global.print("玩家出牌");
- this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnGameOutCard(msg);}});
- return;
- this.OnGameOutCard(msg);
- }
- break;
- case GameProtocol.SUB_S_WAIT_START:{
- Global.print("等待开始");
- this.OnWaitStart(msg);
- }
- break;
- case GameProtocol.SUB_S_GAME_INFO:{
- Global.print("控制信息");
- this.OnGameInfo(msg);
- }
- break;
- case GameProtocol.SUB_S_TRUSTEE_STATUS:{
- this.OnPlayerTrustee(msg);
- break;
- }
- case GameProtocol.SUB_S_FORCE_LEAVE_CHOOSE:{
- this.node.getComponent("TrucoFuncBtnMgr").showForceExit();
- break;
- }
- case GameProtocol.SUB_S_CELL_SCORE:{
- Global.print("底分倍数");
- this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnCellScore(msg);}});
- return;
- this.OnCellScore(msg);
- break;
- }
- case GameProtocol.SUB_S_FINAL_ROUND:{
- Global.print("OnFinalRound");
- this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnFinalRound(msg);}});
- break;
- }
- case GameProtocol.SUB_S_FINAL_CHOOSE:{
- Global.print("OnFinalChoose");
- this._msgCallback.push({id:msgHead.s, data:msg, call:(msg)=>{this.OnFinalChoose(msg);}});
- break;
- }
- default: {
- Global.print("RUMMYGameSence onEventGameMessage error ");
- }
- break;
- }
- },
- getSceneState: function () {
- return this._isPlaying;
- },
- OnGameInfo(msg) {
- if(!BaseDefine.LOCALTEST)
- return;
- Global.print(JSON.stringify(msg));
- let layer_player = this.node.getChildByName("layer_control");
- layer_player.active = true;
- let labelNode = layer_player.getChildByName("label_item");
- let playerNode = layer_player.getChildByName("parent");
- let ControlInfo = msg.tagControlInfo;
- let type = ControlInfo.cbControlType;
- let info1 = "控制类型__" + ["无控制", "1后台单控赢", "2后台单控输", "3库存控制赢", "4库存控制输", "5自动控制赢", "6自动控制输"][type];
- let info2 = "控制结果__" + ["无控制", "1控制赢", "2控制输"][ControlInfo.cbControlReslut];
- let str = info1 + "\r\n" + info2 + "\r\n";
- let info3 = "控制玩家__" + ControlInfo.wControlUser; //控制玩家
- let info4 = ControlInfo.wControlWinUser; //控制赢玩家
- let info5 = ControlInfo.wControlLoseUser; //控制输玩家
- let info6 = ControlInfo.nControlRadian; //控制概率[]
- let info7 = "随机值__" + ControlInfo.nRnd; //随机值
- let info8 = ControlInfo.nControlValue; //单控值 0~20[]
-
- // labelNode.getChildByName("label2").getComponent(cc.Label).string = info2;
- // labelNode.getChildByName("label3").getComponent(cc.Label).string = info3;
- // labelNode.getChildByName("label4").getComponent(cc.Label).string = info4;
- // labelNode.getChildByName("label5").getComponent(cc.Label).string = info5;
- // labelNode.getChildByName("label6").getComponent(cc.Label).string = info7;
- // labelNode.getChildByName("label7").getComponent(cc.Label).string = info1;
- let index = ControlInfo.lRet;
- //库存控制的返回 索引2代表当前库存, 索引3代表当前杀率 索引4代表系统赢概率 索引5代表系统输概率 索引6代表随机值
- let info9 = "控制结果" + ["0不控制", "1控制系统赢", "2控制系统输"][index[0]];
- let info10 = "是否需要控制" + ["0不需要", "1需要"][index[1]];
- let info11 = "库存剩余__" + index[2];
- let info12 = "杀率__" + index[3];
- let info13 = "系统赢概率__" + index[4];
- let info14 = "系统输概率__" + index[5];
- let info15 = "随机值__" + index[6];
- if (type == 0) {
- str += info7;
- } if (type == 1 || type == 2) {
- str += info3 + "\r\n" + info7;
- } else if (type == 3 || type == 4) {
- str += info3 + "\r\n" + info9 + "\r\n" + info10 + "\r\n" + info11 + "\r\n" + info12 + "\r\n" + info13 + "\r\n" + info14 + "\r\n" + info15;
- } else if (type == 5 || type == 6) {
- str += info3 + "\r\n" + info7;
- }
- labelNode.getChildByName("label1").getComponent(cc.Label).string = str;
-
- for(let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
- let index = this.getPlayerIndex(i);
- let label = playerNode.getChildByName("label"+index);
- if(label) {
- let player = this.getLocalPlayerByIndex(i);
- if(player && player.getUserItem()) {
- let ssstr = "";
- if (info4 == i) {
- ssstr += "控赢\r\n";
- }
- if(info5 == i) {
- ssstr += "控输\r\n";
- }
- ssstr += "控制概率__"+info6[i]+"\r\n";
- ssstr += "单控值__"+info8[i];
- label.getComponent(cc.Label).string = ssstr;
- }
- }
- }
- },
- //断线续连
- onFreeScence: function (data) {
- Global.print("onFreeScence "+JSON.stringify(data))
- // this.node.getChildByName("RoomInfo").getChildByName("bg1").getChildByName("bet").getComponent(cc.Label).string = Global.formatString2Score(data.lCellScore);
- var selfPlayer = this.getSelfPlayer();
- if (!selfPlayer) {
- return;
- }
- this.initPlayers(GameProtocol.GAME_PLAYER);
- this.resetView();
- this._bFirstIn = true;
- this._isPlaying = false;
- this._baseScore = data.lCellScore;
- this._gameInfoJS.setBaseCellScore(data.lCellScore);
- this.startNode.getChildByName("startTime").active = true;
- this.resetFreeStatus();
- },
- //游戏场景重连
- onPlayScence: function (data) {
- Global.print("RUMMY 游戏重连 " + JSON.stringify(data));
- // this._gameInfoJS
- var selflayer = this.getSelfPlayer();
- if (!selflayer) {
- return;
- }
-
- this.initPlayers(GameProtocol.GAME_PLAYER);
- this.resetView();
- this._bFirstIn = false;
- this._gameState = GameState.OUTCARD;
- this._isPlaying = true;
- this._CurrentUser = data.wCurrentUser;
- this._MagicCardData = data.cbMagicCardValue;
- this._outCard = data.cbOpenCardData;
- this._trucoSide = data.cbTruco;
- this._trucoScore = data.cbTrucoScore;
- this._nowScore = data.cbNowScore;
- this._myTeam = data.cbTeam;
- this._baseScore = data.lCellScore;
- this._gameInfoJS.setTeam(this._myTeam);
- this._gameInfoJS.setBaseCellScore(data.lCellScore);
- this._gameInfoJS.setMagicCardValue(data.cbMagicCardValue);
- this._gameInfoJS.upNowScore(data.cbNowScore);
- this._gameInfoJS.initRoundState(data.cbRoundResult, data.cbPlayCount);
- this._gameInfoJS.upRoundScore(data.cTotalScore);
- this._gameInfoJS.upBetScore(data.nCellMulti);
- this.leftNode.active = true;
- let magicCard = this.leftNode.getChildByName("cardl");
- magicCard.getComponent("TrucoCard").setId(data.cbMagicShowCardData, 0);
- magicCard.scale = 0.42;
- magicCard.angle = 18;
- magicCard.position = cc.v2(-74, 0);
- let selfPlayer = this.getSelfLocalPlayer();
- let handCard = data.cbCardData;
- selfPlayer.changeMingCard(data.cbFinalRound != 2);
- // selfPlayer.changeMingCard(true);
- for (let i = 0; i < GameProtocol.GAME_PLAYER; i++) {
- var index = this.getPlayerIndex(i);
- var player = this.getLocalPlayerByIndex(index);
- if (player) {
- player.setMagicCardValue(this._MagicCardData);
- player.setHandCards(handCard, data.cbCardCount[i], true);
- player.showOutCard(data.cbCardOut[i], this._MagicCardData);
- player.changeTrusteeState(data.cbUserTrustee[i]);
- }
- }
- this.node.getChildByName("TrusteeNode").active = data.cbUserTrustee[selfPlayer.getChairID()] == 1;
- this.upForceExitBtnState(data.cbForceLeaveChoose[selfPlayer.getChairID()] == 0);
- this.showPePlayer(data.wFirstUser);
- //正在truco
- if(data.cbTruco > 0) {
- //当前拍了的队伍
- // let bSameTeam = (selfPlayer.getChairID()-data.wCurrentUser+4)%2 == 0;
- let trucoPlayer = this.getLocalPlayerByChairId(data.wTrucoChair);
- if(trucoPlayer) {
- let trucoAni = this.AniNode.getChildByName("trucoNode");
- trucoAni.active = true;
- let ani = trucoAni.getChildByName("trucoAni").getComponent(sp.Skeleton);
- ani.clearTracks();
- ani.setAnimation(0, "a1", false);
- trucoPlayer.playTruco(this._trucoScore);
- }
- for(let i = 0; i < 2; ++i) {
- let chairID = (data.wTrucoChair+1+i*2)%GameProtocol.GAME_PLAYER;
- let sPlayer = this.getLocalPlayerByChairId(chairID);
- if(sPlayer) {
- if(data.cbTrucoStatus[chairID] > 0) {
- sPlayer.showTrucoChoose(data.cbTrucoStatus[chairID]);
- }else{
- if(sPlayer == selfPlayer) {
- this.showTrucoBtns();
- }
- sPlayer.playTimeAction(data.cbTimeCount);
- }
- }
- }
- }else{
- this.SetCurrentUser(this._CurrentUser,data.cbTimeCount);
- }
- if(data.cbFinalRound > 0) {
- if(data.cbFinalRound == 2) {
- // selfPlayer.changeMingCard(false);
- for (let i = 0; i < GameProtocol.GAME_PLAYER; i++) {
- var index = this.getPlayerIndex(i);
- var player = this.getLocalPlayerByIndex(index);
- if (player && data.cbFinalStatus[i] > 0) {
- player.showTrucoChoose(data.cbFinalStatus[i]);
- }
- }
- }else{
- let ppID = (selfPlayer.getChairID()+this._myTeam-data.cbFinalTeam+GameProtocol.GAME_PLAYER)%GameProtocol.GAME_PLAYER;
- for (let i = 0; i < GameProtocol.SIDE_NUM; i++) {
- let pid = (ppID + i * 2)%GameProtocol.GAME_PLAYER;
- var index = this.getPlayerIndex(pid);
- var player = this.getLocalPlayerByIndex(index);
- if (player && data.cbFinalStatus[pid] > 0) {
- player.showTrucoChoose(data.cbFinalStatus[pid]);
- }
- }
- }
- }
- },
- upForceExitBtnState(bShow) {
- this.node.getChildByName("FuncBtnNode").getChildByName("btn_Exit").active = bShow;
- },
- //游戏结束 隐藏牌面
- hideCardsNode() {
- var EventNode = this.node.getChildByName("Cards").getChildByName("EventNode");
- EventNode.active = false;
- for (let i = 0; i < this._players.length; i++) {
- var player = this._players[i];
- if (player) {
- player.cardsNode.active = false;
- }
- }
- },
- hideBtns() {
- var funcBtnNode = this.node.getChildByName("FuncBtnNode");
- funcBtnNode.getChildByName("btn_Truco").active = false;
- funcBtnNode.getChildByName("btn_Ace").active = false;
- funcBtnNode.getChildByName("btn_Cor").active = false;
- // funcBtnNode.getChildByName("btn_Listener").active = false;
- // funcBtnNode.getChildByName("btn_Finish").active = false;
- // funcBtnNode.getChildByName("btn_Descartar").active = false;
- },
- //每局游戏结束后重置UI
- resetView: function () {
- this.node.getChildByName("GameEnd").active = false;
- this.leftNode.active = false;
- this.AniNode.getChildByName("trucoNode").active = false;
- this.startNode.getChildByName("startTime").active = false;
- //按钮
- this.hideBtns();
- //对局
- this._gameInfoJS.reset();
- this._msgCallback.splice(0);
- this.upForceExitBtnState(false);
- this._isPlaying = false;
- this._gameEnd = false;
- this._roundStarting = false;
- this._needDelaySet = false;
- this._gameState = GameState.FREE;
- for (let i = 0; i < this._players.length; i++) {
- var player = this._players[i];
- if(!player) {
- // player.node.active = false;
- continue;
- }
- player.node.active = player.getUserItem();
- player.hideHandCard();
- player.setNameLabelActive(true);
- player.changeTrusteeState(false);
- player.setVIPActive(true);
- player.upPlayerHead();
- player.hideTimeNode();
- }
-
- },
- resetRound() {
- for (let i = 0; i < this._players.length; i++) {
- var player = this._players[i];
- if(!player) {
- continue;
- }
- player.node.active = player.getUserItem();
- player.hideHandCard();
- player.hideTimeNode();
- player.hideTruco();
- player.hideTrucoChoose();
- player.showPe(false);
- }
- this._gameInfoJS.roundStart();
- this.leftNode.active = false;
- this.leftNode.getChildByName("cardNode").active = false;
- this.node.getChildByName("CoinNode").active = false;
- this._nowScore = 1;
- this._trucoScore = 0;
- this._trucoSide = -1;
- },
- hideAllMene() {
- for (let i = 0; i < this._players.length; i++) {
- var player = this._players[i];
- if(!player) {
- continue;
- }
- player.hideInfoNode();
- }
- },
- hideAllTimes() {
- for (let i = 0; i < this._players.length; i++) {
- var player = this._players[i];
- if(!player) {
- continue;
- }
- player.hideTimeNode();
- }
- },
- hideAllTrucos() {
- for (let i = 0; i < this._players.length; i++) {
- var player = this._players[i];
- if(!player) {
- continue;
- }
- player.hideTruco();
- }
- },
- hideAllTrucoChoose() {
- for (let i = 0; i < this._players.length; i++) {
- var player = this._players[i];
- if(!player) {
- continue;
- }
- player.hideTrucoChoose();
- }
- },
- resetFreeStatus:function(){//匹配状态中
- for (let i = 0; i < this._players.length; i++) {
- const player = this._players[i];
- if(!player || player.getChairID() == this.getSelfPlayer().getChairID()){
- continue;
- }
- player.setNameLabelActive(false);
- player.setVIPActive(false);
- }
- },
- resetGameStatus:function(){//游戏状态中
- this.node.getChildByName("TipNode").getChildByName("tip_wait").active = false;
- this.node.getChildByName("TipNode").getChildByName("tip_wait1").active = false;
- this.node.getChildByName("TipNode").getChildByName("tip_start").active = false;
- for (let i = 0; i < this._players.length; i++) {
- const player = this._players[i];
- if(!player || !player.getUserItem()){
- continue;
- }
- player.node.active = true;
- player.setNameLabelActive(true);
- player.setVIPActive(true);
- player.upPlayerHead();
- }
- },
- updateLeftCards() {
- let resIdx = parseInt(this._leftCardCount / 5);
- let notLast = this._leftCardCount > 0;
- for(let i = 0; i < 20; ++i) {
- this.leftCardsArr[i].active = (i <= resIdx) && notLast;
- }
- },
- reduceOneCard() {
- this._leftCardCount--;
- if(this._leftCardCount % 5 == 4 || this._leftCardCount == 0) {
- this.updateLeftCards();
- }
- },
- autoReady:function() {
- },
- cardNum(cardid) {
- return (cardid & 0x0F);
- },
- //cbCardState 1拿牌 2丢牌
- SetCurrentUser:function(_CurrentUser, cbUserTime){
- var selfPlayer = this.getSelfPlayer();
- if (!selfPlayer) {
- return;
- }
- // return;
- this._CurrentUser = _CurrentUser;
- var index = this.getPlayerIndex(_CurrentUser);
- for (let i = 0; i < this._players.length; i++) {
- const player = this._players[i];
- if(!player){
- continue;
- }
- if (player.getIndex() == index) {
- //全部减掉3秒
- player.playTimeAction(cbUserTime);
- }else{
- player.hideTimeNode();
- }
- }
- this._canGetCard = false;
- this._canOutCard = false;
- if(this._CurrentUser == selfPlayer.getChairID()){
- this._canOutCard = true;
- this.showTrucoBtns(false);
- if(this._trucoSetData) {
- this.OnTrucoSet(this._trucoSetData);
- }
- cc.vv.reflection.shake(100);
- }else{
- Global.print("不是我")
- }
- },
- upTrusteeMask(width) {
- this.node.getChildByName("TrusteeNode").getChildByName("mask").width = width;
- },
- OnPlayerTrustee(data) {
- Global.print("托管"+JSON.stringify(data))
- var index = this.getPlayerIndex(data.wChairID);
- var tPlayer = this.getLocalPlayerByIndex(index);
- if(tPlayer) {
- tPlayer.changeTrusteeState(data.cbStatus);
- if(tPlayer == this.getSelfLocalPlayer()) {
- this.node.getChildByName("TrusteeNode").active = data.cbStatus == 1;
- // if(data.cbStatus == 0) {
- // topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.cancel_hosting"));
- // }
- }
- }
- },
- showPePlayer(firstUserID) {
- let chairid = (firstUserID + 3) % GameProtocol.GAME_PLAYER;
- let player = this.getLocalPlayerByChairId(chairid);
- if(player) {
- player.showPe(true);
- }
- },
- OnWaitStart(data) {
- let aniNode = this.startNode.getChildByName("startTime").getChildByName("aniNode");
- aniNode.getChildByName("ani").active = false;
- aniNode.getChildByName("ani2").active = true;
- },
- OnGameStart: function (data) {
- this.resetView();
- Global.print("Truco 游戏开始 " + JSON.stringify(data));
- SoundFun.playEffectEX(SoundFun.GAME_START);
- this._gameState = GameState.PLAYING;
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return;
- }
- this._isPlaying = true;
- this._myTeam = data.cbTeam;
- this._gameInfoJS.setTeam(this._myTeam);
- this._gameInfoJS.upBetScore(1);
- this.upForceExitBtnState(true);
- },
- preSetEndPlayerInfo(data) {
- Global.print("Truco 游戏结束 预设玩家信息 " + JSON.stringify(data));
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return;
- }
- let bWin = data.cbWinSide == this._myTeam;
- let playerNode = this.node.getChildByName("GameEnd").getChildByName("RootNode").getChildByName("playerNode");
- playerNode.getChildByName("loseBG").active = !bWin;
- playerNode.getChildByName("winBG").active = bWin;
- let startChairID = selfPlayer.getChairID();
- for(let i = 0; i < 2; ++i) {
- let playerN = playerNode.getChildByName("player"+i);
- let iChairID = (startChairID+i*2)%GameProtocol.GAME_PLAYER;
- let player = this.getLocalPlayerByChairId(iChairID);
- if(playerN && player) {
- playerN.getChildByName("headNode").getChildByName("head").getComponent(cc.Sprite).spriteFrame = player.getHeadSpriteFrame();
- playerN.getChildByName("Name").getComponent(cc.Label).string = player.getnickName();
- let winS = playerN.getChildByName("winScore");
- let loseS = playerN.getChildByName("loseScore");
- winS.active = bWin;
- loseS.active = !bWin;
- winS.getComponent(cc.Label).string = '+'+Global.formatString2Score(data.lUserScore[iChairID]);
- loseS.getComponent(cc.Label).string = Global.formatString2Score(data.lUserScore[iChairID]);
- }
- }
- },
- OnGameEnd(data) {
- Global.print("Truco 游戏结束 " + JSON.stringify(data));
- this.gameEndData = data;
- this._gameState = GameState.ENDING;
- this._isPlaying = false;
- this._bFirstIn = false;
- this.node.getChildByName("TrusteeNode").active = false;
- this._gameEnd = true;
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return false;
- }
- this.hideBtns();
- this._gameInfoJS.upRoundScore(data.cTotalScore);
- let bWin = data.cbWinSide == this._myTeam;
- let GameEnd = this.node.getChildByName("GameEnd");
- GameEnd.active = true;
- let rootNode = GameEnd.getChildByName("RootNode");
- let ani = rootNode.getChildByName("ani").getComponent(sp.Skeleton);
- ani.clearTracks();
- if(bWin) {
- ani.setAnimation(0, "a1", false);
- ani.addAnimation(0, "a2", true);
- SoundFun.playEffectEX(SoundFun.GAME_WIN);
- }else{
- ani.setAnimation(0, "a3", false);
- ani.addAnimation(0, "a4", true);
- SoundFun.playEffectEX(SoundFun.GAME_LOSE);
- }
- rootNode.getChildByName("playerNode").getComponent(cc.Animation).play("showEndLayer");
- cc.tween(GameEnd)
- .delay(5)
- .call(()=>{
- GameEnd.active = false;
- this.resetView();
- this.startNode.getChildByName("startTime").active = true;
- })
- .start()
- },
- OnGameContinue(data) {
- Global.print("Truco OnGameContinue " + JSON.stringify(data));
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return false;
- }
- this.hideBtns();
- this._gameInfoJS.upNowScore(this._trucoScore?this._trucoScore:1);
- for (let i = 0; i < this._players.length; i++) {
- var player = this._players[i];
- if(!player) {
- continue;
- }
- player.hideTimeNode();
- player.hideTruco();
- player.hideTrucoChoose();
- }
- this.SetCurrentUser(data.wCurrentUser, data.cbTimeCount);
- },
- OnTruco(data) {
- Global.print("Truco OnTruco " + JSON.stringify(data));
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return false;
- }
- var trucoPlayer = this.getLocalPlayerByChairId(data.wTrucoUser);
- if(!trucoPlayer) {
- return;
- }
- this._trucoScore = data.cbTrucoScore;
- this._trucoSide = data.cbTrucoSide;
- SoundFun.playEffectEX("truco"+this._trucoScore);
- this.hideAllTimes();
- this.hideAllTrucos();
- this.hideAllTrucoChoose();
- this.hideBtns();
- this.AniNode.active = true;
- let trucoAni = this.AniNode.getChildByName("trucoNode");
- trucoAni.active = true;
- let ani = trucoAni.getChildByName("trucoAni").getComponent(sp.Skeleton);
- ani.clearTracks();
- ani.setAnimation(0, "a1", false);
- trucoPlayer.playTruco(this._trucoScore);
- trucoPlayer.hideTimeNode();
- if(this._myTeam != this._trucoSide) {
- this.showTrucoBtns();
- }
- let side1 = this.getLocalPlayerByChairId((data.wTrucoUser+1)%GameProtocol.GAME_PLAYER);
- if(side1) {
- side1.playTimeAction(data.cbTimeCount);
- }
- let side2 = this.getLocalPlayerByChairId((data.wTrucoUser+3)%GameProtocol.GAME_PLAYER);
- if(side2) {
- side2.playTimeAction(data.cbTimeCount);
- }
-
- },
- showTrucoBtns(nFirst = true) {
- var funcBtnNode = this.node.getChildByName("FuncBtnNode")
- funcBtnNode.getChildByName("btn_Ace").active = nFirst;
- funcBtnNode.getChildByName("btn_Cor").active = nFirst;
- // funcBtnNode.getChildByName("btn_Truco").active = true;
- // funcBtnNode.getChildByName("btn_Truco").getChildByName("Label").getComponent(cc.Label).string = '+'+(this._trucoScore+3);
- },
- OnTrucoChoose(data) {
- Global.print("Truco OnTrucoChoose " + JSON.stringify(data));
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return false;
- }
- var trucoPlayer = this.getLocalPlayerByChairId(data.wTrucoUser);
- if(!trucoPlayer) {
- return;
- }
- if(selfPlayer == trucoPlayer || (data.cbTrucoChoose == 1 && (selfPlayer.getChairID()+2)%GameProtocol.GAME_PLAYER == data.wTrucoUser)) {
- this.hideBtns();
- }
- if(data.cbTrucoChoose == 1) {
- SoundFun.playEffectEX(SoundFun.TRUCO_TY);
- }else{
- SoundFun.playEffectEX(SoundFun.TRUCO_FQ);
- }
-
- trucoPlayer.hideTimeNode();
- trucoPlayer.showTrucoChoose(data.cbTrucoChoose);
- this._trucoChooseTimes = new Date().getTime();
- this._needDelaySet = data.cbTrucoChoose == 2;
- if(this._msgCallback.length > 1 && this._msgCallback[0].id == GameProtocol.SUB_S_TRUCO_CHOOSE) {
- this._delayEvalTimes = 0;
- }
- },
- OnTrucoSet(data) {
- Global.print("Truco OnTrucoSet " + JSON.stringify(data));
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return false;
- }
- var funcBtnNode = this.node.getChildByName("FuncBtnNode")
- funcBtnNode.getChildByName("btn_Truco").active = true;
- funcBtnNode.getChildByName("btn_Truco").getChildByName("Label").getComponent(cc.Label).string = '+'+(data.cbTrucoScore);
- this._trucoSetData = null;
- this._needDelaySet = false;
- },
- OnCompareCard(data) {
- Global.print("Truco OnCompareCard " + JSON.stringify(data));
- this._compareCarding = true;
- this._needDelaySet = true;
- this._gameState = GameState.COMPARECARD;
- let winPlayer = this.getLocalPlayerByChairId(data.wWinChairID);
- if(!winPlayer) {
- return;
- }
- winPlayer.playLightCardAni();
- let winCard = this.cardNum(winPlayer.getOutCard());
- if(winCard == this._MagicCardData) {
- SoundFun.playEffectEX(SoundFun.WINKING);
- }
- var setUser = ()=>{
- // this.SetCurrentUser(data.wWinChairID, data.cbTimeCount);
- this._compareCarding = false;
- if(data.cbRoundEnd) {
- // this._gameInfoJS.upRoundScore(data.cbRoundScore);
- if(this._gameResultData) {
- this.OnGameEnd(JSON.parse(JSON.stringify(this._gameResultData)));
- this._gameResultData = null;
- }else if(this._roundStartData) {
- this.OnRoundStart(JSON.parse(JSON.stringify(this._roundStartData)));
- this._roundStartData = null;
- }
- }else{
- this.SetCurrentUser(data.wWinChairID, data.cbTimeCount);
- }
- }
- var upWinState = ()=>{
- this._gameInfoJS.initRoundState(data.cbRoundResult, data.cbPlayCount);
- SoundFun.playEffectEX(SoundFun.MOVECARD);
- for(let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
- let index = this.getPlayerIndex(i);
- let player = this.getLocalPlayerByIndex(index);
- if(player) {
- player.outCardMoveToTrush();
- }
- }
- setTimeout(()=>{
- setUser();
- }, 500)
- }
- if(data.cbWinSide == 0) {
- for(let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
- let index = this.getPlayerIndex(i);
- let player = this.getLocalPlayerByIndex(index);
- if(player && player.getChairID() != data.wWinChairID) {
- if(this.cardNum(player.getOutCard()) == winCard) {
- player.playLightCardAni()
- }
- }
- }
- }else{
- let player = this.getLocalPlayerByChairId((data.wWinChairID+2)%GameProtocol.GAME_PLAYER);
- if(player && this.cardNum(player.getOutCard()) == winCard && winCard != this._MagicCardData) {
- player.playLightCardAni()
- }
- }
- cc.tween(this.node)
- .delay(1.5)
- .call(()=>{
- upWinState();
- })
- .start()
- },
- OnRoundStart(data) {
- Global.print("Truco 小局开始 " + JSON.stringify(data));
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return;
- }
- this.resetRound();
- this._isPlaying = true;
- this._bLastRound = false;
- this._roundStarting = true;
- this._needDelaySet = true;
- this._gameState = GameState.ROUNDSTART;
- this._gameInfoJS.setMagicCardValue(0);
- this._gameInfoJS.upNowScore(0);
- this._gameInfoJS.upRoundScore(data.cTotalScore);
- this.leftNode.active = true;
- let magicCard = this.leftNode.getChildByName("cardl");
- magicCard.getComponent("TrucoCard").setId(0, 0);
- magicCard.scale = 0.42;
- magicCard.angle = 0;
- magicCard.position = cc.v2(0, 0);
- magicCard.active = false;
- this._MagicCardData = data.cbMagicCardValue;
- let handCard = data.cbCardData;
- selfPlayer.changeMingCard(true);
- selfPlayer.setHandCards(handCard, handCard.length);
- let bEnd = data.cTotalScore[0] == data.cTotalScore[1] && data.cTotalScore[0] == 11;
- this.showPePlayer(data.wCurrentUser);
- this.shuffleAniNode.active = true;
- let ani = this.shuffleAniNode.getComponent(sp.Skeleton);
- ani.clearTracks();
- ani.setAnimation(0, "a1", false);
- var next = ()=>{
- if(data.cbFinalRound == 1) {
- let ppID = (selfPlayer.getChairID()+this._myTeam-data.cbFinalTeam+GameProtocol.GAME_PLAYER)%GameProtocol.GAME_PLAYER;
- for (let i = 0; i < GameProtocol.SIDE_NUM; i++) {
- let pid = (ppID + i * 2)%GameProtocol.GAME_PLAYER;
- var index = this.getPlayerIndex(pid);
- var player = this.getLocalPlayerByIndex(index);
- if (player) {
- player.playTimeAction(data.cbTimeCount);
- }
- }
- }else{
- this.SetCurrentUser(data.wCurrentUser, data.cbTimeCount);
- }
- }
- var openMagicCard = ()=>{
- magicCard.active = true;
- magicCard.getComponent("TrucoCard").setId(data.cbMagicShowCardData, 0);
- cc.tween(magicCard)
- .to(0.3, {angle: 18, x: -74})
- .call(()=>{
- // next();
- this.SetCurrentUser(data.wCurrentUser, data.cbTimeCount);
- this._gameInfoJS.setMagicCardValue(data.cbMagicCardValue);
- this._gameInfoJS.upNowScore(1);
- this._roundStarting = false;
- this._gameState = GameState.OUTCARD;
- this._needDelaySet = false;
- })
- .start()
- }
- var openCard = ()=>{
- for(let i = 0; i < selfPlayer.cardsNode.childrenCount; ++i) {
- let card = selfPlayer.cardsNode.children[i];
- if(card){
- let scale = card.scale;
- cc.tween(card)
- .delay(0.1*i)
- .to(0.1, {scaleX: 0})
- .call(()=>{
- // let cardId = handCard[i];
- card.getComponent("TrucoCard").setId(handCard[i], this._MagicCardData);
- })
- .to(0.1, {scaleX: scale})
- .start()
- }
- }
- cc.tween(this.node)
- .delay(0.5)
- .call(()=>{
- openMagicCard();
- })
- .start()
- }
-
- let cardIdx = 0;
- var sendCard = ()=>{
- if(cardIdx >= 3) {
- this.unschedule(sendCard);
- setTimeout(()=>{
- if(bEnd) {
- selfPlayer.changeMingCard(false);
- selfPlayer.resetHandCardPos();
- openMagicCard();
- }else
- openCard();
- }, 300)
- }
- SoundFun.playEffectEX(SoundFun.SENDCARD);
- for(let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
- let index = this.getPlayerIndex(i);
- let player = this.getLocalPlayerByIndex(index);
- if(player) {
- player.oneCardMove(cardIdx);
- player.setMagicCardValue(this._MagicCardData);
- }
- }
- cardIdx++;
-
- }
- cc.tween(this.node)
- .delay(1.4)
- .call(()=>{
- // sendCard();
- this.leftNode.getChildByName("cardNode").active = true;
- this.schedule(sendCard, 1/60);
- })
- .start()
- },
- OnGameOperareOutCard(data) {
- Global.print("RUMMY 操作失败 " + JSON.stringify(data));
- this._gameEnd = false;
- this._isPlayingAni = false;
- var cbFailCode = data.cbFailCode;
- this.resetHandCards();
- return;
- if(cbFailCode == 100){//长时间没操作踢出房间
- Global.print("长时间没操作踢出房间");
- this._willExit_LongTimeNoOperation = true;
- return;
- }
- /*
- 出牌失败:
- 0 状态不是游戏状态!
- 1 还没轮到您操作!
- 2 出牌之前请先抓牌!
- 3 出牌数据异常!
- 4 手牌没有出的这张牌!!
- 5 组合数超出最大范围
- 6 有错误组合,牌数量错误
- 7 有错误组合,牌数据异常
- 8 有错误组合,手牌没有这张牌
- 9 牌总数错误
- ==============================
- 操作错误:
- 20 状态不是游戏状态!
- ==============================
- 获取牌组错误:
- 30 状态不是游戏状态!
- ==============================
- 放弃错误:
- 40 状态不是游戏状态!
- 41 还没轮到您操作!
- 42 您本回合已经抓过牌,不能申请放弃!
- */
- //出牌失败:
- if(cbFailCode == 0){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_dqbsyxzt);
- }else if(cbFailCode == 1){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_hmldncz);
- }else if(cbFailCode == 2){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_cpzqqxzp);
- }else if(cbFailCode == 3){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_cpsjyc);
- }else if(cbFailCode == 4){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_spzmycdzzp);
- }else if(cbFailCode == 5){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_zhscczdfw);
- }else if(cbFailCode == 6){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_ycwzhpcw);
- }else if(cbFailCode == 7){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_ycwzhpyc);
- }else if(cbFailCode == 8){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_ycwzhmyzzp);
- }else if(cbFailCode == 9){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_pzscw);
- }
- //获取记录失败:
- else if(cbFailCode == 20){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_dqbsyxzt);
- }
- //获取牌组失败:
- else if(cbFailCode == 30){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_dqbsyxzt);
- }
- //放弃失败:
- else if(cbFailCode == 40){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_dqbsyxzt);
- }else if(cbFailCode == 41){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_hmldncz);
- }else if(cbFailCode == 42){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_yjzgpbnfq);
- }
- //抓牌失败:
- else if(cbFailCode == 40){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_dqbsyxzt);
- }else if(cbFailCode == 41){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_hmldncz);
- }else if(cbFailCode == 42){
- topTipMsg.showTopTipMsg(LanguageKey.Rummy.TopTip_yjzgp);
- }
- this._readyOutCard = null;
- },
- OnGameOutCard(data) {
- Global.print("TRUCO 玩家出牌 " + JSON.stringify(data));
- this._gameEnd = false;
- this._isOutCarding = true;
- this._canOutCard = false;
- this._needDelaySet = false;
- this._gameState = GameState.OUTCARD;
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return false;
- }
- if(data.wCurrentUser < 0) { //本轮出牌完毕
- this._needDelaySet = true;
- this._gameState = GameState.COMPARECARD;
- }
- this.hideBtns();
- this._outCard = data.cbOutCardData;
- let nowTime = new Date().getTime();
- var setUser = ()=>{
- this._isOutCarding = false;
- //-1 表示小轮结束,需要比牌
- if(data.wCurrentUser >= 0)
- this.SetCurrentUser(data.wCurrentUser, data.cbTimeCount);
- else if(this._compareData){
- this.OnCompareCard(this._compareData);
- }
- }
- if(this.cardNum(this._outCard) == this._MagicCardData) {
- SoundFun.playEffectEX(SoundFun.OUTKING);
- }else{
- SoundFun.playEffectEX(SoundFun.CARD);
- }
- var index = this.getPlayerIndex(data.wOutCardUser);
- var player = this.getLocalPlayerByIndex(index);
- if(player){
- player.hideTimeNode();
- player.outOneCard(this._outCard, this._MagicCardData);
- }
- setTimeout(()=>{
- setUser();
- }, 800)
- },
- OnCellScore(data) {
- Global.print("TRUCO OnCellScore " + JSON.stringify(data));
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return false;
- }
- SoundFun.playEffectEX(SoundFun.ADDBET);
- let startPos = [cc.v2(-367,-340), cc.v2(-561,0), cc.v2(-77,300), cc.v2(575,0)];
- let endPos = cc.v2(-642,324);
- endPos.x -= cc.winSize.width/2-812;
- let coinNode = this.node.getChildByName("CoinNode");
- coinNode.active = true;
- for(let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
- let coin = coinNode.getChildByName("coin"+i);
- if(coin) {
- coin.position = startPos[i];
- coin.active = true;
- cc.tween(coin)
- .to(0.3, {position: endPos})
- .call(()=>{
- coin.active = false;
- })
- .start()
- }
- }
- cc.tween(coinNode)
- .delay(0.3)
- .call(()=>{
- this._gameInfoJS.upBetScore(data.nMulti);
- })
- .start()
- },
- OnFinalRound(data) {
- Global.print("TRUCO OnFinalRound " + JSON.stringify(data));
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return false;
- }
- this._bLastRound = true;
- let dPlayer = this.getLocalPlayerByIndex(2);
- if(!dPlayer) {return;}
- if(data.cbFinalRound == 2) {
- selfPlayer.changeMingCard(false);
- dPlayer.changeMingCard(false);
- dPlayer.setHandCards(data.cbTeamCardData, data.cbTeamCardData.length, true);
- // dPlayer.playTimeAction(data.cbTimeCount);
- }
- if(data.cbFinalRound == 1) {
- this.hideAllTimes();
- if(data.cbFinalTeam == this._myTeam) {
- this.showTrucoBtns(true);
- selfPlayer.playTimeAction(data.cbTimeCount);
- dPlayer.changeMingCard(true);
- dPlayer.setHandCards(data.cbTeamCardData, data.cbTeamCardData.length, true);
- dPlayer.playTimeAction(data.cbTimeCount);
- }else{ //展示对方两家的时间倒计时
- let ppID = (selfPlayer.getChairID()+this._myTeam-data.cbFinalTeam+GameProtocol.GAME_PLAYER)%GameProtocol.GAME_PLAYER;
- for (let i = 0; i < GameProtocol.SIDE_NUM; i++) {
- let pid = (ppID + i * 2)%GameProtocol.GAME_PLAYER;
- var index = this.getPlayerIndex(pid);
- var player = this.getLocalPlayerByIndex(index);
- if (player) {
- player.playTimeAction(data.cbTimeCount);
- }
- }
- }
- }
-
-
- // let dPlayer = this.getLocalPlayerByIndex(2);
- // if(dPlayer) {
- // dPlayer.changeMingCard(true);
- // dPlayer.setHandCards(data.cbTeamCardData, data.cbTeamCardData.length, true);
-
- // }
- },
- OnFinalChoose(data) {
- Global.print("TRUCO OnFinalChoose " + JSON.stringify(data));
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return false;
- }
- let dPlayer = this.getLocalPlayerByChairId(data.wFinalUser);
- if(dPlayer) {
- dPlayer.showTrucoChoose(data.cbFinalChoose);
- dPlayer.hideTimeNode();
- }
- if(selfPlayer == dPlayer) {
- this.showTrucoBtns(false);
- }
- if(data.cbFinalChoose == 1) {
- SoundFun.playEffectEX(SoundFun.TRUCO_TY);
- // this._gameInfoJS.upNowScore(3);
- this._trucoScore = 3;
- }else{
- SoundFun.playEffectEX(SoundFun.TRUCO_FQ);
- }
- },
- onClickTruco() {
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return false;
- }
- var data = {};
- this.SendGameSocketData(GameProtocol.SUB_C_TRUCO,data);
- },
- onClickTrucoChoose:function(type){
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return false;
- }
- var data = {cbChoose: type};
- if(this._bLastRound) {
- this.SendGameSocketData(GameProtocol.SUB_C_FINAL_CHOOSE,data);
- return;
- }
- this.SendGameSocketData(GameProtocol.SUB_C_TRUCO_CHOOSE,data);
- },
- isTurnSelf:function(){
- var selfPlayer = this.getSelfPlayer();
- if (!selfPlayer) {
- return false;
- }
- if (this._CurrentUser == selfPlayer.getChairID()) {
- return true;
- }
- return false;
- },
- reqUserInfo:function(userID){
- if (!this.m_kReqPlayerInfo) {
- this.m_kReqPlayerInfo = new CGPIndividualMission({ URL: cc.vv.config.Address, Port: cc.vv.config.Port });
- this.m_kReqPlayerInfo.setMissionSink(this);
- }
- this.m_kReqPlayerInfo.queryIndividual(userID);
- },
- updateUserInfo: function (kNetInfo) {
- Global.print("Rummy onGPAccountInfoHttpIP! kNetInfo.UserID = " + JSON.stringify(kNetInfo));
-
- },
- //初始化玩家信息
- initPlayers: function (playerCnt) {
- // console.log('playerCnt', playerCnt);
- if (this._players.length > 0) {
- return;
- }
- this._localPlayer = this.playerNode.getChildByName("Player0");
- var selfPlayer = this.getSelfPlayer();
- if (!selfPlayer) {
- return;
- }
- for (let i = 0; i < GameProtocol.GAME_PLAYER; i++) {
- var playerjs = this.playerNode.getChildByName("Player" + i).getComponent("TrucoPlayer");
- if (playerjs && playerjs.node) {
- playerjs.node.active = true;
- }
- }
- for (let i = 0; i < playerCnt/*GameProtocol.GAME_PLAYER*/; i++) {
- var index = this.getPlayerIndex(i);
- var playerjs = this.playerNode.getChildByName("Player" + index).getComponent("TrucoPlayer");
- if (!playerjs) {
- continue;
- }
- var gamePlayer = this.getPlayerByChairID(i);
- if (gamePlayer) {
- playerjs.setUserItem(gamePlayer.getUserItem());
- playerjs.playerEnter();
- playerjs.upPlayerInfo();
- playerjs.upPlayerState();
- }
- this._players.push(playerjs);
- }
- },
- //得到玩家的index标识 (0:下,1:左,2:上,3:右)
- getPlayerIndex: function (seatId) {
- var selfPlayer = this.getSelfPlayer();
- if (!selfPlayer) {
- return;
- }
- if (seatId == selfPlayer.getChairID()) {
- return 0;
- }
- // switch(seatId){
- // case 1:
- // return 3;
- // break;
- // case 2:
- // return 2;
- // break;
- // case 3:
- // return 1;
- // break;
- // }
- var index = (GameProtocol.GAME_PLAYER + seatId - selfPlayer.getChairID()) % GameProtocol.GAME_PLAYER;
- return index;
- },
- onUserEnter(clientUserItem) {
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return;
- }else{
- if(this._offlineNode){
- this._offlineNode.getComponent("OfflineNodeJS").showWait();
- this._isOffLine = false;
- }
- }
- var index = this.getPlayerIndex(clientUserItem.GetChairID());
- var player = this.getLocalPlayerByIndex(index);
- if (player) {
- player.setUserItem(clientUserItem);
- player.playerEnter();
- player.upPlayerInfo();
- player.upPlayerHead();
- player.upPlayerState();
-
- }
- },
- onUserLeave(clientUserItem) {
- if (Global.IsEmpty(clientUserItem)) {
- return;
- }
- if (!this.getSelfPlayer()) {
- if(this._gameEnd) {
- return;
- }
- Global.print("onUserLeave 自己已经离开当前房间");
- Global.print("onUserLeave :" + this._isPlaying);
- this.stopCountdown();
- this.unschedule(this.updataMobileTime);
- if(CServerItem.get().IsService()){// 区别断网
- Global.print("onUserLeave exitGame");
- ScenceManager.Instance().gameBackScence();
- GameManagerBase.Instance().setInGameServerID(-1);
- this.exitGame();
- }else
- {
- if(this._isPlaying){
- var self = this;
- cc.resources.load("GamePrefabs/homescence/OfflineNode", cc.Prefab, function (err, prefab) {
- if (!self._offlineNode) {
- self._offlineNode = cc.instantiate(prefab);
- self._offlineNode.parent = self.node;
- }
- self._offlineNode.getComponent("OfflineNodeJS").showWait();
- });
- /*var Ok = function(){};
- popScence.initPopScence(LanguageKey.Rummy.TopTip_ConnectionFailure, this, Ok);*/
- var playerViewJS = this.node.getChildByName("Players").getChildByName("Player0").getComponent("TrucoPlayer");
- playerViewJS.setOffline(true);
- if(!this._isOffLine) {
- // cc.userOperate.sendRecord("Rummy2R-Number of disconnections");
- this._isOffLine = true;
- }
- }
- }
- return;
- }
- var player = this.getLocalPlayerByChairId(clientUserItem.GetChairID());
- if (player) {
- player.playerLeave();
- player.setUserItem(null);
- }
- },
- upPlayerInfo(clientUserItem) {
- var player = this.getLocalPlayerByChairId(clientUserItem.GetChairID());
- if (player) {
- player.setUserItem(clientUserItem);
- player.upPlayerInfo();
- }
- },
- upSelfPlayerInfo: function () {
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer) {
- return;
- }
- var clientUserItem = selfPlayer.getUserItem(false);
- if (!clientUserItem) {
- return;
- }
- var userInfo = clientUserItem.GetUserInfo();
- userInfo.szUnderWrite = cc.vv.globalUserInfo.getAutoGraph();
- selfPlayer.upPlayerInfo();
- return;
- },
- upPlayerHead(clientUserItem) {
- var player = this.getLocalPlayerByChairId(clientUserItem.GetChairID());
- if (player) {
- player.setUserItem(clientUserItem);
- player.upPlayerHead();
- }
- },
- upPlayerState(clientUserItem) {
- var player = this.getLocalPlayerByChairId(clientUserItem.GetChairID());
- if (player) {
- player.setUserItem(clientUserItem);
- player.upPlayerState();
- var status = player.getUserStatus();
- if(this.isSelf(player)){
- }
- }
- },
- getLocalPlayerByChairId: function (chairId) {
- for (let index = 0; index < this._players.length; index++) {
- const element = this._players[index];
- if (element.getChairID() == chairId) {
- return element;
- }
- }
- return null;
- },
- getLocalPlayerByIndex: function (index) {
- for (let i = 0; i < this._players.length; i++) {
- const element = this._players[i];
- if (element.getIndex() == index) {
- return element;
- }
- }
- return null;
- },
- //得到DSMJGamePlayer (是GamePlayer的派生类)
- getSelfLocalPlayer: function () {
- if(this._willExit_LackOfGold) {
- return this._players[0];
- }
- for (let index = 0; index < this._players.length; index++) {
- const element = this._players[index];
- if (this.isSelf(element)) {
- return element;
- }
- }
- return null;
- },
- getLocalPlayerByUserID: function(userID)
- {
- for (let index = 0; index < this._players.length; index++) {
- const element = this._players[index];
- if (element.getUserID() == userID) {
- return element;
- }
- }
- return null;
- },
- showHeadInfo(player) {
- // GameHeadInfo
- if (player != null) {
- var selfPlayer = this.getSelfLocalPlayer();
- if (!selfPlayer || !player.getUserItem() || this.isSelf(player)) {
- return;
- }
- var self = this;
- UIHelper.loadRes("resourcesPrefab/GameHeadInfo", cc.Prefab, function (prefab) {
- if (!self._GameHeadInfo) {
- self._GameHeadInfo = cc.instantiate(prefab);
- self._GameHeadInfo.parent = self.node;
- var GameHeadInfoJS = self._GameHeadInfo.getComponent("GameHeadInfo");
- if (!GameHeadInfoJS) {
- self._GameHeadInfo.addComponent("GameHeadInfo");
- }
- }
- self._GameHeadInfo.getComponent("GameHeadInfo").show(player);
- // let currentGame = Global.getLocalStorageVaule("GoldCurrentGame");
- // let gameName = GameConstant.getGameNameByByKey(currentGame);
- // if (gameName) {
- // cc.userOperate.sendRecord(gameName + "-Click on the avatar");
- // }
- });
- }
- },
- OnSocketSubProtectBack: function (bLookonUser, data) {//低保信息
- if (bLookonUser) {
- return;
- }
- var selfPlayer = this.getSelfPlayer();
- if (!selfPlayer) {
- return;
- }
- if (data.dwUserId != selfPlayer.getUserID()) {
- var player = this.getLocalPlayerByChairId(this.getPlayerByUserID(data.dwUserId).getChairID());
- player.setUserScore(data.nCurScore);
- player.setScore(data.nCurScore);
- return;
- }
- selfPlayer.setUserScore(data.nCurScore);
- selfPlayer.setScore(data.nCurScore);
- selfPlayer.upPlayerInfo();
- return true;
- },
- onGameServerItem:function(gameServerItem) {
- GameBase.prototype.onGameServerItem.apply(this, [gameServerItem]);
- if (GameManagerBase.Instance().IsGoldGame()) {
-
- }
- },
- //聊天协议
- revTalk: function (data) {//
- var databuf = ProtocolGameServer.CMD_GR_C_TableTalk.data();
- var dataView = new DataView(data);
- dataView.pos = 8;
- databuf.Type = Global.GetUint8(dataView);
- databuf.ChairID = Global.GetUint8(dataView);
- databuf.String = Global.Read2CharUtf(dataView, 128);
- databuf.TalkSize = Global.GetInt32(dataView);
- databuf.TalkData = Global.Read2Char(dataView, data.byteLength - databuf.pos);
- Global.print(databuf);
- var player = this.getLocalPlayerByChairId(databuf.ChairID);
- if (player != null) {
- player.showTalkState(databuf);
- }
- },
- revVoice: function (data) {
- var databuf = ProtocolGameServer.CMD_GR_TabelVoice.data();
- var dataView = new DataView(data);
- dataView.pos = 8;
- databuf.ChairID = Global.GetUint8(dataView);
- databuf.SerVerID = Global.Read2String(dataView);
- Global.print("收到语音消息::");
- Global.print(databuf);
- var player = this.getLocalPlayerByChairId(databuf.ChairID);
- if (player != null) {
- player.showVoice(databuf);
- }
- var curTime = new Date();
- var filePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + curTime.getTime() + '.ptt');
- this.node.getComponent("TrucoFuncBtnMgr").getAr().downloadRecordedFile(databuf.SerVerID, filePath);
- },
- hideVoice: function () {
- for (let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
- var player = this.getLocalPlayerByChairId(i);
- if (player != null) {
- player.hideVoice();
- }
- }
- },
- ////////////////////////////////////////////////////////////////////////////
- //银行信息
- OnSocketSubUserInsureInfo: function (pNetInfo) {
- var selfPlayer = this.getSelfPlayer();
- if (!selfPlayer) {
- return;
- }
- this.showBank(pNetInfo);
- },
- OnSocketSubUserInsureSuccess: function (pNetInfo) {
- var selfPlayer = this.getSelfPlayer();
- if (!selfPlayer) {
- return;
- }
- selfPlayer.setScore(pNetInfo.UserScore);
- selfPlayer.setUserScore(pNetInfo.UserScore);
- cc.vv.globalUserInfo.setUserScore(pNetInfo.UserScore);
- cc.vv.globalUserInfo.setBankScore(pNetInfo.UserInsure);
- if (this._bankNode) {
- this._bankNode.active = false;
- }
- //TODO ENDTIP
- if (pNetInfo.cbType == 0) { //银行正常操作
- } else if (pNetInfo.cbType == 1) { //存钱继续
- if (this._goldUnusual) {
- this._goldUnusual.active = false;
- }
- GameManagerBase.Instance().connectGameServer(this._gameServerItem);
- } else if (pNetInfo.cbType == 2) { //取钱继续
- if (this._goldUnusual) {
- this._goldUnusual.active = false;
- }
- GameManagerBase.Instance().connectGameServer(this._gameServerItem);
- }
- },
- OnSocketSubUserInsureFailure: function (pNetInfo) {
- var selfPlayer = this.getSelfPlayer();
- if (!selfPlayer) {
- return;
- }
- var str = Global.gbk2Utf8(pNetInfo.DescribeString);
- //Global.print(str);
- this._bankNode.active = false;
- topTipMsg.showTopTipMsg(LanguageKey.Public.TopTip_yxzbnck);
- //topTipMsg.showTopTipMsg("游戏中不能存款");
- },
- showBank: function (data) {
- var self = this;
- /*cc.resources.load("GamePrefabs/homescence/BankNode", cc.Prefab, function (err, prefab) {
- if (!self._bankNode) {
- self._bankNode = cc.instantiate(prefab);
- self._bankNode.parent = self.node;
- self._bankNode.addComponent("bankSence");
- }
- self._bankNode.getComponent("bankSence").showBankNode(data, true);
- });*/
- },
- //初始化UI
- initView: function () {
- },
- defaultPrivateState: function () {
- },
- //返回大厅
- backHome: function () {
- if (CServerItem.get()) {
- CServerItem.get().PerformStandUpAction(1);
- } else {
- this.exitGame();
- }
- this.unschedule(this.nextRecordAction);
- this.unschedule(this.updataMobileTime);
- ScenceManager.Instance().gameBackScence();
- GameManagerBase.Instance().setInGameServerID(-1);
- },
- //解散房间
- dissmissRoom: function (bAgree) {
- },
- exitGameWhenPlaying: function () {
- var self = this;
- if (this.getSceneState()) {
- // this.node.getChildByName("tipNode").active = true;
- // this.node.getChildByName("tipNode").getComponent(cc.Animation).play("showTipNode");
- topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.not_exit_game"));
- } else {
- if(cc.vv.config.ReviewApk) {
- cc.game.end();
- return;
- }
- this.backHome();
- this.exitGame();
- this._isPlaying = false;
- }
- },
- makeXieYi: function (m, s, data) {
- return MakeXieYi.makeGameData(m, s, data);
- },
- isRecord: function() {
- return false;
- },
- _GameHeadInfoCB(msg) {
- // this.showHeadInfo(this.getPlayerByUserID(msg.userID));
- var self = this;
- UIHelper.loadRes("resourcesPrefab/GameHeadInfo", cc.Prefab, function (prefab) {
- if (!self._GameHeadInfo) {
- self._GameHeadInfo = cc.instantiate(prefab);
- self._GameHeadInfo.parent = self.node;
- var GameHeadInfoJS = self._GameHeadInfo.getComponent("GameHeadInfo");
- if (!GameHeadInfoJS) {
- self._GameHeadInfo.addComponent("GameHeadInfo");
- }
- }
- self._GameHeadInfo.getComponent("GameHeadInfo").playMemeAni(msg);
- });
- },
- onSocketSubExchangeRoom(data) {
- if (data.cbReason == 1 || data.cbReason == 2) {
- var self = this;
- var OK = function () {
- self.backHome();
- self.exitGame();
- }
- popScence.initPopScence("Not enough chips,you can't continue the game", this, OK);
- }
- },
- LackOfGoldWillExitGame: function(type) {
- this._willExit_LackOfGold = true;
- this.willExit = ()=>{
- if (type == "low") {
- popScence.initPopScence(LanguageKey.t("pubWords.money_notenghou"), this, () => { this.backHome() });
- } else {
- popScence.initPopScence(LanguageKey.t("pubWords.money_somore"), this, () => { this.backHome() });
- }
- GameManagerBase.Instance().setInGameServerID(-1);
- }
- if(!this._gameEnd) {
- this.willExit();
- }
-
- },
- //唯一对局码
- onSocketUpdateUniqueCode(data){
- Global.print("RUMMY 唯一对局码 " + JSON.stringify(data));
- this.node.getChildByName("RoomInfo").getChildByName("GameId").active = BaseDefine.LOCALTEST;
- this.node.getChildByName("RoomInfo").getChildByName("GameId").getComponent(cc.Label).string = data.strUniqueCode;
- },
- update(dt) {
- //TODO GOLDSCENE
- if (CServerItem.get().GetServerAttribute().wServerType == Define.GAME_GENRE_GOLD) {
- this._changeTableLimit -= dt;
- }
- this._delayEvalTimes -= dt;
- if(this._delayEvalTimes <= 0) {
- if(this._msgCallback.length > 0) {
- let info = this._msgCallback.shift();
- info.call(info.data);
- if(this.msgDelayTime[info.id] > 0) {
- this._delayEvalTimes = this.msgDelayTime[info.id];
- }
- }
- }
- },
- runCountdown:function(LabelNode,time,callFunc){
- this.stopCountdown();
- this._countdown = time;
- LabelNode.active = true;
- //var skt = LabelNode.getComponent(sp.Skeleton);
- LabelNode.getChildByName("Label").getComponent(cc.Label).string = this._countdown;
- this.timeCallback = function(){
- self._countdown = self._countdown-1;
- LabelNode.getChildByName("Label").getComponent(cc.Label).string = self._countdown;
- if(self._countdown < 0){
- //skt.setAnimation(0,"a1",true);
- LabelNode.active = false;
- if(callFunc){
- callFunc();
- callFunc = null;
- }
- self.stopCountdown();
- }else if(self._countdown <= 3){
- //skt.setAnimation(0,"a2",true);
- SoundFun.playEffectEX(SoundFun.EX_COUNTDOWN);
- }
- }
- var self = this;
- this.schedule(this.timeCallback,1);
- },
- stopCountdown:function(){
- this.unschedule(this.timeCallback);
- this.timeCallback = null;
- },
- getFuncBtnComponent: function(){
- return this.node.getComponent("TrucoFuncBtnMgr");
- },
- sendTalkBiaoqing: function(memeIdx){
- let ichair = this.getSelfPlayer().getChairID();
- var data = ProtocolGameServer.CMD_GR_C_TableTalk.data();
- data.ChairID = ichair;
- data.Type = ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_BIAOQING;
- data.String = memeIdx.toString();
- this.sendTalkDefineSocketData(ProtocolGameServer.SUB_GR_TABLE_TALK,data);
- },
- sendInputTxt: function(txt){
- let ichair = this.getSelfPlayer().getChairID();
- var data = ProtocolGameServer.CMD_GR_C_TableTalk.data();
- data.ChairID = ichair;
- data.Type = ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_WORD;
- data.String = txt;
- this.sendTalkDefineSocketData(ProtocolGameServer.SUB_GR_TABLE_TALK,data);
- },
- });
|