123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313 |
- 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 = `<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>\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;
- },
- // 显示趋势图
- 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));
- },
- });
|