FruitRollPanel.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. var RollPanel = require("LBRollPanel");
  2. var Global = require("Global");
  3. var UIHelper = require("UIHelper");
  4. var BaseDefine = require("BaseDefine");
  5. var GameProtocol = require("FruitGameProtocol");
  6. import ScenceManager from 'HNScenceManager'
  7. const arr_posX = [-392, -198, 2, 199, 396];
  8. cc.Class({
  9. extends: RollPanel,
  10. editor: {
  11. menu: 'Game/Fruit/RollPanel'
  12. },
  13. properties: {
  14. aniNode: cc.Node,
  15. itemLayer: cc.Node,
  16. endLayer: cc.Node,
  17. fraLayer: cc.Node,
  18. kuangClone: cc.Node,
  19. },
  20. // LIFE-CYCLE CALLBACKS:
  21. initOthers () {
  22. this.endNode = [];
  23. this.endNodeJS = [];
  24. this.kuangArrs = [];
  25. this.endLayer.removeAllChildren();
  26. this.fraLayer.removeAllChildren();
  27. for(let i = 0; i < this.MAX_ROW_NUM; ++i) {
  28. this.endNode[i] = [];
  29. this.endNodeJS[i] = [];
  30. this.kuangArrs[i] = [];
  31. for(let j = 0; j < this.MAX_COL_NUM; ++j) {
  32. let item = cc.instantiate(this.itemClone);
  33. item.x = arr_posX[j];
  34. item.y = (1-i)*(this.sizec);
  35. item.parent = this.endLayer;
  36. item.active = false;
  37. this.endNode[i][j] = item;
  38. this.endNodeJS[i][j] = this.endNode[i][j].getComponent("LBItem");
  39. this.endNodeJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  40. let kuang = cc.instantiate(this.kuangClone);
  41. kuang.x = arr_posX[j];
  42. kuang.y = (1-i)*(this.sizec);
  43. kuang.parent = this.fraLayer;
  44. kuang.active = false;
  45. this.kuangArrs[i][j] = kuang;
  46. }
  47. }
  48. this.endLayer.active = false;
  49. this.fraLayer.active = false;
  50. },
  51. getRandomValue() {
  52. return Math.floor(Math.random()*100)%8;
  53. },
  54. startRollActions() {
  55. this.itemLayer.active = true;
  56. this.endLayer.active = false;
  57. this.fraLayer.active = false;
  58. this._super();
  59. },
  60. openPrizes(justEnd, bQuick) {
  61. if(this.bGameEnd == true) {
  62. return;
  63. }
  64. let endTime = new Date().getTime();
  65. let leftTime = this._startRollTime - endTime + 1000;
  66. this.delayTime = 0.2;
  67. if(bQuick) {
  68. leftTime -= 500;
  69. }
  70. if(leftTime < 0 || justEnd) {
  71. leftTime = 0;
  72. }
  73. if(justEnd) {
  74. this.delayTime = 0;
  75. }
  76. this.node.stopAllActions();
  77. this.bQuick = bQuick;
  78. this.FreeCount = 0;
  79. //快速,并且前四排骷髅头总数少于2
  80. if(bQuick || justEnd) {
  81. for(let i = 0;i < this.MAX_COL_NUM; ++i) {
  82. if(this.FreeCount >= 2) {
  83. // SoundFun.playEffect("freeicon");
  84. cc.tween(this.node)
  85. .delay(leftTime/1000+0.2)
  86. .call(()=>{
  87. this.hotRolls(i);
  88. })
  89. .start()
  90. return;
  91. }
  92. cc.tween(this.node)
  93. .delay(leftTime/1000)
  94. .call(()=>{
  95. this.quickEnd(i);
  96. if(i >= 4) {
  97. this.delayShowPrizes(1000);
  98. }
  99. })
  100. .start()
  101. for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
  102. if(this.tempValue[i][j+1] == this.SPECIAL_ICON) {
  103. this.FreeCount++;
  104. }
  105. }
  106. }
  107. // SoundFun.playEffect("normal_stop");
  108. return;
  109. }
  110. cc.tween(this.node)
  111. .delay(leftTime/1000)
  112. .call(()=>{
  113. this.rollEnds(0);
  114. })
  115. .start()
  116. },
  117. setItemColInfo(i, dIdx) {
  118. let bHasFree = false;
  119. for(let j = this.maxRolItemlLen-5; j < this.maxRolItemlLen; ++j) {
  120. this.elementNode[i][j-this.maxRolItemlLen+dIdx-1].active = true;
  121. this.elementNode[i][j].active = true;
  122. this.tempValue[i][j] = this.tempValue[i][j-this.maxRolItemlLen+dIdx-1];
  123. this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  124. if(j > this.maxRolItemlLen-5 && j < this.maxRolItemlLen-1) {
  125. if(this.tempValue[i][j] == this.SPECIAL_ICON) {
  126. bHasFree = true;
  127. }
  128. }
  129. }
  130. this.playEffect("line"+i);
  131. },
  132. quickEnd(i) {
  133. if(i >= this.MAX_COL_NUM) {
  134. return;
  135. }
  136. let rollbg = this.rollBG[i];
  137. rollbg.stopAllActions();
  138. let yy = rollbg.y;
  139. let destIdx = this.maxRolItemlLen - 3 - Math.floor(yy/-this.sizec);
  140. for(let j = destIdx-3; j >= destIdx-6; --j) {
  141. this.tempValue[i][j] = this.tempValue[i][j-destIdx+6];
  142. this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  143. }
  144. let destY = (this.maxRolItemlLen - destIdx+1) * -this.sizec;
  145. let lastTime = (yy - destY + 50)/this.sizec/12;
  146. cc.tween(rollbg)
  147. .to(lastTime, {y: destY-50})
  148. .to(0.1, {y: destY}, {easing: 'sineInOut'})
  149. .call(()=>{
  150. this.setItemColInfo(i, destIdx);
  151. rollbg.y = 0;
  152. })
  153. .start()
  154. },
  155. justEnd(i) {
  156. if(i >= this.MAX_COL_NUM) {
  157. return;
  158. }
  159. let rollbg = this.rollBG[i];
  160. rollbg.stopAllActions();
  161. let yy = rollbg.y;
  162. let destIdx = this.maxRolItemlLen - 3 - Math.floor(yy/-this.sizec);
  163. for(let j = destIdx-3; j >= destIdx-6; --j) {
  164. this.tempValue[i][j] = this.tempValue[i][j-destIdx+6];
  165. this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  166. }
  167. let destY = (this.maxRolItemlLen - destIdx+1) * -this.sizec;
  168. let lastTime = (yy - destY + 50)/this.sizec/12*0.5;
  169. cc.tween(rollbg)
  170. .to(lastTime, {y: destY-50})
  171. .call(()=>{
  172. this.hotRolls(i+1);
  173. })
  174. .to(0.1, {y: destY}, {easing: 'sineInOut'})
  175. .call(()=>{
  176. this.setItemColInfo(i, destIdx);
  177. rollbg.y = 0;
  178. })
  179. .start()
  180. },
  181. hotRolls(i) {
  182. if(i >= this.MAX_COL_NUM) {
  183. this.delayShowPrizes(600);
  184. return;
  185. }
  186. this.playLPEffect("hotroll");
  187. let rollbg = this.rollBG[i];
  188. rollbg.stopAllActions();
  189. this.aniNode.active = true;
  190. this.aniNode.x = arr_posX[i];
  191. let yy = rollbg.y;
  192. let lessY = yy + 12*this.sizec;
  193. let lastTime = lessY/this.sizec/12*0.3;
  194. cc.tween(rollbg)
  195. .to(lastTime, {y: -12*this.sizec})
  196. .sequence(
  197. cc.tween().call(()=>{ rollbg.y = 0, this.resetRollingItemValue(i) }),
  198. cc.tween().to(0.5, {y: -12*this.sizec})
  199. )
  200. .repeatForever()
  201. .start()
  202. cc.tween(this.node)
  203. .delay(2)
  204. .call(()=>{
  205. this.aniNode.active = false;
  206. this.justEnd(i);
  207. })
  208. .start()
  209. },
  210. rollEnds(i) {
  211. if(i == 0) {
  212. ScenceManager.Instance().getGameComponent().onGameEnd();
  213. }
  214. if(this.FreeCount >= 2) {
  215. cc.tween(this.node)
  216. .delay(0.3)
  217. .call(()=>{
  218. this.hotRolls(i);
  219. })
  220. .start()
  221. // this.hotRolls(i);
  222. return;
  223. }
  224. if(i > 4) {
  225. this.delayShowPrizes(600);
  226. return;
  227. }
  228. //先统计骷髅头数量
  229. for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
  230. if(this.tempValue[i][j+1] == this.SPECIAL_ICON) {
  231. this.FreeCount++;
  232. }
  233. }
  234. let rollbg = this.rollBG[i];
  235. rollbg.stopAllActions();
  236. let yy = rollbg.y;
  237. let destIdx = this.maxRolItemlLen - 3 - Math.floor(yy/-this.sizec);
  238. // Global.print("i"+i+" "+destIdx)
  239. for(let j = destIdx-3; j >= destIdx-6; --j) {
  240. this.tempValue[i][j] = this.tempValue[i][j-destIdx+6];
  241. this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  242. }
  243. let destY = (this.maxRolItemlLen - destIdx+1) * -this.sizec;
  244. let lastTime = (yy - destY + 50)/this.sizec/12;
  245. if(this.bQuick) {
  246. cc.tween(rollbg)
  247. .call(()=>{
  248. this.rollEnds(i+1);
  249. })
  250. .to(lastTime, {y: destY-50})
  251. .to(0.1, {y: destY}, {easing: 'sineInOut'})
  252. .call(()=>{
  253. this.setItemColInfo(i, destIdx);
  254. rollbg.y = 0;
  255. })
  256. .start()
  257. return;
  258. }
  259. cc.tween(rollbg)
  260. .to(lastTime, {y: destY-50})
  261. .call(()=>{
  262. this.rollEnds(i+1);
  263. })
  264. .to(0.1, {y: destY}, {easing: 'sineInOut'})
  265. // .delay(this.delayTime)
  266. .call(()=>{
  267. this.setItemColInfo(i, destIdx);
  268. rollbg.y = 0;
  269. // rollbg.y = -16*140;
  270. // this.rollEnds(i+1);
  271. })
  272. .start()
  273. },
  274. delayShowPrizes(delayTime) {
  275. cc.tween(this.node)
  276. .delay(delayTime/1000)
  277. .call(()=>{
  278. this.beforeShowPrize();
  279. })
  280. .delay(0.3)
  281. .call(()=>{
  282. this.bGameEnd = true;
  283. ScenceManager.Instance().getGameComponent().showGameWinScore();
  284. // if(this._lineCount > 0)
  285. // SoundFun.playEffect("line");
  286. this.showPrizes();
  287. })
  288. .delay(0.3)
  289. .call(()=>{
  290. // ScenceManager.Instance().getGameComponent().resetAllBtn();
  291. ScenceManager.Instance().getGameComponent().showGameEnd();
  292. })
  293. .start()
  294. },
  295. beforeShowPrize() {
  296. this.endLayer.active = true;
  297. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  298. for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
  299. // this.endNodeJS[j][i].showLightAni();
  300. this.endNodeJS[j][i].node.active = true;
  301. this.kuangArrs[j][i].active = false;
  302. }
  303. }
  304. this.fraLayer.active = true;
  305. this.itemLayer.active = false;
  306. },
  307. showPrizes() {
  308. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  309. for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
  310. this.kuangArrs[j][i].active = this.endNodeJS[j][i].getCount() > 0;
  311. this.endNodeJS[j][i].showLightAniNoScale();
  312. if(this._hasSpecial) {
  313. this.endNodeJS[j][i].showSpecialAni();
  314. }
  315. // Global.print("active value::"+this.endNodeJS[j][i].node.active)
  316. }
  317. }
  318. cc.tween(this.node)
  319. .delay(2.5)
  320. .call(()=>{
  321. this.resetItemsShow();
  322. })
  323. .delay(0.5)
  324. .call(()=>{
  325. this.showLines(0);
  326. })
  327. .start();
  328. },
  329. showLines(iIndex) {
  330. if(iIndex >= this._lineCount) {
  331. this.showPrizes();
  332. return;
  333. }
  334. let lineID = this._lineID[iIndex];
  335. let lineArr = this.linesArr[lineID];
  336. let count = this._lineSize[iIndex];
  337. let hWild = false;
  338. for(let k = 0; k < count; ++k) {
  339. let idx = lineArr[k];
  340. let i = idx % 10;
  341. let j = Math.floor(idx/10);
  342. this.kuangArrs[j][i].active = true;
  343. this.endNodeJS[j][i].showLightAni();
  344. if(this.endNodeJS[j][i]._value == GameProtocol.WILD_ICON) {
  345. hWild = true;
  346. }
  347. }
  348. if(hWild) {
  349. this.playEffect("wild");
  350. }
  351. cc.tween(this.node)
  352. .delay(2)
  353. .call(()=>{
  354. this.resetItemsShow();
  355. })
  356. .delay(0.5)
  357. .call(()=>{
  358. this.showLines(iIndex+1);
  359. })
  360. .start();
  361. },
  362. // setItemDatas(itemData) {
  363. // this.allFreeCount = 0;
  364. // for(let i = 0; i < GameProtocol.MAX_ROW_NUM; ++i) {
  365. // for(let j = 0;j < GameProtocol.MAX_COL_NUM; ++j) {
  366. // this.tempValue[j][i+1] = itemData[i][j];
  367. // // Global.print("i:"+i+" j:"+j+" v:"+this.tempValue[j][i+1]+" cc:"+itemData[i][j]);
  368. // this.elementJS[j][i+1].setValue(itemData[i][j], this.itemSpines[this.tempValue[i][j]]);
  369. // if(itemData[i][j] == GameProtocol.FREE_ICON && j < GameProtocol.MAX_COL_NUM-1) {
  370. // this.allFreeCount++;
  371. // }
  372. // }
  373. // }
  374. // Global.print(this.tempValue);
  375. // Global.print(itemData);
  376. // },
  377. // resetItemCounts() {
  378. // for(let i = 0; i < GameProtocol.MAX_COL_NUM; ++i) {
  379. // for(let j = 0; j < this.maxRolItemlLen; ++j) {
  380. // this.elementJS[i][j].resetCount();
  381. // }
  382. // }
  383. // },
  384. resetItemsShow() {
  385. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  386. for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
  387. this.kuangArrs[j][i].active = false;
  388. this.endNodeJS[j][i].showNormal();
  389. }
  390. }
  391. },
  392. doOthersWithResultData() {
  393. //设置
  394. let data = this._rollResultData.m_desk_data;
  395. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  396. for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
  397. this.endNodeJS[j][i].setValue(data[j][i], this.itemSpines[data[j][i]], this.isSpecialIcon(data[j][i]));
  398. this.endNodeJS[j][i].setCount(this.elementJS[i][j+17].getCount());
  399. // Global.print("j:"+j+" i:"+i+" count:"+this.elementJS[i][j+17].getCount())
  400. }
  401. }
  402. // this.endLayer.active = true;
  403. // this.fraLayer.active = true;
  404. },
  405. // analyzeLinesData() {
  406. // this._allTimers = 0;
  407. // for(let i = 0; i < this._lineCount; ++i) {
  408. // let lineID = this._lineID[i];
  409. // let lineArr = linesArr[lineID];
  410. // this._allTimers += this._lineTimes[i];
  411. // for(let j = 0; j < this._lineSize[i]; ++j) {
  412. // let idx = lineArr[j];
  413. // let x = idx % 10;
  414. // let y = Math.floor(idx/10);
  415. // this.elementJS[x][y+17].addCount();
  416. // }
  417. // }
  418. // },
  419. });