GameScene.ts 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. import { _decorator, Button, Component, EventTouch, find, native, Label, math, Node, Prefab, sp, Sprite, SpriteAtlas, Tween, tween, Vec3, AudioClip, UIOpacity, Color } from 'cc';
  2. import { GameRollNode } from './GameRollNode';
  3. import { GameConstant } from './GameConstant';
  4. import { ResourceLoader } from './ResourceLoader';
  5. import { Player } from './Player';
  6. import { SoundManager } from './SoundManager';
  7. import { GameRule } from './GameRule';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('GameScene')
  10. export class GameScene extends Component {
  11. @property(Node)
  12. bgNode: Node = null;
  13. @property(Node)
  14. slotRectNode: Node = null;
  15. @property(Node)
  16. rollNode: Node = null;
  17. @property(Node)
  18. btnStart: Node = null;
  19. @property(Node)
  20. btnStop: Node = null;
  21. @property(Node)
  22. btnStopAuto: Node = null;
  23. @property(Node)
  24. btnBetSub: Node = null;
  25. @property(Node)
  26. btnBetAdd: Node = null;
  27. @property(Node)
  28. btnAuto: Node = null;
  29. @property(Node)
  30. autoNode: Node = null;
  31. @property(Node)
  32. betScoreNode: Node = null;
  33. @property(Node)
  34. winTitle: Node = null;
  35. @property(Node)
  36. winScore: Node = null;
  37. @property(Node)
  38. playerScore: Node = null;
  39. @property(Node)
  40. hintTitle: Node = null;
  41. @property(Node)
  42. freeCountNode: Node = null;
  43. @property(Node)
  44. buyFreeNode: Node = null;
  45. @property(Node)
  46. buyFreeWindow: Node = null;
  47. @property(Node)
  48. transitionSpine: Node = null;
  49. @property(Node)
  50. resultNode: Node = null;
  51. @property(Node)
  52. freeWindowNode: Node = null;
  53. @property(Node)
  54. gameRuleNode: Node = null;
  55. @property(SoundManager)
  56. soundManager: SoundManager = null;
  57. @property(Node)
  58. btnSound: Node = null;
  59. public bSpecialGame = false;
  60. public bQuickGame = false;
  61. public bAutoGame = false;
  62. public nAutoCount = 0;
  63. public autoIndex = -1;
  64. public curBetIndex = 0;
  65. public isGameEnd = true;
  66. public gameEndData = {
  67. "m_desk_data": [[1,4,7,6,2,10],[9,10,9,11,12,12],[6,3,11,11,8,12],[8,9,2,10,4,6]],//[[12,11,11,8,2,12],[12,11,9,8,8,4],[8,0,5,12,10,11],[8,12,1,12,10,9]],
  68. "m_wildTimes_data": [[1,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]],//[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]],
  69. "m_isSpecialGame": 0,
  70. "m_freeCount": 0,
  71. "m_freeCountAdd": 0,
  72. "m_betIndex": 0,
  73. "m_lottery_size": 5000,
  74. "m_lCurScore":0,
  75. "m_line_icon": [],
  76. "m_line_size": [],
  77. "m_line_icon_active": [],
  78. "m_line_times": [],
  79. "m_line_index": [],
  80. "totalFreeCount": 0
  81. }
  82. public gameConfig = {
  83. "nJetton": [100,200,300,400,500],
  84. }
  85. public winAniIdx = -1;
  86. public allWinScore = 0;
  87. public currentScore = 0;
  88. public lastScore = 0;
  89. public isPlayingScoreAddAni = false;
  90. public upScoreLabel = undefined;
  91. public bFreeState = 0;
  92. public freeCount = 0;
  93. public freeCountAdd = 0;
  94. public isShowTransitionSpine = false;
  95. public isShowReverse = false;
  96. public gameResults =
  97. {
  98. "results": [],
  99. "totalFreeCount": 0,
  100. };
  101. public gameCounts = 0;
  102. public filePath = "";
  103. private httpRetryCount: number = 0;
  104. private maxRetries: number = 3;
  105. private hasHttpResponse: boolean = false;
  106. public isPlaying = false;
  107. public stopPlayingTime = 0;
  108. public isCanClickFreeWindow = false;
  109. start() {
  110. this.upBetAddOrDelState();
  111. this.changeBtnState(false);
  112. this.gameConfig.nJetton = Player.getInstance().betConfig;
  113. this.playerScore.getComponent(Label).string = GameConstant.formatNumber(Player.getInstance().score);
  114. this.betScoreNode.getComponent(Label).string = GameConstant.formatNumber(this.gameConfig.nJetton[this.curBetIndex] * GameConstant.MAX_BET_TIMES);
  115. this.lastScore = Player.getInstance().score;
  116. this.soundManager.playBGM(ResourceLoader.instance.getResource<AudioClip>("bgm"));
  117. this.soundManager.playLoopEffect(ResourceLoader.instance.getResource<AudioClip>("gameing"), 0);
  118. this.scheduleOnce(()=>{
  119. this.btnSound.getComponent(Sprite).color = this.soundManager.musicEnabled ? new Color(255, 255, 255, 255) : new Color(255, 0, 0, 255);
  120. }, 0.2);
  121. }
  122. update(dt) {
  123. if (this.stopPlayingTime > 0) {
  124. this.stopPlayingTime -= dt;
  125. if (this.stopPlayingTime <= 0) {
  126. this.soundManager.setLoopEffectVolume(0);
  127. this.isPlaying = false;
  128. this.stopPlayingTime = 0;
  129. }
  130. }
  131. }
  132. // onClick函数块------------------------------------------------------------------------
  133. onClickStart() {
  134. this.soundManager.playClick();
  135. this.onStartRoll();
  136. }
  137. onClickStop() {
  138. this.soundManager.playClick();
  139. this.onStopRoll();
  140. }
  141. onClickSkip() {
  142. this.soundManager.playClick();
  143. // this.rollNode.getComponent(GameRollNode).showPrizes();
  144. // this.showGameWinScore();
  145. // this.showFreeWindow(0, false);
  146. if (this.gameCounts % 3 == 2)
  147. this.showFreeWin();
  148. else if (this.gameCounts % 3 == 1)
  149. this.showFreeWindow(20, true);
  150. else {
  151. this.showTransitionSpine(this.gameCounts % 2, ()=>{
  152. this.showFreeWindow(0, false);
  153. });
  154. }
  155. this.gameCounts++;
  156. }
  157. onClickBetSub() {
  158. this.soundManager.playClick();
  159. this.curBetIndex--;
  160. // this.playButtonEffect();
  161. this.refreshBet();
  162. }
  163. onClickBetAdd() {
  164. this.soundManager.playClick();
  165. this.curBetIndex++;
  166. // this.playButtonEffect();
  167. this.refreshBet();
  168. }
  169. onClickMax() {
  170. this.soundManager.playClick();
  171. this.curBetIndex = this.gameConfig.nJetton.length-1;
  172. // this.playButtonEffect();
  173. this.refreshBet();
  174. }
  175. onClickAuto() {
  176. this.soundManager.playClick();
  177. this.autoNode.active = true;
  178. }
  179. onClickAutoNumber(event: EventTouch, customData: string) {
  180. this.soundManager.playClick();
  181. this.autoNode.active = false;
  182. this.nAutoCount = GameConstant.AUTO_TYPE_COUNT[parseInt(customData)];
  183. this.bAutoGame = true;
  184. // this.showStartAndStopButton(false);
  185. this.onStartRoll();
  186. }
  187. onClickStopAuto() {
  188. this.soundManager.playClick();
  189. this.onCancelAutoRoll();
  190. }
  191. onCancelAutoRoll() {
  192. this.bAutoGame = false;
  193. this.nAutoCount = 0;
  194. // if(this._gameState == GAME_FREE) {
  195. // this.resetAllBtn();
  196. // }
  197. this.btnStopAuto.active = false;
  198. }
  199. onClickGameRule() {
  200. this.soundManager.playClick();
  201. this.gameRuleNode.getComponent(GameRule).show(this.curBetIndex);
  202. }
  203. onClickSound(event) {
  204. this.soundManager.toggleMusic();
  205. this.soundManager.toggleSound();
  206. this.btnSound.getComponent(Sprite).color = this.soundManager.musicEnabled ? new Color(255, 255, 255, 255) : new Color(255, 0, 0, 255);
  207. }
  208. onClickBuyFree() {
  209. this.buyFreeWindow.active = true;
  210. }
  211. onClickBuyFreeWindowClose() {
  212. this.buyFreeWindow.active = false;
  213. }
  214. onClickBuyFreeWindowSure() {
  215. this.buyFreeWindow.active = false;
  216. }
  217. onClickResultMask() {
  218. // console.log("onClickResultMask this.isPlayingScoreAddAni = " + this.isPlayingScoreAddAni);
  219. if(this.isPlayingScoreAddAni) {
  220. this.skipScoreAdd(this.resultNode.getChildByName("scoreNode").getChildByName("scoreBg").getChildByName("score"));
  221. }else{
  222. this.hideResultPanel();
  223. }
  224. }
  225. onClickFreeWindowMask() {
  226. if (!this.isCanClickFreeWindow) return;
  227. let bg = this.freeWindowNode.getChildByName("bg");
  228. tween(bg)
  229. .by(0.25, {position: new Vec3(0, 750, 0)})
  230. .call(()=>{
  231. bg.position = new Vec3(bg.x, bg.y - 750, bg.z);
  232. this.freeWindowNode.active = false;
  233. if (this.isShowReverse) {
  234. this.isShowReverse = false;
  235. this.showTransitionSpine(true, ()=>{ this.delayStartNextRoll(1); });
  236. } else
  237. this.delayStartNextRoll(1);
  238. })
  239. .start()
  240. this.isShowTransitionSpine = false;
  241. Tween.stopAllByTarget(this.node);
  242. }
  243. onClickAutoMask() {
  244. this.autoNode.active = false;
  245. }
  246. // onClick函数块------------------------------------------------------------------------
  247. // UI刷新模块---------------------------------------------------------------------------
  248. refreshBet() {
  249. this.upBetAddOrDelState();
  250. let bet = this.gameConfig.nJetton[this.curBetIndex] * GameConstant.MAX_BET_TIMES;
  251. this.betScoreNode.getComponent(Label).string = GameConstant.formatNumber(bet);
  252. }
  253. upBetAddOrDelState() {
  254. this.upBtnInteractable(this.btnBetSub, this.curBetIndex>0);
  255. this.upBtnInteractable(this.btnBetAdd, this.curBetIndex<this.gameConfig.nJetton.length-1);
  256. }
  257. upBtnInteractable(btn, state) {
  258. btn.getComponent(Button).interactable = state;
  259. }
  260. resetAllBtn() {
  261. if(this.bAutoGame || this.bSpecialGame) return;
  262. this.upBtnInteractable(this.btnStart, true);
  263. this.upBtnInteractable(this.btnStop, true);
  264. this.upBtnInteractable(this.btnAuto, true);
  265. // this.upBtnInteractable(this.maxBtn, true);
  266. this.upBetAddOrDelState();
  267. }
  268. onStartRoll() {
  269. if(!this.isGameEnd) return;
  270. Tween.stopAllByTarget(this.node);
  271. //是否可以开始游戏
  272. if(!this.judgeCannotRollGame()) {
  273. this.showStartAndStopButton(true);
  274. return;
  275. }
  276. this.isGameEnd = false;
  277. this.isPlaying = true;
  278. if (this.stopPlayingTime >= 0 && !this.bSpecialGame) {
  279. this.stopPlayingTime = 10;
  280. this.soundManager.setLoopEffectVolume(0.5);
  281. }
  282. this.upLeftCount();
  283. this.onSendRoll();
  284. this.showCenterNormal();
  285. this.onGameStart();
  286. this.rollNode.getComponent(GameRollNode).startRollActions();
  287. }
  288. onStopRoll() {
  289. if(this.isGameEnd) {
  290. return;
  291. }
  292. this.rollNode.getComponent(GameRollNode).openPrizes(true, this.bQuickGame);
  293. this.onGameEnd();
  294. }
  295. upLeftCount() {
  296. if (this.bSpecialGame) {
  297. this.freeCount--;
  298. this.freeCountNode.active = true;
  299. this.freeCountNode.getChildByName("count").getComponent(Label).string = this.freeCount.toString();
  300. return;
  301. }
  302. if(!this.bAutoGame) return;
  303. this.nAutoCount--;
  304. this.bAutoGame = this.nAutoCount != 0;
  305. this.btnStopAuto.active = this.bAutoGame;
  306. let left = this.btnStopAuto.getChildByName("Label");
  307. left.active = true;
  308. if (this.nAutoCount > 0)
  309. left.getComponent(Label).string = this.nAutoCount.toString();
  310. else if (this.nAutoCount < 0)
  311. left.getComponent(Label).string = "∞";
  312. }
  313. showCenterNormal() {
  314. // console.log("enter showCenterNormal");
  315. if(this.bSpecialGame) return;
  316. this.winScore.getComponent(Label).string = "$" + '0';
  317. this.winScore.active = false;
  318. this.winTitle.active = false;
  319. this.hintTitle.active = true;
  320. this.hintTitle.getComponent(Label).string = "GOOD LUCK!";
  321. }
  322. showWinScoreTitle(score) {
  323. // console.log("enter showWinScoreTitle");
  324. this.winScore.getComponent(Label).string = GameConstant.formatNumber(score);
  325. this.winScore.active = true;
  326. this.winTitle.active = true;
  327. this.hintTitle.getComponent(Label).string = "GOOD LUCK!";
  328. this.hintTitle.active = false;
  329. }
  330. onGameStart() {
  331. this.upBtnInteractable(this.btnStart, false);
  332. this.upBtnInteractable(this.btnBetAdd, false);
  333. this.upBtnInteractable(this.btnBetSub, false);
  334. this.upBtnInteractable(this.btnAuto, false);
  335. }
  336. onGameEnd() {
  337. this.changeBtnState(false);
  338. }
  339. showGameEnd() {
  340. this.isGameEnd = true;
  341. //获得免费次数
  342. if (this.freeCountAdd > 0) {
  343. this.showTransitionSpine(false, ()=>{ this.showFreeWindow(this.freeCountAdd, true); });
  344. } else if(this.bFreeState == 1) {
  345. this.showTransitionSpine(false, ()=>{ this.showFreeWindow(this.freeCount, false); });
  346. } else if(this.winAniIdx < 0 || this.bSpecialGame){
  347. this.delayStartNextRoll(0.5);
  348. }
  349. }
  350. showGameWinScore() {
  351. this.winAniIdx = -1;
  352. //所有赢钱
  353. this.allWinScore += this.gameEndData.m_lottery_size;
  354. let score = this.gameEndData.m_lottery_size;
  355. console.log("showGameWinScore this.bSpecialGame = " + this.bSpecialGame + ", this.gameResults.results.length = " + this.gameResults.results.length + ", this.gameCounts = " + this.gameCounts);
  356. //免费游戏中
  357. if(this.bSpecialGame) {
  358. // if(this.bFreeState) {
  359. // this.playEffect("freestart");
  360. // }
  361. // let nnode = this.node.getChildByName("FuncBtnNode").getChildByName("betInfoBg").getChildByName("img_1");
  362. // nnode.getChildByName("normalNode").active = false;
  363. // nnode.getChildByName("winNode").active = true;
  364. this.showWinScoreTitle(this.allWinScore);
  365. return;
  366. }
  367. //免费游戏结束
  368. if(this.gameResults.results.length > 1 && this.gameCounts == 1) {
  369. // this.nowPlayBgm = "bgm";
  370. // cc.vv.audioMgr.playBGM("bgm");
  371. // this.needPlayinfScore = this.allWinScore;
  372. this.lastScore = this.currentScore + this.allWinScore;
  373. this.currentScore = this.lastScore;
  374. this.upPlayerScore(this.currentScore);
  375. this.showWinScoreTitle(this.allWinScore);
  376. this.showFreeWin();
  377. return;
  378. }
  379. this.lastScore = this.currentScore + this.allWinScore;
  380. let timers = Math.floor(score / this.gameConfig.nJetton[this.curBetIndex]);
  381. this.currentScore = this.lastScore;
  382. this.upPlayerScore(this.currentScore);
  383. if(score <= 0){
  384. return;
  385. }
  386. if (timers >= 50)
  387. this.winAniIdx = 3;
  388. else if (timers >= 35)
  389. this.winAniIdx = 2;
  390. else if (timers >= 20)
  391. this.winAniIdx = 1;
  392. else if (timers >= 15)
  393. this.winAniIdx = 0;
  394. else
  395. this.showWinScoreTitle(this.allWinScore);
  396. if(this.winAniIdx >= 0) {
  397. this.showResultPanel();
  398. }
  399. }
  400. hideResultPanel() {
  401. this.resultNode.active = false;
  402. let title = this.resultNode.getChildByName("scoreNode").getChildByName("title");
  403. Tween.stopAllByTarget(title);
  404. this.showWinScoreTitle(this.allWinScore);
  405. }
  406. showResultPanel() {
  407. this.resultNode.active = true;
  408. let goldAni = this.resultNode.getChildByName("goldAni");
  409. let title = this.resultNode.getChildByName("scoreNode").getChildByName("title");
  410. let winScore = this.resultNode.getChildByName("scoreNode").getChildByName("scoreBg").getChildByName("score");
  411. winScore.getComponent(Label).string = "$0";
  412. this.isPlayingScoreAddAni = true;
  413. // console.log("showResultPanel this.isPlayingScoreAddAni = " + this.isPlayingScoreAddAni);
  414. this.soundManager.playResultLoopEffect(ResourceLoader.instance.getResource<AudioClip>("showResult"), 1);
  415. goldAni.active = this.winAniIdx > 0;
  416. goldAni.getComponent(sp.Skeleton).setAnimation(0, "a" + this.winAniIdx, true);
  417. let spriteFrameName = GameConstant.RESULT_TITLE[this.winAniIdx];
  418. title.getComponent(Sprite).spriteFrame = ResourceLoader.instance.getResource<SpriteAtlas>("atlas_BigWinCustom").getSpriteFrame(spriteFrameName);
  419. tween(title)
  420. .sequence(
  421. tween().to(0.5, {scale: new Vec3(1.2, 1.2, 1.2)}),
  422. tween().to(0.5, {scale: new Vec3(1, 1, 1)})
  423. )
  424. .repeatForever()
  425. .start()
  426. this.playScoreAddAni(winScore);
  427. }
  428. playScoreAddAni(sLabel) {
  429. let start = 0;
  430. let bet = this.gameConfig.nJetton[this.curBetIndex];
  431. let endScore = this.allWinScore;
  432. let add = 0.01;
  433. Tween.stopAllByTarget(sLabel);
  434. this.upScoreLabel = ()=>{
  435. start += add;
  436. if(start >= endScore) {
  437. this.skipScoreAdd(sLabel);
  438. }else{
  439. sLabel.getComponent(Label).string = "$" + start.toFixed(2);
  440. }
  441. }
  442. if(this.upScoreLabel) {
  443. this.unschedule(this.upScoreLabel);
  444. }
  445. this.schedule(this.upScoreLabel, 0.01);
  446. }
  447. skipScoreAdd(sLabel) {
  448. if(this.upScoreLabel) {
  449. this.unschedule(this.upScoreLabel);
  450. }
  451. this.soundManager.stopResultLoopEffect();
  452. this.soundManager.playEffect1(ResourceLoader.instance.getResource<AudioClip>("showResultEnd"));
  453. let score = this.allWinScore;
  454. sLabel.getComponent(Label).string = GameConstant.formatNumber(score);
  455. tween(sLabel)
  456. .repeat(
  457. 3,
  458. tween()
  459. .to(0.25, { scale: new Vec3(1.2,1.2,1.2) })
  460. .to(0.25, { scale: new Vec3(1.0,1.0,1.0) })
  461. )
  462. .call(()=>{
  463. if (this.bSpecialGame || this.bAutoGame) {
  464. this.hideResultPanel();
  465. this.delayStartNextRoll(1);
  466. }
  467. this.isPlayingScoreAddAni = false;
  468. })
  469. .start();
  470. // console.log("skipScoreAdd this.isPlayingScoreAddAni = " + this.isPlayingScoreAddAni);
  471. }
  472. changeBtnState(bEnd) {
  473. if (this.bAutoGame) return;
  474. this.btnStop.active = bEnd;
  475. this.btnStart.active = !bEnd;
  476. }
  477. showStartAndStopButton(isShow) {
  478. this.btnStop.active = isShow;
  479. this.btnStart.active = isShow;
  480. }
  481. delayStartNextRoll(delayTime) {
  482. this.resetAllBtn();
  483. Tween.stopAllByTarget(this.node);
  484. tween(this.node)
  485. .delay(delayTime)
  486. .call(()=>{
  487. if(this.bAutoGame || this.bSpecialGame){ //自动游戏时
  488. this.onStartRoll();
  489. }
  490. })
  491. .start()
  492. }
  493. showFreeWindow(freeCount, isAdd) {
  494. console.log(freeCount, isAdd);
  495. if (isAdd) this.soundManager.playEffect1(ResourceLoader.instance.getResource<AudioClip>("enterBonus"));
  496. this.isShowTransitionSpine = !isAdd;
  497. this.freeWindowNode.active = true;
  498. let bg = this.freeWindowNode.getChildByName("bg");
  499. let title = this.freeWindowNode.getChildByName("bg").getChildByName("title");
  500. let youwin = this.freeWindowNode.getChildByName("bg").getChildByName("youwin");
  501. let scoreBg = this.freeWindowNode.getChildByName("bg").getChildByName("scoreBg");
  502. let freeSpins = this.freeWindowNode.getChildByName("bg").getChildByName("freeSpins");
  503. let hintStr = this.freeWindowNode.getChildByName("bg").getChildByName("hintStr");
  504. bg.position = new Vec3(bg.x, bg.y + 750, bg.z);
  505. let actionNodes = [title, youwin, scoreBg, freeSpins, hintStr];
  506. this.freeWindowNode.getChildByName("bg").getChildByName("freeCountsNode").active = false;
  507. freeSpins.active = true;
  508. scoreBg.getChildByName("freeCount").getComponent(Label).string = (isAdd ? "+" : "") + freeCount.toString();
  509. this.freeCountNode.active = true;
  510. this.freeCountNode.getChildByName("count").getComponent(Label).string = this.freeCount.toString();
  511. title.getComponent(UIOpacity).opacity = 0;
  512. youwin.getComponent(UIOpacity).opacity = 0;
  513. scoreBg.getComponent(UIOpacity).opacity = 0;
  514. freeSpins.getComponent(UIOpacity).opacity = 0;
  515. hintStr.getComponent(UIOpacity).opacity = 0;
  516. tween(bg)
  517. .by(0.2, {position: new Vec3(0, -750, 0)})
  518. .sequence(
  519. tween().by(0.05, {position: new Vec3(-5, -5, 0)}),
  520. tween().by(0.05, {position: new Vec3(10, 10, 0)}),
  521. tween().by(0.05, {position: new Vec3(-10, -10, 0)}),
  522. tween().by(0.05, {position: new Vec3(5, 5, 0)}),
  523. )
  524. .call(()=>{
  525. for (let i = 0; i < actionNodes.length; i++) {
  526. tween(actionNodes[i])
  527. .to(0.01, {scale: new Vec3(0,0,0)})
  528. .delay((i + 1) * 0.2)
  529. .parallel(
  530. tween().to(0.15, {scale: new Vec3(1,1,1)}),
  531. tween(actionNodes[i].getComponent(UIOpacity)).to(0.15, {opacity: 255})
  532. )
  533. .start();
  534. }
  535. })
  536. .delay(2.5)
  537. .call(()=>{
  538. this.isCanClickFreeWindow = true;
  539. if (this.bSpecialGame) {
  540. tween(this.node)
  541. .delay(3)
  542. .call(()=>{
  543. this.onClickFreeWindowMask();
  544. })
  545. .start();
  546. }
  547. })
  548. .start();
  549. }
  550. showFreeWin() {
  551. this.soundManager.stopBGM();
  552. this.soundManager.playEffect1(ResourceLoader.instance.getResource<AudioClip>("showFreeGameWin"));
  553. this.isShowTransitionSpine = true;
  554. this.isShowReverse = true;
  555. this.freeWindowNode.active = true;
  556. let bg = this.freeWindowNode.getChildByName("bg");
  557. let title = this.freeWindowNode.getChildByName("bg").getChildByName("title");
  558. let youwin = this.freeWindowNode.getChildByName("bg").getChildByName("youwin");
  559. let scoreBg = this.freeWindowNode.getChildByName("bg").getChildByName("scoreBg");
  560. let freeSpins = this.freeWindowNode.getChildByName("bg").getChildByName("freeSpins");
  561. let hintStr = this.freeWindowNode.getChildByName("bg").getChildByName("hintStr");
  562. let freeCount = this.freeWindowNode.getChildByName("bg").getChildByName("freeCountsNode");
  563. let actionNodes = [title, youwin, scoreBg, freeCount, hintStr];
  564. bg.position = new Vec3(bg.x, bg.y + 750, bg.z);
  565. freeCount.active = true;
  566. freeSpins.active = false;
  567. scoreBg.getChildByName("freeCount").getComponent(Label).string = GameConstant.formatNumber(this.allWinScore);
  568. find("bg/freeCountsNode/freeCount", this.freeWindowNode).getComponent(Label).string = "" + this.gameResults.totalFreeCount;
  569. this.freeCountNode.active = false;
  570. title.getComponent(UIOpacity).opacity = 0;
  571. youwin.getComponent(UIOpacity).opacity = 0;
  572. scoreBg.getComponent(UIOpacity).opacity = 0;
  573. freeCount.getComponent(UIOpacity).opacity = 0;
  574. hintStr.getComponent(UIOpacity).opacity = 0;
  575. tween(bg)
  576. .by(0.25, {position: new Vec3(0, -750, 0)})
  577. .call(()=>{
  578. for (let i = 0; i < actionNodes.length; i++) {
  579. tween(actionNodes[i])
  580. .to(0.01, {scale: new Vec3(0,0,0)})
  581. .delay((i + 1) * 0.25)
  582. .parallel(
  583. tween().to(0.25, {scale: new Vec3(1,1,1)}),
  584. tween(actionNodes[i].getComponent(UIOpacity)).to(0.25, {opacity: 255})
  585. )
  586. .start();
  587. }
  588. })
  589. .delay(2.5)
  590. .call(()=>{
  591. this.isCanClickFreeWindow = true;
  592. if (this.bSpecialGame) {
  593. tween(this.node)
  594. .delay(3)
  595. .call(()=>{
  596. this.onClickFreeWindowMask();
  597. })
  598. .start();
  599. }
  600. })
  601. .start();
  602. }
  603. // UI刷新模块---------------------------------------------------------------------------
  604. judgeCannotRollGame() {
  605. //下注配置为空
  606. if(!this.gameConfig || !this.gameConfig.nJetton || this.curBetIndex == null) {
  607. return false;
  608. }
  609. if(this.freeCount > 0) {
  610. return true;
  611. }
  612. //检测钱是否够用
  613. if(this.lastScore < this.gameConfig.nJetton[this.curBetIndex]) {
  614. // this.showLowLackMoney();
  615. return false;
  616. }
  617. this.currentScore = this.lastScore - this.gameConfig.nJetton[this.curBetIndex];
  618. this.upPlayerScore(this.currentScore);
  619. return true;
  620. }
  621. showTransitionSpine(isReverse, callback) {
  622. if (isReverse)
  623. this.soundManager.playEffect1(ResourceLoader.instance.getResource<AudioClip>("endBonus"));
  624. else {
  625. this.soundManager.playEffect1(ResourceLoader.instance.getResource<AudioClip>("endBonus"));
  626. this.soundManager.playEffect2(ResourceLoader.instance.getResource<AudioClip>("enterBonus"));
  627. }
  628. this.transitionSpine.active = true;
  629. this.transitionSpine.getComponent(sp.Skeleton).setAnimation(0, isReverse ? "transition_reverse" : "transition", false);
  630. this.transitionSpine.getComponent(sp.Skeleton).setCompleteListener((event)=>{
  631. this.transitionSpine.getComponent(sp.Skeleton).setCompleteListener(null)
  632. let bgFs = ResourceLoader.instance.getResource<SpriteAtlas>("bg_opaque_fs_landscape").getSpriteFrame("landscape");
  633. let bgNormal = ResourceLoader.instance.getResource<SpriteAtlas>("bg_opaque_normal_landscape").getSpriteFrame("bg_normal_landscape");
  634. let slotRectBgFs = ResourceLoader.instance.getResource<SpriteAtlas>("playfield_common").getSpriteFrame("playfield_frame_fs");
  635. let slotRectBgNormal = ResourceLoader.instance.getResource<SpriteAtlas>("playfield_common").getSpriteFrame("playfield_frame");
  636. let slotBgFs = ResourceLoader.instance.getResource<SpriteAtlas>("bg_opaque_fs_landscape").getSpriteFrame("reel_bg_fs");
  637. let slotBgNormal = ResourceLoader.instance.getResource<SpriteAtlas>("bg_opaque_normal_landscape").getSpriteFrame("reel_bg_normal");
  638. tween(this.bgNode.getComponent(UIOpacity))
  639. .to(0.1, {opacity: 0})
  640. .call(()=>{
  641. this.bgNode.getComponent(Sprite).spriteFrame = event.animation.name == "transition" ? bgFs : bgNormal;
  642. })
  643. .to(0.1, {opacity: 255})
  644. .delay(2)
  645. .call(()=>{
  646. callback();
  647. })
  648. .start();
  649. tween(this.slotRectNode.getComponent(UIOpacity))
  650. .to(0.1, {opacity: 0})
  651. .call(()=>{
  652. this.slotRectNode.getComponent(Sprite).spriteFrame = event.animation.name == "transition" ? slotRectBgFs : slotRectBgNormal;
  653. for (let i = 0; i < 6; i ++) {
  654. tween(this.rollNode.getChildByName("slotBg" + (i + 1)).getComponent(UIOpacity))
  655. .to(0.1, {opacity: 0})
  656. .call(()=>{
  657. this.rollNode.getChildByName("slotBg" + (i + 1)).getComponent(Sprite).spriteFrame = event.animation.name == "transition" ? slotBgFs : slotBgNormal;
  658. })
  659. .to(0.1, {opacity: 255})
  660. .start();
  661. }
  662. })
  663. .to(0.1, {opacity: 255})
  664. .start();
  665. let audio = ResourceLoader.instance.getResource<AudioClip>(event.animation.name == "transition" ? "fs_bgm" : "bgm");
  666. this.soundManager.playBGM(audio);
  667. this.transitionSpine.active = false;
  668. });
  669. }
  670. /**
  671. * 发送游戏信息请求,失败会重试三次
  672. */
  673. sendHttpRequest() {
  674. const url = GameConstant.HTTP_HOST + "game-api/" + GameConstant.GAMEID + "/v2/spin";
  675. console.log("请求游戏信息:", url);
  676. GameConstant.httpRequest("POST", url, {cs: this.gameConfig.nJetton[this.curBetIndex], ml: 1}, false)
  677. .then((res: any) => {
  678. console.log("HTTP 回包成功:", res);
  679. this.hasHttpResponse = true;
  680. if (res.dt) {
  681. if (res.dt.si) {
  682. this.gameResults = res.dt.si;
  683. } else {
  684. this.gameResults = res.dt;
  685. }
  686. this.gameEndData = this.gameResults.results[0];
  687. this.gameCounts = this.gameResults.results.length;
  688. this.onRollEndInfo(this.gameEndData);
  689. }
  690. })
  691. .catch((err: any) => {
  692. this.httpRetryCount++;
  693. console.error(`HTTP 请求失败 (第 ${this.httpRetryCount} 次):`, err);
  694. if (this.httpRetryCount < this.maxRetries) {
  695. this.scheduleOnce(() => this.sendHttpRequest(), 0.5);
  696. } else {
  697. // TODO: 弹出提示框,提示用户重试或退出游戏
  698. console.error("三次重试失败,停止请求。");
  699. }
  700. });
  701. }
  702. onSendRoll() {
  703. if (this.gameResults.results.length > 1 && this.gameCounts > 1) {
  704. this.gameCounts--;
  705. this.gameEndData = this.gameResults.results[this.gameResults.results.length - this.gameCounts];
  706. this.scheduleOnce(()=>{
  707. this.onRollEndInfo(this.gameEndData);
  708. }, 0.5);
  709. } else {
  710. // spin请求
  711. // this.sendHttpRequest();
  712. this.scheduleOnce(()=>{
  713. let results = GameConstant.playRound(this.gameConfig.nJetton[this.curBetIndex]);
  714. console.log(results);
  715. this.gameResults = results;
  716. this.gameEndData = results.results[0];
  717. this.gameCounts = results.results.length;
  718. this.onRollEndInfo(this.gameEndData);
  719. }, 0.5);
  720. }
  721. }
  722. onRollEndInfo(data) {
  723. if(!this.bQuickGame)
  724. this.changeBtnState(true);
  725. this.gameEndData = data;
  726. if(this.gameResults.results.length > 1) {
  727. // this.upFreeCount();
  728. }else{
  729. this.allWinScore = 0;
  730. this.freeCountAdd = 0;
  731. }
  732. this.bFreeState = data.m_isSpecialGame;
  733. this.freeCount = data.m_curTotalFreeCount;
  734. this.freeCountAdd = data.m_freeCountAdd
  735. this.bSpecialGame = data.m_curTotalFreeCount > 0;
  736. // 转动层数值传递
  737. this.rollNode.getComponent(GameRollNode).setRollDatas(data, this.bSpecialGame);
  738. this.rollNode.getComponent(GameRollNode).openPrizes(false, this.bQuickGame);
  739. }
  740. getSingleLineBet() {
  741. return this.gameConfig.nJetton[0];
  742. }
  743. upPlayerScore(score) {
  744. // cc.vv.globalUserInfo.setUserScore(score);
  745. this.playerScore.getComponent(Label).string = GameConstant.formatNumber(score);
  746. }
  747. }