BRTPGameSence.js 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313
  1. var GameBase = require("GameBase");
  2. var ProtocolGameServer = require("ProtocolGameServer");
  3. var GameProtocol = require("BRTPGameProtocol");
  4. var AnalyzeBRTPXieYi = require("AnalyzeBRTPXieYi");
  5. var MakeBRTPXieYi = require("MakeBRTPXieYi");
  6. var Global = require("Global");
  7. var topTipMsg = require("topTipMsg");
  8. var UIHelper = require("UIHelper");
  9. var BaseDefine = require("BaseDefine");
  10. var CGPFSActivity = require("CGPFSActivity");
  11. import { CServerItem } from 'CServerItem'
  12. import GameManagerBase from 'GameManagerBase'
  13. import ScenceManager from 'HNScenceManager'
  14. var importInstance = {};
  15. var BRTPSoundFun = require("BRTPSoundFun");
  16. var popScence = require("popScence");
  17. //游戏状态
  18. var GameState = cc.Enum(
  19. {
  20. BRTP_STATE_NULL: 0,
  21. BRTP_STATE_FREE: 1, //空闲状态
  22. BRTP_STATE_CHIP: 2, //下注状态
  23. BRTP_STATE_END: 3, //结算状态
  24. }
  25. )
  26. cc.Class({
  27. extends: GameBase,
  28. properties: {
  29. //玩家信息
  30. playerNode: cc.Node,
  31. playerPrefab: cc.Node,
  32. pubCardNode: cc.Node,
  33. JettonPrefab: cc.Node,
  34. playListContent: cc.Node,
  35. BankerListContent: cc.Node,
  36. OperateRecordContent: cc.Node, // RecordPanel,记录列表根节点
  37. TrendContent: cc.Node, // TrendPanel, 胜负列表根节点
  38. jetonWinLost: [cc.SpriteFrame],
  39. mWifiSpfArr: [cc.SpriteFrame],
  40. mNormalSpfArr: [cc.SpriteFrame],
  41. ChipsSprite: [cc.SpriteFrame], // 筹码bg图
  42. ChipsLabel: [cc.Font], // 筹码字体文件
  43. cardAtlas: cc.SpriteAtlas,
  44. _seatPlayer: [],//主界面显示的6个玩家
  45. _TotalNum: 0,//本局下注上限
  46. _JetonNum: 0,//本局下注值
  47. _AreaJetonTotal: [],//区域总下注
  48. _AreaJetonSelf: [],//区域自己下注
  49. _bankerUserId: -1,//庄家ID
  50. _SelfIsZhuang: false,//自己本局是否是庄家
  51. _ZhuangChipArray: [],//庄家赢的筹码数组(动画用)
  52. _SeatArray: [],//坐着的6个玩家椅子号
  53. //_players:[],
  54. _gameState: 0,
  55. _bIsRecord: false,
  56. _RecordActSpeed: 2,
  57. _goldZorder: 0,
  58. _alreadyJoin: false,//本局下注了
  59. _noJoinCount: 0,//连续未下注次数
  60. goldArr: [],
  61. _selfScore: 0,//自己本局可下注
  62. _experienceStart: false,//经历过开始
  63. _gameRecordData: null,//最新游戏记录数据
  64. _gameWinLostData: null,//最新游戏输赢数据
  65. _chipCache: [], // 下注记录缓存(用于续压)
  66. _chipRecord: [], // 下注记录
  67. },
  68. onLoad() {
  69. this.initConfig();
  70. this.initLogic();
  71. this.initUI();
  72. // if (importInstance.GameManagerBase.IsGoldGame()) {//金币场
  73. // this.setMenuBtnVisibleArr({"dissMiss":false,"back":true,"set":true,"help":true,"auto":false,"bank":false,"location":false})
  74. // }
  75. cc.game.once(cc.game.EVENT_HIDE, () => {
  76. if (this.node.active == false || this.node.parent == null) { return; }
  77. GameManagerBase.Instance().disconnectServer();
  78. });
  79. cc.game.once(cc.game.EVENT_SHOW, () => {
  80. if (this.node.active == false || this.node.parent == null) { return; }
  81. GameManagerBase.Instance().connectServer();
  82. });
  83. },
  84. initConfig() {
  85. importInstance = {
  86. CServerItem: CServerItem.get(),
  87. ScenceManager: ScenceManager.Instance(),
  88. GameManagerBase: GameManagerBase.Instance(),
  89. get CServerItem() { return this._CServerItem ? this._CServerItem : CServerItem.get() },
  90. get ScenceManager() { return this._ScenceManager ? this._ScenceManager : ScenceManager.Instance() },
  91. get GameManagerBase() { return this._GameManagerBase ? this._GameManagerBase : GameManagerBase.Instance() },
  92. }
  93. this.gameMessageConfig = {};
  94. this.preGameMessageConfig = {
  95. "SUB_S_GAME_FREE": { print: "BRTP::游戏空闲", functions: "OnGameFree" },
  96. "SUB_S_GAME_START": { print: "BRTP::游戏开始", functions: "OnGameStart" },
  97. "SUB_S_PLACE_JETTON": { print: "BRTP::玩家下注", functions: "OnGameJetonSelf" },
  98. "SUB_S_GAME_END": { print: "BRTP::游戏结束", functions: "OnGameEnd" },
  99. "SUB_S_APPLY_BANKER": { print: "BRTP::申请庄家成功", functions: "OnApplyBanker" },
  100. "SUB_S_APPLEY_BANKER_FAILURE": { print: "BRTP::申请庄家失败", functions: "OnFailInfo" },
  101. "SUB_S_CANCEL_BANKER": { print: "BRTP::取消庄家成功", functions: "OnCancelBanker" },
  102. "SUB_S_CANCEL_FAILURE": { print: "BRTP::取消庄家失败", functions: "OnFailInfo" },
  103. "SUB_S_CHANGE_BANKER": { print: "BRTP::切换庄家", functions: "setZhuangInfo" },
  104. "SUB_S_BANK_LIST": { print: "BRTP::庄家列表", functions: "onReceiveBankerList" },
  105. "SUB_S_SEND_RECORD": {
  106. print: "BRTP::游戏记录", functions: (msg) => {
  107. this._gameResultRecords = msg;
  108. this._experienceStart ? (this._gameRecordData = msg) : this.OnGameRecord(msg);
  109. }
  110. },
  111. "SUB_S_SEND_WINLOST": {
  112. print: "BRTP::游戏输赢", functions: (msg) => {
  113. this._experienceStart ? (this._gameWinLostData = msg) : this.OnWinLost(msg);
  114. }
  115. },
  116. "SUB_S_PLACE_JETTON_FAIL": { print: "BRTP::下注失败", functions: "OnFailInfo" },
  117. "SUB_S_ONLINE_PLAYER": { print: "BRTP::在线用户", functions: null },
  118. "SUB_S_OTHER_JETTON": { print: "BRTP::其它玩家下注", functions: "OnGameJetonOther" },
  119. "SUB_S_SEAT_JETTON": { print: "BRTP::占位玩家下注", functions: "OnGameJetonOther" },
  120. "SUB_S_SEND_CONTROL_INFO": { print: "BRTP::群控信息", functions: "onSubSendControlInfo" },
  121. "SUB_S_GAME_RECORD_INFO": { print: "BRTP::操作记录", functions: "showOperateRecordPanel" },
  122. };
  123. for (let i = 0, keys = Object.keys(this.preGameMessageConfig); i < keys.length; i += 1) {
  124. this.gameMessageConfig[GameProtocol[keys[i]]] = this.preGameMessageConfig[keys[i]];
  125. }
  126. },
  127. initLogic() {
  128. this._chipPool = new cc.NodePool(); // 筹码池
  129. this.registerTouchEventHandle();
  130. },
  131. initUI() {
  132. let PubCardNode = this.node.getChildByName("PubCardNode");
  133. let PourBtnList = this.node.getChildByName("PourBtnList");
  134. let TrendNode = this.node.getChildByName("RecordNode").getChildByName("TrendNode");
  135. let layout = PourBtnList.getComponent(cc.Layout);
  136. layout.spacingX = (cc.winSize.width / 1.61305 - 197 * 4) / 3;
  137. layout.updateLayout();
  138. for (let i = 0; i < 4; i += 1) {
  139. let node1 = PubCardNode.children[i];
  140. let node2 = TrendNode.children[i];
  141. node1.x = PourBtnList.children[i].x;
  142. node2.x = PourBtnList.children[i].x;
  143. if (i == 0) {
  144. node1.x = PourBtnList.children[i].x - 15;
  145. node2.x = PourBtnList.children[i].x - 15;
  146. } else if (i == 3) {
  147. node1.x = PourBtnList.children[i].x + 15;
  148. node2.x = PourBtnList.children[i].x + 15;
  149. }
  150. }
  151. },
  152. start() {
  153. BRTPSoundFun.playBackMusic(BRTPSoundFun.GAME_BACKGRUAND);
  154. // popScence.createPopScenceNode();
  155. },
  156. /*************************网络协议相关*****************************/
  157. //场景消息
  158. onEventSceneMessage(gameStatus, lookonUser, data) {
  159. Global.print("BRTPGameSence onEventSceneMessage 场景消息 ");
  160. var arr = new DataView(data.slice(0, 8));
  161. var dataView = new DataView(data.slice(8));
  162. var msgHead = { m: arr.getUint16(4, true), s: arr.getUint16(6, true), d: null };
  163. arr = null;
  164. switch (gameStatus) {
  165. case GameProtocol.GS_TK_FREE: {
  166. var msg = AnalyzeBRTPXieYi.analyze_StatusFree(dataView);
  167. Global.print("BRTP:: onFreeScence......")
  168. this.onFreeScence(msg);
  169. }
  170. break;
  171. case GameProtocol.GS_TK_END:
  172. case GameProtocol.GS_TK_CHIP:
  173. {
  174. Global.print("BRTP:: onPlayScence......")
  175. var msg = AnalyzeBRTPXieYi.analyze_StatusPlay(dataView);
  176. this.onPlayScence(msg);
  177. }
  178. break;
  179. default: {
  180. Global.print("BRTPGameSence onEventSceneMessage error ");
  181. }
  182. break;
  183. };
  184. },
  185. //游戏消息
  186. onEventGameMessage(data) {
  187. let arr = new DataView(data.slice(0, 8));
  188. let dataView = new DataView(data.slice(8));
  189. let msgHead = { m: arr.getUint16(4, true), s: arr.getUint16(6, true), d: null };
  190. let msg = AnalyzeBRTPXieYi.analyzeData(msgHead.m, msgHead.s, dataView);
  191. let config = this.gameMessageConfig[msgHead.s];
  192. if (config) {
  193. let print = config.print;
  194. let functions = config.functions;
  195. print && Global.print(config.print);
  196. typeof functions === 'function' ? functions(msg) : this[functions](msg);
  197. } else {
  198. Global.print("BRTPGameSence onEventGameMessage error ");
  199. }
  200. },
  201. getSceneState() {
  202. return this._gameState;
  203. },
  204. //断线续连
  205. onFreeScence(msg) {
  206. var selfPlayer = this.getSelfPlayer();
  207. if (!selfPlayer) {
  208. return;
  209. }
  210. this._alreadyJoin = false;
  211. this._noJoinCount = 0;
  212. this._experienceStart = false;
  213. this._selfScore = 0;
  214. this._chipConfig = msg.nChip; // 可投掷筹码配置,服务器控制
  215. this.resetView();
  216. this.initPourChips(); // 初始化下注配置
  217. this.initPlayers();
  218. this.initPlayerData(msg.wSeatUser);
  219. this.setZhuangInfo(msg.wBankerUser, false);
  220. this._TotalNum = (msg.lBankerScore / 5).toFixed(2);//msg.lAreaLimitScore;//本局最大可下注数量
  221. this._gameState = GameState.BRTP_STATE_FREE;
  222. this.updateState(msg.cbTimeLeave);
  223. },
  224. //返水信息同步
  225. onSocketBetInfoSync(data) {
  226. if (this.FS_interval) {
  227. clearInterval(this.FS_interval);
  228. }
  229. this.bJoin = (data.dwNowBet > 0);//data.bJoin;//是否参与过
  230. this._recharge = (data.dwRecharge > 0) ? true : false;//是否充值过
  231. cc.find("BetNode/Bet", this.node).active = true;
  232. let FingerAniNode = cc.find("BetNode/Bet/FingerAni", this.node);
  233. this._NowBet = data.dwNowBet;
  234. let BetAniNode = cc.find("BetNode/Bet/btn_Bet", this.node).getComponent(sp.Skeleton);
  235. if (BetAniNode.animation != "b3") {
  236. BetAniNode.setAnimation(0, "b1", true);
  237. cc.find("BetNode/Bet/info_2", this.node).getComponent(cc.Label).string = Global.formatString2Score(this._NowBet, 2);
  238. }
  239. cc.find("BetNode/Bet/info_3", this.node).getComponent(cc.Label).string = "Rebate:" + data.wRate + "%";
  240. cc.find("BetNode/Bet/info_1", this.node).getComponent(cc.Label).string = "Cumulative bonus";
  241. this._canCollect = false;
  242. this._timeStr = "";
  243. var self = this;
  244. let nowTime = Date.parse(new Date()) + cc.vv.config.tSysTimeMilliseconds;
  245. let RewardTime = Date.parse(data.RewardTime);
  246. if (this.bJoin && nowTime >= RewardTime) {//可领取
  247. if (BetAniNode.animation != "b3") {
  248. BetAniNode.setAnimation(0, "b2", true);
  249. }
  250. this._canCollect = true;
  251. cc.find("BetNode/Bet/info_1", this.node).getComponent(cc.Label).string = "You can get bonus";
  252. cc.find("BetNode/Bet/btn_Bet/TimeNode", self.node).active = self.bJoin;
  253. cc.find("BetNode/Bet/btn_Bet/TimeNode/Time", self.node).getComponent(cc.Label).string = "00:00:00";
  254. FingerAniNode.active = true;
  255. FingerAniNode.getComponent(sp.Skeleton).setAnimation(0, "a2", true);
  256. } else {
  257. let residueTime = RewardTime - nowTime;
  258. this.FS_interval = setInterval(function () {
  259. if (residueTime < 0) {
  260. clearInterval(self.FS_interval);
  261. if (self.bJoin) {
  262. if (BetAniNode.animation != "b3") {
  263. BetAniNode.setAnimation(0, "b2", true);
  264. }
  265. self._canCollect = true;
  266. cc.find("BetNode/Bet/info_1", self.node).getComponent(cc.Label).string = "You can get bonus";
  267. FingerAniNode.active = true;
  268. FingerAniNode.getComponent(sp.Skeleton).setAnimation(0, "a2", true);
  269. }
  270. }
  271. residueTime -= 1000;
  272. let timeStr = Global.formatSeconds(residueTime / 1000);
  273. self._timeStr = timeStr;
  274. cc.find("BetNode/Bet/btn_Bet/TimeNode", self.node).active = self.bJoin;
  275. cc.find("BetNode/Bet/btn_Bet/TimeNode/Time", self.node).getComponent(cc.Label).string = timeStr;
  276. if (cc.find("BetNode/TipNode_cantCollect", self.node).active) {
  277. cc.find("BetNode/TipNode_cantCollect/rootNode/TimeInfo", self.node).getComponent(cc.Label).string = timeStr;
  278. }
  279. }, 1000);
  280. }
  281. },
  282. //玩家返水信息
  283. onSocketUpdateBetScore(data) {
  284. if (this._NowBet && this._NowBet == data.lGameBet) {
  285. return;
  286. }
  287. this._NowBet = data.lGameBet;
  288. let rebateNode = cc.find("BetNode/Bet/info_2", this.node);
  289. if (cc.find("BetNode/CollectNode", this.node).active) {
  290. let num = Global.formatString2Score(this._NowBet, 2);
  291. cc.find("BetNode/CollectNode/ChipNode/num", this.node).getComponent(cc.Label).string = parseFloat(num).toLocaleString();
  292. }
  293. var self = this;
  294. if (this._NowBet > 0) {
  295. let BetAniNode = cc.find("BetNode/Bet/btn_Bet", this.node).getComponent(sp.Skeleton);
  296. BetAniNode.setAnimation(0, "b3", false);
  297. BetAniNode.setCompleteListener(function () {
  298. rebateNode.getComponent(cc.Label).string = Global.formatString2Score(self._NowBet, 2);
  299. if (self._canCollect) {
  300. BetAniNode.setAnimation(0, "b2", true);
  301. } else {
  302. BetAniNode.setAnimation(0, "b1", true);
  303. }
  304. });
  305. }
  306. /*let PotOpenAni = cc.find("BetNode/PotOpenAni", this.node);
  307. PotOpenAni.active = true;
  308. PotOpenAni.getComponent(sp.Skeleton).setAnimation(0,"b3",false);*/
  309. },
  310. onBtnBet() {
  311. if (!this._recharge) {
  312. cc.find("BetNode/TipNode_notCharge", this.node).active = true;
  313. } else if (!this.bJoin) {
  314. cc.find("BetNode/TipNode_notJoin", this.node).active = true;
  315. } else if (!this._canCollect) {
  316. cc.find("BetNode/TipNode_cantCollect/rootNode/TimeInfo", this.node).getComponent(cc.Label).string = this._timeStr;
  317. cc.find("BetNode/TipNode_cantCollect", this.node).active = true;
  318. } else {
  319. cc.find("BetNode/CollectNode", this.node).active = true;
  320. let num = Global.formatString2Score(this._NowBet, 2);
  321. cc.find("BetNode/CollectNode/ChipNode/num", this.node).getComponent(cc.Label).string = parseFloat(num).toLocaleString();
  322. }
  323. },
  324. onBtnCloseTipNode(event) {
  325. if (event) {
  326. event.target.parent.parent.active = false;
  327. }
  328. },
  329. onBtnCollect() {
  330. if (!this.m_CGPFSActivity) {
  331. this.m_CGPFSActivity = new CGPFSActivity({ URL: cc.vv.config.Address, Port: cc.vv.config.Port });
  332. this.m_CGPFSActivity.setMissionSink(this);
  333. }
  334. this.m_CGPFSActivity.getBetDrawInfo();
  335. },
  336. onBtnCloseCollectNode() {
  337. cc.find("BetNode/CollectNode", this.node).active = false;
  338. },
  339. //游戏场景重连
  340. onPlayScence(msg) {
  341. var selfPlayer = this.getSelfPlayer();
  342. if (!selfPlayer) {
  343. return;
  344. }
  345. this._alreadyJoin = false;
  346. this._noJoinCount = 0;
  347. this._experienceStart = false;
  348. this._selfScore = 0;
  349. this._chipConfig = msg.nChip; // 可投掷筹码配置,服务器控制
  350. this.resetView();
  351. this.initPlayers();
  352. this.initPlayerData(msg.wSeatUser);
  353. this.setZhuangInfo(msg.wBankerUser, false);
  354. this.initPourChips(); // 初始化下注配置
  355. this._TotalNum = (msg.lBankerScore / 5).toFixed(2); //msg.lBankerScore/10;//msg.lAreaLimitScore;//本局最大可下注数量
  356. if (msg.cbStatus == 1) {//下注状态
  357. this._gameState = GameState.BRTP_STATE_CHIP
  358. if (this._SelfIsZhuang) {//自己是庄
  359. this.node.getChildByName("SelfZhuang").active = true;
  360. } else {
  361. var selfPlayerView = this.getSelfNode().getComponent("BRTPPlayerView");
  362. this._selfScore = parseFloat(selfPlayerView.getScore() / 5);
  363. this.node.getChildByName("SelfZhuang").active = false;
  364. this.disabledPourChips(true);
  365. this.updateJetonBtn();
  366. }
  367. // this.node.getChildByName("TIpNode").active = true;
  368. var AreaNode = this.node.getChildByName("PourBtnList");
  369. for (let i = 0; i < GameProtocol.AREA_MAX; i++) {
  370. AreaNode.children[i].getChildByName("SelfScore").active = true;
  371. AreaNode.children[i].getChildByName("AllPlayerScore").active = true;
  372. AreaNode.children[i].getChildByName("bg_score").active = true;
  373. }
  374. this.showChipAndCard(msg);//显示牌和筹码
  375. //this._experienceStart = true;
  376. } else {//结算状态
  377. this._gameState = GameState.BRTP_STATE_END;
  378. // this.node.getChildByName("AllAniNode").getChildByName("Ani_wait").active = true;
  379. var AreaNode = this.node.getChildByName("PourBtnList");
  380. for (let i = 0; i < GameProtocol.AREA_MAX; i++) {
  381. AreaNode.children[i].getChildByName("SelfScore").active = true;
  382. AreaNode.children[i].getChildByName("AllPlayerScore").active = true;
  383. AreaNode.children[i].getChildByName("bg_score").active = true;
  384. }
  385. this.showChipAndCard(msg);//显示牌和筹码
  386. const selfPlayer = this.getSelfNode().getComponent("BRTPPlayerView");//自己
  387. selfPlayer.addScoreAni(msg.lPlayerWinScore);
  388. for (let i = 0; i < GameProtocol.AREA_MAX + 1; ++i) {
  389. let cardParentNode = this.pubCardNode.getChildByName("card" + i);
  390. let isWin = (msg.cbResult[i - 1] == 1);
  391. this.playCardType(cardParentNode, (msg.cbCardType[i] * 2 + 5));
  392. AreaNode.children[i - 1] && (AreaNode.children[i - 1].getChildByName("winAni").active = isWin);
  393. cardParentNode.getChildByName("winAni") && (cardParentNode.getChildByName("winAni").active = isWin);
  394. }
  395. this._alreadyJoin = false;
  396. }
  397. this.updateState(msg.cbTimeLeave);
  398. },
  399. updateState(cbTimeLeave) {
  400. var timeNode = this.node.getChildByName("TimeNode");
  401. if (this._gameState == GameState.BRTP_STATE_CHIP) {//下注状态
  402. timeNode.getChildByName("img_state").active = true;
  403. timeNode.getChildByName("img_state").getChildByName("label").getComponent(cc.Label).string = "Betting time";
  404. } else if (this._gameState == GameState.BRTP_STATE_END) {//结算状态
  405. timeNode.getChildByName("img_state").active = true;
  406. timeNode.getChildByName("img_state").getChildByName("label").getComponent(cc.Label).string = "Waiting";
  407. } else {//空闲状态
  408. timeNode.getChildByName("img_state").active = true;
  409. timeNode.getChildByName("img_state").getChildByName("label").getComponent(cc.Label).string = "Readying...";
  410. }
  411. this.playTimeAction(cbTimeLeave);
  412. },
  413. showChipAndCard(msg) {
  414. this._JetonNum = 0;
  415. var AreaNode = this.node.getChildByName("PourBtnList");
  416. for (var i = 0; i < GameProtocol.AREA_MAX; i++) {
  417. this.createChip(msg.lAllJettonScore[i + 1], i);//创建筹码
  418. this._AreaJetonTotal[i] = msg.lAllJettonScore[i + 1];//区域总下注
  419. AreaNode.children[i].getChildByName("AllPlayerScore").getComponent(cc.Label).string = parseInt(this._AreaJetonTotal[i]);
  420. this._AreaJetonSelf[i] = msg.lPlayerJettonScore[i + 1];//区域自己下注
  421. AreaNode.children[i].getChildByName("SelfScore").getChildByName("label").getComponent(cc.Label).string = parseInt(this._AreaJetonSelf[i]);
  422. if (this._AreaJetonSelf[i] > 0) {
  423. this._alreadyJoin = true;//下过注
  424. }
  425. this._JetonNum += msg.lAllJettonScore[i + 1];
  426. }
  427. this.node.getChildByName("TIpNode").getChildByName("totalLabel").getComponent(cc.Label).string = this._JetonNum.toFixed(2);
  428. var surplusScore = this._TotalNum - this._JetonNum;
  429. this.node.getChildByName("TIpNode").getChildByName("surplusLabel").getComponent(cc.Label).string = surplusScore.toFixed(2);
  430. for (var i = 0; i < GameProtocol.AREA_MAX + 1; i++) {
  431. this.showPubCard(msg.cbTableCardArray[i], i, false);
  432. }
  433. },
  434. /**
  435. * 发牌动画
  436. */
  437. sendCardAni() {
  438. return new Promise((resolve, reject) => {
  439. const deTime = 1; // 动画总时间
  440. const iterValScale = 0.3; // 牌依次向上移动比例
  441. const cardPreFab = this.pubCardNode.getChildByName("SendCardPrefab");
  442. const SendCardNode = this.pubCardNode.getChildByName("SendCardNode");
  443. let cardsNode = null; // 牌根节点
  444. let cardsPos = null; // 牌根节点坐标
  445. let cardScale = null; // 牌原始比例
  446. let cardIterValX = null; // 牌X轴间距(动画中X不变)
  447. let cardIterValY = null; // 动画开始牌Y轴间距
  448. // 牌节点与牌动画节点不在同一父节点下
  449. BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SENDCARD);
  450. for (let i = 0; i < GameProtocol.AREA_MAX + 1; ++i) {
  451. cardsNode = this.pubCardNode.getChildByName("card" + i);
  452. cardsPos = SendCardNode.convertToNodeSpaceAR(cardsNode.parent.convertToWorldSpaceAR(cardsNode.position));
  453. cardScale = cardsNode.children[0].scale;
  454. cardIterValX = Math.abs(cardsNode.children[0].x - cardsNode.children[1].x);
  455. cardIterValY = cardsNode.children[0].height * iterValScale * cardScale;
  456. for (let j = 0; j < GameProtocol.CARDS_NUM; ++j) {
  457. let card = cc.instantiate(cardPreFab);
  458. let start_p = cc.v3(
  459. cardsPos.x + (j - (GameProtocol.CARDS_NUM - 1) / 2) * cardIterValX,
  460. cardsPos.y + ((j + 1) * cardIterValY),
  461. 0
  462. );
  463. card.active = true;
  464. card.zIndex = j;
  465. card.setScale(cardScale);
  466. card.setPosition(start_p);
  467. card.parent = SendCardNode;
  468. var act = cc.moveTo(deTime, cc.v2(start_p.x, cardsPos.y));
  469. act.easing(cc.easeQuinticActionOut());
  470. card.runAction(act);
  471. }
  472. }
  473. setTimeout(resolve, deTime * 1000);
  474. });
  475. },
  476. showPubCard(cardData, AreaIdx, isAni) {
  477. var cardParentNode = this.pubCardNode.getChildByName("card" + AreaIdx);
  478. const finalScale = cardParentNode.children[0].scale;
  479. const addlen = Math.abs(cardParentNode.children[0].x - cardParentNode.children[1].x);
  480. console.log("show card")
  481. console.log(cardData);
  482. for (let j = 0; j < GameProtocol.CARDS_NUM; j++) {
  483. var card = cardParentNode.children[j];
  484. var component = card.getComponent("BRTPCard");
  485. if (!component) {
  486. component = card.addComponent("BRTPCard");
  487. }
  488. var cardId = cardData[j];
  489. let finalP = cc.v2((j - (GameProtocol.CARDS_NUM - 1) / 2) * addlen, 0);
  490. component.setId(cardId);
  491. card.scale = finalScale;
  492. card.setPosition(finalP);
  493. card.active = true;
  494. var num = component.tileNum();
  495. var color = (num == 0) ? 0 : component.tileColor() + 1;
  496. var frame = this.cardAtlas.getSpriteFrame("handmah_" + color.toString() + num.toString());
  497. card.getComponent(cc.Sprite).spriteFrame = frame;
  498. if (isAni) {
  499. card.setScale(0, card.scaleY);
  500. card.runAction(cc.scaleTo(0.3, card.scaleY, card.scaleY));
  501. BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SHOWCARD);
  502. }
  503. }
  504. },
  505. /**
  506. * 翻牌动画
  507. */
  508. turnPubCard(cardNode, cardData) {
  509. const finalScale = cardNode.children[0].scale; // 牌组最终大小
  510. const addlen = Math.abs(cardNode.children[0].x - cardNode.children[1].x); // 牌组最终间隔
  511. return new Promise((resolve, reject) => {
  512. for (let i = 0; i < GameProtocol.CARDS_NUM; i++) {
  513. let card = cardNode.children[i];
  514. let component = card.getComponent("BRTPCard");
  515. if (!component) {
  516. component = card.addComponent("BRTPCard");
  517. }
  518. let cardId = cardData[i];
  519. component.setId(cardId);
  520. let finalP = cc.v2((i - (GameProtocol.CARDS_NUM - 1) / 2) * addlen, 0);
  521. card.scale = finalScale;
  522. card.setPosition(finalP);
  523. card.active = true;
  524. let num = component.tileNum();
  525. let color = (num == 0) ? 0 : component.tileColor() + 1;
  526. let frame = this.cardAtlas.getSpriteFrame("handmah_" + color.toString() + num.toString());
  527. let moveTime = 0.25;
  528. let delayTime = 0.1;
  529. let starPos = card.getPosition();
  530. let endPos = cc.v2(0, 0);
  531. card.runAction(cc.sequence(
  532. cc.moveTo(moveTime, cc.v2(endPos.x, endPos.y)),
  533. cc.callFunc(() => { card.getComponent(cc.Sprite).spriteFrame = frame; }),
  534. cc.delayTime(delayTime),
  535. cc.spawn(
  536. cc.moveTo(moveTime, cc.v2(starPos.x, starPos.y)),
  537. cc.callFunc(() => {
  538. if (i == GameProtocol.CARDS_NUM - 1) resolve();
  539. })
  540. )
  541. )
  542. );
  543. }
  544. });
  545. },
  546. playCardType(cardNode, cardType) {//牌型动画
  547. return new Promise((resolve, reject) => {
  548. BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SHOWCARD);
  549. const TypeNode = cardNode.getChildByName("TypeNode");
  550. TypeNode.active = true;
  551. const TypeSke = TypeNode.getComponent(sp.Skeleton);
  552. TypeSke.setTrackCompleteListener(
  553. TypeSke.setAnimation(0, "a" + cardType.toString(), false),
  554. () => {
  555. TypeSke.setAnimation(0, "a" + (cardType + 1).toString());
  556. resolve();
  557. }
  558. );
  559. });
  560. },
  561. hidePubCard() {
  562. for (let i = 0; i < GameProtocol.AREA_MAX + 1; i++) {
  563. var cardParentNode = this.pubCardNode.getChildByName("card" + i);
  564. for (let j = 0; j < GameProtocol.CARDS_NUM; j++) {
  565. var card = cardParentNode.children[j];
  566. card.active = false;
  567. }
  568. }
  569. },
  570. OnGameFree(data) {
  571. this._gameState = GameState.BRTP_STATE_FREE;
  572. this.resetView();
  573. this.updateState(data.cbTimeLeave);
  574. this.node.getChildByName("AllAniNode").getChildByName("Ani_wait").active = true;
  575. },
  576. OnGameStart(data) {
  577. this._gameState = GameState.BRTP_STATE_CHIP;
  578. this.initPlayerData(data.wSeatUser);
  579. this.node.getChildByName("AllAniNode").getChildByName("Ani_wait").active = false;
  580. // this.node.getChildByName("TIpNode").active = true;
  581. // if(data.BankTimes > 0){
  582. // this.node.getChildByName("TIpNode").getChildByName("bankerNum").getChildByName("label").getComponent(cc.Label).string = data.BankTimes;//连庄次数
  583. // this.node.getChildByName("TIpNode").getChildByName("bankerNum").active = true;
  584. // var self = this;
  585. // setTimeout(() => {
  586. // self.node.getChildByName("TIpNode").getChildByName("bankerNum").active = false;
  587. // }, 3000);
  588. // }
  589. //播放开始动画
  590. // BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_CHIPSTART);
  591. this.goldArr = [];
  592. this.node.getChildByName("AllAniNode").getChildByName("AniNode_jetonTip").active = true;
  593. var startAni = this.node.getChildByName("AllAniNode").getChildByName("AniNode_jetonTip").getComponent(sp.Skeleton);
  594. startAni.setTrackCompleteListener(
  595. startAni.setAnimation(0, "a2", false),
  596. () => {
  597. this.node.getChildByName("AllAniNode").getChildByName("AniNode_jetonTip").active = false;
  598. if (this._SelfIsZhuang) {//自己是庄
  599. this.node.getChildByName("SelfZhuang").active = true;
  600. } else {
  601. var selfPlayerView = this.getSelfNode().getComponent("BRTPPlayerView");
  602. this._selfScore = parseFloat(selfPlayerView.getScore() / 5);
  603. this.node.getChildByName("SelfZhuang").active = false;
  604. this.disabledPourChips(true);
  605. this.updateJetonBtn();
  606. }
  607. }
  608. );
  609. //发牌动画
  610. this.sendCardAni()
  611. .then(() => {
  612. for (var i = 0; i < GameProtocol.AREA_MAX + 1; i++) {
  613. // 结束后 清空动画节点
  614. this.showPubCard(data.cbTableCardArray[i], i, false);
  615. this.pubCardNode.getChildByName("SendCardNode").removeAllChildren();
  616. }
  617. });
  618. var AreaNode = this.node.getChildByName("PourBtnList");
  619. for (let i = 0; i < GameProtocol.AREA_MAX; i++) {
  620. AreaNode.children[i].getChildByName("SelfScore").active = true;
  621. AreaNode.children[i].getChildByName("AllPlayerScore").active = true;
  622. AreaNode.children[i].getChildByName("bg_score").active = true;
  623. }
  624. this._TotalNum = data.lBankerScore;
  625. this.node.getChildByName("TIpNode").getChildByName("surplusLabel").getComponent(cc.Label).string = this._TotalNum.toFixed(2);
  626. this.updateState(data.cbTimeLeave);
  627. this._alreadyJoin = false;
  628. this._experienceStart = true;
  629. },
  630. OnGameJetonSelf(data) {
  631. this._alreadyJoin = true;
  632. this._JetonNum += data.lBetScore;
  633. this.node.getChildByName("TIpNode").getChildByName("totalLabel").getComponent(cc.Label).string = this._JetonNum.toFixed(2);//本局总下注
  634. var num = this._TotalNum - this._JetonNum;
  635. this.node.getChildByName("TIpNode").getChildByName("surplusLabel").getComponent(cc.Label).string = num.toFixed(2);//本局剩余可下注
  636. this._AreaJetonTotal[data.cbBetArea] += data.lBetScore;//区域总下注
  637. var selfPlayer = this.getSelfPlayer();
  638. if (selfPlayer.getChairID() == data.wChairID) {//自己下注
  639. this._AreaJetonSelf[data.cbBetArea] += data.lBetScore;//区域自己下注
  640. this._selfScore -= data.lBetScore;//自己本局可下注--
  641. }
  642. var AreaNode = this.node.getChildByName("PourBtnList");
  643. AreaNode.children[data.cbBetArea].getChildByName("AllPlayerScore").getComponent(cc.Label).string = parseInt(this._AreaJetonTotal[data.cbBetArea]);
  644. AreaNode.children[data.cbBetArea].getChildByName("SelfScore").getChildByName("label").getComponent(cc.Label).string = parseInt(this._AreaJetonSelf[data.cbBetArea]);
  645. if (this.getSelfPlayer().getChairID() == data.wChairID) {//桌子座位上的
  646. var selfPlayerJs = this.getSelfNode().getComponent("BRTPPlayerView");
  647. selfPlayerJs.setScore(data.lPlayerRestScore);
  648. }
  649. var seatPlayer = this.getSeatPlayerJsByChairId(data.wChairID);
  650. if (seatPlayer) {
  651. seatPlayer.setScore(data.lPlayerRestScore);
  652. }
  653. var otherPlayer = this.getOtherPlayerJSByChairId(data.wChairID);//玩家列表里的
  654. if (otherPlayer) {
  655. otherPlayer.setScore(data.lPlayerRestScore);
  656. }
  657. this.playJetonAni(data.lBetScore, data.wChairID, data.cbBetArea);
  658. this.updateJetonBtn();
  659. this._experienceStart = true;
  660. this._chipRecord.push({
  661. dwIndex: data.cbBetArea,
  662. lScore: data.lBetScore * 100
  663. });
  664. },
  665. OnGameJetonOther(data) {
  666. this._JetonNum += data.lBetScore;
  667. this.node.getChildByName("TIpNode").getChildByName("totalLabel").getComponent(cc.Label).string = this._JetonNum.toFixed(2);//本局总下注
  668. var num = this._TotalNum - this._JetonNum;
  669. this.node.getChildByName("TIpNode").getChildByName("surplusLabel").getComponent(cc.Label).string = num.toFixed(2);//本局剩余可下注
  670. this._AreaJetonTotal[data.cbBetArea] += data.lBetScore;//区域总下注
  671. var selfPlayer = this.getSelfPlayer();
  672. if (selfPlayer.getChairID() == data.wChairID) {//自己下注
  673. this._AreaJetonSelf[data.cbBetArea] += data.lBetScore;//区域自己下注
  674. }
  675. var AreaNode = this.node.getChildByName("PourBtnList");
  676. AreaNode.children[data.cbBetArea].getChildByName("AllPlayerScore").getComponent(cc.Label).string = parseInt(this._AreaJetonTotal[data.cbBetArea]);
  677. AreaNode.children[data.cbBetArea].getChildByName("SelfScore").getChildByName("label").getComponent(cc.Label).string = parseInt(this._AreaJetonSelf[data.cbBetArea]);
  678. if (this.getSelfPlayer().getChairID() == data.wChairID) {//桌子座位上的
  679. var selfPlayerJs = this.getSelfNode().getComponent("BRTPPlayerView");
  680. selfPlayerJs.setScore(data.lPlayerRestScore);
  681. }
  682. var seatPlayer = this.getSeatPlayerJsByChairId(data.wChairID);
  683. if (seatPlayer) {
  684. // star 投掷星星Ani
  685. seatPlayer.setScore(data.lPlayerRestScore);
  686. const starAniNode = AreaNode.children[data.cbBetArea].getChildByName("starAni");
  687. const allAniNode = this.node.getChildByName("AllAniNode");
  688. const isClimaxArea = (AreaNode.children.filter(childe => childe.getChildByName("starAni").active).length >= 2); //是否超出最大区域显示限制,当前为2个
  689. if (seatPlayer.isSpecialPlayer && !starAniNode.active && !isClimaxArea) {
  690. const end_p = allAniNode.convertToNodeSpaceAR(starAniNode.parent.convertToWorldSpaceAR(starAniNode.position));
  691. let aniNode = cc.instantiate(starAniNode);
  692. allAniNode.addChild(aniNode, 1);
  693. aniNode.active = true;
  694. aniNode.x = seatPlayer.node.x;
  695. aniNode.y = seatPlayer.node.y;
  696. starAniNode.active = true;
  697. starAniNode.getComponent(cc.Sprite).enabled = false;
  698. cc.tween(aniNode)
  699. .to(0.5, { x: end_p.x, y: end_p.y }, { easing: "circOut" })
  700. .call(() => {
  701. starAniNode.getComponent(cc.Sprite).enabled = true;
  702. aniNode.destroy();
  703. })
  704. .start();
  705. }
  706. }
  707. var otherPlayer = this.getOtherPlayerJSByChairId(data.wChairID);//玩家列表里的
  708. if (otherPlayer) {
  709. otherPlayer.setScore(data.lPlayerRestScore);
  710. }
  711. if (selfPlayer.getChairID() != data.wChairID) {
  712. this.playJetonAni(data.lBetScore, data.wChairID, data.cbBetArea);
  713. }
  714. this._experienceStart = true;
  715. },
  716. OnGameEnd(data) {
  717. this.saveSysLocalStorage(data);
  718. const selfChair = this.getSelfNode().getComponent("BRTPPlayerView").getChairID();
  719. // 各阶段动画总时间
  720. const areaResultAniTime = 1;
  721. const moveChipsToBankerAniTime = 1;
  722. const moveChipsToAreaAniTime = 1;
  723. const moveChipsToPlayerAniTime = 1;
  724. // 归属玩家的筹码列表
  725. const seatPlayerChips = new Array(GameProtocol.MAX_SEAT_COUNT);
  726. for (let i = 0; i < GameProtocol.MAX_SEAT_COUNT; i++) {
  727. seatPlayerChips[i] = new Array(GameProtocol.AREA_MAX);
  728. for (let j = 0; j < GameProtocol.AREA_MAX; j++) {
  729. seatPlayerChips[i][j] = new Array();
  730. }
  731. }
  732. const otherPlayerChips = new Array(GameProtocol.AREA_MAX);
  733. for (let i = 0; i < GameProtocol.AREA_MAX; i++) {
  734. otherPlayerChips[i] = new Array();
  735. }
  736. const selfPlayerChips = new Array(GameProtocol.AREA_MAX);
  737. for (let i = 0; i < GameProtocol.AREA_MAX; i++) {
  738. selfPlayerChips[i] = new Array();
  739. }
  740. this.disabledPourChips(false);
  741. this.unScheduleChipMove(); // 立即结束投掷动画定时器,投掷所有未投掷的筹码
  742. this._gameState = GameState.BRTP_STATE_END;
  743. this._chipCache = Array.from(this._chipRecord); // 保存当前玩家投掷筹码的记录缓存,用于续投
  744. this._chipRecord = [];
  745. this.node.getChildByName("TimeNode").active = false;
  746. // this.updateState(data.cbTimeLeave);
  747. /* 结束提示Ani */
  748. var endTipAni = () => {
  749. return new Promise((resolve, reject) => {
  750. BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SENDCARD);
  751. // BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_CHIPEND);
  752. let endTipAni = this.node.getChildByName("AllAniNode").getChildByName("AniNode_jetonTip").getComponent(sp.Skeleton);
  753. endTipAni.node.active = true;
  754. endTipAni.setTrackCompleteListener(
  755. endTipAni.setAnimation(0, "a3", false),
  756. () => {
  757. endTipAni.node.active = false;
  758. resolve();
  759. }
  760. );
  761. });
  762. }
  763. /* 翻转牌Ani */
  764. var turnCardAni = () => {
  765. return new Promise((resolve, reject) => {
  766. const areaNode = this.node.getChildByName("PourBtnList");
  767. let cardParentNode = null;
  768. let ani = (i) => {
  769. if (i == GameProtocol.AREA_MAX + 1) {
  770. return resolve();
  771. }
  772. cardParentNode = this.pubCardNode.getChildByName("card" + i);
  773. // 翻转牌
  774. this.turnPubCard(cardParentNode, data.cbTableCardArray[i])
  775. .then(() => {
  776. // 显示牌型 (牌型sp,下标从7开始,单数动态,双数静态)
  777. this.playCardType(cardParentNode, (data.cbCardType[i] * 2 + 5))
  778. .then(() => {
  779. let isWin = (data.cbResult[i - 1] == 1);
  780. areaNode.children[i - 1] && (areaNode.children[i - 1].getChildByName("winAni").active = isWin);
  781. cardParentNode.getChildByName("winAni") && (cardParentNode.getChildByName("winAni").active = isWin);
  782. ani(++i);
  783. });
  784. });
  785. }
  786. ani(0);
  787. });
  788. }
  789. /* 区域输赢Ani */
  790. var areaResultAni = () => {
  791. return new Promise((resolve, reject) => {
  792. /* for(let i = 0;i < GameProtocol.AREA_MAX;i++){
  793. var resultNode = self.node.getChildByName("AllAniNode").children[i];
  794. var end = function(){}
  795. resultNode.getComponent(sp.Skeleton).setCompleteListener(end);
  796. if(data.cbResult[i] == 1){
  797. resultNode.active = true;
  798. resultNode.getComponent(sp.Skeleton).setAnimation(0,"ying",false)
  799. }else{
  800. resultNode.active = false;
  801. }
  802. } */
  803. setTimeout(resolve, areaResultAniTime * 1000);
  804. });
  805. }
  806. /* 区域筹码移动到庄家Ani */
  807. var moveChipsToBankerAni = () => {
  808. return new Promise((resolve, reject) => {
  809. const banker_p = this.getBankerNode().getPosition();
  810. let areaChipsNode = null;
  811. let isSounded = false; // 移动筹码音效,只播放一次
  812. for (let i = 0; i < GameProtocol.AREA_MAX; i++) {
  813. // Banker赢的情况下
  814. if (data.cbResult[i] <= 0) {
  815. areaChipsNode = this.node.getChildByName("JetonNode").children[i];
  816. areaChipsNode.children.forEach(node => {
  817. this.playChipMoveAni(node, node.getPosition(), banker_p, false, false).then(() => this.destroyChipNode(node));
  818. });
  819. if (!isSounded) {
  820. BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SCORE);
  821. isSounded = true;
  822. }
  823. }
  824. }
  825. setTimeout(resolve, moveChipsToBankerAniTime * 1000);
  826. });
  827. }
  828. /* 庄家筹码移动到区域Ani */
  829. var moveChipsToAreaAni = () => {
  830. return new Promise((resolve, reject) => {
  831. setTimeout(resolve, moveChipsToAreaAniTime * 1000);
  832. const areaChips = this.node.getChildByName("JetonNode").children;
  833. let isSounded = false; // 移动筹码音效,只播放一次
  834. for (let areaIndex = 0; areaIndex < GameProtocol.AREA_MAX; areaIndex++) {
  835. // 玩家已下注筹码数
  836. let selfScore = this._AreaJetonSelf[areaIndex];
  837. let seatScore = data.lSeatUserArerScore.map((item, i) => {
  838. if (this._SeatArray[i] == selfChair) {
  839. return 0;
  840. } else if (i < 3 && this._SeatArray.slice(3, 3).includes(this._SeatArray[i])) {
  841. return 0;
  842. } else {
  843. return item[areaIndex];
  844. }
  845. });
  846. // 其他玩家获胜筹码数
  847. let otherScore = -(data.lBankAreaWinScore[areaIndex] + data.lSeatUserArerScore.reduce((ans, cur) => ans + cur[areaIndex], 0));
  848. // 在座玩家获胜筹码数
  849. let ex_seatScore = seatScore.map(item => item * (data.cbMulti[areaIndex]));
  850. if (data.cbResult[areaIndex] > 0) {
  851. // 使用已下注筹码节点 从已生成筹码中获取对应筹码
  852. for (let chipIndex = 0; chipIndex < areaChips[areaIndex].childrenCount; chipIndex++) {
  853. let chipNode = areaChips[areaIndex].children[chipIndex];
  854. if (selfScore - chipNode.chipScore >= 0) {
  855. selfPlayerChips[areaIndex].push(chipNode);
  856. selfScore -= chipNode.chipScore;
  857. continue;
  858. } else {
  859. let seatIndex = 0;
  860. for (; seatIndex < GameProtocol.MAX_SEAT_COUNT; seatIndex++) {
  861. if (this._SeatArray[seatIndex] == selfChair) {
  862. seatScore[seatIndex] = 0;
  863. continue;
  864. }
  865. if (seatScore[seatIndex] > 0 && seatScore[seatIndex] - chipNode.chipScore >= 0) {
  866. seatPlayerChips[seatIndex][areaIndex].push(chipNode);
  867. seatScore[seatIndex] -= chipNode.chipScore;
  868. break;
  869. }
  870. }
  871. if (seatIndex == GameProtocol.MAX_SEAT_COUNT) {
  872. otherPlayerChips[areaIndex].push(chipNode);
  873. }
  874. }
  875. }
  876. // 生成玩家获胜得到的筹码,即庄家应该投掷的筹码
  877. [data.lPlayAreaScore[areaIndex], ...otherScore, ...ex_seatScore].forEach((score, i) => {
  878. if (score > 0) {
  879. for (let idx = this._chipConfig.length; idx--;) {
  880. if (score >= this._chipConfig[idx]) {
  881. let num = parseInt(score / this._chipConfig[idx]);
  882. let startPos = this.getBankerNode().getPosition();
  883. let endPos = this.node.getChildByName("PourBtnList").children[areaIndex].getPosition();
  884. let centerPos = this.node.getChildByName("PourBtnList").children[areaIndex].getChildByName("CentreNode").getPosition();
  885. endPos.x += centerPos.x;
  886. endPos.y += centerPos.y;
  887. for (let j = 0; j < num; j++) {
  888. let gold = this.getChipNode(this._chipConfig[idx]);
  889. areaChips[areaIndex].addChild(gold);
  890. gold.setPosition(startPos);
  891. gold.zIndex = this._goldZorder++;
  892. gold.active = true;
  893. if (i == 0) {
  894. selfPlayerChips[areaIndex].push(gold);
  895. } else if (i == 1) {
  896. otherPlayerChips[areaIndex].push(gold);
  897. } else {
  898. seatPlayerChips[i - 2][areaIndex].push(gold);
  899. }
  900. this.playChipMoveAni(gold, startPos, endPos, true, true, areaIndex);
  901. if (!isSounded) {
  902. BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SCORE);
  903. isSounded = true;
  904. }
  905. }
  906. score = score % this._chipConfig[idx];
  907. }
  908. }
  909. }
  910. });
  911. }
  912. }
  913. })
  914. }
  915. /* 区域筹码移动到玩家Ani */
  916. var moveChipsToPlayerAni = () => {
  917. return new Promise((resolve, reject) => {
  918. setTimeout(resolve, moveChipsToPlayerAniTime * 1000);
  919. // 移动到当前玩家
  920. const self_p = this.getSelfNode().getPosition();
  921. const other_p = this.getOtherPlayerNode().getPosition();
  922. let needSound = false;
  923. for (let areaIndex = 0; areaIndex < GameProtocol.AREA_MAX; areaIndex++) {
  924. for (let i = 0; i < selfPlayerChips[areaIndex].length; i++) {
  925. let chipNode = selfPlayerChips[areaIndex][i];
  926. this.playChipMoveAni(chipNode, chipNode.getPosition(), self_p, false, false).then(() => this.destroyChipNode(chipNode));
  927. needSound = true;
  928. }
  929. for (let seatIndex = 0; seatIndex < GameProtocol.MAX_SEAT_COUNT; seatIndex++) {
  930. let seatPlay = this.getSeatPlayerNodeByChairId(this._SeatArray[seatIndex]);
  931. if (!seatPlay) continue;
  932. for (let i = 0; i < seatPlayerChips[seatIndex][areaIndex].length; i++) {
  933. let chipNode = seatPlayerChips[seatIndex][areaIndex][i];
  934. this.playChipMoveAni(chipNode, chipNode.getPosition(), seatPlay.getPosition(), false, false).then(() => this.destroyChipNode(chipNode));
  935. needSound = true;
  936. }
  937. }
  938. for (let i = 0; i < otherPlayerChips[areaIndex].length; i++) {
  939. let chipNode = otherPlayerChips[areaIndex][i];
  940. this.playChipMoveAni(chipNode, chipNode.getPosition(), other_p, false, false).then(() => this.destroyChipNode(chipNode));
  941. needSound = true;
  942. }
  943. }
  944. if (needSound) {
  945. BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SCORE);
  946. }
  947. });
  948. }
  949. /* 输赢分数Ani */
  950. var addScoreAni = () => {
  951. return new Promise((resolve, reject) => {
  952. if (data.lPlayerWinScore > 0) {
  953. var selfWin = this.node.getChildByName("AllAniNode").getChildByName("Ani_selfWin").getComponent(sp.Skeleton);
  954. selfWin.node.active = true;
  955. selfWin.setTrackCompleteListener(
  956. selfWin.setAnimation(0, "a1", false),
  957. () => {
  958. selfWin.active = false;
  959. }
  960. );
  961. BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_GAME_WIN);
  962. } else if (data.lPlayerWinScore < 0) {
  963. // BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_GAME_LOSE);
  964. } else {
  965. BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_GAME_NO_BET);
  966. }
  967. BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SCORE);
  968. const banker = this.getBankerNode().getComponent("BRTPPlayerView");//庄家
  969. const selfPlayer = this.getSelfNode().getComponent("BRTPPlayerView");//自己
  970. banker.setScore(data.lBankerRestScore);
  971. selfPlayer.setScore(data.lPlayerRestScore);
  972. selfPlayer.addScoreAni(data.lPlayerWinScore);
  973. (data.lPlayerWinScore > 0) && selfPlayer.playWinAni();
  974. for (let i = 0; i < GameProtocol.MAX_SEAT_COUNT; i++) {//6个座位上的玩家
  975. const seatPlayer = this.getSeatPlayerJsByChairId(this._SeatArray[i]);
  976. if (seatPlayer && this._SeatArray[i] != selfChair) {
  977. //seatPlayer.setScore(data.lSeatUserWinScore[i]);
  978. seatPlayer.addScoreAni(data.lSeatUserWinScore[i]);
  979. (data.lSeatUserWinScore[i] > 0) && seatPlayer.playWinAni();
  980. }
  981. }
  982. //其他玩家
  983. if (data.lOtherPlayerWinScore != 0) {
  984. let score = Math.abs(data.lOtherPlayerWinScore);
  985. let otherPlayerScoreAni = this.node.getChildByName('FuncBtnNode').getChildByName("OtherPlayer").getChildByName("scoreAni");
  986. const isWin = (data.lOtherPlayerWinScore > 0)
  987. otherPlayerScoreAni.getChildByName("scoreWinLabel").active = isWin;
  988. otherPlayerScoreAni.getChildByName("scoreLoseLabel").active = !isWin;
  989. otherPlayerScoreAni.getChildByName("scoreWinLabel").getChildByName("label").getComponent(cc.Label).string = "+" + score.toFixed(2);
  990. otherPlayerScoreAni.getChildByName("scoreLoseLabel").getChildByName("label").getComponent(cc.Label).string = "-" + score.toFixed(2);
  991. otherPlayerScoreAni.getComponent(cc.Animation).play("showScoreAni");
  992. otherPlayerScoreAni.active = true;
  993. }
  994. resolve();
  995. });
  996. }
  997. // 按顺序播放结束动画
  998. endTipAni()
  999. .then(areaResultAni)
  1000. .then(turnCardAni)
  1001. .then(moveChipsToBankerAni)
  1002. .then(moveChipsToAreaAni)
  1003. .then(moveChipsToPlayerAni)
  1004. .then(addScoreAni)
  1005. .then(() => {
  1006. if (this._gameRecordData) {
  1007. this.OnGameRecord(this._gameRecordData);
  1008. this._gameRecordData = null;
  1009. }
  1010. if (this._gameWinLostData) {
  1011. this.OnWinLost(this._gameWinLostData);
  1012. this._gameWinLostData = null;
  1013. }
  1014. this._gameState = GameState.BRTP_STATE_FREE;
  1015. if (!this._alreadyJoin && !this._SelfIsZhuang) {//没下注并且自己不是庄家
  1016. this._noJoinCount++;
  1017. topTipMsg.showTopTipMsg("BRTP.hang_up_tip");
  1018. } else {
  1019. this._noJoinCount = 0;
  1020. }
  1021. if (this._noJoinCount >= 5) {//5局没下注自己退出
  1022. this._noJoinCount = 0;
  1023. this.exitGameWhenPlaying();
  1024. cc.vv.GetHallScript().LongTimeOutOfOperation("BRTP.time_out_exit_tip");
  1025. }
  1026. });
  1027. },
  1028. OnApplyBanker(data) {
  1029. if (data.wApplyUser == this.getSelfPlayer().getChairID()) {
  1030. var ApplyBankerNode = this.node.getChildByName("FuncBtnNode").getChildByName("ApplyBankerNode");
  1031. ApplyBankerNode.getChildByName("Button_callUp").active = false;
  1032. ApplyBankerNode.getChildByName("Button_callDown").active = true;
  1033. // topTipMsg.showTopTipMsg("你已加入庄家列表!");
  1034. var data = {};
  1035. importInstance.ScenceManager.getGameComponent().SendGameSocketData(GameProtocol.SUB_C_BANK_LIST, data);
  1036. }
  1037. },
  1038. OnCancelBanker(data) {
  1039. if (data.wCancelUser == this.getSelfPlayer().getChairID()) {
  1040. var ApplyBankerNode = this.node.getChildByName("FuncBtnNode").getChildByName("ApplyBankerNode");
  1041. ApplyBankerNode.getChildByName("Button_callUp").active = true;
  1042. ApplyBankerNode.getChildByName("Button_callDown").active = false;
  1043. // topTipMsg.showTopTipMsg("你已离开庄家列表!");
  1044. var data = {};
  1045. importInstance.ScenceManager.getGameComponent().SendGameSocketData(GameProtocol.SUB_C_BANK_LIST, data);
  1046. }
  1047. },
  1048. OnGameRecord(data) {
  1049. if (!data) return;
  1050. const recordNode = this.node.getChildByName("RecordNode").getChildByName("TrendNode");
  1051. const areaSpades = recordNode.getChildByName("record_spades"); // 黑桃
  1052. const areaHearts = recordNode.getChildByName("record_hearts"); // 红心
  1053. const areaDiamonds = recordNode.getChildByName("record_diamonds"); // 方块
  1054. const areaClubs = recordNode.getChildByName("record_clubs"); // 梅花
  1055. if (areaSpades.active && areaHearts.active && areaDiamonds.active && areaClubs.active) {
  1056. const AniTime = 0.5;
  1057. let parentNodes = [areaSpades, areaHearts, areaDiamonds, areaClubs];
  1058. parentNodes.forEach(parentNode => {
  1059. let children = parentNode.children;
  1060. let firstChild_p = children[0].position;
  1061. const oriScale = children[0].scale;
  1062. children[0].scale = 0;
  1063. children[0].position = children[children.length - 1].position;
  1064. for (let i = 1; i < children.length; ++i) {
  1065. let child = children[i];
  1066. child.runAction(cc.sequence(
  1067. cc.moveBy(AniTime, cc.v2(-child.width, 0)),
  1068. cc.moveBy(0, cc.v2(child.width, 0))
  1069. ));
  1070. }
  1071. children[0].runAction(cc.sequence(
  1072. cc.scaleTo(AniTime, oriScale),
  1073. cc.callFunc(() => {
  1074. children[0].position = firstChild_p;
  1075. })
  1076. ))
  1077. });
  1078. setTimeout(() => {
  1079. areaSpades.active = true;
  1080. areaHearts.active = true;
  1081. areaDiamonds.active = true;
  1082. areaClubs.active = true;
  1083. const RECORD_LENGTH = areaSpades.children.length;
  1084. let idx = data.record.length - 1;
  1085. for (var i = 0; i < RECORD_LENGTH && idx >= 0; i++) {
  1086. areaSpades.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinTian];
  1087. areaHearts.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinDi];
  1088. areaDiamonds.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinXuan];
  1089. areaClubs.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinHuang];
  1090. idx--;
  1091. }
  1092. }, AniTime);
  1093. } else {
  1094. areaSpades.active = true;
  1095. areaHearts.active = true;
  1096. areaDiamonds.active = true;
  1097. areaClubs.active = true;
  1098. const RECORD_LENGTH = areaSpades.children.length;
  1099. let idx = data.record.length - 1;
  1100. for (var i = 0; i < RECORD_LENGTH && idx >= 0; i++) {
  1101. areaSpades.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinTian];
  1102. areaHearts.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinDi];
  1103. areaDiamonds.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinXuan];
  1104. areaClubs.children[RECORD_LENGTH - 1 - i].getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[data.record[idx].bWinHuang];
  1105. idx--;
  1106. }
  1107. }
  1108. },
  1109. OnWinLost(data) {
  1110. if (!data) {
  1111. return;
  1112. }
  1113. this._trendData = data;
  1114. },
  1115. OnFailInfo(msg) {
  1116. topTipMsg.showTopTipMsg(Global.gbk2Utf8(msg.szBuffer));
  1117. },
  1118. onReceiveBankerList(msg) {
  1119. this.BankerListContent.removeAllChildren();
  1120. for (var i = 0; i < msg.BankLists.length; i++) {
  1121. var gamePlayer = this.getPlayerByChairID(msg.BankLists[i]);
  1122. if (gamePlayer) {
  1123. var bankerNode = cc.instantiate(this.playerPrefab);
  1124. bankerNode.active = true;
  1125. //this.node.getComponent("BRTPFuncBtnMgr").initButtonHandler(bankerNode.getChildByName("PlayerHead").getChildByName("ButtonPlayerHeadClick"));
  1126. this.BankerListContent.addChild(bankerNode);
  1127. var playerjs = bankerNode.getComponent("BRTPPlayer");
  1128. playerjs.setUserItem(gamePlayer.getUserItem());
  1129. playerjs.playerEnter();
  1130. playerjs.upPlayerInfo();
  1131. playerjs.upPlayerHead();
  1132. }
  1133. }
  1134. this.showBankerList(true);
  1135. },
  1136. getChipNode(Jeton) {
  1137. let node = null;
  1138. if (this._chipPool.size() > 0) {
  1139. node = this._chipPool.get();
  1140. } else {
  1141. node = cc.instantiate(this.JettonPrefab);
  1142. }
  1143. let chipIndex = this._chipConfig.findIndex(item => item == Jeton);
  1144. (chipIndex == -1) && (chipIndex = 0);
  1145. node.getComponent(cc.Sprite).spriteFrame = this.ChipsSprite[chipIndex + 1];
  1146. node.getChildByName("label").getComponent(cc.Label).font = this.ChipsLabel[chipIndex + 1];
  1147. node.getChildByName("label").getComponent(cc.Label).string = Jeton;
  1148. node.chipScore = Jeton;
  1149. return node;
  1150. },
  1151. destroyChipNode(node) {
  1152. this._chipPool.put(node);
  1153. },
  1154. //直接显示对应区域的筹码(断线重连用)
  1155. createChip(JetonScore, cbBetArea) {
  1156. var self = this;
  1157. var setChipAnimation = function (gold, endPos, cbBetArea) {
  1158. var offX = self.getBetAreaSize(cbBetArea).x;
  1159. var offY = self.getBetAreaSize(cbBetArea).y;
  1160. let randx = Math.floor(Math.random() * offX * (Math.random() > 0.5 ? 1 : -1));
  1161. let randy = Math.floor(Math.random() * offY * (Math.random() > 0.5 ? 1 : -1));
  1162. let rotate = Math.floor(Math.random() * 360 + 180);
  1163. gold.active = true
  1164. gold.setScale(0.3);
  1165. gold.setPosition(cc.v2(endPos.x + randx, endPos.y + randy));
  1166. gold.angle = rotate;
  1167. }
  1168. var endPos = this.node.getChildByName("PourBtnList").children[cbBetArea].getPosition();
  1169. var centerPos = this.node.getChildByName("PourBtnList").children[cbBetArea].getChildByName("CentreNode").getPosition();
  1170. endPos.x += centerPos.x;
  1171. endPos.y += centerPos.y;
  1172. var goldArr = [];
  1173. var JetonArr = this._chipConfig;
  1174. var nowJetonScore = JetonScore;
  1175. for (var i = JetonArr.length - 1; i >= 0; i--) {
  1176. if (nowJetonScore >= JetonArr[i]) {
  1177. var num = parseInt(nowJetonScore / JetonArr[i]);
  1178. for (var j = 0; j < num; j++) {
  1179. var gold = this.getChipNode(JetonArr[i]);
  1180. goldArr.push(gold);
  1181. }
  1182. nowJetonScore = nowJetonScore % JetonArr[i];
  1183. }
  1184. }
  1185. for (var i = 0; i < goldArr.length; i++) {
  1186. goldArr[i].zIndex = (this._goldZorder++)
  1187. this.node.getChildByName("JetonNode").children[cbBetArea].addChild(goldArr[i]);
  1188. setChipAnimation(goldArr[i], endPos, cbBetArea);
  1189. }
  1190. },
  1191. //下注筹码移动到天地玄区域动画
  1192. playJetonAni(JetonScore, wChairID, cbBetArea) {
  1193. var self = this;
  1194. var endPos = this.node.getChildByName("PourBtnList").children[cbBetArea].getPosition();
  1195. var centerPos = this.node.getChildByName("PourBtnList").children[cbBetArea].getChildByName("CentreNode").getPosition();
  1196. endPos.x += centerPos.x;
  1197. endPos.y += centerPos.y;
  1198. var JetonArr = this._chipConfig;
  1199. var selfPlayer = this.getSelfPlayer();
  1200. // 头像抖动效果
  1201. const Wobble_px = 10; // 抖动距离
  1202. const ACTION_TAG = 1;
  1203. let player = this.getSeatPlayerNodeByChairId(wChairID) || this.getOtherPlayerNode();
  1204. if (wChairID == selfPlayer.getChairID()) player = this.getSelfNode()
  1205. let player_p = player.getPosition();
  1206. let wobble_r = Wobble_px / Math.sqrt(Math.pow((endPos.y - player_p.y), 2) + Math.pow((endPos.x - player_p.x), 2)); // 移动距离与头像到目标位置的比例
  1207. let wobble_p = cc.v2((endPos.x - player_p.x) * wobble_r, (endPos.y - player_p.y) * wobble_r);
  1208. let moveby = cc.moveBy(0.1, wobble_p);
  1209. let moveRe = moveby.reverse();
  1210. let moveNode = player.getChildByName("PlayerHead") || player;
  1211. if (!moveNode.getActionByTag(ACTION_TAG) || moveNode.getActionByTag(ACTION_TAG).isDone()) {
  1212. let sqAction = cc.sequence(moveby, moveRe);
  1213. sqAction.setTag(ACTION_TAG);
  1214. moveNode.runAction(sqAction);
  1215. console.log(`position (${player_p}) (${endPos}) (${wobble_p})`);
  1216. }
  1217. if (selfPlayer.getChairID() == wChairID)//自己下注
  1218. {
  1219. startPos = this.getSelfNode().getPosition();
  1220. var goldArr = [];
  1221. var nowJetonScore = JetonScore;
  1222. for (var i = JetonArr.length - 1; i >= 0; i--) {
  1223. if (nowJetonScore >= JetonArr[i]) {
  1224. var num = parseInt(nowJetonScore / JetonArr[i]);
  1225. for (var j = 0; j < num; j++) {
  1226. var gold = this.getChipNode(JetonArr[i]);
  1227. goldArr.push(gold);
  1228. gold.startPos = startPos;
  1229. gold.endPos = endPos;
  1230. gold.cbBetArea = cbBetArea;
  1231. gold.isSelf = true;
  1232. }
  1233. nowJetonScore = nowJetonScore % JetonArr[i];
  1234. }
  1235. }
  1236. var callFun = function () {
  1237. if (goldArr.length <= 0) {
  1238. //self.unschedule(callFun);
  1239. return;
  1240. }
  1241. var num = goldArr.length;//parseInt(Math.random()*5);
  1242. var arr = goldArr.splice(0, num);
  1243. for (var i = 0; i < arr.length; i++) {
  1244. arr[i].zIndex = (self._goldZorder++)
  1245. self.node.getChildByName("JetonNode").children[arr[i].cbBetArea].addChild(arr[i]);
  1246. self.playChipAnimation(arr[i], arr[i]);
  1247. }
  1248. }
  1249. callFun();
  1250. //self.schedule(callFun,0.5);
  1251. } else {//别人下注
  1252. var isOther = true;//其他不在座位上的玩家
  1253. var startPos = this.getOtherPlayerNode().getPosition();
  1254. for (var i = 0; i < this._seatPlayer.length; ++i) {
  1255. if (wChairID == this._seatPlayer[i].getChairID()) {
  1256. startPos = this._seatPlayer[i].node.getPosition();
  1257. isOther = false;//6个座位上的玩家
  1258. break;
  1259. }
  1260. }
  1261. if (isOther) {
  1262. startPos = this.getOtherPlayerNode().getPosition();
  1263. }
  1264. var nowJetonScore = JetonScore;
  1265. for (var i = JetonArr.length - 1; i >= 0; i--) {
  1266. if (nowJetonScore >= JetonArr[i]) {
  1267. var num = parseInt(nowJetonScore / JetonArr[i]);
  1268. for (var j = 0; j < num; j++) {
  1269. var gold = this.getChipNode(JetonArr[i]);
  1270. this.goldArr.push(gold);
  1271. gold.startPos = startPos;
  1272. gold.endPos = endPos;
  1273. gold.cbBetArea = cbBetArea;
  1274. gold.isSelf = false;
  1275. }
  1276. nowJetonScore = nowJetonScore % JetonArr[i];
  1277. }
  1278. }
  1279. this.schedule(this.scheduleChipMove, 0.05);
  1280. }
  1281. },
  1282. playChipAnimation(gold, { startPos, endPos, cbBetArea, isSelf }) {
  1283. var offX = this.getBetAreaSize(cbBetArea).x;
  1284. var offY = this.getBetAreaSize(cbBetArea).y;
  1285. var moveTime = 0.2;
  1286. var scaleSize = 0.5;
  1287. var easeOutNum = 1
  1288. var scaleAddNum = 0.3 // 最终大小
  1289. var scaleAddTime = 0.05
  1290. gold.active = true
  1291. gold.setScale(0.3);
  1292. gold.setPosition(cc.v2(startPos.x, startPos.y));
  1293. if (!this._isSounding) {
  1294. BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_BETLOW);
  1295. this._isSounding = true;
  1296. this.scheduleOnce(() => this._isSounding = false, 0.3);
  1297. }
  1298. let randx = Math.floor(Math.random() * offX * (Math.random() > 0.5 ? 1 : -1));
  1299. let randy = Math.floor(Math.random() * offY * (Math.random() > 0.5 ? 1 : -1));
  1300. let rotate = Math.floor(Math.random() * 360 + 180);
  1301. var scaleto = cc.scaleTo(moveTime, scaleSize).easing(cc.easeOut(easeOutNum));
  1302. var moveto = cc.moveTo(moveTime, cc.v2(randx + endPos.x, randy + endPos.y)).easing(cc.easeOut(easeOutNum));//
  1303. var rotateto1 = cc.rotateBy(0.1, rotate);
  1304. rotate = Math.floor(Math.random() * 30 + 10);
  1305. var rotateto2 = cc.rotateBy(0.1, rotate).easing(cc.easeOut(easeOutNum));
  1306. gold.runAction(cc.sequence(cc.spawn(moveto, scaleto, rotateto1), rotateto2, cc.scaleTo(scaleAddTime, scaleAddNum)));
  1307. },
  1308. scheduleChipMove() {
  1309. // 投掷筹码Ani定时器
  1310. if (this.goldArr.length <= 0) {
  1311. this.unschedule(this.scheduleChipMove);
  1312. return;
  1313. }
  1314. var gold = this.goldArr.splice(0, 1)[0];
  1315. gold.zIndex = (this._goldZorder++)
  1316. this.node.getChildByName("JetonNode").children[gold.cbBetArea].addChild(gold);
  1317. this.playChipAnimation(gold, gold);
  1318. },
  1319. unScheduleChipMove() {
  1320. // 一次性清空未投掷的筹码
  1321. for (const gold of this.goldArr) {
  1322. gold.zIndex = (this._goldZorder++)
  1323. this.node.getChildByName("JetonNode").children[gold.cbBetArea].addChild(gold);
  1324. this.playChipAnimation(gold, gold);
  1325. }
  1326. this.goldArr = [];
  1327. },
  1328. getBetAreaSize(cbBetArea) {
  1329. var offX = 0;
  1330. var offY = 0;
  1331. if (cbBetArea == 0) {
  1332. offX = 80;
  1333. offY = 40;
  1334. } else if (cbBetArea == 1) {
  1335. offX = 80;
  1336. offY = 40;
  1337. } else if (cbBetArea == 2) {
  1338. offX = 80;
  1339. offY = 40;
  1340. } else if (cbBetArea == 3) {
  1341. offX = 80;
  1342. offY = 40;
  1343. }
  1344. var size = {};
  1345. size.x = offX;
  1346. size.y = offY;
  1347. return size;
  1348. },
  1349. //筹码移动动画
  1350. playChipMoveAni(gold, startPos, endPos, endRand, endShow, cbBetArea) {//筹码节点,开始坐标,终点坐标,终点是否小范围随机,播放结束显示或隐藏,下注区域
  1351. return new Promise((resolve, reject) => {
  1352. var offX = 0;
  1353. var offY = 0;
  1354. if (endRand && cbBetArea >= 0 && cbBetArea < GameProtocol.AREA_MAX) {
  1355. offX = this.getBetAreaSize(cbBetArea).x;
  1356. offY = this.getBetAreaSize(cbBetArea).y;
  1357. }
  1358. var moveTime = 0.3;
  1359. var scaleSize = 0.5;
  1360. var easeOutNum = 1
  1361. var scaleAddNum = 0.3 // 最终大小
  1362. var scaleAddTime = 0.05
  1363. gold.active = true
  1364. gold.setPosition(cc.v2(startPos.x, startPos.y));
  1365. gold.setScale(0.3);
  1366. let randx = 0;
  1367. let randy = 0;
  1368. if (endRand) {
  1369. randx = Math.floor(Math.random() * offX * (Math.random() > 0.5 ? 1 : -1));
  1370. randy = Math.floor(Math.random() * offY * (Math.random() > 0.5 ? 1 : -1));
  1371. }
  1372. let rotate = Math.floor(Math.random() * 360 + 180);
  1373. var scaleto = cc.scaleTo(moveTime, scaleSize).easing(cc.easeOut(easeOutNum));
  1374. var moveto = cc.moveTo(moveTime, cc.v2(randx + endPos.x, randy + endPos.y)).easing(cc.easeOut(easeOutNum));
  1375. var rotateto1 = cc.rotateBy(0.1, rotate);
  1376. rotate = Math.floor(Math.random() * 30 + 10);
  1377. var rotateto2 = cc.rotateBy(0.1, rotate).easing(cc.easeOut(easeOutNum));
  1378. gold.runAction(cc.sequence(cc.spawn(moveto, scaleto, rotateto1), rotateto2, cc.scaleTo(scaleAddTime, scaleAddNum),
  1379. cc.callFunc(() => {
  1380. gold.active = endShow;
  1381. resolve();
  1382. },
  1383. this))
  1384. );
  1385. });
  1386. },
  1387. disabledPourChips(Bool) {
  1388. console.log("myTest: " + Bool)
  1389. var PourBtnList = this.node.getChildByName("PourBtnList");
  1390. for (var i = 0; i < GameProtocol.AREA_MAX; i++) {
  1391. PourBtnList.children[i].getComponent(cc.Button).interactable = Bool;
  1392. }
  1393. PourBtnList.active = true;
  1394. var GoldNode = this.node.getChildByName("FuncBtnNode").getChildByName("GoldBtnNode");
  1395. for (let i = 0; i < 6; ++i) {
  1396. GoldNode.getChildByName("Button_GoldAdd" + i).getComponent(cc.Button).interactable = Bool;
  1397. GoldNode.getChildByName("Button_GoldAdd" + i).getChildByName("label").getComponent(cc.Label).font = (Bool) ? this.ChipsLabel[i + 1] : this.ChipsLabel[0];
  1398. }
  1399. GoldNode.getChildByName("Button_GoldAddAgain").getComponent(cc.Button).interactable = Bool
  1400. GoldNode.getChildByName("tip_ring").active = Bool
  1401. },
  1402. updateJetonBtn() {
  1403. if (this._gameState > GameState.BRTP_STATE_CHIP) return;
  1404. var GoldNode = this.node.getChildByName("FuncBtnNode").getChildByName("GoldBtnNode");
  1405. var score = this._selfScore;
  1406. var scoreArr = this._chipConfig;
  1407. for (var i = 0; i < scoreArr.length; i++) {
  1408. if (score >= scoreArr[i]) {
  1409. GoldNode.getChildByName("Button_GoldAdd" + i).getComponent(cc.Button).interactable = true;
  1410. GoldNode.getChildByName("Button_GoldAdd" + i).getChildByName("label").getComponent(cc.Label).font = this.ChipsLabel[i + 1];
  1411. } else {
  1412. GoldNode.getChildByName("Button_GoldAdd" + i).getComponent(cc.Button).interactable = false;
  1413. GoldNode.getChildByName("Button_GoldAdd" + i).getChildByName("label").getComponent(cc.Label).font = this.ChipsLabel[0];
  1414. }
  1415. }
  1416. this.node.getComponent("BRTPFuncBtnMgr").unpdateJetonTag();
  1417. },
  1418. initPourChips() {
  1419. Global.print(`BRTP:: 初始化筹码${this._chipConfig}`)
  1420. // UIHelper.
  1421. let GoldNode = this.node.getChildByName("FuncBtnNode").getChildByName("GoldBtnNode");
  1422. let scoreArr = this._chipConfig;
  1423. let index = 0;
  1424. let child = GoldNode.getChildByName("Button_GoldAdd" + index);
  1425. while (child) {
  1426. child.active = !!scoreArr[index];
  1427. child.getChildByName("label").getComponent(cc.Label).string = scoreArr[index] || 0;
  1428. index++;
  1429. child = GoldNode.getChildByName("Button_GoldAdd" + index);
  1430. }
  1431. },
  1432. //每局游戏结束后重置UI
  1433. resetView() {
  1434. this._goldZorder = 0;
  1435. this.node.getChildByName("TIpNode").active = false;
  1436. this.disabledPourChips(false);//下注按钮置灰
  1437. for (var i = 0; i < this.playerNode.children.length; i++) {
  1438. var playerjs = this.playerNode.children[i].getComponent("BRTPPlayerView");
  1439. playerjs.resetView();
  1440. }
  1441. var otherPlayerScoreAni = this.node.getChildByName('FuncBtnNode').getChildByName("OtherPlayer").getChildByName("scoreAni");
  1442. otherPlayerScoreAni.active = false;
  1443. var AreaNode = this.node.getChildByName("PourBtnList");
  1444. for (var i = 0; i < GameProtocol.AREA_MAX; i++) {
  1445. this._AreaJetonSelf[i] = 0;//区域自己下注
  1446. this._AreaJetonTotal[i] = 0;//区域总下注
  1447. AreaNode.children[i].getChildByName("AllPlayerScore").getComponent(cc.Label).string = parseInt(this._AreaJetonTotal[i]);
  1448. AreaNode.children[i].getChildByName("SelfScore").getChildByName("label").getComponent(cc.Label).string = parseInt(this._AreaJetonSelf[i]);
  1449. AreaNode.children[i].getChildByName("AllPlayerScore").active = false;
  1450. AreaNode.children[i].getChildByName("SelfScore").active = false;
  1451. // AreaNode.children[i].getChildByName("bg_score").active = false;
  1452. AreaNode.children[i].getChildByName("winAni").active = false;
  1453. AreaNode.children[i].getChildByName("starAni").active = false;
  1454. }
  1455. this._JetonNum = 0;
  1456. this._TotalNum = 0;
  1457. this.node.getChildByName("TIpNode").getChildByName("totalLabel").getComponent(cc.Label).string = this._JetonNum.toFixed(2);
  1458. this.node.getChildByName("TIpNode").getChildByName("surplusLabel").getComponent(cc.Label).string = this._TotalNum.toFixed(2);
  1459. var JetonNode = this.node.getChildByName("JetonNode");//桌子上的筹码
  1460. for (var i = 0; i < JetonNode.childrenCount; i++) {
  1461. JetonNode.children[i].removeAllChildren();
  1462. }
  1463. var AllAniNode = this.node.getChildByName("AllAniNode");
  1464. for (var i = 0; i < AllAniNode.childrenCount; i++) {//所有动画
  1465. AllAniNode.children[i].active = false;
  1466. }
  1467. var cardTypeNode = this.node.getChildByName("PubCardNode");//牌型动画
  1468. for (var i = 0; i < GameProtocol.AREA_MAX + 1; i++) {
  1469. cardTypeNode.getChildByName("card" + i).getChildByName("TypeNode").active = false;
  1470. cardTypeNode.getChildByName("card" + i).getChildByName("winAni").active = false;
  1471. }
  1472. this.hidePubCard();//牌
  1473. this.node.getChildByName("TIpNode").active = false;
  1474. this.node.getChildByName("SelfZhuang").active = false;
  1475. // 清除房间号
  1476. cc.find("RoomInfoNode/num", this.node).getComponent(cc.Label).string = "";
  1477. // 低于最低下注额提醒
  1478. let isNeedTip = (importInstance.GameManagerBase.getGameServerItem().CellScore > cc.vv.globalUserInfo.getUserScore());
  1479. this.node.getChildByName("ChipTip").active = isNeedTip;
  1480. if (isNeedTip) {
  1481. cc.find("ChipTip/label/num", this.node).getComponent(cc.Label).string = this.getGameServerItem().CellScore;
  1482. }
  1483. },
  1484. //初始化玩家信息
  1485. initPlayers() {
  1486. var selfPlayer = this.getSelfPlayer();
  1487. if (!selfPlayer) {
  1488. return;
  1489. }
  1490. this.playListContent.removeAllChildren();
  1491. //this._players = [];
  1492. for (let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
  1493. var gamePlayer = this.getPlayerByChairID(i);
  1494. if (gamePlayer) {
  1495. var playerNode = cc.instantiate(this.playerPrefab);
  1496. playerNode.active = true;
  1497. //this.node.getComponent("BRTPFuncBtnMgr").initButtonHandler(playerNode.getChildByName("PlayerHead").getChildByName("ButtonPlayerHeadClick"));
  1498. this.playListContent.addChild(playerNode);
  1499. var playerjs = playerNode.getComponent("BRTPPlayer");
  1500. playerjs.setUserItem(gamePlayer.getUserItem());
  1501. playerjs.playerEnter();
  1502. playerjs.upPlayerInfo();
  1503. playerjs.upPlayerHead();
  1504. //playerjs.upPlayerState();
  1505. //this._players.push(playerjs);
  1506. }
  1507. }
  1508. this.node.getChildByName('FuncBtnNode').getChildByName("OtherPlayer").getChildByName("playerCount").getComponent(cc.Label).string = this.playListContent.childrenCount;
  1509. },
  1510. initPlayerData(wSeatUser) {
  1511. this._SeatArray = wSeatUser;
  1512. this._seatPlayer = [];
  1513. for (var i = 0; i < GameProtocol.MAX_SEAT_COUNT; ++i) {
  1514. var index = i + 1;
  1515. var player = this.getOtherPlayerJSByChairId(wSeatUser[i]);
  1516. if (player) {
  1517. this.playerNode.getChildByName("Player" + index).active = true;
  1518. var playerjs = this.playerNode.getChildByName("Player" + index).getComponent("BRTPPlayerView");
  1519. playerjs.resetView();
  1520. playerjs.setUserItem(player.getUserItem());
  1521. playerjs.setChairID(wSeatUser[i])
  1522. playerjs.playerEnter();
  1523. playerjs.upPlayerInfo();
  1524. playerjs.upPlayerState();
  1525. playerjs.upPlayerHead();
  1526. playerjs.isSpecialPlayer = ([1].some(i => i == index)); // 特殊标记玩家,1最幸运,4最富有
  1527. this._seatPlayer.push(playerjs);
  1528. } else {
  1529. this.playerNode.getChildByName("Player" + index).active = false;
  1530. }
  1531. }
  1532. var selfPlayer = this.getSelfPlayer();
  1533. if (selfPlayer) {
  1534. this.playerNode.getChildByName("Player0").active = true;
  1535. var playerjs = this.playerNode.getChildByName("Player0").getComponent("BRTPPlayerView");
  1536. playerjs.resetView();
  1537. playerjs.setUserItem(selfPlayer.getUserItem());
  1538. playerjs.setChairID(selfPlayer.getChairID());
  1539. playerjs.playerEnter();
  1540. playerjs.upPlayerInfo();
  1541. playerjs.upPlayerState();
  1542. playerjs.upPlayerHead();
  1543. }
  1544. },
  1545. setZhuangInfo(wBankerUser, playSound) {
  1546. var PlayerBanker = this.getOtherPlayerJSByChairId(wBankerUser);
  1547. if (PlayerBanker) {
  1548. this.getBankerNode().active = true;
  1549. var playerjs = this.getBankerNode().getComponent("BRTPPlayerView");
  1550. playerjs.resetView();
  1551. playerjs.setUserItem(PlayerBanker.getUserItem());
  1552. playerjs.setChairID(wBankerUser)
  1553. playerjs.playerEnter();
  1554. playerjs.upPlayerInfo();
  1555. playerjs.upPlayerState();
  1556. playerjs.upPlayerHead();
  1557. } else {//系统庄
  1558. this.getBankerNode().getChildByName("PlayerInfo").getChildByName("Name").getChildByName("label").getComponent(cc.Label).string = "Dealer";
  1559. this.getBankerNode().getChildByName("PlayerInfo").getChildByName("ScoreImagic").getChildByName("Score").getComponent(cc.Label).string = "100000";
  1560. }
  1561. this._bankerUserId = wBankerUser;//庄家ID
  1562. this._SelfIsZhuang = (this.getSelfPlayer().getChairID() == wBankerUser);
  1563. if (playSound) {
  1564. BRTPSoundFun.playEffectByGender(this.getSelfPlayer().getGender(), BRTPSoundFun.EX_CHANGEBANKER);
  1565. }
  1566. },
  1567. onUserEnter(clientUserItem) {
  1568. Global.print("onUserEnter......")
  1569. var selfPlayer = this.getSelfPlayer();
  1570. if (!selfPlayer) {
  1571. return;
  1572. }
  1573. var player = this.getOtherPlayerJSByChairId(clientUserItem.GetChairID());
  1574. if (!player) {
  1575. var playerNode = cc.instantiate(this.playerPrefab);
  1576. playerNode.active = true;
  1577. //this.node.getComponent("BRTPFuncBtnMgr").initButtonHandler(playerNode.getChildByName("PlayerHead").getChildByName("ButtonPlayerHeadClick"));
  1578. this.playListContent.addChild(playerNode);
  1579. this.node.getChildByName('FuncBtnNode').getChildByName("OtherPlayer").getChildByName("playerCount").getComponent(cc.Label).string = this.playListContent.childrenCount;
  1580. var playerjs = playerNode.getComponent("BRTPPlayer");
  1581. playerjs.setUserItem(clientUserItem);
  1582. playerjs.playerEnter();
  1583. playerjs.upPlayerInfo();
  1584. //playerjs.upPlayerState();
  1585. for (var i = 0; i < GameProtocol.MAX_SEAT_COUNT; ++i) {
  1586. if (this.playerNode.getChildByName("Player" + i).active) {
  1587. continue;
  1588. }
  1589. this.playerNode.getChildByName("Player" + i).active = true;
  1590. var PlayerViewjs = this.playerNode.getChildByName("Player" + i).getComponent("BRTPPlayerView");
  1591. PlayerViewjs.resetView();
  1592. PlayerViewjs.setUserItem(clientUserItem);
  1593. PlayerViewjs.setChairID(playerjs.getChairID());
  1594. PlayerViewjs.playerEnter();
  1595. PlayerViewjs.upPlayerInfo();
  1596. PlayerViewjs.upPlayerState();
  1597. PlayerViewjs.upPlayerHead();
  1598. this._seatPlayer.push(PlayerViewjs);
  1599. break;
  1600. }
  1601. }
  1602. },
  1603. onUserLeave(clientUserItem) {
  1604. if (Global.IsEmpty(clientUserItem)) {
  1605. return;
  1606. }
  1607. for (var i = 0; i < this._seatPlayer.length; ++i) {//从6个座位上删除
  1608. var playerJs = this._seatPlayer[i];//BRTPPlayerView
  1609. if (playerJs.getChairID() == clientUserItem.GetChairID()) {
  1610. playerJs.playerLeave();
  1611. this._seatPlayer.splice(i, 1);
  1612. break;
  1613. }
  1614. }
  1615. for (var i = 0; i < this.playListContent.childrenCount; i++) {//从玩家列表删除
  1616. var playerNode = this.playListContent.children[i];
  1617. var playerJs = playerNode.getComponent("BRTPPlayer")
  1618. if (playerJs.getChairID() == clientUserItem.GetChairID()) {
  1619. playerNode.removeFromParent();
  1620. break;
  1621. }
  1622. }
  1623. this.node.getChildByName('FuncBtnNode').getChildByName("OtherPlayer").getChildByName("playerCount").getComponent(cc.Label).string = this.playListContent.childrenCount;
  1624. },
  1625. upPlayerInfo(clientUserItem) {
  1626. var player = this.getOtherPlayerJSByChairId(clientUserItem.GetChairID());
  1627. if (player) {
  1628. player.setUserItem(clientUserItem);
  1629. player.upPlayerInfo();
  1630. }
  1631. },
  1632. upPlayerHead(clientUserItem) {
  1633. var player = this.getOtherPlayerJSByChairId(clientUserItem.GetChairID());
  1634. if (player) {
  1635. player.setUserItem(clientUserItem);
  1636. player.upPlayerHead();
  1637. }
  1638. },
  1639. upPlayerState(clientUserItem) {
  1640. var player = this.getOtherPlayerJSByChairId(clientUserItem.GetChairID());
  1641. if (player) {
  1642. player.setUserItem(clientUserItem);
  1643. player.upPlayerState();
  1644. }
  1645. },
  1646. getSelfNode() {//获取自己节点
  1647. return this.node.getChildByName("Players").getChildByName("Player0");
  1648. },
  1649. getBankerNode() {//获取庄家节点
  1650. return this.node.getChildByName("Players").getChildByName("PlayerBanker");
  1651. },
  1652. getSeatPlayerNodeByChairId(chairId) {//获取6个座位上的玩家节点
  1653. for (var i = 1; i < GameProtocol.MAX_SEAT_COUNT + 1; i++) {
  1654. var playerNode = this.playerNode.getChildByName("Player" + i);
  1655. var PlayerViewJs = playerNode.getComponent("BRTPPlayerView");
  1656. if (PlayerViewJs.getChairID() == chairId) {
  1657. return playerNode;
  1658. }
  1659. }
  1660. return null;
  1661. },
  1662. getOtherPlayerNode() {//不在座位上的其他玩家节点
  1663. return this.node.getChildByName("FuncBtnNode").getChildByName("OtherPlayer");
  1664. },
  1665. getSeatPlayerJsByChairId(chairId) {//获取6个座位上的玩家Js
  1666. for (var i = 1; i < GameProtocol.MAX_SEAT_COUNT + 1; i++) {
  1667. var playerNode = this.playerNode.getChildByName("Player" + i);
  1668. var PlayerViewJs = playerNode.getComponent("BRTPPlayerView");
  1669. if (PlayerViewJs.getChairID() == chairId) {
  1670. return PlayerViewJs;
  1671. }
  1672. }
  1673. return null;
  1674. },
  1675. getOtherPlayerJSByChairId(chairId) {//获取所有玩家列表的Js
  1676. for (var i = 0; i < this.playListContent.childrenCount; i++) {
  1677. var playerNode = this.playListContent.children[i];
  1678. var playerJs = playerNode.getComponent("BRTPPlayer");
  1679. if (playerJs.getChairID() == chairId) {
  1680. return playerJs;
  1681. }
  1682. }
  1683. return null;
  1684. },
  1685. //得到DSMJGamePlayer (是GamePlayer的派生类)
  1686. getSelfLocalPlayer() {
  1687. for (var i = 0; i < this.playListContent.childrenCount; i++) {
  1688. var playerNode = this.playListContent.children[i];
  1689. var playerJs = playerNode.getComponent("BRTPPlayer");
  1690. if (playerJs.getChairID() == this.getSelfPlayer().getChairID()) {
  1691. return playerJs;
  1692. }
  1693. }
  1694. /*for (let index = 0; index < this._players.length; index++) {
  1695. const element = this._players[index];
  1696. if (this.isSelf(element)) {
  1697. return element;
  1698. }
  1699. }*/
  1700. return null;
  1701. },
  1702. playTimeAction(timeNum) {
  1703. if (this.timeCallback != null) {
  1704. this.unschedule(this.timeCallback);
  1705. this.timeCallback = null;
  1706. }
  1707. this._countdown = timeNum;
  1708. var time = timeNum;
  1709. const timeNode = this.node.getChildByName("TimeNode");
  1710. const timeLabel = timeNode.getChildByName("TimeLabel").getComponent(cc.Label);
  1711. const timeMask = timeNode.getChildByName("AniNode").getChildByName("mask").getComponent(cc.Sprite);
  1712. timeLabel.string = this._countdown;
  1713. timeNode.active = true;
  1714. this.timeCallback = (dt) => {
  1715. time -= dt;
  1716. if (time < 0) {
  1717. timeNode.active = false;
  1718. this.unschedule(this.timeCallback);
  1719. this.timeCallback = null;
  1720. }
  1721. else {
  1722. timeMask.fillRange = (time / this._countdown);
  1723. timeLabel.string = Math.round(time);
  1724. }
  1725. }
  1726. if (this._gameState == GameState.BRTP_STATE_CHIP) {
  1727. this.schedule(() => BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_TIME), 1, 1, timeNum - 5);
  1728. }
  1729. this.schedule(this.timeCallback, 0.1);
  1730. },
  1731. showAllPlayerList(show) {
  1732. var playerListNode = this.node.getChildByName("PlayerList").getChildByName("AllPlayerList")
  1733. playerListNode.active = show;
  1734. },
  1735. showBankerList(show) {
  1736. var bankerListNode = this.node.getChildByName("PlayerList").getChildByName("AllBankerList")
  1737. bankerListNode.active = show;
  1738. this.node.getComponent("BRTPFuncBtnMgr")._openBankerList = show;
  1739. },
  1740. OnSocketSubProtectBack(bLookonUser, data) {//低保信息
  1741. if (bLookonUser) {
  1742. return;
  1743. }
  1744. var selfPlayer = this.getSelfPlayer();
  1745. if (!selfPlayer) {
  1746. return;
  1747. }
  1748. if (data.dwUserId != selfPlayer.getUserID()) {
  1749. var player = this.getOtherPlayerJSByChairId(this.getPlayerByUserID(data.dwUserId).getChairID());
  1750. player.setUserScore(data.nCurScore);
  1751. player.setScore(data.nCurScore);
  1752. return;
  1753. }
  1754. selfPlayer.setUserScore(data.nCurScore);
  1755. selfPlayer.setScore(data.nCurScore);
  1756. selfPlayer.upPlayerInfo();
  1757. return true;
  1758. },
  1759. //聊天协议
  1760. revTalk(data) {//
  1761. var databuf = ProtocolGameServer.CMD_GR_C_TableTalk.data();
  1762. var dataView = new DataView(data);
  1763. dataView.pos = 8;
  1764. databuf.Type = Global.GetUint8(dataView);
  1765. databuf.ChairID = Global.GetUint8(dataView);
  1766. databuf.String = Global.Read2CharUtf(dataView, 128);
  1767. databuf.TalkSize = Global.GetInt32(dataView);
  1768. databuf.TalkData = Global.Read2Char(dataView, data.byteLength - databuf.pos);
  1769. var player = this.getOtherPlayerJSByChairId(databuf.ChairID);
  1770. if (player != null) {
  1771. player.showTalkState(databuf);
  1772. }
  1773. },
  1774. revVoice(data) {
  1775. var databuf = ProtocolGameServer.CMD_GR_TabelVoice.data();
  1776. var dataView = new DataView(data);
  1777. dataView.pos = 8;
  1778. databuf.ChairID = Global.GetUint8(dataView);
  1779. databuf.SerVerID = Global.Read2String(dataView);
  1780. Global.print("收到语音消息::");
  1781. Global.print(databuf);
  1782. var player = this.getOtherPlayerJSByChairId(databuf.ChairID);
  1783. if (player != null) {
  1784. player.showVoice(databuf);
  1785. }
  1786. var curTime = new Date();
  1787. var filePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + curTime.getTime() + '.ptt');
  1788. this.node.getComponent("BRTPFuncBtnMgr").getAr().downloadRecordedFile(databuf.SerVerID, filePath);
  1789. },
  1790. hideVoice() {
  1791. for (let i = 0; i < GameProtocol.GAME_PLAYER; ++i) {
  1792. var player = this.getOtherPlayerJSByChairId(i);
  1793. if (player != null) {
  1794. player.hideVoice();
  1795. }
  1796. }
  1797. },
  1798. ////////////////////////////////////////////////////////////////////////////
  1799. //银行信息
  1800. OnSocketSubUserInsureInfo(pNetInfo) {
  1801. var selfPlayer = this.getSelfPlayer();
  1802. if (!selfPlayer) {
  1803. return;
  1804. }
  1805. this.showBank(pNetInfo);
  1806. },
  1807. OnSocketSubUserInsureSuccess(pNetInfo) {
  1808. var selfPlayer = this.getSelfPlayer();
  1809. if (!selfPlayer) {
  1810. return;
  1811. }
  1812. selfPlayer.setScore(pNetInfo.UserScore);
  1813. selfPlayer.setUserScore(pNetInfo.UserScore);
  1814. cc.vv.globalUserInfo.setUserScore(pNetInfo.UserScore);
  1815. cc.vv.globalUserInfo.setBankScore(pNetInfo.UserInsure);
  1816. if (this._bankNode) {
  1817. this._bankNode.active = false;
  1818. }
  1819. //TODO ENDTIP
  1820. if (pNetInfo.cbType == 0) { //银行正常操作
  1821. } else if (pNetInfo.cbType == 1) { //存钱继续
  1822. if (this._goldUnusual) {
  1823. this._goldUnusual.active = false;
  1824. }
  1825. importInstance.GameManagerBase.connectGameServer(this._gameServerItem);
  1826. } else if (pNetInfo.cbType == 2) { //取钱继续
  1827. if (this._goldUnusual) {
  1828. this._goldUnusual.active = false;
  1829. }
  1830. importInstance.GameManagerBase.connectGameServer(this._gameServerItem);
  1831. }
  1832. },
  1833. OnSocketSubUserInsureFailure(pNetInfo) {
  1834. var selfPlayer = this.getSelfPlayer();
  1835. if (!selfPlayer) {
  1836. return;
  1837. }
  1838. var str = Global.gbk2Utf8(pNetInfo.DescribeString);
  1839. //Global.print(str);
  1840. this._bankNode.active = false;
  1841. // topTipMsg.showTopTipMsg("游戏中不能存款");
  1842. },
  1843. showBank(data) {
  1844. var self = this;
  1845. cc.resources.load("GamePrefabs/homescence/BankNode", cc.prefab, function (err, prefab) {
  1846. if (!self._bankNode) {
  1847. self._bankNode = cc.instantiate(prefab);
  1848. self._bankNode.parent = self.node;
  1849. self._bankNode.addComponent("bankSence");
  1850. }
  1851. self._bankNode.getComponent("bankSence").showBankNode(data, true);
  1852. });
  1853. },
  1854. /*************************UI相关*****************************/
  1855. //注册触摸事件
  1856. registerTouchEventHandle() {
  1857. this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
  1858. }, this);
  1859. this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
  1860. }, this);
  1861. this.node.on(cc.Node.EventType.TOUCH_END, function (event) {
  1862. }, this);
  1863. this.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
  1864. }, this);
  1865. },
  1866. //初始化UI
  1867. initView() {
  1868. },
  1869. defaultPrivateState() {
  1870. },
  1871. //返回大厅
  1872. backHome() {
  1873. this._bIsRecord = false;
  1874. this.unschedule(this.nextRecordAction);
  1875. this.unschedule(this.updataMobileTime);
  1876. importInstance.ScenceManager.gameBackScence();
  1877. importInstance.GameManagerBase.setInGameServerID(-1);
  1878. importInstance.CServerItem ? importInstance.CServerItem.PerformStandUpAction(1) : this.exitGame();
  1879. },
  1880. //解散房间
  1881. dissmissRoom(bAgree) {
  1882. if (bAgree > 0) {
  1883. if (this.getPlayCount() <= 0) {
  1884. var msgDismissPrivate = ProtocolGameServer.CMD_GR_Dismiss_Private.data();
  1885. msgDismissPrivate.Dismiss = 1;
  1886. this.SendPrivteSocketData(ProtocolGameServer.SUB_GR_PRIVATE_DISMISS, msgDismissPrivate);
  1887. } else {
  1888. //poptip
  1889. var msgDismissPrivate = ProtocolGameServer.CMD_GR_Dismiss_Private.data();
  1890. msgDismissPrivate.Dismiss = 1;
  1891. this.SendPrivteSocketData(ProtocolGameServer.SUB_GR_PRIVATE_DISMISS, msgDismissPrivate);
  1892. }
  1893. } else {
  1894. var msgDismissPrivate = ProtocolGameServer.CMD_GR_Dismiss_Private.data();
  1895. msgDismissPrivate.Dismiss = 0;
  1896. this.SendPrivteSocketData(ProtocolGameServer.SUB_GR_PRIVATE_DISMISS, msgDismissPrivate);
  1897. }
  1898. },
  1899. exitGameWhenPlaying() {
  1900. //BRTP_STATE_FREE :1, //空闲状态
  1901. //BRTP_STATE_CHIP :2, //下注状态
  1902. //BRTP_STATE_END :3, //结算状态
  1903. if (this.getSceneState() != 1 && this._alreadyJoin) {
  1904. topTipMsg.showTopTipMsg("BRTP.exit_tip");
  1905. } else {
  1906. // CChatServerItem.get().ConnectServer(cc.vv.config.ChatAddress, 8340);
  1907. this.backHome();
  1908. this.exitGame();
  1909. }
  1910. },
  1911. makeXieYi(m, s, data) {
  1912. return MakeBRTPXieYi.makeGameData(m, s, data);
  1913. },
  1914. isRecord() {
  1915. return this._bIsRecord;
  1916. },
  1917. onGAGetActivityUserMultiScore(data) {
  1918. var nRevenue = data.lRevenue - cc.vv.globalUserInfo.getRevenue();
  1919. if (nRevenue == 0)
  1920. return;
  1921. cc.vv.globalUserInfo.setRevenue(data.lRevenue);
  1922. var OK = function () {
  1923. }
  1924. // popScence.initPopScence("恭喜您,获得" + nRevenue + "张福卡",this,OK);
  1925. },
  1926. onSocketSubExchangeRoom(data) {
  1927. if (data.cbReason == 1 || data.cbReason == 2) {
  1928. var self = this;
  1929. var OK = function () {
  1930. self.backHome();
  1931. self.exitGame();
  1932. }
  1933. // popScence.initPopScence("金豆不足,无法继续游戏。",this,OK);
  1934. }
  1935. },
  1936. onBtnCloseOnlinePlayerUI() {
  1937. UIHelper.playButtonEffect("close");
  1938. var node = this.node.getChildByName("PlayerRankList");
  1939. if (node) {
  1940. node.runAction(cc.sequence(cc.scaleTo(0.2, 1, 0), cc.callFunc(function () { node.active = false; })));
  1941. }
  1942. },
  1943. getFuncBtnComponent() {
  1944. return this.node.getComponent("BRTPFuncBtnMgr")
  1945. },
  1946. // 唯一对局码
  1947. onSocketUpdateUniqueCode(data) {
  1948. Global.print(`收到唯一对局码: (${data.strUniqueCode})`);
  1949. if (!data.strUniqueCode) { return; }
  1950. let roomNumNode = cc.find("RoomInfoNode/num", this.node);
  1951. roomNumNode.active = true;
  1952. roomNumNode.getComponent(cc.Label).string = data.strUniqueCode;
  1953. },
  1954. // 控制数据
  1955. onSubSendControlInfo(data) {
  1956. if (BaseDefine.LOCALTEST) {
  1957. this.node.getChildByName("ControlInfo").active = true;
  1958. this._controlInfo = data.areaInfo || [];
  1959. this.showControlInfo();
  1960. } else {
  1961. this.node.getChildByName("ControlInfo").active = false;
  1962. }
  1963. },
  1964. showControlInfo() {
  1965. const infoNode = cc.find("ControlInfo/info", this.node);
  1966. if (!infoNode.active) return;
  1967. const areaType = ["黑桃池", "红桃池", "方块池", "梅花池"];
  1968. let txt = `<b>`
  1969. + `<color=#ffffff>\t\t\t\t\t\t房间杀率:${parseFloat(this._controlInfo[0].RoomSha / 100.0).toFixed(2)}%</c> `
  1970. + `<color=#ffffff>触发系统赢:\n\t\t\t\t\t\t${parseFloat(this._controlInfo[0].RoomWin / 100.0).toFixed(2)}%</c> `
  1971. + `<color=#ffffff>触发系统输:${parseFloat(this._controlInfo[0].RoomLost / 100.0).toFixed(2)}%</c>\n`;
  1972. for (let i = 0; i < this._controlInfo.length; ++i) {
  1973. let data = this._controlInfo[i];
  1974. txt += `<color=#ffffff>${areaType[i]}: </c>`
  1975. + (
  1976. (!!data.IsDanKong) ? (
  1977. `<color=#ffffff>单控有</c> `
  1978. + `<color=#ffffff>单控玩家${(data.DanType == 1) ? "输" : ((data.DanType == 2) ? "赢" : "无")}</c> `
  1979. + `<color=#ffffff>随到${data.RoomSuiRate}%</c> `
  1980. + `<color=#ffffff>玩家: ${data.szNickName}</c> `
  1981. + `<color=#ffffff>门槛: ${data.DanMinBet}</c>`
  1982. ) : (
  1983. (!!data.QunState) ? (
  1984. `<color=#ffffff>群控${(data.RoomResult == 1) ? "系统赢" : ((data.RoomResult == 2) ? "系统输" : "无控制")}</c>`
  1985. + `<color=#ffffff>随到概率${parseFloat(data.RoomSuiRate / 100.0).toFixed(2)}%</c>\t`
  1986. ) : (
  1987. `<color=#ffffff>单控无, 群控无</c>`
  1988. )
  1989. )
  1990. )
  1991. + `\n`;
  1992. }
  1993. txt += `</b>`;
  1994. infoNode.getChildByName("label").getComponent(cc.RichText).string = txt;
  1995. },
  1996. // 显示趋势图
  1997. showTrendPanel(data) {
  1998. this.node.getChildByName("TrendPanel").active = true;
  1999. if (!this._gameResultRecords && !this._trendData) return;
  2000. let records = this._gameResultRecords.record;
  2001. let recordAnalyze = this._trendData.record;
  2002. const recordNodes = this.TrendContent.getChildByName("result").children;
  2003. // 载入输赢记录
  2004. let recordNode = null;
  2005. for (let i = 1; i <= recordNodes.length; i++) {
  2006. recordNode = recordNodes[recordNodes.length - i];
  2007. recordNode.getChildByName("spades").getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[records[records.length - i].bWinTian];
  2008. recordNode.getChildByName("hearts").getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[records[records.length - i].bWinDi];
  2009. recordNode.getChildByName("diamonds").getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[records[records.length - i].bWinXuan];
  2010. recordNode.getChildByName("clubs").getComponent(cc.Sprite).spriteFrame = this.jetonWinLost[records[records.length - i].bWinHuang];
  2011. }
  2012. // 提取已经成功载入的记录, 分析输赢率
  2013. const spades_r_node = this.TrendContent.getChildByName("result_data").getChildByName("spades").getChildByName("label");
  2014. const hearts_r_node = this.TrendContent.getChildByName("result_data").getChildByName("hearts").getChildByName("label");
  2015. const diamonds_r_node = this.TrendContent.getChildByName("result_data").getChildByName("diamonds").getChildByName("label");
  2016. const clubs_r_node = this.TrendContent.getChildByName("result_data").getChildByName("clubs").getChildByName("label");
  2017. const spades_r = (recordAnalyze[0].lWinTian / recordAnalyze[0].lDrawCount);
  2018. const hearts_r = (recordAnalyze[0].lWinDi / recordAnalyze[0].lDrawCount);
  2019. const diamonds_r = (recordAnalyze[0].lWinXuan / recordAnalyze[0].lDrawCount);
  2020. const clubs_r = (recordAnalyze[0].lWinHuang / recordAnalyze[0].lDrawCount);
  2021. spades_r_node.getComponent(cc.Label).string = parseInt(spades_r * 100) + "%";
  2022. hearts_r_node.getComponent(cc.Label).string = parseInt(hearts_r * 100) + "%";
  2023. diamonds_r_node.getComponent(cc.Label).string = parseInt(diamonds_r * 100) + "%";
  2024. clubs_r_node.getComponent(cc.Label).string = parseInt(clubs_r * 100) + "%";
  2025. },
  2026. // 显示玩家操作记录
  2027. showOperateRecordPanel() {
  2028. let data = JSON.parse(cc.sys.localStorage.getItem("BRTP_OperateRecord"));
  2029. this.node.getChildByName("RecordPanel").active = true;
  2030. if (data.length <= 0) return;
  2031. let item = this.OperateRecordContent.children[0];
  2032. this.OperateRecordContent.removeAllChildren();
  2033. for (let info of data) {
  2034. let child = cc.instantiate(item);
  2035. child.active = true;
  2036. child.parent = this.OperateRecordContent;
  2037. child.getChildByName("time").getComponent(cc.Label).string = info.nTime.toString();
  2038. child.getChildByName("bet").getComponent(cc.Label).string = info.nBet.toString();
  2039. child.getChildByName("result").getComponent(cc.Label).string = info.nWimLost.toString();
  2040. }
  2041. },
  2042. pourChipsAgain() {
  2043. if (this._chipCache && this._chipCache.length > 0) {
  2044. let sumScore = this._chipCache.reduce((ans, cur) => ans + parseInt(cur.lScore / 100), 0);
  2045. if (sumScore < this._selfScore) {
  2046. for (const data of this._chipCache) {
  2047. this.SendGameSocketData(GameProtocol.SUB_C_PLACE_JETTON, data);
  2048. this.node.getComponent("BRTPFuncBtnMgr")._chipCache.push(data);
  2049. }
  2050. this._chipCache = [];
  2051. cc.find("FuncBtnNode/GoldBtnNode/Button_GoldAddAgain", this.node).getComponent(cc.Button).interactable = false;
  2052. } else {
  2053. topTipMsg.showTopTipMsg("BRTP.again_chip_not_score");
  2054. }
  2055. } else {
  2056. topTipMsg.showTopTipMsg("BRTP.again_chip_not_data");
  2057. }
  2058. },
  2059. LackOfGoldWillExitGame() {
  2060. Global.print("LackOfGoldWillExitGame")
  2061. this._willExit_LackOfGold = true;
  2062. if (this._willExit_LackOfGold) {
  2063. var item = importInstance.GameManagerBase.getGameServerItem();
  2064. Global.print(item);
  2065. this.backHome();
  2066. this.exitGame();
  2067. var homeStart = cc.vv.GetHallScript();
  2068. homeStart.showShortage(item);
  2069. }
  2070. },
  2071. saveSysLocalStorage(data) {
  2072. let score = data.lPlayAreaScore;
  2073. let number = Math.abs(score[0]) + Math.abs(score[1]) + Math.abs(score[2]) + Math.abs(score[3]);
  2074. let local = JSON.parse(cc.sys.localStorage.getItem("BRTP_OperateRecord"));
  2075. if (!Array.isArray(local)) { local = []; }
  2076. if (local.length > 50) { local.shift(); }
  2077. if (number != 0) {
  2078. local.shift({
  2079. nBet: number,
  2080. nTime: new Date().toLocaleString("ja"),
  2081. nWimLost: data.lPlayerWinScore
  2082. });
  2083. }
  2084. cc.sys.localStorage.setItem("BRTP_OperateRecord", JSON.stringify(local));
  2085. },
  2086. });