1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147 |
- let Global = require("Global");
- let TPGameBase = require("TPGameBase");
- let { CServerItem } = require("CServerItem");
- let ScenceManager = require("HNScenceManager");
- let GameManagerBase = require("GameManagerBase");
- let BaseDefine = require("BaseDefine");
- let BRTPSoundFun = require("BRABSoundFun");
- let topTipMsg = require("topTipMsg");
- const UIHelper = require("UIHelper");
- cc.Class({
- extends: TPGameBase,
- properties: {
- chipSprite: [cc.SpriteFrame],
- chipBmFont: [cc.BitmapFont],
- avatarsSpriteAtlas: cc.SpriteAtlas
- },
- onLoad() {
- this.GameStateEnum = {
- "Free": 0,
- "Start": 1,
- "End": 2,
- }
- this.GameState = null;
- this.baseType = "brab";
- this.menuOpenState = false;
- this.menuNode = UIHelper.pathGetNode(this.node, "TP_Base/menuNode");
- this.menuNode.scaleY = 0;
- this.initMenuBtn();
- this.initData();
- this._super();
- BRTPSoundFun.playBackMusic(BRTPSoundFun.GAME_BACKGRUAND);
- },
- /*------------------------------------------------ 数据初始化 -----------------------------------------------*/
- initMenuBtn() {
- UIHelper.addButtonListener(this.menuNode.getChildByName("img_cb_sz"), this.node, "BRABGameScene", "onBtnGameSettings");
- UIHelper.addButtonListener(this.menuNode.getChildByName("img_cb_gz"), this.node, "BRABGameScene", "onBtnRule");
- UIHelper.addButtonListener(this.menuNode.getChildByName("img_cb_tc"), this.node, "BRABGameScene", "onBtnExitToLobby");
- },
- initData() {
- this.animManager = this.node.getComponent("BRABAnimManager");
- this.layer_playControlButton_mode2 = UIHelper.pathGetNode(this.node, "TP_Base/layer_bottom/layer_playControlButton_mode2");
- this.tip_ring = UIHelper.pathGetNode(this.node, "TP_Base/layer_bottom/layer_playControlButton_mode2/tip_ring");
- this.layer_gameBg = UIHelper.pathGetNode(this.node, "layer_gameBg");
- this.button_andar = UIHelper.pathGetNode(this.node, "layer_gameBg/button_andar");
- this.button_bahar = UIHelper.pathGetNode(this.node, "layer_gameBg/button_bahar");
- this.layer_allChipTotle = UIHelper.pathGetNode(this.node, "layer_allChipTotle");
- this.label_allPoolA = UIHelper.pathGetNode(this.node, "layer_allChipTotle/label_allPoolA");
- this.label_allPoolB = UIHelper.pathGetNode(this.node, "layer_allChipTotle/label_allPoolB");
- this.layer_myChipTotle = UIHelper.pathGetNode(this.node, "layer_myChipTotle");
- this.label_myPoolA = UIHelper.pathGetNode(this.node, "layer_myChipTotle/label_myPoolA");
- this.label_myPoolB = UIHelper.pathGetNode(this.node, "layer_myChipTotle/label_myPoolB");
- this.layer_bank = UIHelper.pathGetNode(this.node, "layer_bank");
- this.layer_stateAnim = UIHelper.pathGetNode(this.node, "layer_stateAnim");
- this.ani_wait = UIHelper.pathGetNode(this.node, "layer_stateAnim/ani_wait");
- this.spine_jetonTip = UIHelper.pathGetNode(this.node, "layer_stateAnim/spine_jetonTip");
- this.layer_standPlayer = UIHelper.pathGetNode(this.node, "layer_standPlayer");
- this.button_playerCount = UIHelper.pathGetNode(this.node, "layer_standPlayer/button_playerCount");
- this.label_playerCount = UIHelper.pathGetNode(this.node, "layer_standPlayer/button_playerCount/label_playerCount");
- this.scroll_playerList = UIHelper.pathGetNode(this.node, "layer_standPlayer/scroll_playerList");
- this.copyNode_playerList = UIHelper.pathGetNode(this.node, "layer_standPlayer/scroll_playerList/copyNode_playerList");
- this.scroll_playerList_content = UIHelper.pathGetNode(this.node, "layer_standPlayer/scroll_playerList/view/scroll_playerList_content");
- this.layer_poker = UIHelper.pathGetNode(this.node, "layer_poker");
- this.layer_bankPoker = UIHelper.pathGetNode(this.node, "layer_poker/layer_bankPoker");
- this.layer_andarPoker = UIHelper.pathGetNode(this.node, "layer_poker/layer_andarPoker");
- this.layer_baharPoker = UIHelper.pathGetNode(this.node, "layer_poker/layer_baharPoker");
- this.layer_chipShow = UIHelper.pathGetNode(this.node, "layer_chipShow");
- this.layer_time = UIHelper.pathGetNode(this.node, "layer_time");
- this.sprite_timeMask = UIHelper.pathGetNode(this.node, "layer_time/sprite_timeMask");
- this.label_timeClock = UIHelper.pathGetNode(this.node, "layer_time/label_timeClock");
- this.label_timeState = UIHelper.pathGetNode(this.node, "layer_time/label_timeState");
- this.layer_winLine = UIHelper.pathGetNode(this.node, "layer_winLine");
- this.layer_panelLine = UIHelper.pathGetNode(this.node, "layer_winLine/layer_panelLine");
- this.sprite_lineA = UIHelper.pathGetNode(this.node, "layer_winLine/sprite_lineA");
- this.sprite_lineB = UIHelper.pathGetNode(this.node, "layer_winLine/sprite_lineB");
- this.layer_abWinAnim = UIHelper.pathGetNode(this.node, "layer_abWinAnim");
- this.sprite_animAndar = UIHelper.pathGetNode(this.node, "layer_abWinAnim/sprite_animAndar");
- this.sprite_animBahar = UIHelper.pathGetNode(this.node, "layer_abWinAnim/sprite_animBahar");
- this.sprite_kuangAnimAndar = UIHelper.pathGetNode(this.node, "layer_abWinAnim/sprite_kuangAnimAndar");
- this.sprite_kuangAnimBahar = UIHelper.pathGetNode(this.node, "layer_abWinAnim/sprite_kuangAnimBahar");
- this.sprite_kuangAnimBank = UIHelper.pathGetNode(this.node, "layer_abWinAnim/sprite_kuangAnimBank");
- this.spine_jetonTip_component = UIHelper.pathGetNode(this.node, "layer_stateAnim/spine_jetonTip", sp.Skeleton);
- this.Button_GoldAddAgain = UIHelper.pathGetNode(this.node, "TP_Base/layer_bottom/layer_playControlButton_mode2/Button_GoldAddAgain", cc.Button);
- this._notLockState = true;
- this._lockUserEnter = true;//初始化加入玩家锁
- this._standPlayerCount = 0;//站着的玩家总数
- this._choiceChipNumber = 0;//选择的筹码面值
- this._allInChip = 0;//可下注数
- this._nowInChip = 0;//已下注数
- this._allAreaInChip = {
- 0: 0,//A区
- 1: 0,//B区
- }//所有玩家总下注区域数
- this._myAreaInChip = {
- 0: 0,//A区
- 1: 0,//B区
- }//我的总下注区域数
- this._gameNum = -1; //游戏局数
- this._playGameNum = 0;//不玩游戏局数
- this._middleCard = 0;//中心牌ID
- this._andarCard = [];//安达牌
- this._baharCard = [];//巴哈牌
- this._playerJettonArr = [[], []];//本局座位玩家.自己.站着的所有玩家下注在A,B去记录
- this._chipCache = [];//自己所有下注的记录缓存
- this._gameWinRate = null;
- this._endCardList = [];
- this._gameWInLine = [];
- },
- initJettonAreaArr() {
- let playerCount = 6;
- let arae = 2;
- this._playerJettonArr = [];
- for (let i = 0; i < playerCount + 2; i += 1) {
- this._playerJettonArr[i] = [];
- for (let j = 0; j < arae; j += 1) {
- this._playerJettonArr[i][j] = [];
- }
- }
- },
- initScene(data) {
- this.initJettonAreaArr();
- this.initStateAnim();
- this.initPlayer(data);
- this.initChipPool(data);
- this.setGameState(data, data.cbStatus || 0, true);
- this.initDateGameRestrict(data);
- },
- initStateAnim() {
- for (let i = 0; i < this.layer_stateAnim.children.length; i += 1) {
- this.layer_stateAnim.children[i].active = false;
- }
- },
- initPlayer(data) {
- let wSeatUser = data.wSeatUser;
- let playerList = this.getGamePlayerList();
- let myChair = this.getSelfPlayer().getChairID();
- let ojb = {
- 0: 3,
- 1: 4,
- 2: 5,
- 3: 0,
- 4: 1,
- 5: 2
- };
- for (let i = 0; i < this.layer_chairPlayer.children.length - 1; i += 1) {
- this.layer_chairPlayer.children[i].active = false;
- // let node = this.layer_chairPlayer.children[i];
- // if (node.getChildByName("New Label")) {
- // let label = node.getChildByName("New Label").getComponent(cc.Label)
- // label.string = "0";
- // }
- }
- for (let i = 0; i < playerList.length; i += 1) {
- let node = null;
- let script = playerList[i];
- let chairID = playerList[i].getChairID();
- let index = wSeatUser.indexOf(chairID);
- if (index >= 0) {
- //其他桌上的玩家
- node = this.layer_chairPlayer.children[ojb[index]];
- this.initPlayerNode(node, script);
- } else {
- //在旁边站的玩家
- node = cc.instantiate(this.copyNode_playerList);
- node.name = script.getNickName() + Math.round(Math.random() * 999999999);
- node.parent = this.scroll_playerList_content;
- this._standPlayerCount += 1;
- this.initPlayerNode(node, script);
- } if (myChair == chairID) {
- //我自己
- let node2 = this.layer_chairPlayer.children[this.layer_chairPlayer.children.length - 1];
- this.initPlayerNode(node2, this.myselfScript);
- this.myselfScript.initMyself();
- }
- }
- this._lockUserEnter = false;
- this.updateStandPlayerCount();
- },
- initPlayerNode(player, scripts) {
- player.active = true;
- player._saveScript = scripts;
- scripts.inits(player);
- },
- initWinLine(data) {
- let line = [];
- let posArr = [cc.v2(-51, -3), cc.v2(-25, -3), cc.v2(1, -3), cc.v2(27, -3), cc.v2(53, -3)];
- for (let i = data.cbWinArea.length - 1; i >= 0; i -= 1) {
- line.push(data.cbWinArea[i]);
- if (line.length == 5) { break; }
- }
- while (this.layer_panelLine.children.length > 0) {
- let node = this.layer_panelLine.children[0];
- node.removeFromParent();
- node.destroy();
- }
- line.reverse();
- for (let i = 0; i < line.length; i += 1) {
- let number = line[i];
- let node = cc.instantiate(this["sprite_line" + (number == 0 ? "A" : "B")]);
- node.parent = this.layer_panelLine;
- node.active = true;
- node.position = posArr[i];
- }
- },
- initDataByState(data, bool) {
- if (this.GameState == this.GameStateEnum.Start) {
- this._allInChip = parseFloat(this.getSelfPlayer().getUserScore());
- this._nowInChip = 0;
- this._allAreaInChip = { 0: 0, 1: 0, };
- this._myAreaInChip = { 0: 0, 1: 0, };
- this._chipCache[this._gameNum += 1] = [[], [], new Date()];
- this.schedule(() => BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_TIME), 1, 1, data.cbTimeLeave - 5);
- this.updateMiddleCard(data);
- this.updateReBatButton(true);
- this.stopPromises();
- } else if (this.GameState == this.GameStateEnum.End) {
- this._endCardIndex = 0;
- this._endCardList = [];
- this.updateAreaCardArray(data);
- this.updateReBatButton(false);
- this._baharCard.forEach((item, index) => { this._endCardList = this._endCardList.concat(item, this._andarCard[index]); })
- }
- },
- initSceneByState(data) {
- cc.log(data);
- if (this.GameState == this.GameStateEnum.Start || this.GameState == this.GameStateEnum.End) {
- let arr = [0, 0];
- let allPlayerAreachips = data.lSeatUserBetScore;
- let lAllJettonScore = data.lAllJettonScore;
- for (let i = 0; i < 6; i += 1) {
- arr[0] += allPlayerAreachips[i][0];
- arr[1] += allPlayerAreachips[i][1];
- this._playerJettonArr[i] = this.splitChips1(data, allPlayerAreachips[i]);
- };
- this._playerJettonArr[6] = this.splitChips1(data, this._playerJettonArr[6]);
- this._playerJettonArr[7] = this.splitChips1(data, [lAllJettonScore[0] - arr[0], lAllJettonScore[1] - arr[1]]);
- this._allAreaInChip = data.lAllJettonScore;
- this._myAreaInChip = data.lPlayerJettonScore;
- this._gameWInLine = [];
- this.updateMyChipTotle(true);
- this.updateAllChipTotle(true);
- this.stopPromises();
- } if (this.GameState == this.GameStateEnum.Start) {
- this.gameCardOnStart(data, true);
- this.updateMyJettonBtnInteractable(true);
- this.myselfScript.setScore(this.getSelfPlayer().getUserScore() - (data.lPlayerJettonScore[0] + data.lPlayerJettonScore[1]));
- this._nowInChip = data.lPlayerJettonScore[0] + data.lPlayerJettonScore[1];//已下注数
- this._allInChip = parseFloat(this.getSelfPlayer().getUserScore()) - this._nowInChip;//可下注数
- }
- else if (this.GameState == this.GameStateEnum.End) {
- this.gameCardOnEnd(data);
- this.updateMyJettonBtnInteractable(false);
- }
- },
- initDateGameRestrict(data) {
- if (data.nMinBetScore) {
- if (this._allInChip == 0) { this._allInChip = parseFloat(this.getSelfPlayer().getUserScore()) - this._nowInChip; }
- if (this._allInChip < data.nMinBetScore) {
- this._notLockState = false;
- UIHelper.pathGetNode(this.node, "TP_Base/layer_bottom/mask").active = true;
- UIHelper.pathGetNode(this.node, "TP_Base/layer_bottom/mask/label", cc.Label).string = Global.formatString2Score(data.nMinBetScore);
- this.updateMyJettonBtnInteractable(false);
- } else {
- this._notLockState = true;
- UIHelper.pathGetNode(this.node, "TP_Base/layer_bottom/mask").active = false;
- }
- }
- },
- splitChips1(data, arr) {
- let newArr = [];
- let chipsConfig = data.nChip;
- for (let i = 0; i < arr.length; i += 1) {
- let number = arr[i];
- newArr[i] = this.splitChips2(number, chipsConfig, i, []);
- }
- return newArr;
- },
- splitChips2(number, chipsConfig, area, arr) {
- if (number == 0) { return arr; }
- let index = 0;
- let randNumber = 0;
- for (let i = chipsConfig.length; i >= 0; i -= 1) {
- if (number >= chipsConfig[i]) {
- index = i;
- break;
- }
- }
- if (Math.random() < 0.3) {
- randNumber = chipsConfig[Math.floor(Math.random() * index)];
- } else {
- randNumber = chipsConfig[index];
- }
- let offsetX = -50 + Math.random() * 100;
- let offsetY = -50 + Math.random() * 100;
- let areaPos = area == 1 ? this.button_bahar.position : this.button_andar.position;
- // Global.print(randNumber)
- let chips = this.getChip(randNumber);
- chips.active = true;
- chips.parent = this.layer_chipShow.getChildByName(area == 1 ? "bahar" : "andar");
- chips.position = cc.v2(areaPos.x + offsetX, areaPos.y + offsetY);
- number -= randNumber;
- arr.push(randNumber);
- return this.splitChips2(number, chipsConfig, area, arr);
- },
- stopPromises() {
- this._reject && this._reject();
- this.animManager._reject && this.animManager._reject();
- this._reject = null;
- this.animManager._reject = null;
- },
- /*----------------------------------------------------------------------------------------------------------*/
- /*------------------------------------------------- 消息接收 ------------------------------------------------*/
- sceneMessage(gameStatus, typeCode, dataView) {
- let msg = null;
- switch (gameStatus) {
- case typeCode.GS_TK_END:
- case typeCode.GS_TK_CHIP:
- msg = ProtoAnalysis.analysisData(dataView, BRABProto.CMD_S_StatusPlay, BRABProto);
- this.initScene(msg);
- break;
- case typeCode.GS_TK_FREE:
- msg = ProtoAnalysis.analysisData(dataView, BRABProto.CMD_S_StatusFree, BRABProto);
- this.initScene(msg);
- break;
- default: Global.print("BRABGameSence onEventSceneMessage error "); break;
- };
- },
- GameMessage(msgHead, typeCode, dataView) {
- cc.log(msgHead, dataView);
- let msg = null;
- switch (msgHead.s) {
- case typeCode.SUB_S_SEND_CONTROL_INFO:
- msg = ProtoAnalysis.analysisData(dataView, BRABProto.CMD_S_ControlInfo, BRABProto);
- this.onSubSendControlInfo(msg);
- break;
- case typeCode.SUB_S_SEND_WINLOST:
- msg = ProtoAnalysis.analysisData(dataView, BRABProto.tagServerGameWinLost, BRABProto);
- this._gameWinRate = msg;
- break;
- case typeCode.SUB_S_SEND_RECORD:
- let data = { cbWinArea: [] };
- dataView.pos = 0;
- for (let i = 0; i < dataView.buffer.byteLength; i += 1) {
- data.cbWinArea.push(Global.GetInt8(dataView));
- }
- // msg = ProtoAnalysis.analysisData(dataView, BRABProto.tagServerGameRecord, BRABProto);
- // cc.log(msg);
- if (this._gameWInLine.length == 0) {
- this.initWinLine(data);
- }
- this._gameWInLine = data;
- break;
- case typeCode.SUB_S_PLACE_JETTON:
- case typeCode.SUB_S_OTHER_JETTON:
- msg = ProtoAnalysis.analysisData(dataView, BRABProto.CMD_S_PlaceJetton, BRABProto);
- this.playerJetton(msg);
- break;
- case typeCode.SUB_S_GAME_FREE:
- case typeCode.SUB_S_GAME_START:
- case typeCode.SUB_S_GAME_END:
- let cfg = {
- [typeCode.SUB_S_GAME_FREE]: { Func: "stateOnFree", CMD: "CMD_S_FreeState" },
- [typeCode.SUB_S_GAME_START]: { Func: "stateOnStart", CMD: "CMD_S_GameStart" },
- [typeCode.SUB_S_GAME_END]: { Func: "stateOnEnd", CMD: "CMD_S_GameEnd" },
- }[msgHead.s];
- this[cfg.Func](ProtoAnalysis.analysisData(dataView, BRABProto[cfg.CMD], BRABProto));
- break;
- case typeCode.SUB_S_PLACE_JETTON_FAIL:
- window.aaabbb = dataView;
- let dataList = {};
- dataView.pos = 0;
- dataList.szBuffer = Global.Read2Char(dataView, 64);
- if (dataList.szBuffer == "not bet time!") {
- dataList.szBuffer = "não aposta tempo";
- }
- topTipMsg.showTopTipMsg(dataList.szBuffer);
- // cc.log(Global.gbk2Utf8(dataList.szBuffer));
- break;
- default: Global.print("BRABGameSence onEventSceneMessage error "); break;
- };
- },
- /*----------------------------------------------------------------------------------------------------------*/
- /*------------------------------------------------- 状态控制 ------------------------------------------------*/
- setGameState(data, cbStatus, bool = false) {
- let time = data.cbTimeLeave;
- if (cbStatus == 0) {//等待开始
- this.GameState = this.GameStateEnum.Free;
- this.label_timeState.getComponent(cc.Label).string = "Preparando...";
- } else if (cbStatus == 1) {//下注状态
- this.GameState = this.GameStateEnum.Start;
- this.label_timeState.getComponent(cc.Label).string = "Tempo de aposta";
- } else if (cbStatus == 2) {//结算状态
- this.GameState = this.GameStateEnum.End;
- if (bool) {
- this.label_timeState.getComponent(cc.Label).string = "Preparando...";
- }
- } else {
- this.GameState = -1;
- this.label_timeState.getComponent(cc.Label).string = "";
- }
- this.timeFunc && this.unschedule(this.timeFunc);
- this.timeFunc = (dt) => {
- time -= dt;
- if (time > 0) {
- this.layer_time.active = true;
- this.label_timeClock.getComponent(cc.Label).string = Math.round(time);
- this.sprite_timeMask.getComponent(cc.Sprite).fillRange = time / data.cbTimeLeave * -1;
- } else {
- this.layer_time.active = false;
- this.unschedule(this.timeFunc);
- }
- }
- if (cbStatus != 2 || (cbStatus == 2 && bool)) {
- this.schedule(this.timeFunc, 0.1)
- } else {
- this.layer_time.active = false;
- }
- this.initDataByState(data);
- bool && this.initSceneByState(data);
- },
- stateOnFree(data) {
- // this.ani_wait.active = true;
- this.cleanRoom();//清理游戏桌面
- this.hideABAnim();
- this.initJettonAreaArr();
- this.setGameState(data, 0);
- this.updateMyChipTotle(false);
- this.updateAllChipTotle(false);
- this.updatePlayGameNum();
- },
- stateOnStart(data) {
- // this.ani_wait.active = false;
- this.spine_jetonTip.active = true;
- this.spine_jetonTip_component.setTrackCompleteListener(this.spine_jetonTip_component.setAnimation(0, "a1", false), () => {
- this.spine_jetonTip.active = false;
- this.updateMyJettonBtnInteractable(true);
- this.gameCardOnStart(data);
- });
- this.updateChiarPlayer(data);
- this.setGameState(data, 1);
- this.updateMyChipTotle(true);
- this.updateAllChipTotle(true);
- BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SENDCARD);
- },
- stateOnEnd(data) {
- this.spine_jetonTip.active = true;
- this.spine_jetonTip_component.setTrackCompleteListener(this.spine_jetonTip_component.setAnimation(0, "a2", false), () => {
- this.animManager.animTime1 = 0.3;
- this.animManager.animTime2 = 0.25;
- this.spine_jetonTip.active = false;
- this.gameEnd(data);
- });
- this.setGameState(data, 2);
- this.updateMyJettonBtnInteractable(false);
- BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SENDCARD);
- },
- gameCardOnStart(data, bool = false) {
- let pos = cc.v2(0, 290);
- let parent = this.layer_bankPoker;
- let node = this.getPoker(bool ? this._middleCard : 0, parent, true);
- node.position = pos;
- node.active = true;
- !bool && this.animManager.async_sendCardOnGameStart(pos, node, () => {
- this.animManager.rotaCard(pos, node, this.layer_bankPoker, this._middleCard);
- });
- },
- gameCardOnEnd(data) {
- let posArr = [cc.v2(0, 290), cc.v2(75, 85), cc.v2(-75, 85)];
- let index = 0;
- for (let i = 0; i < this._endCardList.length; i += 1) {
- let card1 = this.getCardNum(this._endCardList[i]);
- let card2 = this.getCardNum(data.cbMiddleCard);
- if (card1 == card2) {
- index = i;
- break;
- }
- }
- for (let i = 0; i < 3; i += 1) {
- if (this._endCardList[index]) {
- let node = null;
- let pos = posArr[i];
- if (i == 0) {
- node = this.getPoker(data.cbMiddleCard, this.layer_bankPoker, true);
- node.position = cc.v2(0, 290);
- } else {
- node = this.getPoker(this._endCardList[index], index % 2 == 0 ? this.layer_baharPoker : this.layer_andarPoker, true);
- node.position = cc.v2(index % 2 == 0 ? 75 : -75, 85);
- index -= 1;
- }
- node.active = true;
- }
- }
- // this.showWinAraeAnim(data, index + 1);
- },
- onUserEnter(clientUserItem) {
- if (this._lockUserEnter) { return; }
- let playerList = this.getGamePlayerList();
- let script = playerList.find((item) => { return item.getChairID() == clientUserItem.GetChairID(); })
- let node = cc.instantiate(this.copyNode_playerList);
- node.parent = this.scroll_playerList_content;
- this.initPlayerNode(node, script);
- this._standPlayerCount += 1;
- this.updateStandPlayerCount();
- },
- onUserLeave(clientUserItem, script) {
- if (this._lockUserEnter) { return; }
- let node = script.node;
- if (node.parent.name == "layer_chairPlayer") {
- // script.refreshHeadNode();
- } else if (node.parent.name == "scroll_playerList_content") {
- this._standPlayerCount -= 1;
- node.destroy();
- }
- this.updateStandPlayerCount();
- },
- /*----------------------------------------------------------------------------------------------------------*/
- /*------------------------------------------------- 下注控制 ------------------------------------------------*/
- playerJetton(data) {
- Global.print(data);
- let area = data.cbBetArea;
- let chair = data.wChairID;
- let score = data.lBetScore;
- let areaPos = area == 1 ? this.button_bahar.position : this.button_andar.position;
- let node = this.foundPlayerByChair(chair);
- let myChair = this.getSelfPlayer().getChairID();
- let chips = this.getChip(data.lBetScore);
- let nodePos = null;
- // if (node.getChildByName("New Label")) {
- // node.getChildByName("New Label").active = true;
- // let label = node.getChildByName("New Label").getComponent(cc.Label)
- // label.string = Number(label.string) + Number(Global.formatString2Score(score));
- // }
- if (myChair == chair) {
- node = this.myselfScript.node.getChildByName("sprite_playerHead");
- this.updateMyChipNumber(area, score);
- this.updateMyChipJetton();
- this.updateMyChipTotle(true);
- this.updateReBatButton(false);
- this.myselfScript.refreshMyself(score);
- nodePos = node.parent.position;
- } else if (node.parent.name == "layer_chairPlayer") {
- node = node.getChildByName("sprite_playerHead");
- nodePos = node.parent.position;
- } else if (node.parent.name == "scroll_playerList_content") {
- node = this.button_playerCount;
- nodePos = this.button_playerCount.position;
- }
- let [copyPos1] = [...nodePos];
- if (!node.originalPos) {
- node.originalPos = node.position;
- }
- let normalizeVec = areaPos.subtract(nodePos).normalize();
- this.animManager.jettonHeadMove(node, normalizeVec, node.originalPos);
- this.animManager.moveChips(data, chips, copyPos1);
- this.updateAllAreaInChip(area, score);
- this.updateAllChipTotle(true);
- this.updateJettonAreaArr(area, score, node.parent, myChair == chair);
- },
- foundPlayerByChair(chairID) {
- let playerList = this.getGamePlayerList();
- let script = playerList.find((item) => { return item.getChairID() == chairID; });
- return script.node;
- },
- /*-----------------------------------------------------------------------------------------------------------*/
- /*------------------------------------------------ 数据/界面刷新 ---------------------------------------------*/
- updateMiddleCard(data) {
- this._middleCard = data.cbMiddleCard;
- },
- updateAreaCardArray(data) {
- if (data.cbAreaCardArray) {
- this._andarCard = data.cbAreaCardArray[0];
- this._baharCard = data.cbAreaCardArray[1];
- }
- },
- updateStandPlayerCount() {
- this.label_playerCount.getComponent(cc.Label).string = this._standPlayerCount;
- },
- updateMyChipNumber(area, score) {
- this._nowInChip += score;
- this._allInChip -= score;
- this._myAreaInChip[area] += score;
- this._chipCache[this._gameNum][area].push(score);
- },
- updateMyChipJetton() {
- this.layer_playControlButton_mode2 = UIHelper.pathGetNode(this.node, "TP_Base/layer_bottom/layer_playControlButton_mode2");
- this.tip_ring.active = true;
- let reFind = this._allInChip < this._choiceChipNumber;
- Global.print(this._allInChip)
- for (let i = this.layer_playControlButton_mode2.children.length - 3; i >= 0; i -= 1) {
- let node = this.layer_playControlButton_mode2.children[i];
- let sprite = node.getComponent(cc.Sprite);
- let label = node.children[0].getComponent(cc.Label);
- if (this._allInChip >= node._chipCount) {
- node._canClick = true;
- sprite.spriteFrame = this.chipSprite[i];
- label.font = this.chipBmFont[i];
- if (reFind) {
- this.tip_ring.active = true;
- this.tip_ring.position = node.position;
- this._choiceChipNumber = node._chipCount;
- reFind = false;
- }
- } else {
- node._canClick = false;
- sprite.spriteFrame = this.chipSprite[6];
- label.font = this.chipBmFont[6];
- if (reFind && i == 0) {
- this.tip_ring.active = false;
- }
- }
- }
- },
- updateChiarPlayer(data) {
- this._standPlayerCount = 0;
- for (let i = 0; i < this.scroll_playerList_content.children.length; i += 1) {
- let node = this.scroll_playerList_content.children[i];
- let script = node._saveScript;
- if (script) {
- script.node = null;
- node._components = [];
- }
- node.destroy();
- }
- this.initPlayer(data);
- },
- updateMyJettonBtnInteractable(state) {
- if (state && this._notLockState) {
- this.updateMyChipJetton();
- } else {
- this.tip_ring.active = false;
- for (let i = 0; i < 6; i += 1) {
- let node = this.layer_playControlButton_mode2.children[i];
- node.getComponent(cc.Sprite).spriteFrame = this.chipSprite[6];
- node.children[0].getComponent(cc.Label).font = this.chipBmFont[6];
- }
- }
- },
- updateAllAreaInChip(area, score) {
- this._allAreaInChip[area] += score;
- },
- updateMyChipTotle(state) {
- this.label_myPoolA.getComponent(cc.Label).string = state ? Global.formatString2Score(this._myAreaInChip[0]) : 0;
- this.label_myPoolB.getComponent(cc.Label).string = state ? Global.formatString2Score(this._myAreaInChip[1]) : 0;
- },
- updateAllChipTotle(state) {
- this.label_allPoolA.getComponent(cc.Label).string = state ? Global.formatString2Score(this._allAreaInChip[0]) : 0;
- this.label_allPoolB.getComponent(cc.Label).string = state ? Global.formatString2Score(this._allAreaInChip[1]) : 0;
- },
- updatePlayGameNum() {
- if (this._playGameNum >= 5) {
- this.backHome();
- cc.vv.GetHallScript().LongTimeOutOfOperation("BRTP.time_out_exit_tip");
- }
- },
- updateJettonAreaArr(area, score, node, bool) {
- let order = node.orderIndex;
- let length = this._playerJettonArr.length - 1;
- if (bool) {
- this._playerJettonArr[length - 1][area].push(score);
- } else {
- this._playerJettonArr[order != null ? order : length][area].push(score);
- }
- },
- updateReBatButton(state) {
- if (state == false) {
- this.Button_GoldAddAgain.interactable = false;
- } else {
- let data = this._chipCache[this._gameNum - 1];
- if (data) {
- let area1 = data[0].length > 0 ? data[0].reduce((a, b) => { return a + b; }) : 0;
- let area2 = data[1].length > 0 ? data[1].reduce((a, b) => { return a + b; }) : 0;
- if (this._allInChip > (area1 + area2)) {
- this.Button_GoldAddAgain.interactable = data[0].length > 0 || data[1].length > 0;
- } else {
- this.Button_GoldAddAgain.interactable = false;
- }
- } else {
- this.Button_GoldAddAgain.interactable = false;
- }
- }
- },
- /*-----------------------------------------------------------------------------------------------------------*/
- /*------------------------------------------------- 游戏结束控制 ----------------------------------------------*/
- gameEnd(data) {
- if (this._endCardIndex >= this._endCardList.length) { return; }
- let id = this._endCardList[this._endCardIndex];
- let pos = this._endCardIndex % 2 == 0 ? cc.v2(75, 85) : cc.v2(-75, 85);
- let arae = this._endCardIndex % 2 == 0 ? this.layer_baharPoker : this.layer_andarPoker;
- let callFunc = () => {
- if (this.getCardNum(id) == this.getCardNum(this._middleCard)) {
- this.gameEndAnim(data);
- } else {
- this.gameEnd(data);
- }
- }
- let node = this.getPoker(id, arae, true);
- node.position = pos;
- this.animManager.async_sendCardOnGameStart(pos, node, callFunc);
- this._endCardIndex += 1;
- },
- async gameEndAnim(data) {
- this._endCardIndex -= 1;//由于异步原因_endCardIndex多加了1
- let index = this._endCardIndex;
- this.animManager.animTime1 = 1;
- this.animManager.animTime2 = 0.3;
- this.showWinLine(data, index);
- await this.showWinAraeAnim(data, index);
- await this.recoveryChips(data, index);
- await this.showWinerChipsMove1(data, index);
- await this.showWinerChipsMove2(data, index);
- await this.showWinerPlayerAnim(data, index);
- },
- showWinLine(data, index) {
- let number = index % 2 == 1 ? 0 : 1;
- let length = this.layer_panelLine.children.length;
- let posArr = [cc.v2(-51, -3), cc.v2(-25, -3), cc.v2(1, -3), cc.v2(27, -3), cc.v2(53, -3)];
- if (length == 5) {
- for (let i = 0; i < length; i += 1) {
- let node = this.layer_panelLine.children[i];
- if (i == 0) {
- node.runAction(cc.sequence(
- cc.spawn(
- cc.moveBy(0.3, cc.v2(-10, 0)),
- cc.scaleTo(0.3, 0)
- ),
- cc.callFunc(() => {
- node.destroy();
- })
- ))
- } else if (i != 0) {
- node.runAction(cc.moveTo(0.3, posArr[i - 1]));
- }
- }
- }
- let node = cc.instantiate(this["sprite_line" + (number == 0 ? "A" : "B")]);
- node.parent = this.layer_panelLine;
- node.active = true;
- node.setScale(0);
- node.position = posArr[length] ? posArr[length] : cc.v2(63, -3);
- node.runAction(cc.spawn(
- cc.moveTo(0.3, posArr[length - 1]),
- cc.scaleTo(0.3, 1),
- ));
- },
- async showWinAraeAnim(data, index) {
- return new Promise((resolve, reject) => {
- this._reject = reject;
- this.sprite_animAndar.active = index % 2 == 1;
- this.sprite_animBahar.active = index % 2 == 0;
- this.sprite_kuangAnimAndar.active = index % 2 == 1;
- this.sprite_kuangAnimBahar.active = index % 2 == 0;
- this.sprite_kuangAnimBank.active = true;
- setTimeout(resolve, 2000);
- });
- },
- async recoveryChips(data, index) {
- return new Promise((resolve, reject) => {
- this._reject = reject;
- let parent = this.layer_bank.getChildByName("sprite_playerHead");
- let targetNode = this.layer_chipShow.getChildByName(index % 2 == 0 ? "andar" : "bahar");
- for (let i = 0; i < targetNode.children.length; i += 1) {
- let node = targetNode.children[i];
- node.runAction(cc.sequence(
- cc.moveTo(0.2, parent.position),
- cc.callFunc(() => {
- this.putChip(node);
- }),
- ))
- }
- BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SCORE);
- setTimeout(resolve, 1000);
- });
- },
- async showWinerChipsMove1(data, index) {
- return new Promise((resolve, reject) => {
- this._reject = reject;
- this._chipAnim = [];
- let chipArr = [];
- let bank = this.layer_bank.getChildByName("sprite_playerHead");
- let winArae = this.layer_chipShow.getChildByName(index % 2 == 0 ? "bahar" : "andar");
- for (let i = 0; i < winArae.children.length; i += 1) {
- chipArr.push(winArae.children[i]);
- }
- for (let i = 0; i < this._playerJettonArr.length; i += 1) {
- this._chipAnim[i] = [];
- for (let k = 0; k < this._playerJettonArr[i][(index + 1) % 2].length; k += 1) {
- let num = this._playerJettonArr[i][(index + 1) % 2][k];
- let node1 = null;
- chipArr.find((item, itemIndex) => {
- if (item.name == num) {
- node1 = item;
- chipArr.splice(itemIndex, 1);
- return true;
- }
- return false;
- });
- let node2 = this.getChip(node1.name);
- this._chipAnim[i].push(node1, node2);
- this.animManager.moveChips({ cbBetArea: (index + 1) % 2 }, node2, bank.position);
- }
- }
- BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SCORE);
- setTimeout(resolve, 1000);
- });
- },
- async showWinerChipsMove2(data, index) {
- return new Promise((resolve, reject) => {
- this._reject = reject;
- let mySelfWinNumber = data.lPlayerWinScore;
- let chiarWinNumber = data.lSeatUserWinScore;
- let standWinNumber = data.lOtherPlayerWinScore;
- cc.log(mySelfWinNumber, chiarWinNumber, standWinNumber, "//////////////////////////////////////////");
- for (let i = 0; i < this._chipAnim.length; i += 1) {
- let node = null;
- if (i == this._chipAnim.length - 1) {
- node = this.button_playerCount;
- } else if (i == this._chipAnim.length - 2) {
- node = this.layer_chairPlayer.children[this.layer_chairPlayer.children.length - 1];
- } else {
- node = this.layer_chairPlayer.children[i];
- let script = node._saveScript;
- if (!script) {
- node = this.layer_chairPlayer.children[this.layer_chairPlayer.children.length - 1];
- }
- }
- for (let j = 0; j < this._chipAnim[i].length; j += 1) {
- let chip = this._chipAnim[i][j];
- chip.runAction(cc.sequence(
- cc.delayTime(0.5),
- cc.moveTo(0.3, node.position),
- cc.callFunc(() => {
- this.putChip(chip);
- })
- ))
- }
- }
- BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SCORE);
- setTimeout(resolve, 1000);
- });
- },
- showWinerPlayerAnim(data, index) {
- console.error(data.lSeatUserWinScore);
- this._reject = null;
- let mySelfWinNumber = data.lPlayerWinScore;
- let chiarWinNumber = data.lSeatUserWinScore;
- let standWinNumber = data.lOtherPlayerWinScore;
- let node1 = this.button_playerCount.getChildByName("spine_playerWin");
- let node2 = this.button_playerCount.getChildByName("sprite_playerWin");
- let node3 = this.button_playerCount.getChildByName("sprite_playerFail");
- let ojb = {
- 0: 3,
- 1: 4,
- 2: 5,
- 3: 0,
- 4: 1,
- 5: 2
- };
- for (let i = 0; i < 6; i += 1) {
- let script = this.layer_chairPlayer.children[i]._saveScript;
- if (script && this.getSelfPlayer().getChairID() == script.getChairID()) { continue; }
- script && script.endGameAnim(chiarWinNumber[ojb[i]]);
- }
- this._chipCache[this._gameNum][3] = mySelfWinNumber;
- this.myselfScript.setScore(data.lPlayerRestScore);
- this.myselfScript.endGameAnim(mySelfWinNumber);
- this.animManager.endGameAnim(node1, node2, node3, standWinNumber);
- if (data.lPlayerRestScore > 0) {
- this._playGameNum = 0;
- BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_GAME_WIN);
- } else if (data.lPlayerRestScore == 0) {
- this._playGameNum += 1;
- } else {
- this._playGameNum = 0;
- }
- },
- /*-----------------------------------------------------------------------------------------------------------*/
- cleanRoom() {
- let cleanArr = [this.layer_bankPoker, this.layer_andarPoker, this.layer_baharPoker];
- for (let i = 0; i < 3; i += 1) {
- let parent = cleanArr[i];
- while (parent.children.length > 0) {
- let node = parent.children[0];
- node.active = false;
- node.parent = this.pool_card;
- }
- }
- for (let i = 0; i < this.layer_chipShow.children.length; i += 1) {
- let parent = this.layer_chipShow.children[i];
- while (parent.children.length > 0) {
- let node = parent.children[0];
- node.active = false;
- node.parent = this.pool_card;
- }
- }
- },
- hideABAnim() {
- this.sprite_animAndar.active = false;
- this.sprite_animBahar.active = false;
- this.sprite_kuangAnimAndar.active = false;
- this.sprite_kuangAnimBahar.active = false;
- this.sprite_kuangAnimBank.active = false;
- },
- hideMenu() {
- let menuNode = this.menuNode;
- this.menuOpenState = false;
- let menuBtn = UIHelper.pathGetNode(this.node, "TP_Base/layer_top/btn_menu");
- menuBtn.stopAllActions();
- cc.tween(menuBtn)
- .to(0.1, { angle: 0 })
- .start()
- menuNode.stopAllActions();
- cc.tween(menuNode)
- .to(0.1, { scaleY: 0 })
- .start()
- },
- exitToLobby() {
- let menuNode = this.menuNode;
- this.menuOpenState = !this.menuOpenState;
- let menuBtn = UIHelper.pathGetNode(this.node, "TP_Base/layer_top/btn_menu");
- menuBtn.stopAllActions();
- cc.tween(menuBtn)
- .to(0.1, { angle: this.menuOpenState ? 90 : 0 })
- .start()
- menuNode.stopAllActions();
- cc.tween(menuNode)
- .to(0.1, { scaleY: this.menuOpenState ? 1 : 0 })
- .delay(8)
- .call(() => {
- if (this.menuOpenState) {
- this.hideMenu();
- }
- })
- .start()
- },
- onBtnRule() {
- this.layer_help = UIHelper.pathGetNode(this.node, "layer_help");
- this.layer_help.active = !this.layer_help.active;
- },
- onBtnExitToLobby() {
- UIHelper.playButtonEffect("open");
- ScenceManager.Instance().getGameComponent().exitGameWhenPlaying();
- },
- exitGameWhenPlaying() {
- this.backHome();
- },
- LackOfGoldWillExitGame() {
- ScenceManager.Instance().gameBackScence();
- GameManagerBase.Instance().setInGameServerID(-1);
- CServerItem.get().PerformStandUpAction(1);
- this.exitGame();
- UIHelper.nodeMAP = new Map();
- cc.vv.GetHallScript().showShortage(GameManagerBase.Instance().getGameServerItem());
- },
- //返回大厅
- backHome() {
- if (this.GameState == 1 && this._nowInChip > 0) {
- topTipMsg.showTopTipMsg("BRTP.exit_tip");
- } else {
- ScenceManager.Instance().gameBackScence();
- GameManagerBase.Instance().setInGameServerID(-1);
- CServerItem.get().PerformStandUpAction(1);
- this.exitGame();
- UIHelper.nodeMAP = new Map();
- }
- },
- onSubSendControlInfo(data) {
- if (BaseDefine.LOCALTEST) {
- this.node.getChildByName("ControlInfo").active = true;
- this._controlInfo = [data];
- this.showControlInfo();
- }
- },
- showControlInfo() {
- const infoNode = cc.find("ControlInfo/info", this.node);
- if (!infoNode.active) return;
- const areaType = ["----", "----", "----", "----"];
- let cbControlArea = this._controlInfo[0].cbControlArea;
- let txt = `<b>`
- + `<color=#ffffff>\t\t\t\t\t\t房间杀率:${parseFloat(this._controlInfo[0].RoomSha / 100.0).toFixed(2)}%</c> `
- + `<color=#ffffff>触发系统赢:\n\t\t\t\t\t\t${parseFloat(this._controlInfo[0].RoomWin / 100.0).toFixed(2)}%</c> `
- + `<color=#ffffff>触发系统输:${parseFloat(this._controlInfo[0].RoomLost / 100.0).toFixed(2)}%</c>`
- + `<color=#ffffff>触发系统输:${cbControlArea == 255 ? "不控制" : cbControlArea == 0 ? "控A区" : "控B区"}</c >\n`;
- for (let i = 0; i < this._controlInfo.length; ++i) {
- let data = this._controlInfo[i];
- txt += `< color=#ffffff > ${areaType[i]}: </c > `
- + (
- (!!data.IsDanKong) ? (
- `< color=#ffffff > 单控有</c > `
- + `< color=#ffffff > 单控玩家${(data.DanType == 1) ? "输" : ((data.DanType == 2) ? "赢" : "无")}</c > `
- + `< color=#ffffff > 随到${data.RoomSuiRate} %</c > `
- + `< color=#ffffff > 玩家: ${data.szNickName}</c > `
- + `< color=#ffffff > 门槛: ${data.DanMinBet}</c > `
- ) : (
- (!!data.QunState) ? (
- `< color=#ffffff > 群控${(data.RoomResult == 1) ? "系统赢" : ((data.RoomResult == 2) ? "系统输" : "无控制")}</c > `
- + `< color=#ffffff > 随到概率${parseFloat(data.RoomSuiRate / 100.0).toFixed(2)}%</c >\t`
- ) : (
- `< color=#ffffff > 单控无, 群控无</c > `
- )
- )
- )
- + `\n`;
- }
- txt += `</b > `;
- infoNode.getChildByName("label").getComponent(cc.RichText).string = txt;
- },
- hideControlInfo() {
- this.node.getChildByName("ControlInfo").getChildByName("info").active = !this.node.getChildByName("ControlInfo").getChildByName("info").active;
- },
- onBtnGameSettings() {
- UIHelper.playButtonEffect("open");
- var self = this;
- UIHelper.showWaitNode("loadResSingle", "");
- cc.resources.load("GamePrefabs/homescence/set", cc.Prefab, function (err, prefab) {
- UIHelper.hideWaitNode();
- if (!self._set) {
- self._set = cc.instantiate(prefab);
- self._set.parent = self.node;
- self._set.zIndex = (100);
- }
- self._set.getComponent("homeSet").showSet();
- self._set.getComponent("homeSet").hideNode();
- });
- },
- });
|