123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- var RollPanel = require("LBRollPanel");
- var Global = require("Global");
- var UIHelper = require("UIHelper");
- var BaseDefine = require("BaseDefine");
- var GameProtocol = require("FruitGameProtocol");
- import ScenceManager from 'HNScenceManager'
- const arr_posX = [-392, -198, 2, 199, 396];
- cc.Class({
- extends: RollPanel,
- editor: {
- menu: 'Game/Fruit/RollPanel'
- },
- properties: {
- aniNode: cc.Node,
- itemLayer: cc.Node,
- endLayer: cc.Node,
- fraLayer: cc.Node,
- kuangClone: cc.Node,
- },
- // LIFE-CYCLE CALLBACKS:
- initOthers () {
- this.endNode = [];
- this.endNodeJS = [];
- this.kuangArrs = [];
- this.endLayer.removeAllChildren();
- this.fraLayer.removeAllChildren();
- for(let i = 0; i < this.MAX_ROW_NUM; ++i) {
- this.endNode[i] = [];
- this.endNodeJS[i] = [];
- this.kuangArrs[i] = [];
- for(let j = 0; j < this.MAX_COL_NUM; ++j) {
- let item = cc.instantiate(this.itemClone);
- item.x = arr_posX[j];
- item.y = (1-i)*(this.sizec);
- item.parent = this.endLayer;
- item.active = false;
- this.endNode[i][j] = item;
- this.endNodeJS[i][j] = this.endNode[i][j].getComponent("LBItem");
- this.endNodeJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
- let kuang = cc.instantiate(this.kuangClone);
- kuang.x = arr_posX[j];
- kuang.y = (1-i)*(this.sizec);
- kuang.parent = this.fraLayer;
- kuang.active = false;
- this.kuangArrs[i][j] = kuang;
- }
- }
- this.endLayer.active = false;
- this.fraLayer.active = false;
- },
- getRandomValue() {
- return Math.floor(Math.random()*100)%8;
- },
- startRollActions() {
- this.itemLayer.active = true;
- this.endLayer.active = false;
- this.fraLayer.active = false;
- this._super();
- },
- openPrizes(justEnd, bQuick) {
- if(this.bGameEnd == true) {
- return;
- }
- let endTime = new Date().getTime();
- let leftTime = this._startRollTime - endTime + 1000;
- this.delayTime = 0.2;
- if(bQuick) {
- leftTime -= 500;
- }
- if(leftTime < 0 || justEnd) {
- leftTime = 0;
- }
- if(justEnd) {
- this.delayTime = 0;
- }
- this.node.stopAllActions();
- this.bQuick = bQuick;
- this.FreeCount = 0;
- //快速,并且前四排骷髅头总数少于2
- if(bQuick || justEnd) {
- for(let i = 0;i < this.MAX_COL_NUM; ++i) {
- if(this.FreeCount >= 2) {
- // SoundFun.playEffect("freeicon");
- cc.tween(this.node)
- .delay(leftTime/1000+0.2)
- .call(()=>{
- this.hotRolls(i);
- })
- .start()
- return;
- }
- cc.tween(this.node)
- .delay(leftTime/1000)
- .call(()=>{
- this.quickEnd(i);
- if(i >= 4) {
- this.delayShowPrizes(1000);
- }
- })
- .start()
- for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
- if(this.tempValue[i][j+1] == this.SPECIAL_ICON) {
- this.FreeCount++;
- }
- }
- }
- // SoundFun.playEffect("normal_stop");
- return;
- }
- cc.tween(this.node)
- .delay(leftTime/1000)
- .call(()=>{
- this.rollEnds(0);
- })
- .start()
- },
- setItemColInfo(i, dIdx) {
- let bHasFree = false;
- for(let j = this.maxRolItemlLen-5; j < this.maxRolItemlLen; ++j) {
- this.elementNode[i][j-this.maxRolItemlLen+dIdx-1].active = true;
- this.elementNode[i][j].active = true;
- this.tempValue[i][j] = this.tempValue[i][j-this.maxRolItemlLen+dIdx-1];
- this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
- if(j > this.maxRolItemlLen-5 && j < this.maxRolItemlLen-1) {
- if(this.tempValue[i][j] == this.SPECIAL_ICON) {
- bHasFree = true;
- }
- }
- }
- this.playEffect("line"+i);
- },
- quickEnd(i) {
- if(i >= this.MAX_COL_NUM) {
- return;
- }
- let rollbg = this.rollBG[i];
- rollbg.stopAllActions();
- let yy = rollbg.y;
- let destIdx = this.maxRolItemlLen - 3 - Math.floor(yy/-this.sizec);
- for(let j = destIdx-3; j >= destIdx-6; --j) {
- this.tempValue[i][j] = this.tempValue[i][j-destIdx+6];
- this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
- }
- let destY = (this.maxRolItemlLen - destIdx+1) * -this.sizec;
- let lastTime = (yy - destY + 50)/this.sizec/12;
- cc.tween(rollbg)
- .to(lastTime, {y: destY-50})
- .to(0.1, {y: destY}, {easing: 'sineInOut'})
- .call(()=>{
- this.setItemColInfo(i, destIdx);
- rollbg.y = 0;
- })
- .start()
- },
- justEnd(i) {
- if(i >= this.MAX_COL_NUM) {
- return;
- }
- let rollbg = this.rollBG[i];
- rollbg.stopAllActions();
- let yy = rollbg.y;
- let destIdx = this.maxRolItemlLen - 3 - Math.floor(yy/-this.sizec);
- for(let j = destIdx-3; j >= destIdx-6; --j) {
- this.tempValue[i][j] = this.tempValue[i][j-destIdx+6];
- this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
- }
- let destY = (this.maxRolItemlLen - destIdx+1) * -this.sizec;
- let lastTime = (yy - destY + 50)/this.sizec/12*0.5;
- cc.tween(rollbg)
- .to(lastTime, {y: destY-50})
- .call(()=>{
- this.hotRolls(i+1);
- })
- .to(0.1, {y: destY}, {easing: 'sineInOut'})
- .call(()=>{
- this.setItemColInfo(i, destIdx);
- rollbg.y = 0;
- })
- .start()
- },
- hotRolls(i) {
- if(i >= this.MAX_COL_NUM) {
- this.delayShowPrizes(600);
- return;
- }
- this.playLPEffect("hotroll");
- let rollbg = this.rollBG[i];
- rollbg.stopAllActions();
- this.aniNode.active = true;
- this.aniNode.x = arr_posX[i];
- let yy = rollbg.y;
- let lessY = yy + 12*this.sizec;
- let lastTime = lessY/this.sizec/12*0.3;
- cc.tween(rollbg)
- .to(lastTime, {y: -12*this.sizec})
- .sequence(
- cc.tween().call(()=>{ rollbg.y = 0, this.resetRollingItemValue(i) }),
- cc.tween().to(0.5, {y: -12*this.sizec})
- )
- .repeatForever()
- .start()
- cc.tween(this.node)
- .delay(2)
- .call(()=>{
- this.aniNode.active = false;
- this.justEnd(i);
- })
- .start()
- },
- rollEnds(i) {
- if(i == 0) {
- ScenceManager.Instance().getGameComponent().onGameEnd();
- }
- if(this.FreeCount >= 2) {
- cc.tween(this.node)
- .delay(0.3)
- .call(()=>{
- this.hotRolls(i);
- })
- .start()
- // this.hotRolls(i);
- return;
- }
- if(i > 4) {
- this.delayShowPrizes(600);
- return;
- }
- //先统计骷髅头数量
- for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
- if(this.tempValue[i][j+1] == this.SPECIAL_ICON) {
- this.FreeCount++;
- }
- }
- let rollbg = this.rollBG[i];
- rollbg.stopAllActions();
- let yy = rollbg.y;
- let destIdx = this.maxRolItemlLen - 3 - Math.floor(yy/-this.sizec);
- // Global.print("i"+i+" "+destIdx)
- for(let j = destIdx-3; j >= destIdx-6; --j) {
- this.tempValue[i][j] = this.tempValue[i][j-destIdx+6];
- this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
- }
-
- let destY = (this.maxRolItemlLen - destIdx+1) * -this.sizec;
- let lastTime = (yy - destY + 50)/this.sizec/12;
- if(this.bQuick) {
- cc.tween(rollbg)
- .call(()=>{
- this.rollEnds(i+1);
- })
- .to(lastTime, {y: destY-50})
- .to(0.1, {y: destY}, {easing: 'sineInOut'})
- .call(()=>{
- this.setItemColInfo(i, destIdx);
- rollbg.y = 0;
- })
- .start()
- return;
- }
- cc.tween(rollbg)
- .to(lastTime, {y: destY-50})
- .call(()=>{
- this.rollEnds(i+1);
- })
- .to(0.1, {y: destY}, {easing: 'sineInOut'})
- // .delay(this.delayTime)
- .call(()=>{
- this.setItemColInfo(i, destIdx);
- rollbg.y = 0;
- // rollbg.y = -16*140;
- // this.rollEnds(i+1);
- })
- .start()
- },
- delayShowPrizes(delayTime) {
- cc.tween(this.node)
- .delay(delayTime/1000)
- .call(()=>{
- this.beforeShowPrize();
- })
- .delay(0.3)
- .call(()=>{
- this.bGameEnd = true;
- ScenceManager.Instance().getGameComponent().showGameWinScore();
- // if(this._lineCount > 0)
- // SoundFun.playEffect("line");
-
- this.showPrizes();
- })
- .delay(0.3)
- .call(()=>{
- // ScenceManager.Instance().getGameComponent().resetAllBtn();
- ScenceManager.Instance().getGameComponent().showGameEnd();
- })
- .start()
- },
- beforeShowPrize() {
- this.endLayer.active = true;
- for(let i = 0; i < this.MAX_COL_NUM; ++i) {
- for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
- // this.endNodeJS[j][i].showLightAni();
- this.endNodeJS[j][i].node.active = true;
- this.kuangArrs[j][i].active = false;
- }
- }
- this.fraLayer.active = true;
- this.itemLayer.active = false;
- },
- showPrizes() {
- for(let i = 0; i < this.MAX_COL_NUM; ++i) {
- for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
- this.kuangArrs[j][i].active = this.endNodeJS[j][i].getCount() > 0;
- this.endNodeJS[j][i].showLightAniNoScale();
- if(this._hasSpecial) {
- this.endNodeJS[j][i].showSpecialAni();
- }
- // Global.print("active value::"+this.endNodeJS[j][i].node.active)
- }
- }
- cc.tween(this.node)
- .delay(2.5)
- .call(()=>{
- this.resetItemsShow();
- })
- .delay(0.5)
- .call(()=>{
- this.showLines(0);
- })
- .start();
- },
- showLines(iIndex) {
- if(iIndex >= this._lineCount) {
- this.showPrizes();
- return;
- }
-
- let lineID = this._lineID[iIndex];
- let lineArr = this.linesArr[lineID];
- let count = this._lineSize[iIndex];
- let hWild = false;
- for(let k = 0; k < count; ++k) {
- let idx = lineArr[k];
- let i = idx % 10;
- let j = Math.floor(idx/10);
- this.kuangArrs[j][i].active = true;
- this.endNodeJS[j][i].showLightAni();
- if(this.endNodeJS[j][i]._value == GameProtocol.WILD_ICON) {
- hWild = true;
- }
- }
- if(hWild) {
- this.playEffect("wild");
- }
- cc.tween(this.node)
- .delay(2)
- .call(()=>{
- this.resetItemsShow();
- })
- .delay(0.5)
- .call(()=>{
- this.showLines(iIndex+1);
- })
- .start();
- },
- // setItemDatas(itemData) {
- // this.allFreeCount = 0;
- // for(let i = 0; i < GameProtocol.MAX_ROW_NUM; ++i) {
- // for(let j = 0;j < GameProtocol.MAX_COL_NUM; ++j) {
- // this.tempValue[j][i+1] = itemData[i][j];
- // // Global.print("i:"+i+" j:"+j+" v:"+this.tempValue[j][i+1]+" cc:"+itemData[i][j]);
- // this.elementJS[j][i+1].setValue(itemData[i][j], this.itemSpines[this.tempValue[i][j]]);
- // if(itemData[i][j] == GameProtocol.FREE_ICON && j < GameProtocol.MAX_COL_NUM-1) {
- // this.allFreeCount++;
- // }
- // }
- // }
- // Global.print(this.tempValue);
- // Global.print(itemData);
- // },
- // resetItemCounts() {
- // for(let i = 0; i < GameProtocol.MAX_COL_NUM; ++i) {
- // for(let j = 0; j < this.maxRolItemlLen; ++j) {
- // this.elementJS[i][j].resetCount();
- // }
- // }
- // },
- resetItemsShow() {
- for(let i = 0; i < this.MAX_COL_NUM; ++i) {
- for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
- this.kuangArrs[j][i].active = false;
- this.endNodeJS[j][i].showNormal();
- }
- }
- },
- doOthersWithResultData() {
- //设置
- let data = this._rollResultData.m_desk_data;
- for(let i = 0; i < this.MAX_COL_NUM; ++i) {
- for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
- this.endNodeJS[j][i].setValue(data[j][i], this.itemSpines[data[j][i]], this.isSpecialIcon(data[j][i]));
- this.endNodeJS[j][i].setCount(this.elementJS[i][j+17].getCount());
- // Global.print("j:"+j+" i:"+i+" count:"+this.elementJS[i][j+17].getCount())
- }
- }
- // this.endLayer.active = true;
- // this.fraLayer.active = true;
- },
- // analyzeLinesData() {
- // this._allTimers = 0;
- // for(let i = 0; i < this._lineCount; ++i) {
- // let lineID = this._lineID[i];
- // let lineArr = linesArr[lineID];
- // this._allTimers += this._lineTimes[i];
- // for(let j = 0; j < this._lineSize[i]; ++j) {
- // let idx = lineArr[j];
- // let x = idx % 10;
- // let y = Math.floor(idx/10);
- // this.elementJS[x][y+17].addCount();
- // }
- // }
- // },
- });
|