123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- var Global = require("Global");
- import ScenceManager from 'HNScenceManager'
- cc.Class({
- extends: cc.Component,
- properties: {
- rollBG: [cc.Node],
- itemClone: cc.Prefab,
- // endLayer: cc.Node,
- // getLayer: cc.Node,
- // kuangClone: cc.Node,
- itemSpines: [sp.SkeletonData],
- itemSprites: [cc.SpriteFrame],
- LG_PATH_SC: "",
- LP_PATH_SC: "LB-Public/",
- bGameEnd: false,
- maxRolItemlLen: 21,
- MAX_COL_NUM: 5,
- MAX_ROW_NUM: 3,
- SPECIAL_ICON: 12,
- sizec: 150,
-
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- //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]];
- this._rollResultData = {};
- this._lineCount = 0;
- this._lineSize = [];
- this._lineID = [];
- this._lineIcon = [];
- this._lineTimes = [];
- this.itemData = [];
- this.elementNode = [];
- this.elementJS = [];
- this.tempValue = [];
- // this.kuangArrs = [];
-
- this._startRollTime = 0;
- this.initLists();
- this.initOthers();
- },
- initLists() {
- for(let i = 0; i < this.MAX_COL_NUM; ++i) {
- this.elementNode[i] = [];
- this.elementJS[i] = [];
- this.itemData[i] = [];
- this.tempValue[i] = [];
- this.rollBG[i].active = true;
- for(let j = 0; j < this.maxRolItemlLen-5; ++j) {
- this.tempValue[i][j] = this.getRandomValue();
- }
- for(let j = this.maxRolItemlLen-5; j < this.maxRolItemlLen; ++j) {
- // this.tempValue[i][j] = this.tempValue[i][j-12];
- this.tempValue[i][j] = this.getSpecialRandomValue();
- }
- for(let j = 0; j < this.maxRolItemlLen; ++j) {
- let item = cc.instantiate(this.itemClone);
- item.y = (this.maxRolItemlLen - 3 - j)*(this.sizec);
- item.parent = this.rollBG[i];
- item.active = true;
- this.elementNode[i][j] = item;
- this.elementJS[i][j] = this.elementNode[i][j].getComponent("LBItem");
- this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
- }
- }
- },
- initOthers() {
- },
- isSpecialIcon(val) {
- return val == this.SPECIAL_ICON;
- },
- getSpecialRandomValue(){
- if(!this.sRand)
- this.sRand = Math.floor(Math.random()*100)%10;
- return this.sRand;
- },
- getRandomValue() {
- return Math.floor(Math.random()*100)%10;
- },
- resetRollingItemValue(i) {
- for(let j = 9; j < this.maxRolItemlLen-5; ++j) {
- this.tempValue[i][j] = this.getRandomValue();
- this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
- }
- for(let j = this.maxRolItemlLen-5; j < this.maxRolItemlLen; ++j) {
- this.elementNode[i][j].active = true;
- }
- },
- resetItemCounts() {
- for(let i = 0; i < this.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.maxRolItemlLen; ++j) {
- this.elementJS[i][j].showNormal();
- }
- }
- },
- setItemColInfo(i, dIdx) {
- 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]));
- }
- },
- startRollActions() {
- this.bGameEnd = false;
- this.node.stopAllActions();
- this.resetItemCounts();
- for(let i = 0; i < this.MAX_COL_NUM; ++i) {
- let rollbg = this.rollBG[i];
- rollbg.active = true;
- rollbg.y = 0;
- rollbg.stopAllActions();
- /*
- for(let j = 4; j < 9; ++j) {
- this.tempValue[i][j] = this.tempValue[i][j+12];
- this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
- }
- */
- cc.tween(rollbg)
- .sequence(
- cc.tween().to(0.4, {y: -6*this.sizec}),
- cc.tween().call(()=>{
- for(let j = this.maxRolItemlLen-5; j < this.maxRolItemlLen; ++j) {
- this.tempValue[i][j] = this.tempValue[i][j-12];
- // this.tempValue[i][j] = this.getSpecialRandomValue();
- this.elementJS[i][j].setValue(this.tempValue[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
- }
- }),
- cc.tween().to(0.4, {y: -12*this.sizec}),
- cc.tween().call(()=>{ rollbg.y = 0, this.resetRollingItemValue(i) })
- )
- .repeatForever()
- .start()
- }
- this._startRollTime = new Date().getTime();
- },
- 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;
- if(bQuick || justEnd) {
- for(let i = 0;i < this.MAX_COL_NUM; ++i) {
- cc.tween(this.node)
- .delay(leftTime/1000)
- .call(()=>{
- this.rollEnds(i);
- if(i >= this.MAX_COL_NUM-1) {
- this.delayShowPrizes(1000);
- }
- })
- .start()
- }
- return;
- }
- cc.tween(this.node)
- .delay(leftTime/1000)
- .call(()=>{
- this.rollEnds(0);
- })
- .start()
- },
- rollEnds(i) {
- if(i == 0) {
- // ScenceManager.Instance().getGameComponent().onGameEnd();
- }
- if(i > 4) {
- this.delayShowPrizes(600);
- 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;
- 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'})
- .call(()=>{
- this.setItemColInfo(i, destIdx);
- rollbg.y = 0;
- })
- .start()
- },
- delayShowPrizes(delayTime) {
- cc.tween(this.node)
- .delay(delayTime/1000)
- .call(()=>{
- this.bGameEnd = true;
- // ScenceManager.Instance().getGameComponent().showGameWinScore();
- this.showPrizes();
- })
- .delay(0.6)
- .call(()=>{
- // ScenceManager.Instance().getGameComponent().showGameEnd();
- })
- .start()
- },
- showPrizes() {
- for(let i = 0; i < this.MAX_COL_NUM; ++i) {
- for(let j = 0; j < this.MAX_ROW_NUM; ++j) {
- this.elementJS[i][j+17].showLightAniNoScale();
- if(this._hasSpecial) {
- this.elementJS[i][j+17].showSpecialAni();
- }
- }
- }
- 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];
- for(let k = 0; k < count; ++k) {
- let idx = lineArr[k];
- let i = idx % 10;
- let j = Math.floor(idx/10);
- this.elementJS[i][j+17].showLightAni();
- }
- cc.tween(this.node)
- .delay(2)
- .call(()=>{
- this.resetItemsShow();
- })
- .delay(0.5)
- .call(()=>{
- this.showLines(iIndex+1);
- })
- .start();
- },
- setRollDatas(msg) {
- this._rollResultData = msg;
- this.setItemDatas(msg.m_desk_data);
- this._hasSpecial = msg.m_kongming == 1;
- //线信息
- this._lineCount = msg.m_line_count;
- this._lineID = msg.m_line_id;
- this._lineSize = msg.m_line_size;
- this._lineIcon = msg.m_line_icon;
- this._lineTimes = msg.m_line_times;
- this.analyzeLinesData();
- this.doOthersWithResultData();
- },
- setItemDatas(itemData) {
- for(let i = 0; i < this.MAX_ROW_NUM; ++i) {
- for(let j = 0;j < this.MAX_COL_NUM; ++j) {
- this.tempValue[j][i+1] = itemData[i][j];
- this.elementJS[j][i+1].setValue(itemData[i][j], this.itemSpines[this.tempValue[i][j]], this.isSpecialIcon(this.tempValue[i][j]));
- }
- }
- Global.print(this.tempValue);
- Global.print(itemData);
- },
-
- analyzeLinesData() {
- this._allTimers = 0;
- for(let i = 0; i < this._lineCount; ++i) {
- let lineID = this._lineID[i];
- let lineArr = this.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);
- // console.log('x,y: ', x,y, lineArr);
- this.elementJS[x][y+17].addCount();
- }
- }
- },
- doOthersWithResultData() {
- },
- //播放音效
- playEffect(effName, needStop = false) {
- ScenceManager.Instance().getGameComponent().playEffect(effName, needStop);
- },
- //播放通用音效
- playLPEffect(effName, needStop = false) {
- ScenceManager.Instance().getGameComponent().playLPEffect(effName, needStop);
- },
- update (dt) {
- for(let i = 0; i < this.MAX_COL_NUM; ++i) {
- let yy = this.rollBG[i].y;
- for(let j = 0; j < this.maxRolItemlLen; ++j) {
- let dy = this.elementNode[i][j].y + yy;
- this.elementNode[i][j].active = (dy > -2*this.sizec) && (dy < 2*this.sizec);
- }
- }
- },
- });
|