/** * 挑战游戏 节点 */ import AudioManager from "../../Tools/AudioManager"; import Define from "../../Tools/Define"; import GameResMgr, { soundName, uiPreName } from "../../Tools/GameResMgr"; import PlayData, { GameState } from "../../Tools/PlayData"; import AdsApiMgr, { plaformName } from "../../Tools/Sdk/ads/AdsApiMgr"; import Utils from "../../Tools/Utils"; import gameStorage from "../../Tools/gameStorage"; import TipsManager from "../TipsManager"; import ChallengeSuccessSc from "./ChallengeSuccessSc"; import TimeOutPanelSc from "./TimeOutPanelSc"; import kapaiSc from "./kapaiSc"; import {TrackingManager, TrackingType} from "../../Tracking/TrackingManager"; const {ccclass, property} = cc._decorator; @ccclass export default class ChallengeGameSc extends cc.Component { @property(cc.Prefab) dikuang:cc.Prefab = null @property(cc.Prefab) kapaiPre:cc.Prefab = null @property(cc.Node) dizuo:cc.Node = null @property(cc.Node) //用于移动卡牌 过渡节点 ,移动卡牌的时候 ,卡牌在最高层 moveNode:cc.Node = null @property(cc.Node) notouch:cc.Node = null @property(cc.Layout) dizuolayout:cc.Layout = null @property(cc.Label) guanstr:cc.Label = null @property(cc.Label) timestr:cc.Label = null @property(cc.Label) bushustr:cc.Label = null dizuoState = [] //底座状态 0未解锁,1解锁 levelNum = 0 mixlevelNum = 0 maxlevelNum = 0 moveUp = 15 selectNodeArr = [] //选中的节点 selectIndex = -1 mubiaoIndex = -1 allNodeArr = [] posXY = [[-72,0], [-24,0], [24,0], [72,0]] //posY = [0, -20, -40, -60, -80, -100, -120, -140, -160, -180] maxKaPaiNum = 4 //一个框最多放置 数量 linshijiesuo = 0 //可用于临时解锁的id linshiOperatorNum = [] // time01 = 0.01 weizhigailv = 1 gameconfigdata = null allkapaisezhi = [] needHeCheng = 0 //需要达成条件的个数 shengyukapaizuhe = 0 yushuLabel:cc.Label = null operateNum = 0 countdown = 600 //倒计时10分钟 useTime = 0 operateRecord = [] //操作记录 bushuIndex = 0 //步数计数 zuhenum = 0 onLoad () { //关卡数据 PlayData.Instance.storageGameDate = gameStorage.Instance.getShengJiCheckOutData() PlayData.Instance.guanqia = PlayData.Instance.storageGameDate[0] this.countdown = PlayData.Instance.storageGameDate[1] this.useTime = 600 - this.countdown this.bushuIndex = PlayData.Instance.storageGameDate[6] this.updateBuShuIndex(this.bushuIndex) this.operateNum = 0 this.operateRecord = [] PlayData.Instance.gamestate = GameState.start this.notouch.active = !1 let guan = PlayData.Instance.guanqia this.gameconfigdata = Define.cl_gamedata[0] //Define.cl_gamedata[guan] console.log('打印配置信息', Define.cl_gamedata[0]) this.zuhenum = this.gameconfigdata.zuhenum + PlayData.Instance.guanqia * 5 console.log('游戏组合数量', this.zuhenum) this.dizuolayout.spacingX = this.gameconfigdata.spacex this.dizuolayout.spacingY = this.gameconfigdata.spacey this.guanstr.string = '关卡' + (guan+1) this.updateTime(this.countdown) //this.timestr.string = '00:00' this.schedule(()=>{ if(PlayData.Instance.gamestate != GameState.gaming) return this.countdown -- this.useTime++ PlayData.Instance.storageGameDate[1] = this.countdown this.updateTime(this.countdown) }, 1, cc.macro.REPEAT_FOREVER) } start () { AdsApiMgr.Instance.recording_Video_Start() this.initGameConfig() //this.initGame() } /** * 初始化一些配置 */ initGameConfig(){ let shuzu = [] this.dizuoState = PlayData.Instance.storageGameDate[2] for (let index = 0; index < this.dizuoState.length; index++) { const element = this.dizuoState[index]; let dikuang = cc.instantiate(this.dikuang) dikuang.scale = this.gameconfigdata.dizuoscale dikuang.name = 'di' + index //dikuang.on(cc.Node.EventType.TOUCH_END, this.kapainodeBtnClick, this) dikuang.parent = this.dizuo cc.find('mubiao', dikuang).active = !1 cc.find('duigou', dikuang).active = !1 if(element == 0){ cc.find('suo', dikuang).active = !0 cc.find('suoicon', dikuang).active = !0 cc.find('shipinTag', dikuang).active = !0 cc.find('yushukuang', dikuang).active = !1 }else if(element == 1){ cc.find('suo', dikuang).active = !1 cc.find('suoicon', dikuang).active = !1 cc.find('shipinTag', dikuang).active = !1 cc.find('yushukuang', dikuang).active = !1 }else if(element == 2){ cc.find('suo', dikuang).active = !0 cc.find('suoicon', dikuang).active = !0 cc.find('shipinTag', dikuang).active = !1 cc.find('yushukuang', dikuang).active = !1 }else if(element == 3){ cc.find('suo', dikuang).active = !0 cc.find('suoicon', dikuang).active = !1 cc.find('shipinTag', dikuang).active = !1 cc.find('yushukuang', dikuang).active = !0 } if(index == this.dizuoState.length-1){ this.yushuLabel = cc.find('yushukuang/hechengshu', dikuang).getComponent(cc.Label) } } if(PlayData.Instance.storageGameDate[3].length > 0){ this.allkapaisezhi = PlayData.Instance.storageGameDate[4] this.scheduleOnce(()=>{this.initGame()}, 0.6) }else{ /** 升级版本 begin */ let linshishuzu = [] this.needHeCheng = this.zuhenum var sezhizuhe = [] if(PlayData.Instance.guanqia == 0){ sezhizuhe = [1,2,3,4,5,6,7,8] }else if(PlayData.Instance.guanqia == 1){ sezhizuhe = [1,2,3,4,5,6,7,8,9,10,11,12,13] }else if(PlayData.Instance.guanqia == 2){ sezhizuhe = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18] }else { let num = 20 sezhizuhe = Utils.getRandomValueDif(1,Define.totalSeZhi-1,20) } for (let index = 0; index < this.zuhenum; index++) { let len = sezhizuhe.length-1 let randind = Utils.getRangeRandom(1, len) //console.log('打印randind=',randind) let randindex = sezhizuhe[randind] let linshidata = [randindex, randindex, randindex, randindex] linshishuzu = linshishuzu.concat(linshidata) } linshishuzu = Utils.shuffle(linshishuzu) linshishuzu = Utils.shuffle(linshishuzu) while(linshishuzu.length > 0){ let xiaozu = [] let zhi = linshishuzu.shift() xiaozu.push(zhi) zhi = linshishuzu.shift() xiaozu.push(zhi) zhi = linshishuzu.shift() xiaozu.push(zhi) zhi = linshishuzu.shift() xiaozu.push(zhi) this.allkapaisezhi.push(xiaozu) } this.scheduleOnce(()=>{this.initGame()}, 0.6) //this.moveNode.scale = this.gameconfigdata.dizuoscale /** 升级版本 end */ } } /** * 初始化 */ initGame(){ if(PlayData.Instance.storageGameDate[3].length > 0){ for (let index = 0; index < this.dizuoState.length; index++) { let di = cc.find('di'+index, this.dizuo) let kapainode = cc.find('kapainode', di) kapainode.removeAllChildren() kapainode.on(cc.Node.EventType.TOUCH_END, this.kapainodeBtnClick, this) let sezhinum = PlayData.Instance.storageGameDate[3][index] if(sezhinum.length > 0){ for (let ind = 0; ind < sezhinum.length; ind++) { const leixing = sezhinum[ind]; this.addNewKaPai(kapainode, leixing, true) } } } this.needHeCheng = PlayData.Instance.storageGameDate[5] this.yushuLabel.string = '' + this.allkapaisezhi.length }else{ let usenum = 0 for (let index = 0; index < this.dizuoState.length; index++) { //const ele = this.dizuoState[index]; let di = cc.find('di'+index, this.dizuo) let kapainode = cc.find('kapainode', di) kapainode.removeAllChildren() kapainode.on(cc.Node.EventType.TOUCH_END, this.kapainodeBtnClick, this) PlayData.Instance.storageGameDate[3][index] = [] if(this.dizuoState[index] == 1 && -1 == this.gameconfigdata.kong.indexOf(index)){ let sezhinum = this.allkapaisezhi.shift() PlayData.Instance.storageGameDate[3][index] = sezhinum for (let index = 0; index < sezhinum.length; index++) { const leixing = sezhinum[index]; this.addNewKaPai(kapainode, leixing, true) } usenum ++ }else if(index == (this.dizuoState.length-1)){ let sezhinum = this.allkapaisezhi.shift() PlayData.Instance.storageGameDate[3][index] = sezhinum for (let index = 0; index < sezhinum.length; index++) { const leixing = sezhinum[index]; this.addNewKaPai(kapainode, leixing, true) } usenum ++ } } PlayData.Instance.storageGameDate[4] = this.allkapaisezhi gameStorage.Instance.setShengJiCheckOutData(PlayData.Instance.storageGameDate) this.yushuLabel.string = '' + this.allkapaisezhi.length } } /** * 视频解锁 卡槽 */ videoJieSuoDiZuo(num){ this.dizuoState[num] = 1 this.linshiOperatorNum[num] = 0 let di = cc.find('di'+num, this.dizuo) let suo = cc.find('suo', di) suo.active = !1 cc.find('suoicon', di).active = !1 cc.find('shipinTag', di).active = !1 PlayData.Instance.storageGameDate[2][num] = 1 gameStorage.Instance.setShengJiCheckOutData(PlayData.Instance.storageGameDate) // if(num == 11){ // this.linshijiesuo = 9 // }else{ // this.linshijiesuo = num + 1 // } // if(this.dizuoState[this.linshijiesuo] == 0){ // let nextsuo = cc.find('di'+(this.linshijiesuo) + '/suo', this.dizuo).getComponent(cc.Sprite) // cc.resources.load('kapaikuang/dikuang3', cc.SpriteFrame, (err, assert)=>{ // if(err) return console.error(err) // nextsuo.spriteFrame = assert as cc.SpriteFrame // }) // } AudioManager.playEffect(soundName.kaikacao) } /** * 点击一堆牌 */ kapainodeBtnClick(t){ //开始游戏 计时 PlayData.Instance.gamestate = GameState.gaming let moveUp = this.moveUp let parentname:string = t.currentTarget.parent.name let chaifen = parentname.split('di') let e = chaifen[1] if(this.selectIndex == -1){ if(this.dizuoState[Number(e)] == 2){return} if(this.dizuoState[Number(e)] == 0){ //未解锁 var self = this AdsApiMgr.Instance.motivational_Video_Show(()=>{ self.videoJieSuoDiZuo(Number(e)) }, ()=>{}) return } if(t.currentTarget.children.length > 0){ AudioManager.playEffect(soundName.xuanka) let selectTarget = t.currentTarget let lastnode = selectTarget.children[selectTarget.children.length - 1] let lastnodesc:kapaiSc = lastnode.getComponent(kapaiSc) this.selectIndex = Number(e) //选中的 for (let index = selectTarget.children.length; index > 0; index--) { let zinode = selectTarget.children[index-1] let sc:kapaiSc = zinode.getComponent(kapaiSc) if(sc.kaNum != lastnodesc.kaNum){ break }else{ zinode.y += moveUp //this.selectNodeArr.push(zinode) this.selectNodeArr.push(zinode) //zinode.getComponent(cc.Animation).play() } } if(this.selectNodeArr.length == 4){ this.kapaiReset() this.operateRecord = [] this.heChengKaPai(selectTarget, this.selectIndex) this.notouch.active = !0 }else{ this.operateRecord[2] = selectTarget } } }else{ if(this.dizuoState[Number(e)] == 2){return this.kapaiReset()} if(this.dizuoState[Number(e)] == 0){return TipsManager.Instance.createTips('未解锁')} if(this.selectIndex == Number(e)){ //点击相同位置,复位 AudioManager.playEffect(soundName.xuanka) this.kapaiReset() }else{ //移到对应的位置 this.mubiaoIndex = Number(e) this.operateRecord[0] = [] if(t.currentTarget.children.length >= this.maxKaPaiNum){ //点击的位置满了 this.kapaiReset(1) return }else if(t.currentTarget.children.length == 0){ //点击的位置 没有卡牌 ,选中的全部移动 this.bushuIndex++ this.updateBuShuIndex(this.bushuIndex) let moveindex = 0 for (let index = this.selectNodeArr.length; index > 0; index--) { const element = this.selectNodeArr[index-1]; //element.getComponent(cc.Animation).stop() //element.scale = 1 this.moveKaPai(element, t.currentTarget) this.operateRecord[0].push(element) moveindex ++ } if(cc.find('di' + this.selectIndex + '/duigou', this.dizuo).active == !0){ cc.find('di' + this.selectIndex + '/duigou', this.dizuo).active = !1 this.needHeCheng++ } let kapainode = cc.find('di' + this.selectIndex + '/kapainode', this.dizuo) this.scheduleOnce(()=>{this.checkWenHao(kapainode)}, this.selectNodeArr.length*this.time01+0.2) this.selectIndex = -1 this.selectNodeArr = [] this.operateRecord[1] = t.currentTarget return } this.bushuIndex++ this.updateBuShuIndex(this.bushuIndex) let mubiaochildren = t.currentTarget.children let selectchildren = this.selectNodeArr let mubiaonode = mubiaochildren[mubiaochildren.length - 1] let mubiaonodesc = mubiaonode.getComponent(kapaiSc) let selectnode = selectchildren[0] let selectnodesc = selectnode.getComponent(kapaiSc) let parent = selectnode.parent let cha = parent.children.length - selectchildren.length if(selectnodesc.kaNum == mubiaonodesc.kaNum){ //选中和要放置的位置最上面的卡牌一样 可以移动 let moveindex = 0 let totalnum = t.currentTarget.children.length let duoyu = 0 for (let index = this.selectNodeArr.length; index > 0; index--) { const element = this.selectNodeArr[index-1]; //element.getComponent(cc.Animation).stop() //element.scale = 1 if(totalnum + moveindex >= this.maxKaPaiNum){ element.x = this.posXY[cha + duoyu][0] element.y = this.posXY[cha + duoyu][1] duoyu++ }else{ let zongtime = 0 if((totalnum + this.selectNodeArr.length) > this.maxKaPaiNum){ let yushu = this.maxKaPaiNum - totalnum zongtime = yushu * this.time01 }else{ zongtime = this.selectNodeArr.length * this.time01 } //let deltime = 0.1*moveindex this.moveKaPai(element, t.currentTarget) this.operateRecord[0].push(element) moveindex ++ } } if(cc.find('di' + this.selectIndex + '/duigou', this.dizuo).active == !0){ cc.find('di' + this.selectIndex + '/duigou', this.dizuo).active = !1 this.needHeCheng++ } let kapainode = cc.find('di' + this.selectIndex + '/kapainode', this.dizuo) this.scheduleOnce(()=>{this.checkWenHao(kapainode)}, this.selectNodeArr.length*this.time01+0.2) this.selectIndex = -1 this.selectNodeArr = [] this.operateRecord[1] = t.currentTarget }else{ this.kapaiReset(1) return } } } } /** * 卡牌复位 */ kapaiReset(leixing?){ let movetime = 0.04 let mx = 5 for (let index = 0; index < this.selectNodeArr.length; index++) { const zinode = this.selectNodeArr[index]; const px = zinode.x if(leixing == 1){ AudioManager.playEffect(soundName.dingdong) zinode.getComponent(cc.Animation).stop() zinode.scale = 0.85 cc.tween(zinode) .to(movetime, {x:px-mx}) .to(movetime, {x:px}) .to(movetime, {x:px+mx}) .to(movetime, {x:px}) .to(movetime, {x:px-mx}) .to(movetime, {x:px}) .to(movetime, {x:px+mx}) .to(movetime, {x:px}) .call(()=>{ zinode.y -= this.moveUp }) .start() }else{ zinode.getComponent(cc.Animation).stop() zinode.scale = 0.85 zinode.y -= this.moveUp } } this.selectIndex = -1 this.selectNodeArr = [] } /** * 移动卡牌 * @param znode * @param nodeparent * @param deltime */ moveKaPai(znode, nodeparent){ let chaifen = nodeparent.parent.name.split('di') let weizhi = chaifen[1] let newpos0 = znode.parent.convertToWorldSpaceAR(znode.position) let newpos1 = this.moveNode.convertToNodeSpaceAR(newpos0) //this.moveNode 是个过渡节点 保障移动的节点在最上层 znode.x = newpos1.x znode.y = newpos1.y znode.parent = this.moveNode let key = nodeparent.children.length-1+this.moveNode.children.length let newpos22 = cc.v2(this.posXY[key][0], this.posXY[key][1]) let newpos2 = nodeparent.convertToWorldSpaceAR(newpos22) let newpos3 = this.moveNode.convertToNodeSpaceAR(newpos2) let newpos4 = cc.v3(newpos3.x,newpos3.y,0) var self = this cc.tween(znode) .to(0.12,{position:newpos4}) .call(()=>{ AudioManager.playEffect(soundName.moveka) znode.position = cc.v3(self.posXY[nodeparent.children.length][0], self.posXY[nodeparent.children.length][1], 0) znode.parent = nodeparent if(nodeparent.children.length == self.maxKaPaiNum){ let tongse = !0 let lastnode = nodeparent.children[nodeparent.children.length - 1] let lastnodesc:kapaiSc = lastnode.getComponent(kapaiSc) for (let index = 0; index { if(this.needHeCheng > 0){//发牌 this.needHeCheng -- this.notouch.active = !1 this.fapaiOperate(nodeparent, weizhi) if(this.needHeCheng <= 0){ this.notouch.active = !0 //let openState = gameStorage.Instance.getChallengeCheckOpenState() //openState[PlayData.Instance.guanqia+1] = 1 //gameStorage.Instance.setChallengeCheckOpenState(openState) PlayData.Instance.guanqia++ gameStorage.Instance.resetShengJiCheckOutData(PlayData.Instance.guanqia) AdsApiMgr.Instance.setImRankData_Num('' + PlayData.Instance.guanqia) PlayData.Instance.gamestate = GameState.end this.schedule(()=>{ this.addYanHua() }, 0.8, cc.macro.REPEAT_FOREVER) this.scheduleOnce(()=>{ AdsApiMgr.Instance.recording_Video_End() let newnode:cc.Node = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.challengeSuccess]) newnode.parent = this.node let sc = newnode.getComponent(ChallengeSuccessSc) let str = Utils.secondsFormat(this.useTime, false) sc.showPanel(str) }, 1) } } }, 0.6) } /** * 发牌操作 * @param nodeparent * @param fapaiweizhi 需要发牌的位置 */ fapaiOperate(nodeparent,fapaiweizhi){ let diname = 'di' + (this.gameconfigdata.dikuangnum - 1) let kapainode = cc.find(diname + '/kapainode' , this.dizuo) let len = kapainode.children.length if(len > 0){ for (let index = 0; index < kapainode.children.length; index++) { const element = kapainode.children[index]; this.selectNodeArr.push(element) } }else{ this.closeDiKuang(fapaiweizhi) return console.log('没有存储的卡牌') } let moveindex = 0 for (let index = this.selectNodeArr.length; index > 0; index--) { const element = this.selectNodeArr[index-1]; this.moveKaPai(element, nodeparent) moveindex ++ } this.selectIndex = -1 this.selectNodeArr = [] if(this.allkapaisezhi.length <= 0){ this.closeDiKuang(this.gameconfigdata.dikuangnum - 1) return } //无剩余卡牌 this.scheduleOnce(()=>{ AudioManager.playEffect(soundName.fapai) let sezhinum = this.allkapaisezhi.shift() PlayData.Instance.storageGameDate[4] = this.allkapaisezhi this.storageCheckOutData() for (let index = 0; index < sezhinum.length; index++) { const leixing = sezhinum[index]; this.addNewKaPai(kapainode, leixing, true) } //this.shengyukapaizuhe-- this.yushuLabel.string = '' + this.allkapaisezhi.length }, 0.3) } /** * 关闭底框 * @param id */ closeDiKuang(id){ PlayData.Instance.storageGameDate[2][id] = 2 this.storageCheckOutData() this.dizuoState[id] = 2 let dikuang = cc.find('di' + id, this.dizuo) cc.find('suo', dikuang).active = !0 cc.find('suoicon', dikuang).active = !0 } /** * 添加新牌 * @param parentnode 父节点 * @param kanum 卡牌num */ addNewKaPai(parentnode, kanum, isfapai = false){ let newnode:cc.Node = cc.instantiate(this.kapaiPre) newnode.scale = 0.85 newnode.parent = parentnode let kapaisc = newnode.getComponent(kapaiSc) kapaisc.setKaNum(kanum) if(isfapai == !0){ newnode.y = -cc.winSize.height/2 - parentnode.parent.y cc.tween(newnode) .to(0.2, {position:cc.v3(this.posXY[parentnode.children.length-1][0],this.posXY[parentnode.children.length-1][1],0) }) .call(()=>{ if(parentnode.children.length >= this.maxKaPaiNum){ //添加卡牌满10 let tongse = !0 let lastnode = parentnode.children[parentnode.children.length - 1] let lastnodesc:kapaiSc = lastnode.getComponent(kapaiSc) for (let index = 0; index 0){ let lastnode = childrennode[childrennode.length-1] let lastnodesc = lastnode.getComponent(kapaiSc) if(lastnodesc.kaNum == 0){ for (let ind = childrennode.length; ind > 0; ind--) { const element = childrennode[ind-1]; let elsc:kapaiSc = element.getComponent(kapaiSc) if(elsc.kaNum != lastnodesc.kaNum){ break }else{ selectarr.push(element) } } } } //let leixing = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2) for (let index = 0; index < selectarr.length; index++) { let sc = selectarr[index].getComponent(kapaiSc) sc.setKaNum(sc.bianshu) sc.node.scale = 0 cc.tween(sc.node) .to(0.1, {scale:1}) .start() } } /** * 更新时间 * @param index */ updateTime(index){ let str = Utils.secondsFormat(index, false) this.timestr.string = '' + str if(index == 0){ //时间到了 AdsApiMgr.Instance.recording_Video_End() PlayData.Instance.gamestate = GameState.wait let newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.timeOutPanel]) newnode.parent = cc.director.getScene() let sc = newnode.getComponent(TimeOutPanelSc) sc.setGameSc(this) } } /** * 更新步数 * @param index */ updateBuShuIndex(index){ this.bushustr.string = '步数:' + index } // update (dt) {} /** * 添加烟花 */ addYanHua(){ let winSize = cc.winSize let xx = Utils.getRangeRandom(-winSize.width/2+50, winSize.width/2-50) let yy = Utils.getRangeRandom(-winSize.height/2+50, winSize.height/2-50) let newyanhua:cc.Node = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.yanhua]) newyanhua.position = cc.v3(xx, yy, 0) newyanhua.parent = this.node // let ani = newyanhua.getComponent(sp.Skeleton) // let skinid = Utils.getRangeRandom(1, 5) // ani.setSkin('' + skinid) cc.tween(newyanhua) .delay(0.8) .removeSelf() .start() } /** * 按钮点击 * @param t * @param e */ uiBntClickCallBack(t, e){ var self = this if(e == 'chehui'){ TrackingManager.send(TrackingType.Retract); if(this.operateRecord.length > 0){ AdsApiMgr.Instance.motivational_Video_Show(()=>{ self.cancelOperate() self.operateRecord = [] }, ()=>{}) }else{ TipsManager.Instance.createTips('无操作可撤回') } }else if(e == 'daluan'){ TrackingManager.send(TrackingType.Shuffle); self.operateRecord = [] AdsApiMgr.Instance.motivational_Video_Show(()=>{ self.daluanOperate() }, ()=>{}) }else if(e == 'tishi'){ }else if(e == 'guizi'){ TrackingManager.send(TrackingType.Cabinet); self.addGuiZiOperate() self.operateRecord = [] // AdsApiMgr.Instance.motivational_Video_Show(()=>{ // }, ()=>{}) } } /** * 撤回操作 */ cancelOperate(){ let selectnode = this.operateRecord[0] for (let index = 0; index < selectnode.length; index++) { const element = selectnode[index]; this.moveKaPai(element, this.operateRecord[2]) } } /** * 打乱操作 */ daluanOperate(){ let linshiNodeArr = [] let linshidata = [] this.notouch.active = !0 for (let index = 0; index < this.dizuoState.length-1; index++) { let state = this.dizuoState[index] if(state == 1){ let diname = 'di' + index let kapainode = cc.find(diname + '/kapainode' , this.dizuo) linshidata[index] = kapainode.children.length while(kapainode.children.length > 0){ let element = kapainode.children[0] let newpos0 = element.parent.convertToWorldSpaceAR(element.position) let newpos1 = this.moveNode.convertToNodeSpaceAR(newpos0) //this.moveNode 是个过渡节点 保障移动的节点在最上层 element.position = newpos1 element.parent = this.moveNode cc.tween(element) .to(0.2, {position:cc.v3(0,0,0)}) .start() linshiNodeArr.push(element) } }else{ linshidata[index] = 0 } } linshiNodeArr = Utils.shuffle(linshiNodeArr) this.scheduleOnce(()=>{ for (let index = 0; index < linshidata.length; index++) { const numarr = linshidata[index]; let diname = 'di' + index let kapainode = cc.find(diname + '/kapainode' , this.dizuo) for (let ind = 0; ind < numarr; ind++) { let kapai = linshiNodeArr.pop() //kapai.parent = kapainode //kapai.position = cc.v3(0,0,0) let key = ind //nodeparent.children.length-1+this.moveNode.children.length let newpos22 = cc.v2(this.posXY[key][0], this.posXY[key][1]) let newpos2 = kapainode.convertToWorldSpaceAR(newpos22) let newpos3 = this.moveNode.convertToNodeSpaceAR(newpos2) let newpos4 = cc.v3(newpos3.x,newpos3.y,0) var self = this cc.tween(kapai) .to(0.12, {position:newpos4}) .call(()=>{ kapai.position = cc.v3(self.posXY[kapainode.children.length][0], self.posXY[kapainode.children.length][1], 0) kapai.parent = kapainode }) .start() } } this.notouch.active = !1 },0.3) } /** * 添加柜子操作 */ addGuiZiOperate(){ let canOperate = !1 let shengyukongwei = [] let selectindex = -1 let selectkapainode = null let xiaoshu = 4 for (let index = 0; index < this.dizuoState.length - 1; index++) { let state = this.dizuoState[index] if(state == 1){ let diname = 'di' + index let kapainode = cc.find(diname + '/kapainode' , this.dizuo) if(kapainode.children.length > 0 && kapainode.children.length != 4){ if(xiaoshu > kapainode.children.length){ xiaoshu = kapainode.children.length selectindex = index selectkapainode = kapainode } } } } if(selectindex != -1){ var self = this AdsApiMgr.Instance.motivational_Video_Show(()=>{ self.addGuiZiMoveKaPai(selectkapainode, selectindex) }, ()=>{}) }else{ TipsManager.Instance.createTips('无需操作') } } /** * 添加柜子 操作 分配卡牌 * @param selectnode * @param selectindex */ addGuiZiMoveKaPai(selectnode, selectindex){ // let selectArr = [] // for (let index = 0; index < selectnode.children.length; index++) { // const element = selectnode.children[index]; // selectArr.push(element) // } var self = this let totalnum = selectnode.children.length let yidongindex = 0 for (let index = 0; index < this.dizuoState.length-1; index++) { let state = this.dizuoState[index] if(state == 1){ let diname = 'di' + index let kapainode = cc.find(diname + '/kapainode' , this.dizuo) if(kapainode.children.length > 0 && kapainode.children.length != 4 && index != selectindex){ let chanum = 4 - kapainode.children.length for (let ind = 0; ind < chanum; ind++) { if(totalnum > yidongindex){ const element = selectnode.children[yidongindex] cc.tween(element) .delay(0.2* yidongindex) .call(()=>{ self.moveKaPai(element, kapainode) }) .start() yidongindex ++ }else{ break } } } } } } /** * 存储关卡数据 */ storageCheckOutData(){ PlayData.Instance.storageGameDate[3] = [] for (let index = 0; index < this.dizuoState.length; index++) { PlayData.Instance.storageGameDate[3][index] = [] let di = cc.find('di'+index, this.dizuo) let kapainode = cc.find('kapainode', di) let children = kapainode.children if(children.length > 0){ for (let ind = 0; ind < children.length; ind++) { const element = children[ind]; let sc = element.getComponent(kapaiSc) PlayData.Instance.storageGameDate[3][index].push(sc.kaNum) } } } PlayData.Instance.storageGameDate[2] = this.dizuoState PlayData.Instance.storageGameDate[5] = this.needHeCheng PlayData.Instance.storageGameDate[6] = this.bushuIndex gameStorage.Instance.setShengJiCheckOutData(PlayData.Instance.storageGameDate) } }