OlympusRollPanel.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. // var RollPanel = require("LBRollPanel");
  2. var Global = require("Global");
  3. var UIHelper = require("UIHelper");
  4. var BaseDefine = require("BaseDefine");
  5. var GameProtocol = require("OlympusGameProtocol");
  6. import ScenceManager from 'HNScenceManager'
  7. const topOffY = 294;
  8. cc.Class({
  9. extends: cc.Component,
  10. editor: {
  11. menu: 'Game/Olympus/RollPanel'
  12. },
  13. properties: {
  14. rollBG: [cc.Node],
  15. itemClone: cc.Prefab,
  16. thorNode: cc.Node,
  17. itemSpines: [sp.SkeletonData],
  18. LG_PATH_SC: "",
  19. LP_PATH_SC: "LB-Public/",
  20. bGameEnd: false,
  21. maxRolItemlLen: 21,
  22. MAX_COL_NUM: 6,
  23. MAX_ROW_NUM: 5,
  24. SPECIAL_ICON: 12,
  25. sizec: 120,
  26. aniNode: cc.Node,
  27. topBGKuang: cc.Node,
  28. coinLayer: cc.Node,
  29. coinClone: cc.Node,
  30. qiuClone: cc.Node,
  31. },
  32. // LIFE-CYCLE CALLBACKS:
  33. onLoad () {
  34. this._rollResultData = {};
  35. this.itemData = [];
  36. this.tempValue = [];
  37. this.elementNode = [];
  38. this.elementJS = [];
  39. for(let i = 0; i < GameProtocol.MAX_ROW_NUM; ++i){
  40. this.elementNode[i] = [];
  41. this.elementJS[i] = [];
  42. this.tempValue[i] = [];
  43. for(let j = 0; j < GameProtocol.MAX_COL_NUM; ++j){
  44. this.tempValue[i][j] = this.getSpecialRandomValue();
  45. let item = cc.instantiate(this.itemClone);
  46. item.x = 0;
  47. item.y = (2-i)*(this.sizec);
  48. item.parent = this.rollBG[j];
  49. item.active = true;
  50. this.elementNode[i][j] = item;
  51. this.elementJS[i][j] = this.elementNode[i][j].getComponent("OlympusItem");
  52. this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], 0);
  53. }
  54. }
  55. //538 638
  56. this.thorNode.x = 538 + (cc.winSize.width - 1334)/2.9;
  57. this.thorDB = this.thorNode.getComponent(dragonBones.ArmatureDisplay);
  58. },
  59. showThorAni() {
  60. this.playEffect('thor')
  61. this.playEffect('thors')
  62. this.thorDB.playAnimation('a2', 1);
  63. this.thorDB.addEventListener(dragonBones.EventObject.COMPLETE, this.onAnimationPlayComplete, this);
  64. },
  65. onAnimationPlayComplete(event) {
  66. if (event.type === dragonBones.EventObject.COMPLETE) {
  67. this.thorDB.removeEventListener(dragonBones.EventObject.COMPLETE, this.onAnimationPlayComplete, this);
  68. this.thorDB.playAnimation('a1', 0);
  69. }
  70. },
  71. forceStop() {
  72. for(let i = 0; i < GameProtocol.MAX_COL_NUM; ++i) {
  73. let rollbg = this.rollBG[i];
  74. rollbg.active = true;
  75. rollbg.stopAllActions();
  76. rollbg.y = 0;
  77. }
  78. },
  79. isSpecialIcon(val) {
  80. return val == GameProtocol.SPECIAL_ICON;
  81. },
  82. getSpecialRandomValue(){
  83. if(!this.sRand)
  84. this.sRand = Math.floor(Math.random()*100);
  85. return this.sRand % 10;
  86. },
  87. getRandomValue() {
  88. let rand = Math.floor(Math.random()*100);
  89. return rand % 10;
  90. },
  91. startRollActions() {
  92. // this.playEffect("roll");
  93. this.topBGKuang.active = true;
  94. this.bGameEnd = false;
  95. this._rollResultData = null;
  96. this.currentShowIdx = -1;
  97. this.endIdxCnt = 0;
  98. for(let i = 0; i < this.MAX_ROW_NUM; ++i) {
  99. for(let j = 0; j < this.MAX_COL_NUM; ++j) {
  100. this.elementNode[i][j].stopAllActions();
  101. cc.tween(this.elementNode[i][j])
  102. .delay(0.03*j)
  103. .to(0.2, {y: this.elementNode[i][j].y - 490})
  104. .call(()=>{
  105. this.elementNode[i][j].y = (2-i)*(this.sizec)+490;
  106. this.elementJS[i][j].reset();
  107. // this.addEndCnt();
  108. if(i == this.MAX_ROW_NUM-1 && j == this.MAX_COL_NUM-1) {
  109. this.endIdxCnt = GameProtocol.CELL_COUNT;
  110. this._delayEndTime = 0.2;
  111. }
  112. })
  113. .start()
  114. }
  115. }
  116. // this._delayEndTime = 0.7;
  117. this.tempSortIdx = [[0,1,2,3,4],[0,1,2,3,4],[0,1,2,3,4],[0,1,2,3,4],[0,1,2,3,4],[0,1,2,3,4]];
  118. this.needNewIdx = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29];
  119. this.needAddItem = [];
  120. // this.showThorAni();
  121. },
  122. openPrizes(idx) {
  123. if(this.bGameEnd == true || this._rollResultData == null) {
  124. return;
  125. }
  126. this.endIdxCnt = 0;
  127. this.currentShowIdx = idx;
  128. this.topBGKuang.active = true;
  129. let desData = this._rollResultData.m_result_data[idx];
  130. // Global.print(desData)
  131. if(!desData) return;
  132. let items = this.needAddItem;
  133. if(idx == 0) {
  134. items = desData.m_desk_data;
  135. }
  136. let hasQiu = false;
  137. let qiuIdx = [];
  138. for(let i = 0; i < this.needNewIdx.length; ++i) {
  139. let idx = this.needNewIdx[i];
  140. let x = Math.floor(idx / 6);
  141. let y = idx % 6;
  142. // Global.print(`i:${x} j:${y}`);
  143. let multi = 0;
  144. if(items[i] == GameProtocol.SPECIAL_ICON) {
  145. hasQiu = true;
  146. multi = this._rollAddMulti[this.curAddMultiIdx++];
  147. // qiuIdx
  148. }
  149. this.elementJS[x][y].setValue(items[i], this.itemSpines[items[i]], multi);
  150. }
  151. let delayT = 0;
  152. if(hasQiu) {
  153. delayT = 0.3;
  154. this.showThorAni();
  155. }
  156. // let ddY = 0;
  157. if(idx == 0) {
  158. this.playEffect('luodi');
  159. // ddY = 30;
  160. }
  161. for(let i = this.MAX_ROW_NUM-1; i >= 0; --i) {
  162. for(let j = 0; j < this.MAX_COL_NUM; ++j) {
  163. let k = this.tempSortIdx[j][i];
  164. let dNode = this.elementNode[k][j];
  165. let dY = (2-i)*(this.sizec);
  166. // Global.print(`${i} : ${k} : ${j} : ${items[j][k]} : ${dY} : ${dNode.y}`)
  167. dNode.stopAllActions();
  168. this.elementJS[k][j].showJackpot(delayT, dY);
  169. let ddY = 0;
  170. let leiFunc = ()=>{};
  171. if(dNode.y - dY > this.sizec/2) {
  172. if(this.elementJS[k][j].getItemValue() == GameProtocol.SPECIAL_ICON && !this.elementJS[k][j].playedAni) {
  173. // let node = cc.instantiate(this.qiuClone);
  174. // node.parent = this.coinLayer;
  175. // node.position = cc.v2(this.rollBG[j].x, dY);
  176. // node.active = true;
  177. // let iindx = this.elementJS[k][j].getMultiIdx();
  178. // let ani = node.getComponent(sp.Skeleton);
  179. // ani.setAnimation(0, 'a'+iindx, false);
  180. leiFunc = ()=>{
  181. let node = cc.instantiate(this.qiuClone);
  182. node.parent = this.coinLayer;
  183. node.position = cc.v2(this.rollBG[j].x, dY);
  184. node.active = true;
  185. let iindx = this.elementJS[k][j].getMultiIdx();
  186. let ani = node.getComponent(sp.Skeleton);
  187. ani.setAnimation(0, 'a'+iindx, false);
  188. ani.setCompleteListener(()=>{
  189. ani.setCompleteListener(null);
  190. node.destroy();
  191. })
  192. };
  193. }
  194. ddY = 20;
  195. }
  196. cc.tween(dNode)
  197. .delay(delayT+j*0.03)
  198. .call(()=>{
  199. leiFunc();
  200. })
  201. .to(0.1, {y: dY-ddY}, {easing: 'quartInOut'})
  202. .to(0.05, {y: dY})
  203. .start()
  204. }
  205. }
  206. if(desData.m_win_score > 0 || desData.m_deposit_lotttery > 0) {
  207. // let itemMap = [[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1]];
  208. let desItemPos = [];
  209. let tempNode = [];
  210. let hasLei = false;
  211. for(let i = 0; i < desData.m_item_count.length; ++i) {
  212. if(desData.m_item_count[i] > 0) {
  213. if(desData.m_item_id[i] == GameProtocol.WILD_ICON) {
  214. hasLei = true;
  215. }
  216. desItemPos[i] = [];
  217. let minDis = 100000000;
  218. let dPos = cc.v2(0,0);
  219. let score = 'R$+'+ (Math.floor(this._rollResultData.m_chip_size*desData.m_item_times[i] / 100) / 100).toFixed(2);
  220. for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
  221. for(let k = 0; k < this.MAX_COL_NUM; ++k) {
  222. // let kk = this.tempSortIdx[k][j];
  223. if(this.elementJS[j][k].checkSame(desData.m_item_id[i])){
  224. // let dyy = Math.floor(2 - (this.elementJS[j][k].getEndY() / this.sizec));
  225. // Global.print(`i:${j} j:${dyy} y:${this.elementJS[j][k].getEndY()}`);
  226. // itemMap[j][k] = desData.m_item_id[i];
  227. let ids = this.disToCenter(this.rollBG[k].x, this.elementJS[j][k].getEndY());
  228. desItemPos[i].push({x: this.rollBG[k].x, y: this.elementJS[j][k].getEndY(), dis: ids, score:score});
  229. if(ids < minDis) {
  230. minDis = ids;
  231. dPos = cc.v2(this.rollBG[k].x, this.elementJS[j][k].getEndY());
  232. }
  233. }
  234. }
  235. }
  236. desItemPos[i].sort((A, B)=> {
  237. return A.dis - B.dis;
  238. });
  239. tempNode.push({x:dPos.x, y:dPos.y, score:score});
  240. // let node = cc.instantiate(this.coinClone);
  241. // node.parent = this.coinLayer;
  242. // node.position = dPos;
  243. // // Global.print(node.position)
  244. // node.getComponent(cc.Label).string = '$+'+ (Math.floor(this._rollResultData.m_chip_size*desData.m_item_times[i] / 100) / 100).toFixed(2);
  245. // node.active = false;
  246. }
  247. }
  248. // Global.print(itemMap);
  249. Global.print(desItemPos);
  250. let dddTmp = [];
  251. let okk = false;
  252. for(let i = 0; i < desItemPos[0].length; ++i) {
  253. dddTmp[0] = desItemPos[0][i];
  254. okk = true;
  255. for(let j = 1; j < desItemPos.length; ++j) {
  256. for(let k = 0; k < desItemPos[j].length; ++k) {
  257. // dddTmp[j] = desItemPos[j][k];
  258. let tmpV = desItemPos[j][k];
  259. let nook = false;
  260. for(let kk = 0; kk < j; ++kk) {
  261. if(this.disTwoPoint(tmpV, dddTmp[kk]) < 9600) {
  262. nook = true;
  263. break;
  264. }
  265. }
  266. //距离符合要求
  267. if(!nook) {
  268. dddTmp[j] = tmpV;
  269. break;
  270. }else if(k == desItemPos[j].length-1) { //全都不符合,并且是最后一个点了
  271. okk = false;
  272. break;
  273. }
  274. }
  275. }
  276. if(okk) {break;}
  277. else if(i == desItemPos[0].length-1) {
  278. Global.print("没有找到合适的点位,使用重叠点位")
  279. dddTmp = tempNode;
  280. }
  281. }
  282. Global.print(dddTmp);
  283. for(let i = 0; i < dddTmp.length; ++i) {
  284. let tmp = dddTmp[i];
  285. let node = cc.instantiate(this.coinClone);
  286. node.parent = this.coinLayer;
  287. node.name = 'coin';
  288. node.position = cc.v2(tmp.x, tmp.y);
  289. node.getComponent(cc.Label).string = tmp.score;
  290. node.active = false;
  291. }
  292. let delTime = 2;
  293. if(hasLei) {
  294. delTime = 2.5;
  295. }
  296. cc.tween(this.node)
  297. .delay(0.3+delayT)
  298. .call(()=>{
  299. this.topBGKuang.active = false;
  300. this.showPrizes();
  301. this.showWinLabel();
  302. })
  303. .delay(delTime)
  304. .call(()=>{
  305. ScenceManager.Instance().getGameComponent().addGameWinScore(desData.m_win_score);
  306. this.resetSortIdx(idx);
  307. })
  308. .delay(0.2)
  309. .call(()=>{
  310. if(desData.m_deposit_lotttery > 0) {
  311. ScenceManager.Instance().getGameComponent().showJackpotWin(desData.m_deposit_lotttery);
  312. }else{
  313. this.openPrizes(idx+1);
  314. }
  315. })
  316. .start()
  317. return;
  318. }
  319. cc.tween(this.node)
  320. .delay(0.3)
  321. .call(()=>{
  322. this.topBGKuang.active = false;
  323. this.bGameEnd = true;
  324. this.showPrizes(true);
  325. // ScenceManager.Instance().getGameComponent().showGameWinScore();
  326. // Global.print(Date.now())
  327. })
  328. .delay(0.1)
  329. .call(()=>{
  330. this.showPrizesEnd();
  331. // ScenceManager.Instance().getGameComponent().showGameEnd();
  332. })
  333. .start()
  334. },
  335. disTwoPoint(p1, p2) {
  336. if(p2.y == p1.y) {
  337. if((p1.x-p2.x)*(p1.x-p2.x) == 31329) {
  338. return 6000;
  339. }
  340. }
  341. return (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y);
  342. },
  343. disToCenter(i,j) {
  344. return i*i+j*j//(i-2)*(i-2) + (j-2.5)*(j-2.5);
  345. },
  346. resumeShowPrizes() {
  347. this.openPrizes(this.currentShowIdx+1);
  348. },
  349. resetSortIdx(pidx) {
  350. Global.print(this.elementJS);
  351. let temp = [[0,1,2,3,4],[0,1,2,3,4],[0,1,2,3,4],[0,1,2,3,4],[0,1,2,3,4],[0,1,2,3,4]];
  352. let tmpNew = [];
  353. let tmpNew2 = [];
  354. this.needAddItem = [];
  355. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  356. let idx = this.MAX_ROW_NUM-1;
  357. for(let j = this.MAX_ROW_NUM-1; j >= 0; --j) {
  358. let jdx = this.tempSortIdx[i][j];
  359. if(this.elementJS[jdx][i]._value >= 0) {
  360. temp[i][idx--] = jdx;
  361. }
  362. }
  363. let sY = topOffY;
  364. for(let j = this.MAX_ROW_NUM-1; j >= 0; --j) {
  365. let jdx = this.tempSortIdx[i][j];
  366. if(this.elementJS[jdx][i]._value < 0) {
  367. tmpNew.push(jdx*6+i);
  368. tmpNew2.push(j*6+i);
  369. temp[i][idx--] = jdx;
  370. this.elementNode[jdx][i].y = sY;
  371. sY += this.sizec;
  372. }
  373. }
  374. }
  375. let preData = this._rollResultData.m_result_data[pidx]
  376. let data1 = preData.m_desk_data;
  377. let data2 = this._rollResultData.m_result_data[pidx+1].m_desk_data;
  378. for(let i = 0; i < preData.m_item_count.length; ++i) {
  379. if(preData.m_item_count[i] > 0) {
  380. let iID = preData.m_item_id[i];
  381. for(let j = 0; j < GameProtocol.CELL_COUNT; ++j){
  382. if(data1[j] == iID) {
  383. this.needAddItem.push(data2[j]);
  384. }
  385. }
  386. }
  387. }
  388. this.tempSortIdx = temp;
  389. tmpNew.sort((A, B)=>{
  390. return A-B;
  391. });
  392. this.needNewIdx = tmpNew;
  393. Global.print(this.tempSortIdx);
  394. Global.print(this.needNewIdx);
  395. Global.print(this.needAddItem);
  396. },
  397. testPrint() {
  398. for(let i = 0; i < this.MAX_ROW_NUM; ++i) {
  399. for(let j = 0; j < this.MAX_COL_NUM; ++j) {
  400. Global.print(`${i} : ${j} : ${this.elementJS[i][j]._value}`)
  401. }
  402. }
  403. },
  404. showWinLabel() {
  405. for(let i = 0; i < this.coinLayer.childrenCount; ++i) {
  406. let node = this.coinLayer.children[i];
  407. if(node && node.name == 'coin') {
  408. node.active = true;
  409. node.scale = 0;
  410. node.opacity = 0;
  411. node.stopAllActions();
  412. let dy = node.y + 50;
  413. cc.tween(node)
  414. .to(0.3, {opacity: 255, scale: 1.1})
  415. .to(0.8, {y: dy, scale: 1, opacity: 150})
  416. .call(()=>{
  417. node.active = false;
  418. node.destroy();
  419. })
  420. .start()
  421. }
  422. }
  423. },
  424. showPrizes(bEnd = false) {
  425. let hasRen = false;
  426. let nowVal = -1;
  427. for(let i = 0; i < GameProtocol.MAX_ROW_NUM; ++i) {
  428. for(let j = 0; j < GameProtocol.MAX_COL_NUM; ++j) {
  429. nowVal = this.elementJS[i][j].getItemValue();
  430. if(this.elementJS[i][j].showLightAni()) {
  431. if(nowVal == GameProtocol.WILD_ICON) {
  432. hasRen = true;
  433. }
  434. }
  435. }
  436. }
  437. if(!bEnd) {
  438. if(hasRen) {
  439. this.playEffect('leishen');
  440. }else{
  441. this.playEffect('ending')
  442. }
  443. }
  444. },
  445. showPrizesEnd() {
  446. let delayT = 0.5;
  447. let gameJS = ScenceManager.Instance().getGameComponent();
  448. if(this.curAddMultiIdx > 0 && this._rollResultData.m_lottery_size > 0) {
  449. let idx = 0;
  450. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  451. for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
  452. // ji
  453. if(this.elementJS[j][i].isSpecial()) {
  454. gameJS.playAddScoreMulti(this.elementJS[j][i].getMultiLabelNode(idx), this.elementJS[j][i].getMulti(), idx++);
  455. }else{
  456. this.elementJS[j][i].grayItem();
  457. }
  458. }
  459. }
  460. delayT = 1.2 * idx + 1.5;
  461. }else if(this.curAddMultiIdx > 0) {
  462. delayT = 1.2;
  463. }
  464. delayT -= 0.3; //策划说快一点
  465. cc.tween(this.node)
  466. .delay(delayT)
  467. .call(()=>{
  468. gameJS.showGameWinScore();
  469. this.resetItems();
  470. })
  471. // .delay(0.3)
  472. // .call(()=>{
  473. // gameJS.showGameEnd();
  474. // })
  475. .start()
  476. },
  477. resetItems() {
  478. for(let i = 0; i < this.MAX_COL_NUM; ++i) {
  479. for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
  480. this.elementJS[j][i].ungrayItem();
  481. }
  482. }
  483. },
  484. setRollDatas(msg) {
  485. this._rollResultData = msg;
  486. this._rollAddMulti = msg.m_add_multi;
  487. this.curAddMultiIdx = 0;
  488. Global.print("setRollDatas")
  489. if(this._delayEndTime <= 0 && this.endIdxCnt >= GameProtocol.CELL_COUNT) {
  490. Global.print("openPrizes")
  491. this.openPrizes(0);
  492. }
  493. },
  494. resetItemsShow() {
  495. for(let i = 0; i < GameProtocol.MAX_COL_NUM; ++i) {
  496. for(let j = 0; j < GameProtocol.MAX_ROW_NUM; ++j) {
  497. this.endNodeJS[j][i].showNormal();
  498. }
  499. }
  500. },
  501. doOthersWithResultData() {
  502. //设置
  503. let data = this._rollResultData.m_desk_data;
  504. for(let i = 0; i < GameProtocol.MAX_COL_NUM; ++i) {
  505. for(let j = 0; j < GameProtocol.MAX_ROW_NUM; ++j) {
  506. this.endNodeJS[j][i].setValue(data[j][i], this.itemSpines[data[j][i]], 0);
  507. this.endNodeJS[j][i].setCount(this.elementJS[i][j+17].getCount());
  508. // Global.print("j:"+j+" i:"+i+" count:"+this.elementJS[i][j+17].getCount())
  509. }
  510. }
  511. // this.endLayer.active = true;
  512. },
  513. update (dt) {
  514. if(this._delayEndTime > 0) {
  515. this._delayEndTime -= dt;
  516. if(this._delayEndTime <= 0) {
  517. if(this._rollResultData) {
  518. Global.print("openPrizes2")
  519. this.openPrizes(0);
  520. }
  521. }
  522. }
  523. },
  524. playEffect(effName, needStop = false) {
  525. if(needStop)
  526. cc.vv.audioMgr.stopAllEffects();
  527. cc.vv.audioMgr.playSFX(effName);
  528. },
  529. });