var GameBase = require("GameBase"); var ProtocolGameServer = require("ProtocolGameServer"); var GameProtocol = require("BRTPGameProtocol"); var AnalyzeBRTPXieYi = require("AnalyzeBRTPXieYi"); var MakeBRTPXieYi = require("MakeBRTPXieYi"); var Global = require("Global"); var topTipMsg = require("topTipMsg"); var UIHelper = require("UIHelper"); var BaseDefine = require("BaseDefine"); var CGPFSActivity = require("CGPFSActivity"); import { CServerItem } from 'CServerItem' import GameManagerBase from 'GameManagerBase' import ScenceManager from 'HNScenceManager' var importInstance = {}; var BRTPSoundFun = require("BRTPSoundFun"); var popScence = require("popScence"); //游戏状态 var GameState = cc.Enum( { BRTP_STATE_NULL: 0, BRTP_STATE_FREE: 1, //空闲状态 BRTP_STATE_CHIP: 2, //下注状态 BRTP_STATE_END: 3, //结算状态 } ) cc.Class({ extends: GameBase, properties: { //玩家信息 playerNode: cc.Node, playerPrefab: cc.Node, pubCardNode: cc.Node, JettonPrefab: cc.Node, playListContent: cc.Node, BankerListContent: cc.Node, OperateRecordContent: cc.Node, // RecordPanel,记录列表根节点 TrendContent: cc.Node, // TrendPanel, 胜负列表根节点 jetonWinLost: [cc.SpriteFrame], mWifiSpfArr: [cc.SpriteFrame], mNormalSpfArr: [cc.SpriteFrame], ChipsSprite: [cc.SpriteFrame], // 筹码bg图 ChipsLabel: [cc.Font], // 筹码字体文件 cardAtlas: cc.SpriteAtlas, _seatPlayer: [],//主界面显示的6个玩家 _TotalNum: 0,//本局下注上限 _JetonNum: 0,//本局下注值 _AreaJetonTotal: [],//区域总下注 _AreaJetonSelf: [],//区域自己下注 _bankerUserId: -1,//庄家ID _SelfIsZhuang: false,//自己本局是否是庄家 _ZhuangChipArray: [],//庄家赢的筹码数组(动画用) _SeatArray: [],//坐着的6个玩家椅子号 //_players:[], _gameState: 0, _bIsRecord: false, _RecordActSpeed: 2, _goldZorder: 0, _alreadyJoin: false,//本局下注了 _noJoinCount: 0,//连续未下注次数 goldArr: [], _selfScore: 0,//自己本局可下注 _experienceStart: false,//经历过开始 _gameRecordData: null,//最新游戏记录数据 _gameWinLostData: null,//最新游戏输赢数据 _chipCache: [], // 下注记录缓存(用于续压) _chipRecord: [], // 下注记录 }, onLoad() { this.initConfig(); this.initLogic(); this.initUI(); // if (importInstance.GameManagerBase.IsGoldGame()) {//金币场 // this.setMenuBtnVisibleArr({"dissMiss":false,"back":true,"set":true,"help":true,"auto":false,"bank":false,"location":false}) // } cc.game.once(cc.game.EVENT_HIDE, () => { if (this.node.active == false || this.node.parent == null) { return; } GameManagerBase.Instance().disconnectServer(); }); cc.game.once(cc.game.EVENT_SHOW, () => { if (this.node.active == false || this.node.parent == null) { return; } GameManagerBase.Instance().connectServer(); }); }, initConfig() { importInstance = { CServerItem: CServerItem.get(), ScenceManager: ScenceManager.Instance(), GameManagerBase: GameManagerBase.Instance(), get CServerItem() { return this._CServerItem ? this._CServerItem : CServerItem.get() }, get ScenceManager() { return this._ScenceManager ? this._ScenceManager : ScenceManager.Instance() }, get GameManagerBase() { return this._GameManagerBase ? this._GameManagerBase : GameManagerBase.Instance() }, } this.gameMessageConfig = {}; this.preGameMessageConfig = { "SUB_S_GAME_FREE": { print: "BRTP::游戏空闲", functions: "OnGameFree" }, "SUB_S_GAME_START": { print: "BRTP::游戏开始", functions: "OnGameStart" }, "SUB_S_PLACE_JETTON": { print: "BRTP::玩家下注", functions: "OnGameJetonSelf" }, "SUB_S_GAME_END": { print: "BRTP::游戏结束", functions: "OnGameEnd" }, "SUB_S_APPLY_BANKER": { print: "BRTP::申请庄家成功", functions: "OnApplyBanker" }, "SUB_S_APPLEY_BANKER_FAILURE": { print: "BRTP::申请庄家失败", functions: "OnFailInfo" }, "SUB_S_CANCEL_BANKER": { print: "BRTP::取消庄家成功", functions: "OnCancelBanker" }, "SUB_S_CANCEL_FAILURE": { print: "BRTP::取消庄家失败", functions: "OnFailInfo" }, "SUB_S_CHANGE_BANKER": { print: "BRTP::切换庄家", functions: "setZhuangInfo" }, "SUB_S_BANK_LIST": { print: "BRTP::庄家列表", functions: "onReceiveBankerList" }, "SUB_S_SEND_RECORD": { print: "BRTP::游戏记录", functions: (msg) => { this._gameResultRecords = msg; this._experienceStart ? (this._gameRecordData = msg) : this.OnGameRecord(msg); } }, "SUB_S_SEND_WINLOST": { print: "BRTP::游戏输赢", functions: (msg) => { this._experienceStart ? (this._gameWinLostData = msg) : this.OnWinLost(msg); } }, "SUB_S_PLACE_JETTON_FAIL": { print: "BRTP::下注失败", functions: "OnFailInfo" }, "SUB_S_ONLINE_PLAYER": { print: "BRTP::在线用户", functions: null }, "SUB_S_OTHER_JETTON": { print: "BRTP::其它玩家下注", functions: "OnGameJetonOther" }, "SUB_S_SEAT_JETTON": { print: "BRTP::占位玩家下注", functions: "OnGameJetonOther" }, "SUB_S_SEND_CONTROL_INFO": { print: "BRTP::群控信息", functions: "onSubSendControlInfo" }, "SUB_S_GAME_RECORD_INFO": { print: "BRTP::操作记录", functions: "showOperateRecordPanel" }, }; for (let i = 0, keys = Object.keys(this.preGameMessageConfig); i < keys.length; i += 1) { this.gameMessageConfig[GameProtocol[keys[i]]] = this.preGameMessageConfig[keys[i]]; } }, initLogic() { this._chipPool = new cc.NodePool(); // 筹码池 this.registerTouchEventHandle(); }, initUI() { let PubCardNode = this.node.getChildByName("PubCardNode"); let PourBtnList = this.node.getChildByName("PourBtnList"); let TrendNode = this.node.getChildByName("RecordNode").getChildByName("TrendNode"); let layout = PourBtnList.getComponent(cc.Layout); layout.spacingX = (cc.winSize.width / 1.61305 - 197 * 4) / 3; layout.updateLayout(); for (let i = 0; i < 4; i += 1) { let node1 = PubCardNode.children[i]; let node2 = TrendNode.children[i]; node1.x = PourBtnList.children[i].x; node2.x = PourBtnList.children[i].x; if (i == 0) { node1.x = PourBtnList.children[i].x - 15; node2.x = PourBtnList.children[i].x - 15; } else if (i == 3) { node1.x = PourBtnList.children[i].x + 15; node2.x = PourBtnList.children[i].x + 15; } } }, start() { BRTPSoundFun.playBackMusic(BRTPSoundFun.GAME_BACKGRUAND); // popScence.createPopScenceNode(); }, /*************************网络协议相关*****************************/ //场景消息 onEventSceneMessage(gameStatus, lookonUser, data) { Global.print("BRTPGameSence 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.GS_TK_FREE: { var msg = AnalyzeBRTPXieYi.analyze_StatusFree(dataView); Global.print("BRTP:: onFreeScence......") this.onFreeScence(msg); } break; case GameProtocol.GS_TK_END: case GameProtocol.GS_TK_CHIP: { Global.print("BRTP:: onPlayScence......") var msg = AnalyzeBRTPXieYi.analyze_StatusPlay(dataView); this.onPlayScence(msg); } break; default: { Global.print("BRTPGameSence onEventSceneMessage error "); } break; }; }, //游戏消息 onEventGameMessage(data) { let arr = new DataView(data.slice(0, 8)); let dataView = new DataView(data.slice(8)); let msgHead = { m: arr.getUint16(4, true), s: arr.getUint16(6, true), d: null }; let msg = AnalyzeBRTPXieYi.analyzeData(msgHead.m, msgHead.s, dataView); let config = this.gameMessageConfig[msgHead.s]; if (config) { let print = config.print; let functions = config.functions; print && Global.print(config.print); typeof functions === 'function' ? functions(msg) : this[functions](msg); } else { Global.print("BRTPGameSence onEventGameMessage error "); } }, getSceneState() { return this._gameState; }, //断线续连 onFreeScence(msg) { var selfPlayer = this.getSelfPlayer(); if (!selfPlayer) { return; } this._alreadyJoin = false; this._noJoinCount = 0; this._experienceStart = false; this._selfScore = 0; this._chipConfig = msg.nChip; // 可投掷筹码配置,服务器控制 this.resetView(); this.initPourChips(); // 初始化下注配置 this.initPlayers(); this.initPlayerData(msg.wSeatUser); this.setZhuangInfo(msg.wBankerUser, false); this._TotalNum = (msg.lBankerScore / 5).toFixed(2);//msg.lAreaLimitScore;//本局最大可下注数量 this._gameState = GameState.BRTP_STATE_FREE; this.updateState(msg.cbTimeLeave); }, //返水信息同步 onSocketBetInfoSync(data) { if (this.FS_interval) { clearInterval(this.FS_interval); } this.bJoin = (data.dwNowBet > 0);//data.bJoin;//是否参与过 this._recharge = (data.dwRecharge > 0) ? true : false;//是否充值过 cc.find("BetNode/Bet", this.node).active = true; let FingerAniNode = cc.find("BetNode/Bet/FingerAni", this.node); this._NowBet = data.dwNowBet; let BetAniNode = cc.find("BetNode/Bet/btn_Bet", this.node).getComponent(sp.Skeleton); if (BetAniNode.animation != "b3") { BetAniNode.setAnimation(0, "b1", true); cc.find("BetNode/Bet/info_2", this.node).getComponent(cc.Label).string = Global.formatString2Score(this._NowBet, 2); } cc.find("BetNode/Bet/info_3", this.node).getComponent(cc.Label).string = "Rebate:" + data.wRate + "%"; cc.find("BetNode/Bet/info_1", this.node).getComponent(cc.Label).string = "Cumulative bonus"; this._canCollect = false; this._timeStr = ""; var self = this; let nowTime = Date.parse(new Date()) + cc.vv.config.tSysTimeMilliseconds; let RewardTime = Date.parse(data.RewardTime); if (this.bJoin && nowTime >= RewardTime) {//可领取 if (BetAniNode.animation != "b3") { BetAniNode.setAnimation(0, "b2", true); } this._canCollect = true; cc.find("BetNode/Bet/info_1", this.node).getComponent(cc.Label).string = "You can get bonus"; cc.find("BetNode/Bet/btn_Bet/TimeNode", self.node).active = self.bJoin; cc.find("BetNode/Bet/btn_Bet/TimeNode/Time", self.node).getComponent(cc.Label).string = "00:00:00"; FingerAniNode.active = true; FingerAniNode.getComponent(sp.Skeleton).setAnimation(0, "a2", true); } else { let residueTime = RewardTime - nowTime; this.FS_interval = setInterval(function () { if (residueTime < 0) { clearInterval(self.FS_interval); if (self.bJoin) { if (BetAniNode.animation != "b3") { BetAniNode.setAnimation(0, "b2", true); } self._canCollect = true; cc.find("BetNode/Bet/info_1", self.node).getComponent(cc.Label).string = "You can get bonus"; FingerAniNode.active = true; FingerAniNode.getComponent(sp.Skeleton).setAnimation(0, "a2", true); } } residueTime -= 1000; let timeStr = Global.formatSeconds(residueTime / 1000); self._timeStr = timeStr; cc.find("BetNode/Bet/btn_Bet/TimeNode", self.node).active = self.bJoin; cc.find("BetNode/Bet/btn_Bet/TimeNode/Time", self.node).getComponent(cc.Label).string = timeStr; if (cc.find("BetNode/TipNode_cantCollect", self.node).active) { cc.find("BetNode/TipNode_cantCollect/rootNode/TimeInfo", self.node).getComponent(cc.Label).string = timeStr; } }, 1000); } }, //玩家返水信息 onSocketUpdateBetScore(data) { if (this._NowBet && this._NowBet == data.lGameBet) { return; } this._NowBet = data.lGameBet; let rebateNode = cc.find("BetNode/Bet/info_2", this.node); if (cc.find("BetNode/CollectNode", this.node).active) { let num = Global.formatString2Score(this._NowBet, 2); cc.find("BetNode/CollectNode/ChipNode/num", this.node).getComponent(cc.Label).string = parseFloat(num).toLocaleString(); } var self = this; if (this._NowBet > 0) { let BetAniNode = cc.find("BetNode/Bet/btn_Bet", this.node).getComponent(sp.Skeleton); BetAniNode.setAnimation(0, "b3", false); BetAniNode.setCompleteListener(function () { rebateNode.getComponent(cc.Label).string = Global.formatString2Score(self._NowBet, 2); if (self._canCollect) { BetAniNode.setAnimation(0, "b2", true); } else { BetAniNode.setAnimation(0, "b1", true); } }); } /*let PotOpenAni = cc.find("BetNode/PotOpenAni", this.node); PotOpenAni.active = true; PotOpenAni.getComponent(sp.Skeleton).setAnimation(0,"b3",false);*/ }, onBtnBet() { if (!this._recharge) { cc.find("BetNode/TipNode_notCharge", this.node).active = true; } else if (!this.bJoin) { cc.find("BetNode/TipNode_notJoin", this.node).active = true; } else if (!this._canCollect) { cc.find("BetNode/TipNode_cantCollect/rootNode/TimeInfo", this.node).getComponent(cc.Label).string = this._timeStr; cc.find("BetNode/TipNode_cantCollect", this.node).active = true; } else { cc.find("BetNode/CollectNode", this.node).active = true; let num = Global.formatString2Score(this._NowBet, 2); cc.find("BetNode/CollectNode/ChipNode/num", this.node).getComponent(cc.Label).string = parseFloat(num).toLocaleString(); } }, onBtnCloseTipNode(event) { if (event) { event.target.parent.parent.active = false; } }, onBtnCollect() { if (!this.m_CGPFSActivity) { this.m_CGPFSActivity = new CGPFSActivity({ URL: cc.vv.config.Address, Port: cc.vv.config.Port }); this.m_CGPFSActivity.setMissionSink(this); } this.m_CGPFSActivity.getBetDrawInfo(); }, onBtnCloseCollectNode() { cc.find("BetNode/CollectNode", this.node).active = false; }, //游戏场景重连 onPlayScence(msg) { var selfPlayer = this.getSelfPlayer(); if (!selfPlayer) { return; } this._alreadyJoin = false; this._noJoinCount = 0; this._experienceStart = false; this._selfScore = 0; this._chipConfig = msg.nChip; // 可投掷筹码配置,服务器控制 this.resetView(); this.initPlayers(); this.initPlayerData(msg.wSeatUser); this.setZhuangInfo(msg.wBankerUser, false); this.initPourChips(); // 初始化下注配置 this._TotalNum = (msg.lBankerScore / 5).toFixed(2); //msg.lBankerScore/10;//msg.lAreaLimitScore;//本局最大可下注数量 if (msg.cbStatus == 1) {//下注状态 this._gameState = GameState.BRTP_STATE_CHIP if (this._SelfIsZhuang) {//自己是庄 this.node.getChildByName("SelfZhuang").active = true; } else { var selfPlayerView = this.getSelfNode().getComponent("BRTPPlayerView"); this._selfScore = parseFloat(selfPlayerView.getScore() / 5); this.node.getChildByName("SelfZhuang").active = false; this.disabledPourChips(true); this.updateJetonBtn(); } // this.node.getChildByName("TIpNode").active = true; var AreaNode = this.node.getChildByName("PourBtnList"); for (let i = 0; i < GameProtocol.AREA_MAX; i++) { AreaNode.children[i].getChildByName("SelfScore").active = true; AreaNode.children[i].getChildByName("AllPlayerScore").active = true; AreaNode.children[i].getChildByName("bg_score").active = true; } this.showChipAndCard(msg);//显示牌和筹码 //this._experienceStart = true; } else {//结算状态 this._gameState = GameState.BRTP_STATE_END; // this.node.getChildByName("AllAniNode").getChildByName("Ani_wait").active = true; var AreaNode = this.node.getChildByName("PourBtnList"); for (let i = 0; i < GameProtocol.AREA_MAX; i++) { AreaNode.children[i].getChildByName("SelfScore").active = true; AreaNode.children[i].getChildByName("AllPlayerScore").active = true; AreaNode.children[i].getChildByName("bg_score").active = true; } this.showChipAndCard(msg);//显示牌和筹码 const selfPlayer = this.getSelfNode().getComponent("BRTPPlayerView");//自己 selfPlayer.addScoreAni(msg.lPlayerWinScore); for (let i = 0; i < GameProtocol.AREA_MAX + 1; ++i) { let cardParentNode = this.pubCardNode.getChildByName("card" + i); let isWin = (msg.cbResult[i - 1] == 1); this.playCardType(cardParentNode, (msg.cbCardType[i] * 2 + 5)); AreaNode.children[i - 1] && (AreaNode.children[i - 1].getChildByName("winAni").active = isWin); cardParentNode.getChildByName("winAni") && (cardParentNode.getChildByName("winAni").active = isWin); } this._alreadyJoin = false; } this.updateState(msg.cbTimeLeave); }, updateState(cbTimeLeave) { var timeNode = this.node.getChildByName("TimeNode"); if (this._gameState == GameState.BRTP_STATE_CHIP) {//下注状态 timeNode.getChildByName("img_state").active = true; timeNode.getChildByName("img_state").getChildByName("label").getComponent(cc.Label).string = "Betting time"; } else if (this._gameState == GameState.BRTP_STATE_END) {//结算状态 timeNode.getChildByName("img_state").active = true; timeNode.getChildByName("img_state").getChildByName("label").getComponent(cc.Label).string = "Waiting"; } else {//空闲状态 timeNode.getChildByName("img_state").active = true; timeNode.getChildByName("img_state").getChildByName("label").getComponent(cc.Label).string = "Readying..."; } this.playTimeAction(cbTimeLeave); }, showChipAndCard(msg) { this._JetonNum = 0; var AreaNode = this.node.getChildByName("PourBtnList"); for (var i = 0; i < GameProtocol.AREA_MAX; i++) { this.createChip(msg.lAllJettonScore[i + 1], i);//创建筹码 this._AreaJetonTotal[i] = msg.lAllJettonScore[i + 1];//区域总下注 AreaNode.children[i].getChildByName("AllPlayerScore").getComponent(cc.Label).string = parseInt(this._AreaJetonTotal[i]); this._AreaJetonSelf[i] = msg.lPlayerJettonScore[i + 1];//区域自己下注 AreaNode.children[i].getChildByName("SelfScore").getChildByName("label").getComponent(cc.Label).string = parseInt(this._AreaJetonSelf[i]); if (this._AreaJetonSelf[i] > 0) { this._alreadyJoin = true;//下过注 } this._JetonNum += msg.lAllJettonScore[i + 1]; } this.node.getChildByName("TIpNode").getChildByName("totalLabel").getComponent(cc.Label).string = this._JetonNum.toFixed(2); var surplusScore = this._TotalNum - this._JetonNum; this.node.getChildByName("TIpNode").getChildByName("surplusLabel").getComponent(cc.Label).string = surplusScore.toFixed(2); for (var i = 0; i < GameProtocol.AREA_MAX + 1; i++) { this.showPubCard(msg.cbTableCardArray[i], i, false); } }, /** * 发牌动画 */ sendCardAni() { return new Promise((resolve, reject) => { const deTime = 1; // 动画总时间 const iterValScale = 0.3; // 牌依次向上移动比例 const cardPreFab = this.pubCardNode.getChildByName("SendCardPrefab"); const SendCardNode = this.pubCardNode.getChildByName("SendCardNode"); let cardsNode = null; // 牌根节点 let cardsPos = null; // 牌根节点坐标 let cardScale = null; // 牌原始比例 let cardIterValX = null; // 牌X轴间距(动画中X不变) let cardIterValY = null; // 动画开始牌Y轴间距 // 牌节点与牌动画节点不在同一父节点下 BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SENDCARD); for (let i = 0; i < GameProtocol.AREA_MAX + 1; ++i) { cardsNode = this.pubCardNode.getChildByName("card" + i); cardsPos = SendCardNode.convertToNodeSpaceAR(cardsNode.parent.convertToWorldSpaceAR(cardsNode.position)); cardScale = cardsNode.children[0].scale; cardIterValX = Math.abs(cardsNode.children[0].x - cardsNode.children[1].x); cardIterValY = cardsNode.children[0].height * iterValScale * cardScale; for (let j = 0; j < GameProtocol.CARDS_NUM; ++j) { let card = cc.instantiate(cardPreFab); let start_p = cc.v3( cardsPos.x + (j - (GameProtocol.CARDS_NUM - 1) / 2) * cardIterValX, cardsPos.y + ((j + 1) * cardIterValY), 0 ); card.active = true; card.zIndex = j; card.setScale(cardScale); card.setPosition(start_p); card.parent = SendCardNode; var act = cc.moveTo(deTime, cc.v2(start_p.x, cardsPos.y)); act.easing(cc.easeQuinticActionOut()); card.runAction(act); } } setTimeout(resolve, deTime * 1000); }); }, showPubCard(cardData, AreaIdx, isAni) { var cardParentNode = this.pubCardNode.getChildByName("card" + AreaIdx); const finalScale = cardParentNode.children[0].scale; const addlen = Math.abs(cardParentNode.children[0].x - cardParentNode.children[1].x); console.log("show card") console.log(cardData); for (let j = 0; j < GameProtocol.CARDS_NUM; j++) { var card = cardParentNode.children[j]; var component = card.getComponent("BRTPCard"); if (!component) { component = card.addComponent("BRTPCard"); } var cardId = cardData[j]; let finalP = cc.v2((j - (GameProtocol.CARDS_NUM - 1) / 2) * addlen, 0); component.setId(cardId); card.scale = finalScale; card.setPosition(finalP); card.active = true; var num = component.tileNum(); var color = (num == 0) ? 0 : component.tileColor() + 1; var frame = this.cardAtlas.getSpriteFrame("handmah_" + color.toString() + num.toString()); card.getComponent(cc.Sprite).spriteFrame = frame; if (isAni) { card.setScale(0, card.scaleY); card.runAction(cc.scaleTo(0.3, card.scaleY, card.scaleY)); BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SHOWCARD); } } }, /** * 翻牌动画 */ turnPubCard(cardNode, cardData) { const finalScale = cardNode.children[0].scale; // 牌组最终大小 const addlen = Math.abs(cardNode.children[0].x - cardNode.children[1].x); // 牌组最终间隔 return new Promise((resolve, reject) => { for (let i = 0; i < GameProtocol.CARDS_NUM; i++) { let card = cardNode.children[i]; let component = card.getComponent("BRTPCard"); if (!component) { component = card.addComponent("BRTPCard"); } let cardId = cardData[i]; component.setId(cardId); let finalP = cc.v2((i - (GameProtocol.CARDS_NUM - 1) / 2) * addlen, 0); card.scale = finalScale; card.setPosition(finalP); card.active = true; let num = component.tileNum(); let color = (num == 0) ? 0 : component.tileColor() + 1; let frame = this.cardAtlas.getSpriteFrame("handmah_" + color.toString() + num.toString()); let moveTime = 0.25; let delayTime = 0.1; let starPos = card.getPosition(); let endPos = cc.v2(0, 0); card.runAction(cc.sequence( cc.moveTo(moveTime, cc.v2(endPos.x, endPos.y)), cc.callFunc(() => { card.getComponent(cc.Sprite).spriteFrame = frame; }), cc.delayTime(delayTime), cc.spawn( cc.moveTo(moveTime, cc.v2(starPos.x, starPos.y)), cc.callFunc(() => { if (i == GameProtocol.CARDS_NUM - 1) resolve(); }) ) ) ); } }); }, playCardType(cardNode, cardType) {//牌型动画 return new Promise((resolve, reject) => { BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SHOWCARD); const TypeNode = cardNode.getChildByName("TypeNode"); TypeNode.active = true; const TypeSke = TypeNode.getComponent(sp.Skeleton); TypeSke.setTrackCompleteListener( TypeSke.setAnimation(0, "a" + cardType.toString(), false), () => { TypeSke.setAnimation(0, "a" + (cardType + 1).toString()); resolve(); } ); }); }, hidePubCard() { for (let i = 0; i < GameProtocol.AREA_MAX + 1; i++) { var cardParentNode = this.pubCardNode.getChildByName("card" + i); for (let j = 0; j < GameProtocol.CARDS_NUM; j++) { var card = cardParentNode.children[j]; card.active = false; } } }, OnGameFree(data) { this._gameState = GameState.BRTP_STATE_FREE; this.resetView(); this.updateState(data.cbTimeLeave); this.node.getChildByName("AllAniNode").getChildByName("Ani_wait").active = true; }, OnGameStart(data) { this._gameState = GameState.BRTP_STATE_CHIP; this.initPlayerData(data.wSeatUser); this.node.getChildByName("AllAniNode").getChildByName("Ani_wait").active = false; // this.node.getChildByName("TIpNode").active = true; // if(data.BankTimes > 0){ // this.node.getChildByName("TIpNode").getChildByName("bankerNum").getChildByName("label").getComponent(cc.Label).string = data.BankTimes;//连庄次数 // this.node.getChildByName("TIpNode").getChildByName("bankerNum").active = true; // var self = this; // setTimeout(() => { // self.node.getChildByName("TIpNode").getChildByName("bankerNum").active = false; // }, 3000); // } //播放开始动画 // BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_CHIPSTART); this.goldArr = []; this.node.getChildByName("AllAniNode").getChildByName("AniNode_jetonTip").active = true; var startAni = this.node.getChildByName("AllAniNode").getChildByName("AniNode_jetonTip").getComponent(sp.Skeleton); startAni.setTrackCompleteListener( startAni.setAnimation(0, "a2", false), () => { this.node.getChildByName("AllAniNode").getChildByName("AniNode_jetonTip").active = false; if (this._SelfIsZhuang) {//自己是庄 this.node.getChildByName("SelfZhuang").active = true; } else { var selfPlayerView = this.getSelfNode().getComponent("BRTPPlayerView"); this._selfScore = parseFloat(selfPlayerView.getScore() / 5); this.node.getChildByName("SelfZhuang").active = false; this.disabledPourChips(true); this.updateJetonBtn(); } } ); //发牌动画 this.sendCardAni() .then(() => { for (var i = 0; i < GameProtocol.AREA_MAX + 1; i++) { // 结束后 清空动画节点 this.showPubCard(data.cbTableCardArray[i], i, false); this.pubCardNode.getChildByName("SendCardNode").removeAllChildren(); } }); var AreaNode = this.node.getChildByName("PourBtnList"); for (let i = 0; i < GameProtocol.AREA_MAX; i++) { AreaNode.children[i].getChildByName("SelfScore").active = true; AreaNode.children[i].getChildByName("AllPlayerScore").active = true; AreaNode.children[i].getChildByName("bg_score").active = true; } this._TotalNum = data.lBankerScore; this.node.getChildByName("TIpNode").getChildByName("surplusLabel").getComponent(cc.Label).string = this._TotalNum.toFixed(2); this.updateState(data.cbTimeLeave); this._alreadyJoin = false; this._experienceStart = true; }, OnGameJetonSelf(data) { this._alreadyJoin = true; this._JetonNum += data.lBetScore; this.node.getChildByName("TIpNode").getChildByName("totalLabel").getComponent(cc.Label).string = this._JetonNum.toFixed(2);//本局总下注 var num = this._TotalNum - this._JetonNum; this.node.getChildByName("TIpNode").getChildByName("surplusLabel").getComponent(cc.Label).string = num.toFixed(2);//本局剩余可下注 this._AreaJetonTotal[data.cbBetArea] += data.lBetScore;//区域总下注 var selfPlayer = this.getSelfPlayer(); if (selfPlayer.getChairID() == data.wChairID) {//自己下注 this._AreaJetonSelf[data.cbBetArea] += data.lBetScore;//区域自己下注 this._selfScore -= data.lBetScore;//自己本局可下注-- } var AreaNode = this.node.getChildByName("PourBtnList"); AreaNode.children[data.cbBetArea].getChildByName("AllPlayerScore").getComponent(cc.Label).string = parseInt(this._AreaJetonTotal[data.cbBetArea]); AreaNode.children[data.cbBetArea].getChildByName("SelfScore").getChildByName("label").getComponent(cc.Label).string = parseInt(this._AreaJetonSelf[data.cbBetArea]); if (this.getSelfPlayer().getChairID() == data.wChairID) {//桌子座位上的 var selfPlayerJs = this.getSelfNode().getComponent("BRTPPlayerView"); selfPlayerJs.setScore(data.lPlayerRestScore); } var seatPlayer = this.getSeatPlayerJsByChairId(data.wChairID); if (seatPlayer) { seatPlayer.setScore(data.lPlayerRestScore); } var otherPlayer = this.getOtherPlayerJSByChairId(data.wChairID);//玩家列表里的 if (otherPlayer) { otherPlayer.setScore(data.lPlayerRestScore); } this.playJetonAni(data.lBetScore, data.wChairID, data.cbBetArea); this.updateJetonBtn(); this._experienceStart = true; this._chipRecord.push({ dwIndex: data.cbBetArea, lScore: data.lBetScore * 100 }); }, OnGameJetonOther(data) { this._JetonNum += data.lBetScore; this.node.getChildByName("TIpNode").getChildByName("totalLabel").getComponent(cc.Label).string = this._JetonNum.toFixed(2);//本局总下注 var num = this._TotalNum - this._JetonNum; this.node.getChildByName("TIpNode").getChildByName("surplusLabel").getComponent(cc.Label).string = num.toFixed(2);//本局剩余可下注 this._AreaJetonTotal[data.cbBetArea] += data.lBetScore;//区域总下注 var selfPlayer = this.getSelfPlayer(); if (selfPlayer.getChairID() == data.wChairID) {//自己下注 this._AreaJetonSelf[data.cbBetArea] += data.lBetScore;//区域自己下注 } var AreaNode = this.node.getChildByName("PourBtnList"); AreaNode.children[data.cbBetArea].getChildByName("AllPlayerScore").getComponent(cc.Label).string = parseInt(this._AreaJetonTotal[data.cbBetArea]); AreaNode.children[data.cbBetArea].getChildByName("SelfScore").getChildByName("label").getComponent(cc.Label).string = parseInt(this._AreaJetonSelf[data.cbBetArea]); if (this.getSelfPlayer().getChairID() == data.wChairID) {//桌子座位上的 var selfPlayerJs = this.getSelfNode().getComponent("BRTPPlayerView"); selfPlayerJs.setScore(data.lPlayerRestScore); } var seatPlayer = this.getSeatPlayerJsByChairId(data.wChairID); if (seatPlayer) { // star 投掷星星Ani seatPlayer.setScore(data.lPlayerRestScore); const starAniNode = AreaNode.children[data.cbBetArea].getChildByName("starAni"); const allAniNode = this.node.getChildByName("AllAniNode"); const isClimaxArea = (AreaNode.children.filter(childe => childe.getChildByName("starAni").active).length >= 2); //是否超出最大区域显示限制,当前为2个 if (seatPlayer.isSpecialPlayer && !starAniNode.active && !isClimaxArea) { const end_p = allAniNode.convertToNodeSpaceAR(starAniNode.parent.convertToWorldSpaceAR(starAniNode.position)); let aniNode = cc.instantiate(starAniNode); allAniNode.addChild(aniNode, 1); aniNode.active = true; aniNode.x = seatPlayer.node.x; aniNode.y = seatPlayer.node.y; starAniNode.active = true; starAniNode.getComponent(cc.Sprite).enabled = false; cc.tween(aniNode) .to(0.5, { x: end_p.x, y: end_p.y }, { easing: "circOut" }) .call(() => { starAniNode.getComponent(cc.Sprite).enabled = true; aniNode.destroy(); }) .start(); } } var otherPlayer = this.getOtherPlayerJSByChairId(data.wChairID);//玩家列表里的 if (otherPlayer) { otherPlayer.setScore(data.lPlayerRestScore); } if (selfPlayer.getChairID() != data.wChairID) { this.playJetonAni(data.lBetScore, data.wChairID, data.cbBetArea); } this._experienceStart = true; }, OnGameEnd(data) { this.saveSysLocalStorage(data); const selfChair = this.getSelfNode().getComponent("BRTPPlayerView").getChairID(); // 各阶段动画总时间 const areaResultAniTime = 1; const moveChipsToBankerAniTime = 1; const moveChipsToAreaAniTime = 1; const moveChipsToPlayerAniTime = 1; // 归属玩家的筹码列表 const seatPlayerChips = new Array(GameProtocol.MAX_SEAT_COUNT); for (let i = 0; i < GameProtocol.MAX_SEAT_COUNT; i++) { seatPlayerChips[i] = new Array(GameProtocol.AREA_MAX); for (let j = 0; j < GameProtocol.AREA_MAX; j++) { seatPlayerChips[i][j] = new Array(); } } const otherPlayerChips = new Array(GameProtocol.AREA_MAX); for (let i = 0; i < GameProtocol.AREA_MAX; i++) { otherPlayerChips[i] = new Array(); } const selfPlayerChips = new Array(GameProtocol.AREA_MAX); for (let i = 0; i < GameProtocol.AREA_MAX; i++) { selfPlayerChips[i] = new Array(); } this.disabledPourChips(false); this.unScheduleChipMove(); // 立即结束投掷动画定时器,投掷所有未投掷的筹码 this._gameState = GameState.BRTP_STATE_END; this._chipCache = Array.from(this._chipRecord); // 保存当前玩家投掷筹码的记录缓存,用于续投 this._chipRecord = []; this.node.getChildByName("TimeNode").active = false; // this.updateState(data.cbTimeLeave); /* 结束提示Ani */ var endTipAni = () => { return new Promise((resolve, reject) => { BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SENDCARD); // BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_CHIPEND); let endTipAni = this.node.getChildByName("AllAniNode").getChildByName("AniNode_jetonTip").getComponent(sp.Skeleton); endTipAni.node.active = true; endTipAni.setTrackCompleteListener( endTipAni.setAnimation(0, "a3", false), () => { endTipAni.node.active = false; resolve(); } ); }); } /* 翻转牌Ani */ var turnCardAni = () => { return new Promise((resolve, reject) => { const areaNode = this.node.getChildByName("PourBtnList"); let cardParentNode = null; let ani = (i) => { if (i == GameProtocol.AREA_MAX + 1) { return resolve(); } cardParentNode = this.pubCardNode.getChildByName("card" + i); // 翻转牌 this.turnPubCard(cardParentNode, data.cbTableCardArray[i]) .then(() => { // 显示牌型 (牌型sp,下标从7开始,单数动态,双数静态) this.playCardType(cardParentNode, (data.cbCardType[i] * 2 + 5)) .then(() => { let isWin = (data.cbResult[i - 1] == 1); areaNode.children[i - 1] && (areaNode.children[i - 1].getChildByName("winAni").active = isWin); cardParentNode.getChildByName("winAni") && (cardParentNode.getChildByName("winAni").active = isWin); ani(++i); }); }); } ani(0); }); } /* 区域输赢Ani */ var areaResultAni = () => { return new Promise((resolve, reject) => { /* for(let i = 0;i < GameProtocol.AREA_MAX;i++){ var resultNode = self.node.getChildByName("AllAniNode").children[i]; var end = function(){} resultNode.getComponent(sp.Skeleton).setCompleteListener(end); if(data.cbResult[i] == 1){ resultNode.active = true; resultNode.getComponent(sp.Skeleton).setAnimation(0,"ying",false) }else{ resultNode.active = false; } } */ setTimeout(resolve, areaResultAniTime * 1000); }); } /* 区域筹码移动到庄家Ani */ var moveChipsToBankerAni = () => { return new Promise((resolve, reject) => { const banker_p = this.getBankerNode().getPosition(); let areaChipsNode = null; let isSounded = false; // 移动筹码音效,只播放一次 for (let i = 0; i < GameProtocol.AREA_MAX; i++) { // Banker赢的情况下 if (data.cbResult[i] <= 0) { areaChipsNode = this.node.getChildByName("JetonNode").children[i]; areaChipsNode.children.forEach(node => { this.playChipMoveAni(node, node.getPosition(), banker_p, false, false).then(() => this.destroyChipNode(node)); }); if (!isSounded) { BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SCORE); isSounded = true; } } } setTimeout(resolve, moveChipsToBankerAniTime * 1000); }); } /* 庄家筹码移动到区域Ani */ var moveChipsToAreaAni = () => { return new Promise((resolve, reject) => { setTimeout(resolve, moveChipsToAreaAniTime * 1000); const areaChips = this.node.getChildByName("JetonNode").children; let isSounded = false; // 移动筹码音效,只播放一次 for (let areaIndex = 0; areaIndex < GameProtocol.AREA_MAX; areaIndex++) { // 玩家已下注筹码数 let selfScore = this._AreaJetonSelf[areaIndex]; let seatScore = data.lSeatUserArerScore.map((item, i) => { if (this._SeatArray[i] == selfChair) { return 0; } else if (i < 3 && this._SeatArray.slice(3, 3).includes(this._SeatArray[i])) { return 0; } else { return item[areaIndex]; } }); // 其他玩家获胜筹码数 let otherScore = -(data.lBankAreaWinScore[areaIndex] + data.lSeatUserArerScore.reduce((ans, cur) => ans + cur[areaIndex], 0)); // 在座玩家获胜筹码数 let ex_seatScore = seatScore.map(item => item * (data.cbMulti[areaIndex])); if (data.cbResult[areaIndex] > 0) { // 使用已下注筹码节点 从已生成筹码中获取对应筹码 for (let chipIndex = 0; chipIndex < areaChips[areaIndex].childrenCount; chipIndex++) { let chipNode = areaChips[areaIndex].children[chipIndex]; if (selfScore - chipNode.chipScore >= 0) { selfPlayerChips[areaIndex].push(chipNode); selfScore -= chipNode.chipScore; continue; } else { let seatIndex = 0; for (; seatIndex < GameProtocol.MAX_SEAT_COUNT; seatIndex++) { if (this._SeatArray[seatIndex] == selfChair) { seatScore[seatIndex] = 0; continue; } if (seatScore[seatIndex] > 0 && seatScore[seatIndex] - chipNode.chipScore >= 0) { seatPlayerChips[seatIndex][areaIndex].push(chipNode); seatScore[seatIndex] -= chipNode.chipScore; break; } } if (seatIndex == GameProtocol.MAX_SEAT_COUNT) { otherPlayerChips[areaIndex].push(chipNode); } } } // 生成玩家获胜得到的筹码,即庄家应该投掷的筹码 [data.lPlayAreaScore[areaIndex], ...otherScore, ...ex_seatScore].forEach((score, i) => { if (score > 0) { for (let idx = this._chipConfig.length; idx--;) { if (score >= this._chipConfig[idx]) { let num = parseInt(score / this._chipConfig[idx]); let startPos = this.getBankerNode().getPosition(); let endPos = this.node.getChildByName("PourBtnList").children[areaIndex].getPosition(); let centerPos = this.node.getChildByName("PourBtnList").children[areaIndex].getChildByName("CentreNode").getPosition(); endPos.x += centerPos.x; endPos.y += centerPos.y; for (let j = 0; j < num; j++) { let gold = this.getChipNode(this._chipConfig[idx]); areaChips[areaIndex].addChild(gold); gold.setPosition(startPos); gold.zIndex = this._goldZorder++; gold.active = true; if (i == 0) { selfPlayerChips[areaIndex].push(gold); } else if (i == 1) { otherPlayerChips[areaIndex].push(gold); } else { seatPlayerChips[i - 2][areaIndex].push(gold); } this.playChipMoveAni(gold, startPos, endPos, true, true, areaIndex); if (!isSounded) { BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SCORE); isSounded = true; } } score = score % this._chipConfig[idx]; } } } }); } } }) } /* 区域筹码移动到玩家Ani */ var moveChipsToPlayerAni = () => { return new Promise((resolve, reject) => { setTimeout(resolve, moveChipsToPlayerAniTime * 1000); // 移动到当前玩家 const self_p = this.getSelfNode().getPosition(); const other_p = this.getOtherPlayerNode().getPosition(); let needSound = false; for (let areaIndex = 0; areaIndex < GameProtocol.AREA_MAX; areaIndex++) { for (let i = 0; i < selfPlayerChips[areaIndex].length; i++) { let chipNode = selfPlayerChips[areaIndex][i]; this.playChipMoveAni(chipNode, chipNode.getPosition(), self_p, false, false).then(() => this.destroyChipNode(chipNode)); needSound = true; } for (let seatIndex = 0; seatIndex < GameProtocol.MAX_SEAT_COUNT; seatIndex++) { let seatPlay = this.getSeatPlayerNodeByChairId(this._SeatArray[seatIndex]); if (!seatPlay) continue; for (let i = 0; i < seatPlayerChips[seatIndex][areaIndex].length; i++) { let chipNode = seatPlayerChips[seatIndex][areaIndex][i]; this.playChipMoveAni(chipNode, chipNode.getPosition(), seatPlay.getPosition(), false, false).then(() => this.destroyChipNode(chipNode)); needSound = true; } } for (let i = 0; i < otherPlayerChips[areaIndex].length; i++) { let chipNode = otherPlayerChips[areaIndex][i]; this.playChipMoveAni(chipNode, chipNode.getPosition(), other_p, false, false).then(() => this.destroyChipNode(chipNode)); needSound = true; } } if (needSound) { BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SCORE); } }); } /* 输赢分数Ani */ var addScoreAni = () => { return new Promise((resolve, reject) => { if (data.lPlayerWinScore > 0) { var selfWin = this.node.getChildByName("AllAniNode").getChildByName("Ani_selfWin").getComponent(sp.Skeleton); selfWin.node.active = true; selfWin.setTrackCompleteListener( selfWin.setAnimation(0, "a1", false), () => { selfWin.active = false; } ); BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_GAME_WIN); } else if (data.lPlayerWinScore < 0) { // BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_GAME_LOSE); } else { BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_GAME_NO_BET); } BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SCORE); const banker = this.getBankerNode().getComponent("BRTPPlayerView");//庄家 const selfPlayer = this.getSelfNode().getComponent("BRTPPlayerView");//自己 banker.setScore(data.lBankerRestScore); selfPlayer.setScore(data.lPlayerRestScore); selfPlayer.addScoreAni(data.lPlayerWinScore); (data.lPlayerWinScore > 0) && selfPlayer.playWinAni(); for (let i = 0; i < GameProtocol.MAX_SEAT_COUNT; i++) {//6个座位上的玩家 const seatPlayer = this.getSeatPlayerJsByChairId(this._SeatArray[i]); if (seatPlayer && this._SeatArray[i] != selfChair) { //seatPlayer.setScore(data.lSeatUserWinScore[i]); seatPlayer.addScoreAni(data.lSeatUserWinScore[i]); (data.lSeatUserWinScore[i] > 0) && seatPlayer.playWinAni(); } } //其他玩家 if (data.lOtherPlayerWinScore != 0) { let score = Math.abs(data.lOtherPlayerWinScore); let otherPlayerScoreAni = this.node.getChildByName('FuncBtnNode').getChildByName("OtherPlayer").getChildByName("scoreAni"); const isWin = (data.lOtherPlayerWinScore > 0) otherPlayerScoreAni.getChildByName("scoreWinLabel").active = isWin; otherPlayerScoreAni.getChildByName("scoreLoseLabel").active = !isWin; otherPlayerScoreAni.getChildByName("scoreWinLabel").getChildByName("label").getComponent(cc.Label).string = "+" + score.toFixed(2); otherPlayerScoreAni.getChildByName("scoreLoseLabel").getChildByName("label").getComponent(cc.Label).string = "-" + score.toFixed(2); otherPlayerScoreAni.getComponent(cc.Animation).play("showScoreAni"); otherPlayerScoreAni.active = true; } resolve(); }); } // 按顺序播放结束动画 endTipAni() .then(areaResultAni) .then(turnCardAni) .then(moveChipsToBankerAni) .then(moveChipsToAreaAni) .then(moveChipsToPlayerAni) .then(addScoreAni) .then(() => { if (this._gameRecordData) { this.OnGameRecord(this._gameRecordData); this._gameRecordData = null; } if (this._gameWinLostData) { this.OnWinLost(this._gameWinLostData); this._gameWinLostData = null; } this._gameState = GameState.BRTP_STATE_FREE; if (!this._alreadyJoin && !this._SelfIsZhuang) {//没下注并且自己不是庄家 this._noJoinCount++; topTipMsg.showTopTipMsg("BRTP.hang_up_tip"); } else { this._noJoinCount = 0; } if (this._noJoinCount >= 5) {//5局没下注自己退出 this._noJoinCount = 0; this.exitGameWhenPlaying(); cc.vv.GetHallScript().LongTimeOutOfOperation("BRTP.time_out_exit_tip"); } }); }, OnApplyBanker(data) { if (data.wApplyUser == this.getSelfPlayer().getChairID()) { var ApplyBankerNode = this.node.getChildByName("FuncBtnNode").getChildByName("ApplyBankerNode"); ApplyBankerNode.getChildByName("Button_callUp").active = false; ApplyBankerNode.getChildByName("Button_callDown").active = true; // topTipMsg.showTopTipMsg("你已加入庄家列表!"); var data = {}; importInstance.ScenceManager.getGameComponent().SendGameSocketData(GameProtocol.SUB_C_BANK_LIST, data); } }, OnCancelBanker(data) { if (data.wCancelUser == this.getSelfPlayer().getChairID()) { var ApplyBankerNode = this.node.getChildByName("FuncBtnNode").getChildByName("ApplyBankerNode"); ApplyBankerNode.getChildByName("Button_callUp").active = true; ApplyBankerNode.getChildByName("Button_callDown").active = false; // topTipMsg.showTopTipMsg("你已离开庄家列表!"); var data = {}; importInstance.ScenceManager.getGameComponent().SendGameSocketData(GameProtocol.SUB_C_BANK_LIST, data); } }, OnGameRecord(data) { if (!data) return; const recordNode = this.node.getChildByName("RecordNode").getChildByName("TrendNode"); const areaSpades = recordNode.getChildByName("record_spades"); // 黑桃 const areaHearts = recordNode.getChildByName("record_hearts"); // 红心 const areaDiamonds = recordNode.getChildByName("record_diamonds"); // 方块 const areaClubs = recordNode.getChildByName("record_clubs"); // 梅花 if (areaSpades.active && areaHearts.active && areaDiamonds.active && areaClubs.active) { const AniTime = 0.5; let parentNodes = [areaSpades, areaHearts, areaDiamonds, areaClubs]; parentNodes.forEach(parentNode => { let children = parentNode.children; let firstChild_p = children[0].position; const oriScale = children[0].scale; children[0].scale = 0; children[0].position = children[children.length - 1].position; for (let i = 1; i < children.length; ++i) { let child = children[i]; child.runAction(cc.sequence( cc.moveBy(AniTime, cc.v2(-child.width, 0)), cc.moveBy(0, cc.v2(child.width, 0)) )); } children[0].runAction(cc.sequence( cc.scaleTo(AniTime, oriScale), cc.callFunc(() => { children[0].position = firstChild_p; }) )) }); setTimeout(() => { areaSpades.active = true; areaHearts.active = true; areaDiamonds.active = true; areaClubs.active = true; const RECORD_LENGTH = areaSpades.children.length; let idx = data.record.length - 1; for (var i = 0; i < RECORD_LENGTH && idx >= 0; i++) { areaSpades.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinTian]; areaHearts.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinDi]; areaDiamonds.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinXuan]; areaClubs.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinHuang]; idx--; } }, AniTime); } else { areaSpades.active = true; areaHearts.active = true; areaDiamonds.active = true; areaClubs.active = true; const RECORD_LENGTH = areaSpades.children.length; let idx = data.record.length - 1; for (var i = 0; i < RECORD_LENGTH && idx >= 0; i++) { areaSpades.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinTian]; areaHearts.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinDi]; areaDiamonds.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinXuan]; areaClubs.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinHuang]; idx--; } } }, OnWinLost(data) { if (!data) { return; } this._trendData = data; }, OnFailInfo(msg) { topTipMsg.showTopTipMsg(Global.gbk2Utf8(msg.szBuffer)); }, onReceiveBankerList(msg) { this.BankerListContent.removeAllChildren(); for (var i = 0; i < msg.BankLists.length; i++) { var gamePlayer = this.getPlayerByChairID(msg.BankLists[i]); if (gamePlayer) { var bankerNode = cc.instantiate(this.playerPrefab); bankerNode.active = true; //this.node.getComponent("BRTPFuncBtnMgr").initButtonHandler(bankerNode.getChildByName("PlayerHead").getChildByName("ButtonPlayerHeadClick")); this.BankerListContent.addChild(bankerNode); var playerjs = bankerNode.getComponent("BRTPPlayer"); playerjs.setUserItem(gamePlayer.getUserItem()); playerjs.playerEnter(); playerjs.upPlayerInfo(); playerjs.upPlayerHead(); } } this.showBankerList(true); }, getChipNode(Jeton) { let node = null; if (this._chipPool.size() > 0) { node = this._chipPool.get(); } else { node = cc.instantiate(this.JettonPrefab); } let chipIndex = this._chipConfig.findIndex(item => item == Jeton); (chipIndex == -1) && (chipIndex = 0); node.getComponent(cc.Sprite).spriteFrame = this.ChipsSprite[chipIndex + 1]; node.getChildByName("label").getComponent(cc.Label).font = this.ChipsLabel[chipIndex + 1]; node.getChildByName("label").getComponent(cc.Label).string = Jeton; node.chipScore = Jeton; return node; }, destroyChipNode(node) { this._chipPool.put(node); }, //直接显示对应区域的筹码(断线重连用) createChip(JetonScore, cbBetArea) { var self = this; var setChipAnimation = function (gold, endPos, cbBetArea) { var offX = self.getBetAreaSize(cbBetArea).x; var offY = self.getBetAreaSize(cbBetArea).y; let randx = Math.floor(Math.random() * offX * (Math.random() > 0.5 ? 1 : -1)); let randy = Math.floor(Math.random() * offY * (Math.random() > 0.5 ? 1 : -1)); let rotate = Math.floor(Math.random() * 360 + 180); gold.active = true gold.setScale(0.3); gold.setPosition(cc.v2(endPos.x + randx, endPos.y + randy)); gold.angle = rotate; } var endPos = this.node.getChildByName("PourBtnList").children[cbBetArea].getPosition(); var centerPos = this.node.getChildByName("PourBtnList").children[cbBetArea].getChildByName("CentreNode").getPosition(); endPos.x += centerPos.x; endPos.y += centerPos.y; var goldArr = []; var JetonArr = this._chipConfig; var nowJetonScore = JetonScore; for (var i = JetonArr.length - 1; i >= 0; i--) { if (nowJetonScore >= JetonArr[i]) { var num = parseInt(nowJetonScore / JetonArr[i]); for (var j = 0; j < num; j++) { var gold = this.getChipNode(JetonArr[i]); goldArr.push(gold); } nowJetonScore = nowJetonScore % JetonArr[i]; } } for (var i = 0; i < goldArr.length; i++) { goldArr[i].zIndex = (this._goldZorder++) this.node.getChildByName("JetonNode").children[cbBetArea].addChild(goldArr[i]); setChipAnimation(goldArr[i], endPos, cbBetArea); } }, //下注筹码移动到天地玄区域动画 playJetonAni(JetonScore, wChairID, cbBetArea) { var self = this; var endPos = this.node.getChildByName("PourBtnList").children[cbBetArea].getPosition(); var centerPos = this.node.getChildByName("PourBtnList").children[cbBetArea].getChildByName("CentreNode").getPosition(); endPos.x += centerPos.x; endPos.y += centerPos.y; var JetonArr = this._chipConfig; var selfPlayer = this.getSelfPlayer(); // 头像抖动效果 const Wobble_px = 10; // 抖动距离 const ACTION_TAG = 1; let player = this.getSeatPlayerNodeByChairId(wChairID) || this.getOtherPlayerNode(); if (wChairID == selfPlayer.getChairID()) player = this.getSelfNode() let player_p = player.getPosition(); let wobble_r = Wobble_px / Math.sqrt(Math.pow((endPos.y - player_p.y), 2) + Math.pow((endPos.x - player_p.x), 2)); // 移动距离与头像到目标位置的比例 let wobble_p = cc.v2((endPos.x - player_p.x) * wobble_r, (endPos.y - player_p.y) * wobble_r); let moveby = cc.moveBy(0.1, wobble_p); let moveRe = moveby.reverse(); let moveNode = player.getChildByName("PlayerHead") || player; if (!moveNode.getActionByTag(ACTION_TAG) || moveNode.getActionByTag(ACTION_TAG).isDone()) { let sqAction = cc.sequence(moveby, moveRe); sqAction.setTag(ACTION_TAG); moveNode.runAction(sqAction); console.log(`position (${player_p}) (${endPos}) (${wobble_p})`); } if (selfPlayer.getChairID() == wChairID)//自己下注 { startPos = this.getSelfNode().getPosition(); var goldArr = []; var nowJetonScore = JetonScore; for (var i = JetonArr.length - 1; i >= 0; i--) { if (nowJetonScore >= JetonArr[i]) { var num = parseInt(nowJetonScore / JetonArr[i]); for (var j = 0; j < num; j++) { var gold = this.getChipNode(JetonArr[i]); goldArr.push(gold); gold.startPos = startPos; gold.endPos = endPos; gold.cbBetArea = cbBetArea; gold.isSelf = true; } nowJetonScore = nowJetonScore % JetonArr[i]; } } var callFun = function () { if (goldArr.length <= 0) { //self.unschedule(callFun); return; } var num = goldArr.length;//parseInt(Math.random()*5); var arr = goldArr.splice(0, num); for (var i = 0; i < arr.length; i++) { arr[i].zIndex = (self._goldZorder++) self.node.getChildByName("JetonNode").children[arr[i].cbBetArea].addChild(arr[i]); self.playChipAnimation(arr[i], arr[i]); } } callFun(); //self.schedule(callFun,0.5); } else {//别人下注 var isOther = true;//其他不在座位上的玩家 var startPos = this.getOtherPlayerNode().getPosition(); for (var i = 0; i < this._seatPlayer.length; ++i) { if (wChairID == this._seatPlayer[i].getChairID()) { startPos = this._seatPlayer[i].node.getPosition(); isOther = false;//6个座位上的玩家 break; } } if (isOther) { startPos = this.getOtherPlayerNode().getPosition(); } var nowJetonScore = JetonScore; for (var i = JetonArr.length - 1; i >= 0; i--) { if (nowJetonScore >= JetonArr[i]) { var num = parseInt(nowJetonScore / JetonArr[i]); for (var j = 0; j < num; j++) { var gold = this.getChipNode(JetonArr[i]); this.goldArr.push(gold); gold.startPos = startPos; gold.endPos = endPos; gold.cbBetArea = cbBetArea; gold.isSelf = false; } nowJetonScore = nowJetonScore % JetonArr[i]; } } this.schedule(this.scheduleChipMove, 0.05); } }, playChipAnimation(gold, { startPos, endPos, cbBetArea, isSelf }) { var offX = this.getBetAreaSize(cbBetArea).x; var offY = this.getBetAreaSize(cbBetArea).y; var moveTime = 0.2; var scaleSize = 0.5; var easeOutNum = 1 var scaleAddNum = 0.3 // 最终大小 var scaleAddTime = 0.05 gold.active = true gold.setScale(0.3); gold.setPosition(cc.v2(startPos.x, startPos.y)); if (!this._isSounding) { BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_BETLOW); this._isSounding = true; this.scheduleOnce(() => this._isSounding = false, 0.3); } let randx = Math.floor(Math.random() * offX * (Math.random() > 0.5 ? 1 : -1)); let randy = Math.floor(Math.random() * offY * (Math.random() > 0.5 ? 1 : -1)); let rotate = Math.floor(Math.random() * 360 + 180); var scaleto = cc.scaleTo(moveTime, scaleSize).easing(cc.easeOut(easeOutNum)); var moveto = cc.moveTo(moveTime, cc.v2(randx + endPos.x, randy + endPos.y)).easing(cc.easeOut(easeOutNum));// var rotateto1 = cc.rotateBy(0.1, rotate); rotate = Math.floor(Math.random() * 30 + 10); var rotateto2 = cc.rotateBy(0.1, rotate).easing(cc.easeOut(easeOutNum)); gold.runAction(cc.sequence(cc.spawn(moveto, scaleto, rotateto1), rotateto2, cc.scaleTo(scaleAddTime, scaleAddNum))); }, scheduleChipMove() { // 投掷筹码Ani定时器 if (this.goldArr.length <= 0) { this.unschedule(this.scheduleChipMove); return; } var gold = this.goldArr.splice(0, 1)[0]; gold.zIndex = (this._goldZorder++) this.node.getChildByName("JetonNode").children[gold.cbBetArea].addChild(gold); this.playChipAnimation(gold, gold); }, unScheduleChipMove() { // 一次性清空未投掷的筹码 for (const gold of this.goldArr) { gold.zIndex = (this._goldZorder++) this.node.getChildByName("JetonNode").children[gold.cbBetArea].addChild(gold); this.playChipAnimation(gold, gold); } this.goldArr = []; }, getBetAreaSize(cbBetArea) { var offX = 0; var offY = 0; if (cbBetArea == 0) { offX = 80; offY = 40; } else if (cbBetArea == 1) { offX = 80; offY = 40; } else if (cbBetArea == 2) { offX = 80; offY = 40; } else if (cbBetArea == 3) { offX = 80; offY = 40; } var size = {}; size.x = offX; size.y = offY; return size; }, //筹码移动动画 playChipMoveAni(gold, startPos, endPos, endRand, endShow, cbBetArea) {//筹码节点,开始坐标,终点坐标,终点是否小范围随机,播放结束显示或隐藏,下注区域 return new Promise((resolve, reject) => { var offX = 0; var offY = 0; if (endRand && cbBetArea >= 0 && cbBetArea < GameProtocol.AREA_MAX) { offX = this.getBetAreaSize(cbBetArea).x; offY = this.getBetAreaSize(cbBetArea).y; } var moveTime = 0.3; var scaleSize = 0.5; var easeOutNum = 1 var scaleAddNum = 0.3 // 最终大小 var scaleAddTime = 0.05 gold.active = true gold.setPosition(cc.v2(startPos.x, startPos.y)); gold.setScale(0.3); let randx = 0; let randy = 0; if (endRand) { randx = Math.floor(Math.random() * offX * (Math.random() > 0.5 ? 1 : -1)); randy = Math.floor(Math.random() * offY * (Math.random() > 0.5 ? 1 : -1)); } let rotate = Math.floor(Math.random() * 360 + 180); var scaleto = cc.scaleTo(moveTime, scaleSize).easing(cc.easeOut(easeOutNum)); var moveto = cc.moveTo(moveTime, cc.v2(randx + endPos.x, randy + endPos.y)).easing(cc.easeOut(easeOutNum)); var rotateto1 = cc.rotateBy(0.1, rotate); rotate = Math.floor(Math.random() * 30 + 10); var rotateto2 = cc.rotateBy(0.1, rotate).easing(cc.easeOut(easeOutNum)); gold.runAction(cc.sequence(cc.spawn(moveto, scaleto, rotateto1), rotateto2, cc.scaleTo(scaleAddTime, scaleAddNum), cc.callFunc(() => { gold.active = endShow; resolve(); }, this)) ); }); }, disabledPourChips(Bool) { console.log("myTest: " + Bool) var PourBtnList = this.node.getChildByName("PourBtnList"); for (var i = 0; i < GameProtocol.AREA_MAX; i++) { PourBtnList.children[i].getComponent(cc.Button).interactable = Bool; } PourBtnList.active = true; var GoldNode = this.node.getChildByName("FuncBtnNode").getChildByName("GoldBtnNode"); for (let i = 0; i < 6; ++i) { GoldNode.getChildByName("Button_GoldAdd" + i).getComponent(cc.Button).interactable = Bool; GoldNode.getChildByName("Button_GoldAdd" + i).getChildByName("label").getComponent(cc.Label).font = (Bool) ? this.ChipsLabel[i + 1] : this.ChipsLabel[0]; } GoldNode.getChildByName("Button_GoldAddAgain").getComponent(cc.Button).interactable = Bool GoldNode.getChildByName("tip_ring").active = Bool }, updateJetonBtn() { if (this._gameState > GameState.BRTP_STATE_CHIP) return; var GoldNode = this.node.getChildByName("FuncBtnNode").getChildByName("GoldBtnNode"); var score = this._selfScore; var scoreArr = this._chipConfig; for (var i = 0; i < scoreArr.length; i++) { if (score >= scoreArr[i]) { GoldNode.getChildByName("Button_GoldAdd" + i).getComponent(cc.Button).interactable = true; GoldNode.getChildByName("Button_GoldAdd" + i).getChildByName("label").getComponent(cc.Label).font = this.ChipsLabel[i + 1]; } else { GoldNode.getChildByName("Button_GoldAdd" + i).getComponent(cc.Button).interactable = false; GoldNode.getChildByName("Button_GoldAdd" + i).getChildByName("label").getComponent(cc.Label).font = this.ChipsLabel[0]; } } this.node.getComponent("BRTPFuncBtnMgr").unpdateJetonTag(); }, initPourChips() { Global.print(`BRTP:: 初始化筹码${this._chipConfig}`) // UIHelper. let GoldNode = this.node.getChildByName("FuncBtnNode").getChildByName("GoldBtnNode"); let scoreArr = this._chipConfig; let index = 0; let child = GoldNode.getChildByName("Button_GoldAdd" + index); while (child) { child.active = !!scoreArr[index]; child.getChildByName("label").getComponent(cc.Label).string = scoreArr[index] || 0; index++; child = GoldNode.getChildByName("Button_GoldAdd" + index); } }, //每局游戏结束后重置UI resetView() { this._goldZorder = 0; this.node.getChildByName("TIpNode").active = false; this.disabledPourChips(false);//下注按钮置灰 for (var i = 0; i < this.playerNode.children.length; i++) { var playerjs = this.playerNode.children[i].getComponent("BRTPPlayerView"); playerjs.resetView(); } var otherPlayerScoreAni = this.node.getChildByName('FuncBtnNode').getChildByName("OtherPlayer").getChildByName("scoreAni"); otherPlayerScoreAni.active = false; var AreaNode = this.node.getChildByName("PourBtnList"); for (var i = 0; i < GameProtocol.AREA_MAX; i++) { this._AreaJetonSelf[i] = 0;//区域自己下注 this._AreaJetonTotal[i] = 0;//区域总下注 AreaNode.children[i].getChildByName("AllPlayerScore").getComponent(cc.Label).string = parseInt(this._AreaJetonTotal[i]); AreaNode.children[i].getChildByName("SelfScore").getChildByName("label").getComponent(cc.Label).string = parseInt(this._AreaJetonSelf[i]); AreaNode.children[i].getChildByName("AllPlayerScore").active = false; AreaNode.children[i].getChildByName("SelfScore").active = false; // AreaNode.children[i].getChildByName("bg_score").active = false; AreaNode.children[i].getChildByName("winAni").active = false; AreaNode.children[i].getChildByName("starAni").active = false; } this._JetonNum = 0; this._TotalNum = 0; this.node.getChildByName("TIpNode").getChildByName("totalLabel").getComponent(cc.Label).string = this._JetonNum.toFixed(2); this.node.getChildByName("TIpNode").getChildByName("surplusLabel").getComponent(cc.Label).string = this._TotalNum.toFixed(2); var JetonNode = this.node.getChildByName("JetonNode");//桌子上的筹码 for (var i = 0; i < JetonNode.childrenCount; i++) { JetonNode.children[i].removeAllChildren(); } var AllAniNode = this.node.getChildByName("AllAniNode"); for (var i = 0; i < AllAniNode.childrenCount; i++) {//所有动画 AllAniNode.children[i].active = false; } var cardTypeNode = this.node.getChildByName("PubCardNode");//牌型动画 for (var i = 0; i < GameProtocol.AREA_MAX + 1; i++) { cardTypeNode.getChildByName("card" + i).getChildByName("TypeNode").active = false; cardTypeNode.getChildByName("card" + i).getChildByName("winAni").active = false; } this.hidePubCard();//牌 this.node.getChildByName("TIpNode").active = false; this.node.getChildByName("SelfZhuang").active = false; // 清除房间号 cc.find("RoomInfoNode/num", this.node).getComponent(cc.Label).string = ""; // 低于最低下注额提醒 let isNeedTip = (importInstance.GameManagerBase.getGameServerItem().CellScore > cc.vv.globalUserInfo.getUserScore()); this.node.getChildByName("ChipTip").active = isNeedTip; if (isNeedTip) { cc.find("ChipTip/label/num", this.node).getComponent(cc.Label).string = this.getGameServerItem().CellScore; } }, //初始化玩家信息 initPlayers() { var selfPlayer = this.getSelfPlayer(); if (!selfPlayer) { return; } this.playListContent.removeAllChildren(); //this._players = []; for (let i = 0; i < GameProtocol.GAME_PLAYER; ++i) { var gamePlayer = this.getPlayerByChairID(i); if (gamePlayer) { var playerNode = cc.instantiate(this.playerPrefab); playerNode.active = true; //this.node.getComponent("BRTPFuncBtnMgr").initButtonHandler(playerNode.getChildByName("PlayerHead").getChildByName("ButtonPlayerHeadClick")); this.playListContent.addChild(playerNode); var playerjs = playerNode.getComponent("BRTPPlayer"); playerjs.setUserItem(gamePlayer.getUserItem()); playerjs.playerEnter(); playerjs.upPlayerInfo(); playerjs.upPlayerHead(); //playerjs.upPlayerState(); //this._players.push(playerjs); } } this.node.getChildByName('FuncBtnNode').getChildByName("OtherPlayer").getChildByName("playerCount").getComponent(cc.Label).string = this.playListContent.childrenCount; }, initPlayerData(wSeatUser) { this._SeatArray = wSeatUser; this._seatPlayer = []; for (var i = 0; i < GameProtocol.MAX_SEAT_COUNT; ++i) { var index = i + 1; var player = this.getOtherPlayerJSByChairId(wSeatUser[i]); if (player) { this.playerNode.getChildByName("Player" + index).active = true; var playerjs = this.playerNode.getChildByName("Player" + index).getComponent("BRTPPlayerView"); playerjs.resetView(); playerjs.setUserItem(player.getUserItem()); playerjs.setChairID(wSeatUser[i]) playerjs.playerEnter(); playerjs.upPlayerInfo(); playerjs.upPlayerState(); playerjs.upPlayerHead(); playerjs.isSpecialPlayer = ([1].some(i => i == index)); // 特殊标记玩家,1最幸运,4最富有 this._seatPlayer.push(playerjs); } else { this.playerNode.getChildByName("Player" + index).active = false; } } var selfPlayer = this.getSelfPlayer(); if (selfPlayer) { this.playerNode.getChildByName("Player0").active = true; var playerjs = this.playerNode.getChildByName("Player0").getComponent("BRTPPlayerView"); playerjs.resetView(); playerjs.setUserItem(selfPlayer.getUserItem()); playerjs.setChairID(selfPlayer.getChairID()); playerjs.playerEnter(); playerjs.upPlayerInfo(); playerjs.upPlayerState(); playerjs.upPlayerHead(); } }, setZhuangInfo(wBankerUser, playSound) { var PlayerBanker = this.getOtherPlayerJSByChairId(wBankerUser); if (PlayerBanker) { this.getBankerNode().active = true; var playerjs = this.getBankerNode().getComponent("BRTPPlayerView"); playerjs.resetView(); playerjs.setUserItem(PlayerBanker.getUserItem()); playerjs.setChairID(wBankerUser) playerjs.playerEnter(); playerjs.upPlayerInfo(); playerjs.upPlayerState(); playerjs.upPlayerHead(); } else {//系统庄 this.getBankerNode().getChildByName("PlayerInfo").getChildByName("Name").getChildByName("label").getComponent(cc.Label).string = "Dealer"; this.getBankerNode().getChildByName("PlayerInfo").getChildByName("ScoreImagic").getChildByName("Score").getComponent(cc.Label).string = "100000"; } this._bankerUserId = wBankerUser;//庄家ID this._SelfIsZhuang = (this.getSelfPlayer().getChairID() == wBankerUser); if (playSound) { BRTPSoundFun.playEffectByGender(this.getSelfPlayer().getGender(), BRTPSoundFun.EX_CHANGEBANKER); } }, onUserEnter(clientUserItem) { Global.print("onUserEnter......") var selfPlayer = this.getSelfPlayer(); if (!selfPlayer) { return; } var player = this.getOtherPlayerJSByChairId(clientUserItem.GetChairID()); if (!player) { var playerNode = cc.instantiate(this.playerPrefab); playerNode.active = true; //this.node.getComponent("BRTPFuncBtnMgr").initButtonHandler(playerNode.getChildByName("PlayerHead").getChildByName("ButtonPlayerHeadClick")); this.playListContent.addChild(playerNode); this.node.getChildByName('FuncBtnNode').getChildByName("OtherPlayer").getChildByName("playerCount").getComponent(cc.Label).string = this.playListContent.childrenCount; var playerjs = playerNode.getComponent("BRTPPlayer"); playerjs.setUserItem(clientUserItem); playerjs.playerEnter(); playerjs.upPlayerInfo(); //playerjs.upPlayerState(); for (var i = 0; i < GameProtocol.MAX_SEAT_COUNT; ++i) { if (this.playerNode.getChildByName("Player" + i).active) { continue; } this.playerNode.getChildByName("Player" + i).active = true; var PlayerViewjs = this.playerNode.getChildByName("Player" + i).getComponent("BRTPPlayerView"); PlayerViewjs.resetView(); PlayerViewjs.setUserItem(clientUserItem); PlayerViewjs.setChairID(playerjs.getChairID()); PlayerViewjs.playerEnter(); PlayerViewjs.upPlayerInfo(); PlayerViewjs.upPlayerState(); PlayerViewjs.upPlayerHead(); this._seatPlayer.push(PlayerViewjs); break; } } }, onUserLeave(clientUserItem) { if (Global.IsEmpty(clientUserItem)) { return; } for (var i = 0; i < this._seatPlayer.length; ++i) {//从6个座位上删除 var playerJs = this._seatPlayer[i];//BRTPPlayerView if (playerJs.getChairID() == clientUserItem.GetChairID()) { playerJs.playerLeave(); this._seatPlayer.splice(i, 1); break; } } for (var i = 0; i < this.playListContent.childrenCount; i++) {//从玩家列表删除 var playerNode = this.playListContent.children[i]; var playerJs = playerNode.getComponent("BRTPPlayer") if (playerJs.getChairID() == clientUserItem.GetChairID()) { playerNode.removeFromParent(); break; } } this.node.getChildByName('FuncBtnNode').getChildByName("OtherPlayer").getChildByName("playerCount").getComponent(cc.Label).string = this.playListContent.childrenCount; }, upPlayerInfo(clientUserItem) { var player = this.getOtherPlayerJSByChairId(clientUserItem.GetChairID()); if (player) { player.setUserItem(clientUserItem); player.upPlayerInfo(); } }, upPlayerHead(clientUserItem) { var player = this.getOtherPlayerJSByChairId(clientUserItem.GetChairID()); if (player) { player.setUserItem(clientUserItem); player.upPlayerHead(); } }, upPlayerState(clientUserItem) { var player = this.getOtherPlayerJSByChairId(clientUserItem.GetChairID()); if (player) { player.setUserItem(clientUserItem); player.upPlayerState(); } }, getSelfNode() {//获取自己节点 return this.node.getChildByName("Players").getChildByName("Player0"); }, getBankerNode() {//获取庄家节点 return this.node.getChildByName("Players").getChildByName("PlayerBanker"); }, getSeatPlayerNodeByChairId(chairId) {//获取6个座位上的玩家节点 for (var i = 1; i < GameProtocol.MAX_SEAT_COUNT + 1; i++) { var playerNode = this.playerNode.getChildByName("Player" + i); var PlayerViewJs = playerNode.getComponent("BRTPPlayerView"); if (PlayerViewJs.getChairID() == chairId) { return playerNode; } } return null; }, getOtherPlayerNode() {//不在座位上的其他玩家节点 return this.node.getChildByName("FuncBtnNode").getChildByName("OtherPlayer"); }, getSeatPlayerJsByChairId(chairId) {//获取6个座位上的玩家Js for (var i = 1; i < GameProtocol.MAX_SEAT_COUNT + 1; i++) { var playerNode = this.playerNode.getChildByName("Player" + i); var PlayerViewJs = playerNode.getComponent("BRTPPlayerView"); if (PlayerViewJs.getChairID() == chairId) { return PlayerViewJs; } } return null; }, getOtherPlayerJSByChairId(chairId) {//获取所有玩家列表的Js for (var i = 0; i < this.playListContent.childrenCount; i++) { var playerNode = this.playListContent.children[i]; var playerJs = playerNode.getComponent("BRTPPlayer"); if (playerJs.getChairID() == chairId) { return playerJs; } } return null; }, //得到DSMJGamePlayer (是GamePlayer的派生类) getSelfLocalPlayer() { for (var i = 0; i < this.playListContent.childrenCount; i++) { var playerNode = this.playListContent.children[i]; var playerJs = playerNode.getComponent("BRTPPlayer"); if (playerJs.getChairID() == this.getSelfPlayer().getChairID()) { return playerJs; } } /*for (let index = 0; index < this._players.length; index++) { const element = this._players[index]; if (this.isSelf(element)) { return element; } }*/ return null; }, playTimeAction(timeNum) { if (this.timeCallback != null) { this.unschedule(this.timeCallback); this.timeCallback = null; } this._countdown = timeNum; var time = timeNum; const timeNode = this.node.getChildByName("TimeNode"); const timeLabel = timeNode.getChildByName("TimeLabel").getComponent(cc.Label); const timeMask = timeNode.getChildByName("AniNode").getChildByName("mask").getComponent(cc.Sprite); timeLabel.string = this._countdown; timeNode.active = true; this.timeCallback = (dt) => { time -= dt; if (time < 0) { timeNode.active = false; this.unschedule(this.timeCallback); this.timeCallback = null; } else { timeMask.fillRange = (time / this._countdown); timeLabel.string = Math.round(time); } } if (this._gameState == GameState.BRTP_STATE_CHIP) { this.schedule(() => BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_TIME), 1, 1, timeNum - 5); } this.schedule(this.timeCallback, 0.1); }, showAllPlayerList(show) { var playerListNode = this.node.getChildByName("PlayerList").getChildByName("AllPlayerList") playerListNode.active = show; }, showBankerList(show) { var bankerListNode = this.node.getChildByName("PlayerList").getChildByName("AllBankerList") bankerListNode.active = show; this.node.getComponent("BRTPFuncBtnMgr")._openBankerList = show; }, OnSocketSubProtectBack(bLookonUser, data) {//低保信息 if (bLookonUser) { return; } var selfPlayer = this.getSelfPlayer(); if (!selfPlayer) { return; } if (data.dwUserId != selfPlayer.getUserID()) { var player = this.getOtherPlayerJSByChairId(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; }, //聊天协议 revTalk(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); var player = this.getOtherPlayerJSByChairId(databuf.ChairID); if (player != null) { player.showTalkState(databuf); } }, revVoice(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.getOtherPlayerJSByChairId(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("BRTPFuncBtnMgr").getAr().downloadRecordedFile(databuf.SerVerID, filePath); }, hideVoice() { for (let i = 0; i < GameProtocol.GAME_PLAYER; ++i) { var player = this.getOtherPlayerJSByChairId(i); if (player != null) { player.hideVoice(); } } }, //////////////////////////////////////////////////////////////////////////// //银行信息 OnSocketSubUserInsureInfo(pNetInfo) { var selfPlayer = this.getSelfPlayer(); if (!selfPlayer) { return; } this.showBank(pNetInfo); }, OnSocketSubUserInsureSuccess(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; } importInstance.GameManagerBase.connectGameServer(this._gameServerItem); } else if (pNetInfo.cbType == 2) { //取钱继续 if (this._goldUnusual) { this._goldUnusual.active = false; } importInstance.GameManagerBase.connectGameServer(this._gameServerItem); } }, OnSocketSubUserInsureFailure(pNetInfo) { var selfPlayer = this.getSelfPlayer(); if (!selfPlayer) { return; } var str = Global.gbk2Utf8(pNetInfo.DescribeString); //Global.print(str); this._bankNode.active = false; // topTipMsg.showTopTipMsg("游戏中不能存款"); }, showBank(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相关*****************************/ //注册触摸事件 registerTouchEventHandle() { this.node.on(cc.Node.EventType.TOUCH_START, function (event) { }, this); this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) { }, this); this.node.on(cc.Node.EventType.TOUCH_END, function (event) { }, this); this.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) { }, this); }, //初始化UI initView() { }, defaultPrivateState() { }, //返回大厅 backHome() { this._bIsRecord = false; this.unschedule(this.nextRecordAction); this.unschedule(this.updataMobileTime); importInstance.ScenceManager.gameBackScence(); importInstance.GameManagerBase.setInGameServerID(-1); importInstance.CServerItem ? importInstance.CServerItem.PerformStandUpAction(1) : this.exitGame(); }, //解散房间 dissmissRoom(bAgree) { if (bAgree > 0) { if (this.getPlayCount() <= 0) { var msgDismissPrivate = ProtocolGameServer.CMD_GR_Dismiss_Private.data(); msgDismissPrivate.Dismiss = 1; this.SendPrivteSocketData(ProtocolGameServer.SUB_GR_PRIVATE_DISMISS, msgDismissPrivate); } else { //poptip var msgDismissPrivate = ProtocolGameServer.CMD_GR_Dismiss_Private.data(); msgDismissPrivate.Dismiss = 1; this.SendPrivteSocketData(ProtocolGameServer.SUB_GR_PRIVATE_DISMISS, msgDismissPrivate); } } else { var msgDismissPrivate = ProtocolGameServer.CMD_GR_Dismiss_Private.data(); msgDismissPrivate.Dismiss = 0; this.SendPrivteSocketData(ProtocolGameServer.SUB_GR_PRIVATE_DISMISS, msgDismissPrivate); } }, exitGameWhenPlaying() { //BRTP_STATE_FREE :1, //空闲状态 //BRTP_STATE_CHIP :2, //下注状态 //BRTP_STATE_END :3, //结算状态 if (this.getSceneState() != 1 && this._alreadyJoin) { topTipMsg.showTopTipMsg("BRTP.exit_tip"); } else { // CChatServerItem.get().ConnectServer(cc.vv.config.ChatAddress, 8340); this.backHome(); this.exitGame(); } }, makeXieYi(m, s, data) { return MakeBRTPXieYi.makeGameData(m, s, data); }, isRecord() { return this._bIsRecord; }, onGAGetActivityUserMultiScore(data) { var nRevenue = data.lRevenue - cc.vv.globalUserInfo.getRevenue(); if (nRevenue == 0) return; cc.vv.globalUserInfo.setRevenue(data.lRevenue); var OK = function () { } // popScence.initPopScence("恭喜您,获得" + nRevenue + "张福卡",this,OK); }, onSocketSubExchangeRoom(data) { if (data.cbReason == 1 || data.cbReason == 2) { var self = this; var OK = function () { self.backHome(); self.exitGame(); } // popScence.initPopScence("金豆不足,无法继续游戏。",this,OK); } }, onBtnCloseOnlinePlayerUI() { UIHelper.playButtonEffect("close"); var node = this.node.getChildByName("PlayerRankList"); if (node) { node.runAction(cc.sequence(cc.scaleTo(0.2, 1, 0), cc.callFunc(function () { node.active = false; }))); } }, getFuncBtnComponent() { return this.node.getComponent("BRTPFuncBtnMgr") }, // 唯一对局码 onSocketUpdateUniqueCode(data) { Global.print(`收到唯一对局码: (${data.strUniqueCode})`); if (!data.strUniqueCode) { return; } let roomNumNode = cc.find("RoomInfoNode/num", this.node); roomNumNode.active = true; roomNumNode.getComponent(cc.Label).string = data.strUniqueCode; }, // 控制数据 onSubSendControlInfo(data) { if (BaseDefine.LOCALTEST) { this.node.getChildByName("ControlInfo").active = true; this._controlInfo = data.areaInfo || []; this.showControlInfo(); } else { this.node.getChildByName("ControlInfo").active = false; } }, showControlInfo() { const infoNode = cc.find("ControlInfo/info", this.node); if (!infoNode.active) return; const areaType = ["黑桃池", "红桃池", "方块池", "梅花池"]; let txt = `` + `\t\t\t\t\t\t房间杀率:${parseFloat(this._controlInfo[0].RoomSha / 100.0).toFixed(2)}% ` + `触发系统赢:\n\t\t\t\t\t\t${parseFloat(this._controlInfo[0].RoomWin / 100.0).toFixed(2)}% ` + `触发系统输:${parseFloat(this._controlInfo[0].RoomLost / 100.0).toFixed(2)}%\n`; for (let i = 0; i < this._controlInfo.length; ++i) { let data = this._controlInfo[i]; txt += `${areaType[i]}: ` + ( (!!data.IsDanKong) ? ( `单控有 ` + `单控玩家${(data.DanType == 1) ? "输" : ((data.DanType == 2) ? "赢" : "无")} ` + `随到${data.RoomSuiRate}% ` + `玩家: ${data.szNickName} ` + `门槛: ${data.DanMinBet}` ) : ( (!!data.QunState) ? ( `群控${(data.RoomResult == 1) ? "系统赢" : ((data.RoomResult == 2) ? "系统输" : "无控制")}` + `随到概率${parseFloat(data.RoomSuiRate / 100.0).toFixed(2)}%\t` ) : ( `单控无, 群控无` ) ) ) + `\n`; } txt += ``; infoNode.getChildByName("label").getComponent(cc.RichText).string = txt; }, // 显示趋势图 showTrendPanel(data) { this.node.getChildByName("TrendPanel").active = true; if (!this._gameResultRecords && !this._trendData) return; let records = this._gameResultRecords.record; let recordAnalyze = this._trendData.record; const recordNodes = this.TrendContent.getChildByName("result").children; // 载入输赢记录 let recordNode = null; for (let i = 1; i <= recordNodes.length; i++) { recordNode = recordNodes[recordNodes.length - i]; recordNode.getChildByName("spades").getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[records[records.length - i].bWinTian]; recordNode.getChildByName("hearts").getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[records[records.length - i].bWinDi]; recordNode.getChildByName("diamonds").getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[records[records.length - i].bWinXuan]; recordNode.getChildByName("clubs").getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[records[records.length - i].bWinHuang]; } // 提取已经成功载入的记录, 分析输赢率 const spades_r_node = this.TrendContent.getChildByName("result_data").getChildByName("spades").getChildByName("label"); const hearts_r_node = this.TrendContent.getChildByName("result_data").getChildByName("hearts").getChildByName("label"); const diamonds_r_node = this.TrendContent.getChildByName("result_data").getChildByName("diamonds").getChildByName("label"); const clubs_r_node = this.TrendContent.getChildByName("result_data").getChildByName("clubs").getChildByName("label"); const spades_r = (recordAnalyze[0].lWinTian / recordAnalyze[0].lDrawCount); const hearts_r = (recordAnalyze[0].lWinDi / recordAnalyze[0].lDrawCount); const diamonds_r = (recordAnalyze[0].lWinXuan / recordAnalyze[0].lDrawCount); const clubs_r = (recordAnalyze[0].lWinHuang / recordAnalyze[0].lDrawCount); spades_r_node.getComponent(cc.Label).string = parseInt(spades_r * 100) + "%"; hearts_r_node.getComponent(cc.Label).string = parseInt(hearts_r * 100) + "%"; diamonds_r_node.getComponent(cc.Label).string = parseInt(diamonds_r * 100) + "%"; clubs_r_node.getComponent(cc.Label).string = parseInt(clubs_r * 100) + "%"; }, // 显示玩家操作记录 showOperateRecordPanel() { let data = JSON.parse(cc.sys.localStorage.getItem("BRTP_OperateRecord")); this.node.getChildByName("RecordPanel").active = true; if (data.length <= 0) return; let item = this.OperateRecordContent.children[0]; this.OperateRecordContent.removeAllChildren(); for (let info of data) { let child = cc.instantiate(item); child.active = true; child.parent = this.OperateRecordContent; child.getChildByName("time").getComponent(cc.Label).string = info.nTime.toString(); child.getChildByName("bet").getComponent(cc.Label).string = info.nBet.toString(); child.getChildByName("result").getComponent(cc.Label).string = info.nWimLost.toString(); } }, pourChipsAgain() { if (this._chipCache && this._chipCache.length > 0) { let sumScore = this._chipCache.reduce((ans, cur) => ans + parseInt(cur.lScore / 100), 0); if (sumScore < this._selfScore) { for (const data of this._chipCache) { this.SendGameSocketData(GameProtocol.SUB_C_PLACE_JETTON, data); this.node.getComponent("BRTPFuncBtnMgr")._chipCache.push(data); } this._chipCache = []; cc.find("FuncBtnNode/GoldBtnNode/Button_GoldAddAgain", this.node).getComponent(cc.Button).interactable = false; } else { topTipMsg.showTopTipMsg("BRTP.again_chip_not_score"); } } else { topTipMsg.showTopTipMsg("BRTP.again_chip_not_data"); } }, LackOfGoldWillExitGame() { Global.print("LackOfGoldWillExitGame") this._willExit_LackOfGold = true; if (this._willExit_LackOfGold) { var item = importInstance.GameManagerBase.getGameServerItem(); Global.print(item); this.backHome(); this.exitGame(); var homeStart = cc.vv.GetHallScript(); homeStart.showShortage(item); } }, saveSysLocalStorage(data) { let score = data.lPlayAreaScore; let number = Math.abs(score[0]) + Math.abs(score[1]) + Math.abs(score[2]) + Math.abs(score[3]); let local = JSON.parse(cc.sys.localStorage.getItem("BRTP_OperateRecord")); if (!Array.isArray(local)) { local = []; } if (local.length > 50) { local.shift(); } if (number != 0) { local.shift({ nBet: number, nTime: new Date().toLocaleString("ja"), nWimLost: data.lPlayerWinScore }); } cc.sys.localStorage.setItem("BRTP_OperateRecord", JSON.stringify(local)); }, });