RaioRollPanel.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. var Global = require("Global");
  2. var UIHelper = require("UIHelper");
  3. var BaseDefine = require("BaseDefine");
  4. var GameProtocol = require("RaioGameProtocol");
  5. import ScenceManager from 'HNScenceManager'
  6. const arr_posX = [-357, -178, 0, 178, 357];
  7. cc.Class({
  8. extends: cc.Component,
  9. editor: {
  10. menu: 'Game/Raio/RollPanel'
  11. },
  12. properties: {
  13. rollBG: [cc.Node],
  14. rollAni: [cc.Node],
  15. lineNodes: [cc.Node],
  16. itemClone: cc.Prefab,
  17. lightBG: cc.Node,
  18. itemSpines: [sp.SkeletonData],
  19. numAni: sp.Skeleton,
  20. titleAni: sp.Skeleton,
  21. bgAni: sp.Skeleton,
  22. shakeNode: cc.Node,
  23. bGameEnd: false,
  24. maxRolItemlLen: 21,
  25. MAX_COL_NUM: 5,
  26. MAX_ROW_NUM: 4,
  27. SPECIAL_ICON: 9,
  28. sizec: 150,
  29. },
  30. // LIFE-CYCLE CALLBACKS:
  31. onLoad () {
  32. this.linesArr = [[0,1,2,3,4],[10,11,12,13,14],[20,21,22,23,24],[30,31,32,33,34],[0,11,2,13,4],[10,1,12,3,14],
  33. [10,21,12,23,14],[20,11,22,13,24],[20,31,22,33,24],[30,21,32,23,34],[0,11,22,13,4],[20,11,2,13,24],
  34. [10,21,32,23,14],[30,21,12,23,34],[0,1,12,3,4],[10,11,2,13,14],[10,11,22,13,14],[20,21,12,23,24],
  35. [20,21,32,23,24],[30,31,22,33,34],[0,11,12,13,4],[10,1,2,3,14],[10,21,22,23,14],[20,11,12,13,24],
  36. [20,31,32,33,24],[30,21,22,23,34],[0,1,12,23,24],[20,21,12,3,4],[10,11,22,33,34],[30,31,22,13,14]];
  37. this._rollResultData = {};
  38. this._lineCount = 0;
  39. this._lineSize = [];
  40. this._lineID = [];
  41. this._lineIcon = [];
  42. this._lineTimes = [];
  43. this.itemData = [];
  44. this.elementNode = [];
  45. this.elementJS = [];
  46. this.tempValue = [];
  47. this.lightNode = [];
  48. this.lightJS = [];
  49. this._startRollTime = 0;
  50. this.numAni.node.active = false;
  51. this._lastCashCnt = 0;
  52. this.initLists();
  53. },
  54. start() {
  55. this.titleAni.node.active = true;
  56. this.titleAni.clearTracks();
  57. this.titleAni.setAnimation(0, "1a", false);
  58. this.titleAni.addAnimation(0, "1b", true);
  59. this.nowTitleIdx = 1;
  60. this.delayShowNextTitleTime = 15;
  61. this.updateRollBGAni(0);
  62. },
  63. upTitleAni() {
  64. this.titleAni.clearTracks();
  65. let c = '3c';
  66. let a = ''+this.nowTitleIdx+'a';
  67. let b = ''+this.nowTitleIdx+'b';
  68. if(this.nowTitleIdx == 2) {
  69. c = '1c';
  70. }else if(this.nowTitleIdx == 3) {
  71. c = '2c';
  72. this.nowTitleIdx = 0;
  73. }
  74. this.titleAni.clearTracks();
  75. this.titleAni.setAnimation(0, c, false);
  76. this.titleAni.addAnimation(0, a, false);
  77. this.titleAni.addAnimation(0, b, true);
  78. this.delayShowNextTitleTime = 15;
  79. },
  80. showNumAni(num) {
  81. Global.print("showNumAni:"+num)
  82. if(num < 3) {
  83. this.numAni.node.active = false;
  84. return;
  85. }
  86. if(num < 10) {
  87. num = '0'+num;
  88. }
  89. this.numAni.node.active = true;
  90. this.numAni.clearTracks();
  91. this.numAni.setAnimation(0, ''+num+'a', false);
  92. this.numAni.addAnimation(0, ''+num+'b', true);
  93. },
  94. updateRollBGAni(cnt) {
  95. for(let i = 0; i < GameProtocol.MAX_COL_NUM; ++i) {
  96. this.rollAni[i].active = cnt > 10;
  97. if(cnt >= 10) {
  98. let ani = this.rollAni[i].getComponent(sp.Skeleton);
  99. ani.clearTracks();
  100. ani.setAnimation(0, cnt > 15?'a2':'a1', true);
  101. }
  102. }
  103. },
  104. resetRollBGAni() {
  105. for(let i = 0; i < GameProtocol.MAX_COL_NUM; ++i) {
  106. this.rollAni[i].active = false;
  107. }
  108. },
  109. playEffectByCashCnt() {
  110. if(this.cashCnt == 0) {return;}
  111. if(this.cashCnt < 3) {
  112. this.playEffect('cashcnt12');
  113. }else if(this.cashCnt <= 10) {
  114. this.playEffect('cashcnt310')
  115. this.playEffect('cash310')
  116. }else if(this.cashCnt <= 15) {
  117. this.playEffect('cashcnt1115')
  118. this.playEffect('cash1115')
  119. }else{
  120. this.playEffect('cashcnt1620')
  121. this.playEffect('cash1620')
  122. }
  123. },
  124. startHotBGAct() {
  125. let x = 0//this.bgAni.node.x;
  126. let y = 0//this.bgAni.node.y;
  127. this.shakeNode.stopAllActions();
  128. cc.tween(this.shakeNode)
  129. .sequence(
  130. cc.tween().to(0.03, {x:x+5, y:y+5}),
  131. cc.tween().to(0.03, {x:x, y:y})
  132. )
  133. .repeatForever()
  134. .start()
  135. },
  136. stopHotBGAct() {
  137. this.shakeNode.stopAllActions();
  138. this.shakeNode.x = 0;
  139. this.shakeNode.y = 0;
  140. },
  141. shake2() {
  142. let x = 0//this.bgAni.node.x;
  143. let y = 0//this.bgAni.node.y;
  144. this.shakeNode.stopAllActions();
  145. cc.tween(this.shakeNode)
  146. .sequence(
  147. cc.tween().to(0.03, {x:x-1, y:y-2}),
  148. cc.tween().to(0.03, {x:x, y:y+1}),
  149. cc.tween().to(0.03, {y:y-1}),
  150. cc.tween().to(0.03, {y:y})
  151. )
  152. .repeat(3)
  153. .start()
  154. },
  155. shake3() {
  156. let x = 0//this.bgAni.node.x;
  157. let y = 0//this.bgAni.node.y;
  158. this.shakeNode.stopAllActions();
  159. cc.tween(this.shakeNode)
  160. .sequence(
  161. cc.tween().to(0.03, {x:x-1, y:y-2}),
  162. cc.tween().to(0.03, {x:x, y:y+1}),
  163. cc.tween().to(0.03, {y:y-1}),
  164. cc.tween().to(0.03, {y:y})
  165. )
  166. .repeat(2)
  167. .start()
  168. },
  169. updateBGAni() {
  170. let shake2 = ()=>{
  171. let x = 0//this.bgAni.node.x;
  172. let y = 0//this.bgAni.node.y;
  173. this.shakeNode.stopAllActions();
  174. cc.tween(this.shakeNode)
  175. .sequence(
  176. cc.tween().to(0.03, {x:x-1, y:y-2}),
  177. cc.tween().to(0.03, {x:x, y:y+1}),
  178. cc.tween().to(0.03, {y:y-1}),
  179. cc.tween().to(0.03, {y:y})
  180. )
  181. .repeat(3)
  182. .start()
  183. }
  184. let shake3 = ()=>{
  185. let x = 0//this.bgAni.node.x;
  186. let y = 0//this.bgAni.node.y;
  187. this.shakeNode.stopAllActions();
  188. cc.tween(this.shakeNode)
  189. .sequence(
  190. cc.tween().to(0.03, {x:x-1, y:y-2}),
  191. cc.tween().to(0.03, {x:x, y:y+1}),
  192. cc.tween().to(0.03, {y:y-1}),
  193. cc.tween().to(0.03, {y:y})
  194. )
  195. .repeat(2)
  196. .start()
  197. }
  198. if(this.cashCnt > 0) {
  199. //首次中,10个及以上 用a4 否则用a1
  200. if(this._lastCashCnt == 0) {
  201. this.bgAni.clearTracks();
  202. this.bgAni.setAnimation(0, "a2", false);
  203. this.bgAni.addAnimation(0, this.cashCnt>=10?'a4':'a1', true);
  204. shake2();
  205. }else{
  206. //新增,少于10
  207. if(this.cashCnt <= 10) {
  208. this.bgAni.clearTracks();
  209. this.bgAni.setAnimation(0, "a3", false);
  210. this.bgAni.addAnimation(0, 'a1', true);
  211. shake3();
  212. }else if(this.cashCnt >= 11 && this.cashCnt <= 15) {
  213. this.bgAni.clearTracks();
  214. this.bgAni.setAnimation(0, "a6", false);
  215. this.bgAni.addAnimation(0, 'a4', true);
  216. shake3();
  217. }else{
  218. this.bgAni.clearTracks();
  219. this.bgAni.setAnimation(0, "a5", false);
  220. this.bgAni.addAnimation(0, 'a4', true);
  221. shake2();
  222. }
  223. }
  224. }else{
  225. //未中 使用默认
  226. this.bgAni.clearTracks();
  227. this.bgAni.setAnimation(0, "a1", true);
  228. }
  229. },
  230. initLists() {
  231. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  232. this.elementNode[i] = [];
  233. this.elementJS[i] = [];
  234. this.itemData[i] = [];
  235. this.tempValue[i] = [];
  236. this.lightNode[i] = [];
  237. this.lightJS[i] = [];
  238. this.rollBG[i].active = true;
  239. this.rollBG[i].removeAllChildren();
  240. for(let j = 0; j < this.maxRolItemlLen-5; ++j) {
  241. this.tempValue[i][j] = this.getRandomValue();
  242. }
  243. for(let j = this.maxRolItemlLen-5; j < this.maxRolItemlLen; ++j) {
  244. this.tempValue[i][j] = this.tempValue[i][j-12];
  245. }
  246. for(let j = 0; j < this.maxRolItemlLen; ++j) {
  247. let item = cc.instantiate(this.itemClone);
  248. item.y = (this.maxRolItemlLen - 3.5 - j)*(this.sizec);
  249. item.parent = this.rollBG[i];
  250. item.active = true;
  251. this.elementNode[i][j] = item;
  252. this.elementJS[i][j] = this.elementNode[i][j].getComponent("RaioItem");
  253. this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  254. }
  255. for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
  256. let light = cc.instantiate(this.itemClone);
  257. light.x = arr_posX[i];
  258. light.y = (1.5-j)*this.sizec;
  259. light.parent = this.lightBG;
  260. light.active = false;
  261. this.lightNode[i][j] = light;
  262. this.lightJS[i][j] = this.lightNode[i][j].getComponent("RaioItem");
  263. this.lightJS[i][j].setValue(GameProtocol.LIGHT_ICON, this.itemSpines[GameProtocol.LIGHT_ICON], true);
  264. }
  265. }
  266. },
  267. forceStop() {
  268. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  269. let rollbg = this.rollBG[i];
  270. rollbg.active = false;
  271. rollbg.stopAllActions();
  272. rollbg.y = 0;
  273. }
  274. },
  275. reSetLastData(data, cashCnt) {
  276. // Global.print(data);
  277. this.node.stopAllActions();
  278. this.resetAllLines();
  279. this._hasSpecial = cashCnt >= 3;
  280. this.cashCnt = cashCnt;
  281. this._lastCashCnt = cashCnt;
  282. for(let i = 0; i < this.MAX_ROW_NUM; ++i) {
  283. for(let j = 0;j < this.MAX_COL_NUM; ++j) {
  284. this.tempValue[j][i+16] = data[i][j];
  285. this.elementJS[j][i+16].setValue(data[i][j], this.itemSpines[data[i][j]], this.isSpecialIcon(data[i][j]));
  286. this.lightJS[j][i].resetShow();
  287. this.lightJS[j][i].setValue(data[i][j], this.itemSpines[data[i][j]], this.isSpecialIcon(data[i][j]));
  288. this.lightNode[j][i].active = true;
  289. this.lightJS[j][i].showLightAni(this._hasSpecial);
  290. }
  291. }
  292. this.showNumAni(cashCnt);
  293. this.updateRollBGAni(cashCnt);
  294. ScenceManager.Instance().getGameComponent().changeBGM(this.cashCnt);
  295. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  296. this.rollBG[i].active = false;
  297. for(let j = 0;j < this.MAX_ROW_NUM; ++j) {
  298. this.lightJS[i][j].showNewPrizes(this._hasSpecial);
  299. }
  300. }
  301. // Global.print("reSetLastData:"+this.cashCnt)
  302. this.bgAni.clearTracks();
  303. this.bgAni.setAnimation(0, this.cashCnt>=10?'a4':'a1', true);
  304. },
  305. isSpecialIcon(val) {
  306. return val == GameProtocol.LIGHT_ICON;
  307. },
  308. getRandomValue() {
  309. let rand = Math.floor(Math.random()*100);
  310. return rand % 10;
  311. },
  312. getItemSpineData(id) {
  313. return this.itemSpines[id];
  314. },
  315. resetRollingItemValue(i) {
  316. for(let j = 9; j < this.maxRolItemlLen-5; ++j) {
  317. this.tempValue[i][j] = this.getRandomValue();
  318. this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  319. }
  320. for(let j = this.maxRolItemlLen-5; j < this.maxRolItemlLen; ++j) {
  321. this.elementNode[i][j].active = true;
  322. }
  323. },
  324. startRollActions() {
  325. this.playEffect("roll");
  326. this.bGameEnd = false;
  327. this.node.stopAllActions();
  328. this.resetItemCounts();
  329. if(this.cashCnt > 10) {
  330. this.startHotBGAct();
  331. }
  332. this._lastCashCnt = this.cashCnt;
  333. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  334. let rollbg = this.rollBG[i];
  335. rollbg.active = true;
  336. rollbg.y = 0;
  337. rollbg.stopAllActions();
  338. for(let j = 4; j < 9; ++j) {
  339. this.tempValue[i][j] = this.tempValue[i][j+12];
  340. this.elementJS[i][j].setValue(this.tempValue[i][j], this.getItemSpineData(this.tempValue[i][j]), this.isSpecialIcon(this.tempValue[i][j]));
  341. }
  342. // this.updateRollBGAni(this.cashCnt, i)
  343. cc.tween(rollbg)
  344. .sequence(
  345. cc.tween().to(0.3, {y: -10*this.sizec}),
  346. cc.tween().call(()=>{ rollbg.y = 0, this.resetRollingItemValue(i) })
  347. )
  348. .repeatForever()
  349. .start()
  350. }
  351. this._startRollTime = new Date().getTime();
  352. },
  353. openPrizes(justEnd, bQuick) {
  354. if(this.bGameEnd == true) {
  355. return;
  356. }
  357. let endTime = new Date().getTime();
  358. let leftTime = this._startRollTime - endTime + 1300;
  359. this.delayTime = 0.2;
  360. if(bQuick) {
  361. leftTime -= 500;
  362. }
  363. if(leftTime < 0 || justEnd) {
  364. leftTime = 0;
  365. }
  366. if(justEnd) {
  367. this.delayTime = 0;
  368. }
  369. this.node.stopAllActions();
  370. this.bQuick = bQuick;
  371. this.FreeCount = 0;
  372. cc.tween(this.node)
  373. .delay(leftTime/1000)
  374. .call(()=>{
  375. this.rollEnds(0);
  376. })
  377. .start()
  378. },
  379. setItemColInfo(i, dIdx) {
  380. for(let j = this.maxRolItemlLen-5; j < this.maxRolItemlLen; ++j) {
  381. this.elementNode[i][j-this.maxRolItemlLen+dIdx].active = true;
  382. this.elementNode[i][j].active = true;
  383. this.tempValue[i][j] = this.tempValue[i][j-this.maxRolItemlLen+dIdx];
  384. this.elementJS[i][j].setValue(this.tempValue[i][j], this.getItemSpineData(this.tempValue[i][j]), this.isSpecialIcon(this.tempValue[i][j]));
  385. }
  386. this.rollBG[i].active = false;
  387. // this.updateRollBGAni(0, i);
  388. let hasNewCash = false;
  389. for(let j = 0; j < GameProtocol.MAX_ROW_NUM; ++j) {
  390. if(!this.lightNode[i][j].active) {
  391. this.lightNode[i][j].active = true;
  392. this.lightJS[i][j].showLightAni(this._hasSpecial);
  393. if(this.lightJS[i][j].getValue() == GameProtocol.LIGHT_ICON) {
  394. hasNewCash = true;
  395. }
  396. }
  397. }
  398. if(hasNewCash) {
  399. this.playEffectByCashCnt();
  400. if(this._lastCashCnt == 0 || this.cashCnt == 10) {
  401. this.shake2();
  402. }else{
  403. this.shake3();
  404. }
  405. }
  406. },
  407. quickEnd(i) {
  408. if(i >= this.MAX_COL_NUM) {
  409. return;
  410. }
  411. let rollbg = this.rollBG[i];
  412. rollbg.stopAllActions();
  413. let yy = rollbg.y;
  414. let destIdx = this.maxRolItemlLen - 3 - Math.floor(yy/-this.sizec);
  415. for(let j = destIdx-3; j >= destIdx-6; --j) {
  416. this.tempValue[i][j] = this.tempValue[i][j-destIdx+6];
  417. this.elementJS[i][j].setValue(this.tempValue[i][j], this.getItemSpineData(this.tempValue[i][j]), this.isSpecialIcon(this.tempValue[i][j]));
  418. }
  419. let destY = (this.maxRolItemlLen - destIdx+1) * -this.sizec;
  420. let lastTime = (yy - destY + 50)/this.sizec/10;
  421. cc.tween(rollbg)
  422. .to(lastTime, {y: destY-50})
  423. .to(0.1, {y: destY}, {easing: 'sineInOut'})
  424. .call(()=>{
  425. this.setItemColInfo(i, destIdx);
  426. rollbg.y = 0;
  427. })
  428. .start()
  429. },
  430. justEnd(i) {
  431. if(i >= this.MAX_COL_NUM) {
  432. return;
  433. }
  434. let rollbg = this.rollBG[i];
  435. rollbg.stopAllActions();
  436. let yy = rollbg.y;
  437. let destIdx = this.maxRolItemlLen - 3 - Math.floor(yy/-this.sizec);
  438. for(let j = destIdx-3; j >= destIdx-6; --j) {
  439. this.tempValue[i][j] = this.tempValue[i][j-destIdx+6];
  440. this.elementJS[i][j].setValue(this.tempValue[i][j], this.getItemSpineData(this.tempValue[i][j]), this.isSpecialIcon(this.tempValue[i][j]));
  441. }
  442. let destY = (this.maxRolItemlLen - destIdx+1) * -this.sizec;
  443. let lastTime = (yy - destY + 50)/this.sizec/10*0.5;
  444. cc.tween(rollbg)
  445. .to(lastTime, {y: destY-50})
  446. .call(()=>{
  447. this.hotRolls(i+1);
  448. })
  449. .to(0.1, {y: destY}, {easing: 'sineInOut'})
  450. .call(()=>{
  451. this.setItemColInfo(i, destIdx);
  452. rollbg.y = 0;
  453. })
  454. .start()
  455. },
  456. rollEnds(i) {
  457. // if(i == 0) {
  458. // ScenceManager.Instance().getGameComponent().onGameEnd();
  459. // }
  460. if(i > 4) {
  461. this.delayShowPrizes(600);
  462. return;
  463. }
  464. let rollbg = this.rollBG[i];
  465. rollbg.stopAllActions();
  466. let yy = rollbg.y;
  467. let destIdx = Math.floor(this.maxRolItemlLen - 3.5 - Math.floor(yy/-this.sizec));
  468. // Global.print("i"+i+" "+destIdx)
  469. for(let j = destIdx-2; j >= destIdx-6; --j) {
  470. this.tempValue[i][j] = this.tempValue[i][j-destIdx+6];
  471. this.elementJS[i][j].setValue(this.tempValue[i][j], this.getItemSpineData(this.tempValue[i][j]), this.isSpecialIcon(this.tempValue[i][j]));
  472. }
  473. let destY = (this.maxRolItemlLen - destIdx+1) * -this.sizec;
  474. let lastTime = (yy - destY + 10)/this.sizec/10*0.3;
  475. if(this.bQuick) {
  476. cc.tween(rollbg)
  477. .call(()=>{
  478. this.rollEnds(i+1);
  479. })
  480. .to(lastTime, {y: destY-50})
  481. .to(0.1, {y: destY}, {easing: 'sineInOut'})
  482. .call(()=>{
  483. this.setItemColInfo(i, destIdx);
  484. rollbg.y = 0;
  485. })
  486. .start()
  487. return;
  488. }
  489. // Global.print(`endTime:${i}, ${lastTime}`)
  490. cc.tween(rollbg)
  491. .to(lastTime, {y: destY-50})
  492. .call(()=>{
  493. this.rollEnds(i+1);
  494. this.playEffect("rollend");
  495. })
  496. // .to(0.03, {y: destY-30}, {easing: 'sineIn'})
  497. .to(0.03, {y: destY})
  498. // .delay(this.delayTime)
  499. .call(()=>{
  500. this.setItemColInfo(i, destIdx);
  501. rollbg.y = 0;
  502. // rollbg.y = -16*140;
  503. // this.rollEnds(i+1);
  504. })
  505. .start()
  506. },
  507. delayShowPrizes(delayTime) {
  508. this.stopHotBGAct();
  509. //cash结束, 先播cash中奖动画
  510. if(this._rollResultData.m_ruyi == 1) {
  511. cc.tween(this.node)
  512. .delay(0.1)
  513. .call(()=>{
  514. // this.playEffectByCashCnt();
  515. this.behindShowPrizes();
  516. })
  517. .delay(delayTime/1000)
  518. .call(()=>{
  519. this.goCashPrizes(false);
  520. ScenceManager.Instance().getGameComponent().showCashWin(this.cashCnt);
  521. })
  522. .start()
  523. }else{
  524. this.updateBGAni();
  525. cc.tween(this.node)
  526. .delay(0.1)
  527. .call(()=>{
  528. // this.playEffectByCashCnt();
  529. this.beforeShowPrizes();
  530. })
  531. .delay(delayTime/1000)
  532. .call(()=>{
  533. // this.showNumAni(this.cashCnt);
  534. this.showPrizes();
  535. })
  536. .start()
  537. }
  538. return;
  539. cc.tween(this.node)
  540. .delay(0.1)
  541. .call(()=>{
  542. if(this._rollResultData.m_ruyi == 1) {
  543. this.behindShowPrizes();
  544. }else{
  545. this.beforeShowPrizes();
  546. }
  547. // this.beforeShowPrizes();
  548. })
  549. .delay(delayTime/1000)
  550. .call(()=>{
  551. this.bGameEnd = true;
  552. //没有中彩金和小游戏 才展示
  553. //有
  554. if(this._hasSpecial && this._rollResultData.m_ruyi != 1) {
  555. this.showNumAni(this.cashCnt);
  556. }
  557. if(this._rollResultData.m_ruyi == 1) {
  558. this.goCashPrizes(false);
  559. ScenceManager.Instance().getGameComponent().showCashWin(this.cashCnt);
  560. }else{
  561. this.showPrizes();
  562. }
  563. if(this._rollResultData.m_ruyi == 1 || this.cashCnt < 3) {
  564. this._hasSpecial = false;
  565. this.cashCnt = 0;
  566. }
  567. ScenceManager.Instance().getGameComponent().upDeskRecordCashCnt(this.cashCnt);
  568. // this.showPrizes();
  569. })
  570. .delay(0.3)
  571. .call(()=>{
  572. ScenceManager.Instance().getGameComponent().showGameEnd();
  573. })
  574. .start()
  575. },
  576. goCashPrizes(bShow) {
  577. for(let i = 0; i < GameProtocol.MAX_COL_NUM; ++i) {
  578. for(let j = 0; j < GameProtocol.MAX_ROW_NUM; ++j) {
  579. this.lightJS[i][j].goCashPrizes(bShow);
  580. }
  581. }
  582. },
  583. beforeShowPrizes() {
  584. for(let j = 0; j < GameProtocol.MAX_COL_NUM; ++j) {
  585. for(let i = 0; i < GameProtocol.MAX_ROW_NUM; ++i) {
  586. this.lightJS[j][i].showNewPrizes(this._hasSpecial);
  587. }
  588. }
  589. },
  590. behindShowPrizes() {
  591. for(let j = 0; j < GameProtocol.MAX_COL_NUM; ++j) {
  592. for(let i = 0; i < GameProtocol.MAX_ROW_NUM; ++i) {
  593. this.lightJS[j][i].showEndPrizes();
  594. }
  595. }
  596. },
  597. showPrizes() {
  598. this.bGameEnd = true;
  599. if(this._rollResultData.m_ruyi == 1 || this.cashCnt < 3) {
  600. this._hasSpecial = false;
  601. this.cashCnt = 0;
  602. }
  603. if(this._rollResultData.m_ruyi == 1) {
  604. this.updateBGAni();
  605. }
  606. ScenceManager.Instance().getGameComponent().changeBGM(this.cashCnt);
  607. ScenceManager.Instance().getGameComponent().upDeskRecordCashCnt(this.cashCnt, this._rollResultData.m_ruyi == 1);
  608. this.showNumAni(this.cashCnt);
  609. this.goCashPrizes(true);
  610. // ScenceManager.Instance().getGameComponent().showGameWinScore();
  611. this.updateRollBGAni(this.cashCnt);
  612. if(this._lineCount > 0) {
  613. let nowIdx = 0;
  614. let func = ()=>{
  615. if(nowIdx >= this._lineCount) {
  616. this.unschedule(func);
  617. return;
  618. }
  619. this.lineNodes[this._lineID[nowIdx++]].active = true;
  620. this.playEffect("line");
  621. }
  622. this.schedule(func, 0.1);
  623. cc.tween(this.node)
  624. .delay(this._lineCount*0.1+0.5)
  625. .call(()=>{
  626. ScenceManager.Instance().getGameComponent().showGameWinScore();
  627. this.resetItemsShow();
  628. this.resetAllLines();
  629. })
  630. .delay(0.1)
  631. .call(()=>{
  632. // this.resetItemsShow();
  633. this.showLines(0);
  634. })
  635. .start();
  636. }else{
  637. ScenceManager.Instance().getGameComponent().showGameWinScore();
  638. }
  639. },
  640. resetAllLines() {
  641. for(let i = 0; i < this.lineNodes.length; ++i) {
  642. this.lineNodes[i].active = false;
  643. }
  644. },
  645. showLines(iIndex) {
  646. if(iIndex >= this._lineCount) {
  647. this.showLines(0);
  648. return;
  649. }
  650. // this.resetAllLines();
  651. let lineID = this._lineID[iIndex];
  652. this.lineNodes[lineID].active = true;
  653. let lineArr = this.linesArr[lineID];
  654. let count = this._lineSize[iIndex];
  655. for(let k = 0; k < count; ++k) {
  656. let idx = lineArr[k];
  657. let i = idx % 10;
  658. let j = Math.floor(idx/10);
  659. this.lightJS[i][j].showPrizes();
  660. }
  661. cc.tween(this.node)
  662. .delay(1)
  663. // .call(()=>{
  664. // this.resetItemsShow();
  665. // this.resetAllLines();
  666. // })
  667. // .delay(0.1)
  668. .call(()=>{
  669. this.resetItemsShow();
  670. this.resetAllLines();
  671. this.showLines(iIndex+1);
  672. })
  673. .start();
  674. },
  675. setRollDatas(msg) {
  676. this._rollResultData = msg;
  677. this.setItemDatas(msg.m_desk_data);
  678. this._hasSpecial = msg.m_is_berserk == 1;
  679. //线信息
  680. this._lineCount = msg.m_line_count;
  681. this._lineID = msg.m_line_id;
  682. this._lineSize = msg.m_line_size;
  683. this._lineIcon = msg.m_line_icon;
  684. this._lineTimes = msg.m_line_times;
  685. this.analyzeLinesData();
  686. this.doOthersWithResultData();
  687. },
  688. setItemDatas(itemData) {
  689. this.cashCnt = 0;
  690. for(let i = 0; i < this.MAX_ROW_NUM; ++i) {
  691. for(let j = 0;j < this.MAX_COL_NUM; ++j) {
  692. this.tempValue[j][i+1] = itemData[i][j];
  693. this.elementJS[j][i+1].setValue(itemData[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  694. if(this.isSpecialIcon(itemData[i][j])) {
  695. this.cashCnt++;
  696. }
  697. }
  698. }
  699. // Global.print(this.tempValue);
  700. // Global.print(itemData);
  701. },
  702. resetItemCounts() {
  703. for(let i = 0; i < GameProtocol.MAX_COL_NUM; ++i) {
  704. for(let j = 0; j < this.maxRolItemlLen; ++j) {
  705. this.elementJS[i][j].resetCount();
  706. }
  707. this.rollBG[i].active = true;
  708. }
  709. let showIcon = -1;
  710. if(this._hasSpecial) {
  711. showIcon = GameProtocol.LIGHT_ICON;
  712. }else{
  713. this.numAni.node.active = false;
  714. }
  715. this.resetAllLines();
  716. for(let i = 0; i < GameProtocol.MAX_COL_NUM; ++i) {
  717. for(let j = 0; j < GameProtocol.MAX_ROW_NUM; ++j) {
  718. this.lightJS[i][j].resetShow();
  719. this.lightNode[i][j].active = this.lightJS[i][j].getValue() == showIcon;
  720. this.lightJS[i][j].resetCashShow();
  721. }
  722. }
  723. },
  724. resetItemsShow() {
  725. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  726. for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
  727. this.lightJS[i][j].showNotPrizes();
  728. }
  729. }
  730. },
  731. analyzeLinesData() {
  732. this._allTimers = 0;
  733. for(let i = 0; i < this._lineCount; ++i) {
  734. let lineID = this._lineID[i];
  735. let lineArr = this.linesArr[lineID];
  736. this._allTimers += this._lineTimes[i];
  737. for(let j = 0; j < this._lineSize[i]; ++j) {
  738. let idx = lineArr[j];
  739. let x = idx % 10;
  740. let y = Math.floor(idx/10);
  741. this.elementJS[x][y+16].addCount();
  742. }
  743. }
  744. },
  745. doOthersWithResultData() {
  746. //设置
  747. let data = this._rollResultData.m_desk_data;
  748. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  749. for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
  750. if(this.lightNode[i][j].active == false) {
  751. this.lightJS[i][j].setValue(data[j][i], this.getItemSpineData(data[j][i]), this.isSpecialIcon(data[j][i]));
  752. this.lightJS[i][j].setCount(this.elementJS[i][j+16].getCount());
  753. }
  754. }
  755. }
  756. },
  757. playEffect(effName, needStop = false) {
  758. ScenceManager.Instance().getGameComponent().playEffect(effName, needStop);
  759. },
  760. update (dt) {
  761. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  762. let yy = this.rollBG[i].y;
  763. for(let j = 0; j < this.maxRolItemlLen; ++j) {
  764. let dy = this.elementNode[i][j].y + yy;
  765. this.elementNode[i][j].active = (dy > -3*this.sizec) && (dy < 3*this.sizec);
  766. }
  767. }
  768. if(this.delayShowNextTitleTime <= 0) {
  769. this.nowTitleIdx++;
  770. this.upTitleAni();
  771. }else{
  772. this.delayShowNextTitleTime-=dt;
  773. }
  774. },
  775. });