123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556 |
- // var RollPanel = require("LBRollPanel");
- var Global = require("Global");
- var UIHelper = require("UIHelper");
- var BaseDefine = require("BaseDefine");
- var GameProtocol = require("OlympusGameProtocol");
- import ScenceManager from 'HNScenceManager'
- const topOffY = 294;
- cc.Class({
- extends: cc.Component,
- editor: {
- menu: 'Game/Olympus/RollPanel'
- },
- properties: {
- rollBG: [cc.Node],
- itemClone: cc.Prefab,
- thorNode: cc.Node,
- itemSpines: [sp.SkeletonData],
- LG_PATH_SC: "",
- LP_PATH_SC: "LB-Public/",
- bGameEnd: false,
- maxRolItemlLen: 21,
- MAX_COL_NUM: 6,
- MAX_ROW_NUM: 5,
- SPECIAL_ICON: 12,
- sizec: 120,
- aniNode: cc.Node,
- topBGKuang: cc.Node,
- coinLayer: cc.Node,
- coinClone: cc.Node,
- qiuClone: cc.Node,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this._rollResultData = {};
- this.itemData = [];
- this.tempValue = [];
- this.elementNode = [];
- this.elementJS = [];
- for(let i = 0; i < GameProtocol.MAX_ROW_NUM; ++i){
- this.elementNode[i] = [];
- this.elementJS[i] = [];
- this.tempValue[i] = [];
- for(let j = 0; j < GameProtocol.MAX_COL_NUM; ++j){
- this.tempValue[i][j] = this.getSpecialRandomValue();
- let item = cc.instantiate(this.itemClone);
- item.x = 0;
- item.y = (2-i)*(this.sizec);
- item.parent = this.rollBG[j];
- item.active = true;
- this.elementNode[i][j] = item;
- this.elementJS[i][j] = this.elementNode[i][j].getComponent("OlympusItem");
- this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], 0);
- }
- }
- //538 638
- this.thorNode.x = 538 + (cc.winSize.width - 1334)/2.9;
- this.thorDB = this.thorNode.getComponent(dragonBones.ArmatureDisplay);
- },
- showThorAni() {
- this.playEffect('thor')
- this.playEffect('thors')
- this.thorDB.playAnimation('a2', 1);
- this.thorDB.addEventListener(dragonBones.EventObject.COMPLETE, this.onAnimationPlayComplete, this);
- },
- onAnimationPlayComplete(event) {
- if (event.type === dragonBones.EventObject.COMPLETE) {
- this.thorDB.removeEventListener(dragonBones.EventObject.COMPLETE, this.onAnimationPlayComplete, this);
- this.thorDB.playAnimation('a1', 0);
- }
- },
- forceStop() {
- for(let i = 0; i < GameProtocol.MAX_COL_NUM; ++i) {
- let rollbg = this.rollBG[i];
- rollbg.active = true;
- rollbg.stopAllActions();
- rollbg.y = 0;
- }
- },
- isSpecialIcon(val) {
- return val == GameProtocol.SPECIAL_ICON;
- },
- getSpecialRandomValue(){
- if(!this.sRand)
- this.sRand = Math.floor(Math.random()*100);
- return this.sRand % 10;
- },
- getRandomValue() {
- let rand = Math.floor(Math.random()*100);
- return rand % 10;
- },
- startRollActions() {
- // this.playEffect("roll");
- this.topBGKuang.active = true;
- this.bGameEnd = false;
- this._rollResultData = null;
-
- this.currentShowIdx = -1;
- this.endIdxCnt = 0;
- for(let i = 0; i < this.MAX_ROW_NUM; ++i) {
- for(let j = 0; j < this.MAX_COL_NUM; ++j) {
- this.elementNode[i][j].stopAllActions();
- cc.tween(this.elementNode[i][j])
- .delay(0.03*j)
- .to(0.2, {y: this.elementNode[i][j].y - 490})
- .call(()=>{
- this.elementNode[i][j].y = (2-i)*(this.sizec)+490;
- this.elementJS[i][j].reset();
- // this.addEndCnt();
- if(i == this.MAX_ROW_NUM-1 && j == this.MAX_COL_NUM-1) {
- this.endIdxCnt = GameProtocol.CELL_COUNT;
- this._delayEndTime = 0.2;
- }
- })
- .start()
- }
- }
- // this._delayEndTime = 0.7;
- 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]];
- 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];
- this.needAddItem = [];
- // this.showThorAni();
- },
- openPrizes(idx) {
- if(this.bGameEnd == true || this._rollResultData == null) {
- return;
- }
- this.endIdxCnt = 0;
- this.currentShowIdx = idx;
- this.topBGKuang.active = true;
- let desData = this._rollResultData.m_result_data[idx];
- // Global.print(desData)
- if(!desData) return;
- let items = this.needAddItem;
- if(idx == 0) {
- items = desData.m_desk_data;
- }
- let hasQiu = false;
- let qiuIdx = [];
- for(let i = 0; i < this.needNewIdx.length; ++i) {
- let idx = this.needNewIdx[i];
- let x = Math.floor(idx / 6);
- let y = idx % 6;
- // Global.print(`i:${x} j:${y}`);
- let multi = 0;
- if(items[i] == GameProtocol.SPECIAL_ICON) {
- hasQiu = true;
- multi = this._rollAddMulti[this.curAddMultiIdx++];
- // qiuIdx
- }
- this.elementJS[x][y].setValue(items[i], this.itemSpines[items[i]], multi);
- }
- let delayT = 0;
- if(hasQiu) {
- delayT = 0.3;
- this.showThorAni();
- }
- // let ddY = 0;
- if(idx == 0) {
- this.playEffect('luodi');
- // ddY = 30;
- }
- for(let i = this.MAX_ROW_NUM-1; i >= 0; --i) {
- for(let j = 0; j < this.MAX_COL_NUM; ++j) {
- let k = this.tempSortIdx[j][i];
- let dNode = this.elementNode[k][j];
- let dY = (2-i)*(this.sizec);
- // Global.print(`${i} : ${k} : ${j} : ${items[j][k]} : ${dY} : ${dNode.y}`)
- dNode.stopAllActions();
- this.elementJS[k][j].showJackpot(delayT, dY);
- let ddY = 0;
- let leiFunc = ()=>{};
- if(dNode.y - dY > this.sizec/2) {
- if(this.elementJS[k][j].getItemValue() == GameProtocol.SPECIAL_ICON && !this.elementJS[k][j].playedAni) {
- // let node = cc.instantiate(this.qiuClone);
- // node.parent = this.coinLayer;
- // node.position = cc.v2(this.rollBG[j].x, dY);
- // node.active = true;
- // let iindx = this.elementJS[k][j].getMultiIdx();
- // let ani = node.getComponent(sp.Skeleton);
- // ani.setAnimation(0, 'a'+iindx, false);
- leiFunc = ()=>{
- let node = cc.instantiate(this.qiuClone);
- node.parent = this.coinLayer;
- node.position = cc.v2(this.rollBG[j].x, dY);
- node.active = true;
- let iindx = this.elementJS[k][j].getMultiIdx();
- let ani = node.getComponent(sp.Skeleton);
- ani.setAnimation(0, 'a'+iindx, false);
- ani.setCompleteListener(()=>{
- ani.setCompleteListener(null);
- node.destroy();
- })
- };
- }
- ddY = 20;
- }
- cc.tween(dNode)
- .delay(delayT+j*0.03)
- .call(()=>{
- leiFunc();
- })
- .to(0.1, {y: dY-ddY}, {easing: 'quartInOut'})
- .to(0.05, {y: dY})
- .start()
- }
- }
-
- if(desData.m_win_score > 0 || desData.m_deposit_lotttery > 0) {
- // 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]];
- let desItemPos = [];
- let tempNode = [];
- let hasLei = false;
- for(let i = 0; i < desData.m_item_count.length; ++i) {
- if(desData.m_item_count[i] > 0) {
- if(desData.m_item_id[i] == GameProtocol.WILD_ICON) {
- hasLei = true;
- }
- desItemPos[i] = [];
- let minDis = 100000000;
- let dPos = cc.v2(0,0);
- let score = 'R$+'+ (Math.floor(this._rollResultData.m_chip_size*desData.m_item_times[i] / 100) / 100).toFixed(2);
- for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
- for(let k = 0; k < this.MAX_COL_NUM; ++k) {
- // let kk = this.tempSortIdx[k][j];
- if(this.elementJS[j][k].checkSame(desData.m_item_id[i])){
- // let dyy = Math.floor(2 - (this.elementJS[j][k].getEndY() / this.sizec));
- // Global.print(`i:${j} j:${dyy} y:${this.elementJS[j][k].getEndY()}`);
- // itemMap[j][k] = desData.m_item_id[i];
- let ids = this.disToCenter(this.rollBG[k].x, this.elementJS[j][k].getEndY());
- desItemPos[i].push({x: this.rollBG[k].x, y: this.elementJS[j][k].getEndY(), dis: ids, score:score});
- if(ids < minDis) {
- minDis = ids;
- dPos = cc.v2(this.rollBG[k].x, this.elementJS[j][k].getEndY());
- }
- }
- }
- }
- desItemPos[i].sort((A, B)=> {
- return A.dis - B.dis;
- });
- tempNode.push({x:dPos.x, y:dPos.y, score:score});
- // let node = cc.instantiate(this.coinClone);
- // node.parent = this.coinLayer;
- // node.position = dPos;
- // // Global.print(node.position)
- // node.getComponent(cc.Label).string = '$+'+ (Math.floor(this._rollResultData.m_chip_size*desData.m_item_times[i] / 100) / 100).toFixed(2);
- // node.active = false;
- }
- }
- // Global.print(itemMap);
- Global.print(desItemPos);
- let dddTmp = [];
- let okk = false;
- for(let i = 0; i < desItemPos[0].length; ++i) {
- dddTmp[0] = desItemPos[0][i];
- okk = true;
- for(let j = 1; j < desItemPos.length; ++j) {
- for(let k = 0; k < desItemPos[j].length; ++k) {
- // dddTmp[j] = desItemPos[j][k];
- let tmpV = desItemPos[j][k];
- let nook = false;
- for(let kk = 0; kk < j; ++kk) {
- if(this.disTwoPoint(tmpV, dddTmp[kk]) < 9600) {
- nook = true;
- break;
- }
- }
- //距离符合要求
- if(!nook) {
- dddTmp[j] = tmpV;
- break;
- }else if(k == desItemPos[j].length-1) { //全都不符合,并且是最后一个点了
- okk = false;
- break;
- }
- }
- }
- if(okk) {break;}
- else if(i == desItemPos[0].length-1) {
- Global.print("没有找到合适的点位,使用重叠点位")
- dddTmp = tempNode;
- }
- }
- Global.print(dddTmp);
- for(let i = 0; i < dddTmp.length; ++i) {
- let tmp = dddTmp[i];
- let node = cc.instantiate(this.coinClone);
- node.parent = this.coinLayer;
- node.name = 'coin';
- node.position = cc.v2(tmp.x, tmp.y);
- node.getComponent(cc.Label).string = tmp.score;
- node.active = false;
- }
- let delTime = 2;
- if(hasLei) {
- delTime = 2.5;
- }
- cc.tween(this.node)
- .delay(0.3+delayT)
- .call(()=>{
- this.topBGKuang.active = false;
- this.showPrizes();
- this.showWinLabel();
- })
- .delay(delTime)
- .call(()=>{
- ScenceManager.Instance().getGameComponent().addGameWinScore(desData.m_win_score);
- this.resetSortIdx(idx);
- })
- .delay(0.2)
- .call(()=>{
- if(desData.m_deposit_lotttery > 0) {
- ScenceManager.Instance().getGameComponent().showJackpotWin(desData.m_deposit_lotttery);
- }else{
- this.openPrizes(idx+1);
- }
- })
- .start()
- return;
- }
- cc.tween(this.node)
- .delay(0.3)
- .call(()=>{
- this.topBGKuang.active = false;
- this.bGameEnd = true;
- this.showPrizes(true);
- // ScenceManager.Instance().getGameComponent().showGameWinScore();
- // Global.print(Date.now())
- })
- .delay(0.1)
- .call(()=>{
- this.showPrizesEnd();
- // ScenceManager.Instance().getGameComponent().showGameEnd();
- })
- .start()
- },
- disTwoPoint(p1, p2) {
- if(p2.y == p1.y) {
- if((p1.x-p2.x)*(p1.x-p2.x) == 31329) {
- return 6000;
- }
- }
- return (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y);
- },
- disToCenter(i,j) {
- return i*i+j*j//(i-2)*(i-2) + (j-2.5)*(j-2.5);
- },
- resumeShowPrizes() {
- this.openPrizes(this.currentShowIdx+1);
- },
- resetSortIdx(pidx) {
- Global.print(this.elementJS);
- 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]];
- let tmpNew = [];
- let tmpNew2 = [];
- this.needAddItem = [];
- for(let i = 0; i < this.MAX_COL_NUM; ++i) {
- let idx = this.MAX_ROW_NUM-1;
- for(let j = this.MAX_ROW_NUM-1; j >= 0; --j) {
- let jdx = this.tempSortIdx[i][j];
- if(this.elementJS[jdx][i]._value >= 0) {
- temp[i][idx--] = jdx;
- }
- }
- let sY = topOffY;
- for(let j = this.MAX_ROW_NUM-1; j >= 0; --j) {
- let jdx = this.tempSortIdx[i][j];
- if(this.elementJS[jdx][i]._value < 0) {
- tmpNew.push(jdx*6+i);
- tmpNew2.push(j*6+i);
- temp[i][idx--] = jdx;
- this.elementNode[jdx][i].y = sY;
- sY += this.sizec;
- }
- }
- }
- let preData = this._rollResultData.m_result_data[pidx]
- let data1 = preData.m_desk_data;
- let data2 = this._rollResultData.m_result_data[pidx+1].m_desk_data;
- for(let i = 0; i < preData.m_item_count.length; ++i) {
- if(preData.m_item_count[i] > 0) {
- let iID = preData.m_item_id[i];
- for(let j = 0; j < GameProtocol.CELL_COUNT; ++j){
- if(data1[j] == iID) {
- this.needAddItem.push(data2[j]);
- }
- }
- }
- }
- this.tempSortIdx = temp;
- tmpNew.sort((A, B)=>{
- return A-B;
- });
- this.needNewIdx = tmpNew;
- Global.print(this.tempSortIdx);
- Global.print(this.needNewIdx);
- Global.print(this.needAddItem);
- },
- testPrint() {
- for(let i = 0; i < this.MAX_ROW_NUM; ++i) {
- for(let j = 0; j < this.MAX_COL_NUM; ++j) {
- Global.print(`${i} : ${j} : ${this.elementJS[i][j]._value}`)
- }
- }
- },
- showWinLabel() {
- for(let i = 0; i < this.coinLayer.childrenCount; ++i) {
- let node = this.coinLayer.children[i];
- if(node && node.name == 'coin') {
- node.active = true;
- node.scale = 0;
- node.opacity = 0;
- node.stopAllActions();
- let dy = node.y + 50;
- cc.tween(node)
- .to(0.3, {opacity: 255, scale: 1.1})
- .to(0.8, {y: dy, scale: 1, opacity: 150})
- .call(()=>{
- node.active = false;
- node.destroy();
- })
- .start()
- }
- }
- },
- showPrizes(bEnd = false) {
- let hasRen = false;
- let nowVal = -1;
- for(let i = 0; i < GameProtocol.MAX_ROW_NUM; ++i) {
- for(let j = 0; j < GameProtocol.MAX_COL_NUM; ++j) {
- nowVal = this.elementJS[i][j].getItemValue();
- if(this.elementJS[i][j].showLightAni()) {
- if(nowVal == GameProtocol.WILD_ICON) {
- hasRen = true;
- }
- }
- }
- }
- if(!bEnd) {
- if(hasRen) {
- this.playEffect('leishen');
- }else{
- this.playEffect('ending')
- }
- }
- },
- showPrizesEnd() {
- let delayT = 0.5;
- let gameJS = ScenceManager.Instance().getGameComponent();
- if(this.curAddMultiIdx > 0 && this._rollResultData.m_lottery_size > 0) {
- let idx = 0;
- for(let i = 0; i < this.MAX_COL_NUM; ++i) {
- for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
- // ji
- if(this.elementJS[j][i].isSpecial()) {
- gameJS.playAddScoreMulti(this.elementJS[j][i].getMultiLabelNode(idx), this.elementJS[j][i].getMulti(), idx++);
- }else{
- this.elementJS[j][i].grayItem();
- }
- }
- }
- delayT = 1.2 * idx + 1.5;
- }else if(this.curAddMultiIdx > 0) {
- delayT = 1.2;
- }
- delayT -= 0.3; //策划说快一点
- cc.tween(this.node)
- .delay(delayT)
- .call(()=>{
- gameJS.showGameWinScore();
- this.resetItems();
- })
- // .delay(0.3)
- // .call(()=>{
- // gameJS.showGameEnd();
- // })
- .start()
- },
- resetItems() {
- for(let i = 0; i < this.MAX_COL_NUM; ++i) {
- for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
- this.elementJS[j][i].ungrayItem();
- }
- }
- },
- setRollDatas(msg) {
- this._rollResultData = msg;
- this._rollAddMulti = msg.m_add_multi;
- this.curAddMultiIdx = 0;
- Global.print("setRollDatas")
- if(this._delayEndTime <= 0 && this.endIdxCnt >= GameProtocol.CELL_COUNT) {
- Global.print("openPrizes")
- this.openPrizes(0);
- }
- },
- resetItemsShow() {
- for(let i = 0; i < GameProtocol.MAX_COL_NUM; ++i) {
- for(let j = 0; j < GameProtocol.MAX_ROW_NUM; ++j) {
- this.endNodeJS[j][i].showNormal();
- }
- }
- },
- doOthersWithResultData() {
- //设置
- let data = this._rollResultData.m_desk_data;
- for(let i = 0; i < GameProtocol.MAX_COL_NUM; ++i) {
- for(let j = 0; j < GameProtocol.MAX_ROW_NUM; ++j) {
- this.endNodeJS[j][i].setValue(data[j][i], this.itemSpines[data[j][i]], 0);
- 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;
- },
- update (dt) {
- if(this._delayEndTime > 0) {
- this._delayEndTime -= dt;
- if(this._delayEndTime <= 0) {
- if(this._rollResultData) {
- Global.print("openPrizes2")
- this.openPrizes(0);
- }
- }
- }
- },
- playEffect(effName, needStop = false) {
- if(needStop)
- cc.vv.audioMgr.stopAllEffects();
- cc.vv.audioMgr.playSFX(effName);
- },
- });
|