LBRollPanel.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. var Global = require("Global");
  2. import ScenceManager from 'HNScenceManager'
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. rollBG: [cc.Node],
  7. itemClone: cc.Prefab,
  8. // endLayer: cc.Node,
  9. // getLayer: cc.Node,
  10. // kuangClone: cc.Node,
  11. itemSpines: [sp.SkeletonData],
  12. itemSprites: [cc.SpriteFrame],
  13. LG_PATH_SC: "",
  14. LP_PATH_SC: "LB-Public/",
  15. bGameEnd: false,
  16. maxRolItemlLen: 21,
  17. MAX_COL_NUM: 5,
  18. MAX_ROW_NUM: 3,
  19. SPECIAL_ICON: 12,
  20. sizec: 150,
  21. },
  22. // LIFE-CYCLE CALLBACKS:
  23. onLoad () {
  24. //this.linesArr = [[0,1,2,3,4],[10,11,12,13,14],[20,21,22,23,24],[0,11,22,13,4],[20,11,2,13,24],[0,1,12,23,24],[20,21,12,3,4],[10,21,2,23,14],[10,1,22,3,14],[0,11,2,13,4],[20,11,22,13,24],[10,1,12,23,14],[10,21,12,3,14],[0,11,12,13,4],[20,11,12,13,24],[10,1,2,3,14],[10,21,22,23,14],[0,21,22,23,4],[20,1,2,3,24],[0,1,22,3,4],[20,21,2,23,24],[10,11,2,13,14],[10,11,22,13,14],[0,21,2,23,4],[20,1,22,3,24],[20,1,12,23,4],[0,21,12,3,24],[0,21,12,23,4],[20,1,12,3,24],[20,11,2,3,14],[0,11,22,23,14],[0,11,2,13,24],[20,11,22,13,4],[10,1,22,13,24],[10,21,2,13,4],[20,21,2,3,4],[0,1,22,23,24],[0,1,12,13,24],[20,21,12,13,4],[0,11,12,23,24],[20,11,12,3,4],[20,11,2,3,4],[0,11,22,23,24],[10,1,2,13,14],[10,21,22,13,14],[10,11,2,3,14],[10,11,22,23,14],[20,11,2,3,24],[0,11,22,23,4],[0,11,12,13,24]];
  25. this._rollResultData = {};
  26. this._lineCount = 0;
  27. this._lineSize = [];
  28. this._lineID = [];
  29. this._lineIcon = [];
  30. this._lineTimes = [];
  31. this.itemData = [];
  32. this.elementNode = [];
  33. this.elementJS = [];
  34. this.tempValue = [];
  35. // this.kuangArrs = [];
  36. this._startRollTime = 0;
  37. this.initLists();
  38. this.initOthers();
  39. },
  40. initLists() {
  41. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  42. this.elementNode[i] = [];
  43. this.elementJS[i] = [];
  44. this.itemData[i] = [];
  45. this.tempValue[i] = [];
  46. this.rollBG[i].active = true;
  47. for(let j = 0; j < this.maxRolItemlLen-5; ++j) {
  48. this.tempValue[i][j] = this.getRandomValue();
  49. }
  50. for(let j = this.maxRolItemlLen-5; j < this.maxRolItemlLen; ++j) {
  51. // this.tempValue[i][j] = this.tempValue[i][j-12];
  52. this.tempValue[i][j] = this.getSpecialRandomValue();
  53. }
  54. for(let j = 0; j < this.maxRolItemlLen; ++j) {
  55. let item = cc.instantiate(this.itemClone);
  56. item.y = (this.maxRolItemlLen - 3 - j)*(this.sizec);
  57. item.parent = this.rollBG[i];
  58. item.active = true;
  59. this.elementNode[i][j] = item;
  60. this.elementJS[i][j] = this.elementNode[i][j].getComponent("LBItem");
  61. this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  62. }
  63. }
  64. },
  65. initOthers() {
  66. },
  67. isSpecialIcon(val) {
  68. return val == this.SPECIAL_ICON;
  69. },
  70. getSpecialRandomValue(){
  71. if(!this.sRand)
  72. this.sRand = Math.floor(Math.random()*100)%10;
  73. return this.sRand;
  74. },
  75. getRandomValue() {
  76. return Math.floor(Math.random()*100)%10;
  77. },
  78. resetRollingItemValue(i) {
  79. for(let j = 9; j < this.maxRolItemlLen-5; ++j) {
  80. this.tempValue[i][j] = this.getRandomValue();
  81. this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  82. }
  83. for(let j = this.maxRolItemlLen-5; j < this.maxRolItemlLen; ++j) {
  84. this.elementNode[i][j].active = true;
  85. }
  86. },
  87. resetItemCounts() {
  88. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  89. for(let j = 0; j < this.maxRolItemlLen; ++j) {
  90. this.elementJS[i][j].resetCount();
  91. }
  92. }
  93. },
  94. resetItemsShow() {
  95. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  96. for(let j = 0; j < this.maxRolItemlLen; ++j) {
  97. this.elementJS[i][j].showNormal();
  98. }
  99. }
  100. },
  101. setItemColInfo(i, dIdx) {
  102. for(let j = this.maxRolItemlLen-5; j < this.maxRolItemlLen; ++j) {
  103. this.elementNode[i][j-this.maxRolItemlLen+dIdx-1].active = true;
  104. this.elementNode[i][j].active = true;
  105. this.tempValue[i][j] = this.tempValue[i][j-this.maxRolItemlLen+dIdx-1];
  106. this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  107. }
  108. },
  109. startRollActions() {
  110. this.bGameEnd = false;
  111. this.node.stopAllActions();
  112. this.resetItemCounts();
  113. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  114. let rollbg = this.rollBG[i];
  115. rollbg.active = true;
  116. rollbg.y = 0;
  117. rollbg.stopAllActions();
  118. /*
  119. for(let j = 4; j < 9; ++j) {
  120. this.tempValue[i][j] = this.tempValue[i][j+12];
  121. this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  122. }
  123. */
  124. cc.tween(rollbg)
  125. .sequence(
  126. cc.tween().to(0.4, {y: -6*this.sizec}),
  127. cc.tween().call(()=>{
  128. for(let j = this.maxRolItemlLen-5; j < this.maxRolItemlLen; ++j) {
  129. this.tempValue[i][j] = this.tempValue[i][j-12];
  130. // this.tempValue[i][j] = this.getSpecialRandomValue();
  131. this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  132. }
  133. }),
  134. cc.tween().to(0.4, {y: -12*this.sizec}),
  135. cc.tween().call(()=>{ rollbg.y = 0, this.resetRollingItemValue(i) })
  136. )
  137. .repeatForever()
  138. .start()
  139. }
  140. this._startRollTime = new Date().getTime();
  141. },
  142. openPrizes(justEnd, bQuick) {
  143. if(this.bGameEnd == true) {
  144. return;
  145. }
  146. let endTime = new Date().getTime();
  147. let leftTime = this._startRollTime - endTime + 1000;
  148. this.delayTime = 0.2;
  149. if(bQuick) {
  150. leftTime -= 500;
  151. }
  152. if(leftTime < 0 || justEnd) {
  153. leftTime = 0;
  154. }
  155. if(justEnd) {
  156. this.delayTime = 0;
  157. }
  158. this.node.stopAllActions();
  159. this.bQuick = bQuick;
  160. if(bQuick || justEnd) {
  161. for(let i = 0;i < this.MAX_COL_NUM; ++i) {
  162. cc.tween(this.node)
  163. .delay(leftTime/1000)
  164. .call(()=>{
  165. this.rollEnds(i);
  166. if(i >= this.MAX_COL_NUM-1) {
  167. this.delayShowPrizes(1000);
  168. }
  169. })
  170. .start()
  171. }
  172. return;
  173. }
  174. cc.tween(this.node)
  175. .delay(leftTime/1000)
  176. .call(()=>{
  177. this.rollEnds(0);
  178. })
  179. .start()
  180. },
  181. rollEnds(i) {
  182. if(i == 0) {
  183. // ScenceManager.Instance().getGameComponent().onGameEnd();
  184. }
  185. if(i > 4) {
  186. this.delayShowPrizes(600);
  187. return;
  188. }
  189. let rollbg = this.rollBG[i];
  190. rollbg.stopAllActions();
  191. let yy = rollbg.y;
  192. let destIdx = this.maxRolItemlLen - 3 - Math.floor(yy/-this.sizec);
  193. for(let j = destIdx-3; j >= destIdx-6; --j) {
  194. this.tempValue[i][j] = this.tempValue[i][j-destIdx+6];
  195. this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  196. }
  197. let destY = (this.maxRolItemlLen - destIdx+1) * -this.sizec;
  198. let lastTime = (yy - destY + 50)/this.sizec/12;
  199. if(this.bQuick) {
  200. cc.tween(rollbg)
  201. .call(()=>{
  202. this.rollEnds(i+1);
  203. })
  204. .to(lastTime, {y: destY-50})
  205. .to(0.1, {y: destY}, {easing: 'sineInOut'})
  206. .call(()=>{
  207. this.setItemColInfo(i, destIdx);
  208. rollbg.y = 0;
  209. })
  210. .start()
  211. return;
  212. }
  213. cc.tween(rollbg)
  214. .to(lastTime, {y: destY-50})
  215. .call(()=>{
  216. this.rollEnds(i+1);
  217. })
  218. .to(0.1, {y: destY}, {easing: 'sineInOut'})
  219. .call(()=>{
  220. this.setItemColInfo(i, destIdx);
  221. rollbg.y = 0;
  222. })
  223. .start()
  224. },
  225. delayShowPrizes(delayTime) {
  226. cc.tween(this.node)
  227. .delay(delayTime/1000)
  228. .call(()=>{
  229. this.bGameEnd = true;
  230. // ScenceManager.Instance().getGameComponent().showGameWinScore();
  231. this.showPrizes();
  232. })
  233. .delay(0.6)
  234. .call(()=>{
  235. // ScenceManager.Instance().getGameComponent().showGameEnd();
  236. })
  237. .start()
  238. },
  239. showPrizes() {
  240. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  241. for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
  242. this.elementJS[i][j+17].showLightAniNoScale();
  243. if(this._hasSpecial) {
  244. this.elementJS[i][j+17].showSpecialAni();
  245. }
  246. }
  247. }
  248. cc.tween(this.node)
  249. .delay(2.5)
  250. .call(()=>{
  251. this.resetItemsShow();
  252. })
  253. .delay(0.5)
  254. .call(()=>{
  255. this.showLines(0);
  256. })
  257. .start();
  258. },
  259. showLines(iIndex) {
  260. if(iIndex >= this._lineCount) {
  261. this.showPrizes();
  262. return;
  263. }
  264. let lineID = this._lineID[iIndex];
  265. let lineArr = this.linesArr[lineID];
  266. let count = this._lineSize[iIndex];
  267. for(let k = 0; k < count; ++k) {
  268. let idx = lineArr[k];
  269. let i = idx % 10;
  270. let j = Math.floor(idx/10);
  271. this.elementJS[i][j+17].showLightAni();
  272. }
  273. cc.tween(this.node)
  274. .delay(2)
  275. .call(()=>{
  276. this.resetItemsShow();
  277. })
  278. .delay(0.5)
  279. .call(()=>{
  280. this.showLines(iIndex+1);
  281. })
  282. .start();
  283. },
  284. setRollDatas(msg) {
  285. this._rollResultData = msg;
  286. this.setItemDatas(msg.m_desk_data);
  287. this._hasSpecial = msg.m_kongming == 1;
  288. //线信息
  289. this._lineCount = msg.m_line_count;
  290. this._lineID = msg.m_line_id;
  291. this._lineSize = msg.m_line_size;
  292. this._lineIcon = msg.m_line_icon;
  293. this._lineTimes = msg.m_line_times;
  294. this.analyzeLinesData();
  295. this.doOthersWithResultData();
  296. },
  297. setItemDatas(itemData) {
  298. for(let i = 0; i < this.MAX_ROW_NUM; ++i) {
  299. for(let j = 0;j < this.MAX_COL_NUM; ++j) {
  300. this.tempValue[j][i+1] = itemData[i][j];
  301. this.elementJS[j][i+1].setValue(itemData[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
  302. }
  303. }
  304. Global.print(this.tempValue);
  305. Global.print(itemData);
  306. },
  307. analyzeLinesData() {
  308. this._allTimers = 0;
  309. for(let i = 0; i < this._lineCount; ++i) {
  310. let lineID = this._lineID[i];
  311. let lineArr = this.linesArr[lineID];
  312. this._allTimers += this._lineTimes[i];
  313. for(let j = 0; j < this._lineSize[i]; ++j) {
  314. let idx = lineArr[j];
  315. let x = idx % 10;
  316. let y = Math.floor(idx/10);
  317. // console.log('x,y: ', x,y, lineArr);
  318. this.elementJS[x][y+17].addCount();
  319. }
  320. }
  321. },
  322. doOthersWithResultData() {
  323. },
  324. //播放音效
  325. playEffect(effName, needStop = false) {
  326. ScenceManager.Instance().getGameComponent().playEffect(effName, needStop);
  327. },
  328. //播放通用音效
  329. playLPEffect(effName, needStop = false) {
  330. ScenceManager.Instance().getGameComponent().playLPEffect(effName, needStop);
  331. },
  332. update (dt) {
  333. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  334. let yy = this.rollBG[i].y;
  335. for(let j = 0; j < this.maxRolItemlLen; ++j) {
  336. let dy = this.elementNode[i][j].y + yy;
  337. this.elementNode[i][j].active = (dy > -2*this.sizec) && (dy < 2*this.sizec);
  338. }
  339. }
  340. },
  341. });