1151 lines
46 KiB
TypeScript
1151 lines
46 KiB
TypeScript
/**
|
||
* 游戏 节点
|
||
*/
|
||
|
||
import AudioManager from "../../Tools/AudioManager";
|
||
import Define from "../../Tools/Define";
|
||
import GameResMgr, { soundName, uiPreName } from "../../Tools/GameResMgr";
|
||
import PlayData from "../../Tools/PlayData";
|
||
import AdsApiMgr from "../../Tools/Sdk/ads/AdsApiMgr";
|
||
import Utils from "../../Tools/Utils";
|
||
import gameStorage from "../../Tools/gameStorage";
|
||
import TipsManager from "../TipsManager";
|
||
import LevelBarSc from "./LevelBarSc";
|
||
import NumLevelUpPanelSc from "./NumLevelUpPanelSc";
|
||
import kapaiSc from "./kapaiSc";
|
||
import {TrackingManager, TrackingType} from "../../Tracking/TrackingManager";
|
||
|
||
const {ccclass, property} = cc._decorator;
|
||
|
||
@ccclass
|
||
export default class GameSc extends cc.Component {
|
||
@property(cc.Prefab)
|
||
kapaiPre:cc.Prefab = null
|
||
|
||
//@property(cc.Node)
|
||
//gameNode:cc.Node = null
|
||
|
||
@property(cc.Node)
|
||
dizuo:cc.Node = null
|
||
|
||
@property(cc.Node) //用于移动卡牌 过渡节点 ,移动卡牌的时候 ,卡牌在最高层
|
||
moveNode:cc.Node = null
|
||
|
||
@property(LevelBarSc)
|
||
levelbarSc:LevelBarSc = null
|
||
|
||
@property(cc.Node)
|
||
notouch:cc.Node = null
|
||
|
||
@property(cc.Node)
|
||
xipaiBtn:cc.Node = null
|
||
|
||
@property(cc.Node)
|
||
fapaiBtn:cc.Node = null
|
||
|
||
@property(cc.Node)
|
||
hechengBtn:cc.Node = null
|
||
|
||
dizuoState = [1,1,1,1,
|
||
1,0,0,0,
|
||
0,0,0,0] //底座状态 0未解锁,1解锁
|
||
|
||
levelNum = 0
|
||
mixlevelNum = 0
|
||
|
||
moveUp = 15
|
||
|
||
selectNodeArr = [] //选中的节点
|
||
selectIndex = -1
|
||
mubiaoIndex = -1
|
||
|
||
allNodeArr = []
|
||
|
||
posY = [0, -20, -40, -60, -80, -100, -120, -140, -160, -180]
|
||
|
||
maxKaPaiNum = 10 //一个框最多放置 数量
|
||
|
||
linshijiesuo = 0 //可用于临时解锁的id
|
||
|
||
linshiOperatorNum = [] //一个临时卡槽 操作一定的次数后,会关闭
|
||
|
||
time01 = 0.01
|
||
|
||
weizhigailv = 1
|
||
|
||
//gameData = null
|
||
|
||
dizuoKaPaiNum = []
|
||
|
||
onLoad () {
|
||
PlayData.Instance.storageGameDate = gameStorage.Instance.getCheckOutData()
|
||
PlayData.Instance.guanqia = PlayData.Instance.storageGameDate[0]
|
||
this.levelbarSc.jindu = PlayData.Instance.storageGameDate[1]
|
||
this.notouch.active = !1
|
||
|
||
//console.log('打印进度', this.levelbarSc.jindu)
|
||
|
||
this.fapaiBtn.active = !1
|
||
this.hechengBtn.active = !1
|
||
}
|
||
|
||
start () {
|
||
AdsApiMgr.Instance.recording_Video_Start()
|
||
this.scheduleOnce(()=>{this.initGame()}, 0.6)
|
||
//this.initGame()
|
||
//console.log('打印关卡数据', PlayData.Instance.guanqia)
|
||
}
|
||
|
||
/**
|
||
* 初始化
|
||
*/
|
||
initGame(){
|
||
this.xipaiBtn.active = !1
|
||
|
||
this.levelNum = this.levelbarSc.levelnum[this.levelbarSc.jindu]
|
||
this.mixlevelNum = this.levelNum - 4
|
||
//this.mixlevelNum = 5+5*PlayData.Instance.guanqia+PlayData.Instance.guanqia - 4 //正式版本
|
||
|
||
this.linshijiesuo = PlayData.Instance.storageGameDate[2]
|
||
this.linshiOperatorNum = PlayData.Instance.storageGameDate[3]
|
||
|
||
//this.linshijiesuo = 9
|
||
//this.linshiOperatorNum = [0,0,0,0,0,0,0,0,0,0,0,0]
|
||
|
||
//临时卡位
|
||
for (let index = 9; index < 12; index++) {
|
||
if(this.linshiOperatorNum[index] >= 0){
|
||
this.dizuoState[index] = 1
|
||
let di = cc.find('di'+index, this.dizuo)
|
||
let suo = cc.find('suo', di)
|
||
suo.active = !1
|
||
}else{
|
||
if(index == this.linshijiesuo){
|
||
let nextsuo = cc.find('di'+index + '/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
|
||
})
|
||
}else{
|
||
let nextsuo = cc.find('di'+index + '/suo', this.dizuo).getComponent(cc.Sprite)
|
||
cc.resources.load('kapaikuang/dikuang2', cc.SpriteFrame, (err, assert)=>{
|
||
if(err) return console.error(err)
|
||
nextsuo.spriteFrame = assert as cc.SpriteFrame
|
||
})
|
||
}
|
||
}
|
||
}
|
||
|
||
//console.log('打印设定的进度', this.levelbarSc.jindu)
|
||
for (let index = 0; index < this.levelbarSc.jindu; index++) {
|
||
this.dizuoState[5+index] = 1
|
||
}
|
||
|
||
if(PlayData.Instance.storageGameDate[4].length > 0){
|
||
let kknumarr = PlayData.Instance.storageGameDate[4]
|
||
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()
|
||
cc.find('selectkuang', di).active = !1
|
||
|
||
if(this.dizuoState[index] == 1){
|
||
let kknum = kknumarr[index]
|
||
for (let ind = 0; ind < kknum.length; ind++) {
|
||
const leixing = kknum[ind];
|
||
let wenhao = !1
|
||
if(leixing == 0 && kknum[ind+1] != 0){
|
||
wenhao = !0
|
||
}
|
||
this.addNewKaPai(kapainode, leixing, true, wenhao)
|
||
}
|
||
if(cc.find('suo', di)){
|
||
cc.find('suo', di).active = !1
|
||
}
|
||
}else{
|
||
cc.find('suo', di).active = !0
|
||
}
|
||
}
|
||
//console.log('打印底座状态', this.dizuoState)
|
||
this.scheduleOnce(()=>{
|
||
this.checkNeedXiPai()
|
||
}, 0.4)
|
||
}else{
|
||
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()
|
||
cc.find('selectkuang', di).active = !1
|
||
|
||
//this.allNodeArr[index] = []
|
||
|
||
let kknum = []
|
||
|
||
if(this.dizuoState[index] == 1){
|
||
let cengshu = Utils.getRangeRandom(1, 2) //层数
|
||
//console.log('打印随机的层数', cengshu)
|
||
for (let ind = 0; ind < cengshu; ind++) {
|
||
//let leixing = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2) //类型
|
||
let leixing = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 1) //类型
|
||
let randshu = Utils.getRangeRandom(2,4) //每层的数
|
||
for (let inde = 0; inde < randshu; inde++) {
|
||
// let newnode:cc.Node = cc.instantiate(this.kapaiPre)
|
||
// newnode.y = this.posY[kapainode.children.length]
|
||
// newnode.parent = kapainode
|
||
// let kapaisc = newnode.getComponent(kapaiSc)
|
||
// kapaisc.setKaNum(leixing)
|
||
|
||
this.addNewKaPai(kapainode, leixing, true)
|
||
//this.allNodeArr[index].push(newnode)
|
||
kknum.push(leixing)
|
||
}
|
||
}
|
||
if(cc.find('suo', di)){
|
||
cc.find('suo', di).active = !1
|
||
}
|
||
}else{
|
||
cc.find('suo', di).active = !0
|
||
}
|
||
PlayData.Instance.storageGameDate[4].push(kknum)
|
||
gameStorage.Instance.setCheckOutData(PlayData.Instance.storageGameDate)
|
||
}
|
||
}
|
||
//console.log('打印底座卡牌的数据', PlayData.Instance.storageGameDate[4])
|
||
|
||
this.scheduleOnce(()=>{
|
||
this.fapaiBtn.active = !0
|
||
this.hechengBtn.active = !0
|
||
}, 0.5)
|
||
}
|
||
|
||
/**
|
||
* 视频解锁 卡槽
|
||
*/
|
||
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
|
||
if(num == 11){
|
||
this.linshijiesuo = 9
|
||
}else{
|
||
this.linshijiesuo = num + 1
|
||
}
|
||
PlayData.Instance.storageGameDate[2] = this.linshijiesuo
|
||
this.storageCheckOutData()
|
||
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)
|
||
}
|
||
closeJieSuoDiZuo(num){
|
||
this.dizuoState[num] = 0
|
||
this.linshiOperatorNum[num] = -1
|
||
let suo = cc.find('di'+ num + '/suo', this.dizuo).getComponent(cc.Sprite)
|
||
suo.node.active = !0
|
||
|
||
let kuangpath = ''
|
||
if(num == this.linshijiesuo){
|
||
kuangpath = '' + 'kapaikuang/dikuang3'
|
||
}else{
|
||
kuangpath = '' + 'kapaikuang/dikuang2'
|
||
}
|
||
|
||
cc.resources.load(kuangpath, cc.SpriteFrame, (err, assert)=>{
|
||
if(err) return console.error(err)
|
||
suo.spriteFrame = assert as cc.SpriteFrame
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 点击一堆牌
|
||
*/
|
||
kapainodeBtnClick(t, e){
|
||
let moveUp = this.moveUp
|
||
|
||
if(this.selectIndex == -1){
|
||
if(this.dizuoState[Number(e)] == 0){ //未解锁
|
||
if(Number(e) >= 5 && Number(e) <= 8){
|
||
let mubiaolevelnum = this.levelbarSc.levelnum[this.levelbarSc.jindu]
|
||
TipsManager.Instance.createTips('下个目标>>' + mubiaolevelnum + '解锁卡槽')
|
||
}else if(Number(e) >= 9 && Number(e) <= 11 && Number(e) == this.linshijiesuo){
|
||
TrackingManager.send(TrackingType.TemporaryCabinet);
|
||
|
||
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)
|
||
|
||
if(t.currentTarget.children.length >= this.maxKaPaiNum){ //一堆 9个同色不可点击
|
||
let tongse = !0
|
||
for (let index = 0; index < t.currentTarget.children.length; index++) {
|
||
const element = t.currentTarget.children[index];
|
||
let elsc:kapaiSc = element.getComponent(kapaiSc)
|
||
if(elsc.kaNum != lastnodesc.kaNum){
|
||
tongse = !1
|
||
break
|
||
}
|
||
}
|
||
if(tongse == !0){
|
||
cc.tween(t.currentTarget)
|
||
.to(0.1,{y:120})
|
||
.to(0.1,{y:100})
|
||
.start()
|
||
return
|
||
}
|
||
}
|
||
|
||
this.selectIndex = Number(e) //选中的
|
||
|
||
for (let index = selectTarget.children.length; index > 0; index--) {
|
||
//console.log('打印index=', index-1)
|
||
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()
|
||
}
|
||
}
|
||
}
|
||
}else{
|
||
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)
|
||
for (let index = 9; index < 12; index++) { //判断临时卡槽
|
||
if(this.dizuoState[index] != 0){
|
||
this.linshiOperatorNum[index]++
|
||
//console.log('操作次数', this.linshiOperatorNum)
|
||
if(this.linshiOperatorNum[index] > 5 && index != this.mubiaoIndex){
|
||
this.closeLinShiKaCao(index)
|
||
}
|
||
}
|
||
}
|
||
|
||
if(t.currentTarget.children.length >= this.maxKaPaiNum){ //点击的位置满了
|
||
this.kapaiReset(1)
|
||
return
|
||
}else if(t.currentTarget.children.length == 0){ //点击的位置 没有卡牌 ,选中的全部移动
|
||
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
|
||
let deltime = this.selectNodeArr.length*this.time01 - this.time01*moveindex
|
||
this.moveKaPai(element, t.currentTarget, deltime)
|
||
let sc = element.getComponent(kapaiSc)
|
||
moveindex ++
|
||
|
||
PlayData.Instance.storageGameDate[4][this.selectIndex].pop()
|
||
PlayData.Instance.storageGameDate[4][Number(e)].push(sc.kaNum)
|
||
}
|
||
this.storageCheckOutData()
|
||
|
||
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 = []
|
||
|
||
|
||
return
|
||
}
|
||
|
||
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.y = this.posY[cha + duoyu]
|
||
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
|
||
let deltime = zongtime - this.time01*moveindex
|
||
this.moveKaPai(element, t.currentTarget, deltime)
|
||
moveindex ++
|
||
|
||
PlayData.Instance.storageGameDate[4][this.selectIndex].pop()
|
||
PlayData.Instance.storageGameDate[4][Number(e)].push(selectnodesc.kaNum)
|
||
}
|
||
}
|
||
this.storageCheckOutData()
|
||
|
||
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 = []
|
||
}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];
|
||
|
||
if(leixing == 1){
|
||
AudioManager.playEffect(soundName.dingdong)
|
||
zinode.getComponent(cc.Animation).stop()
|
||
zinode.scale = 1
|
||
cc.tween(zinode)
|
||
.to(movetime, {x:-mx})
|
||
.to(movetime, {x:0})
|
||
.to(movetime, {x:mx})
|
||
.to(movetime, {x:0})
|
||
.to(movetime, {x:-mx})
|
||
.to(movetime, {x:0})
|
||
.to(movetime, {x:mx})
|
||
.to(movetime, {x:0})
|
||
.call(()=>{
|
||
zinode.y -= this.moveUp
|
||
})
|
||
.start()
|
||
}else{
|
||
zinode.getComponent(cc.Animation).stop()
|
||
zinode.scale = 1
|
||
zinode.y -= this.moveUp
|
||
}
|
||
|
||
}
|
||
this.selectIndex = -1
|
||
this.selectNodeArr = []
|
||
}
|
||
|
||
/**
|
||
* 关闭临时卡槽
|
||
*/
|
||
closeLinShiKaCao(index){
|
||
let di = cc.find('di'+index, this.dizuo)
|
||
let kapainode = cc.find('kapainode', di)
|
||
if(kapainode.children.length == 0){
|
||
this.closeJieSuoDiZuo(index)
|
||
}else{
|
||
let lastnode = kapainode.children[kapainode.children.length - 1]
|
||
let lastnodesc:kapaiSc = lastnode.getComponent(kapaiSc)
|
||
let tongse = !0
|
||
|
||
let selectNodeArr = []
|
||
for (let inde = kapainode.children.length; inde > 0; inde--) {
|
||
let zinode = kapainode.children[inde-1]
|
||
let elsc:kapaiSc = zinode.getComponent(kapaiSc)
|
||
if(elsc.kaNum != lastnodesc.kaNum){
|
||
tongse = !1
|
||
break
|
||
}
|
||
selectNodeArr.push(zinode)
|
||
}
|
||
|
||
if(tongse == !0){
|
||
for (let mm = 0; mm < 9; mm++) {
|
||
let mdi = cc.find('di'+mm, this.dizuo)
|
||
let mkpnode = cc.find('kapainode', mdi)
|
||
if(mkpnode.children.length == 0 && this.dizuoState[mm] == 1
|
||
&& mm != this.selectIndex && mm != this.mubiaoIndex && this.selectIndex != index){
|
||
let moveindex = 0
|
||
for (let ind = selectNodeArr.length; ind > 0; ind--) {
|
||
const element = selectNodeArr[ind-1];
|
||
let deltime = selectNodeArr.length*this.time01 - this.time01*moveindex
|
||
this.moveKaPai(element, mkpnode, deltime)
|
||
element.getComponent(cc.Animation).stop()
|
||
element.scale = 1
|
||
moveindex ++
|
||
}
|
||
|
||
this.scheduleOnce(()=>{
|
||
this.closeJieSuoDiZuo(index)
|
||
}, 0.4)
|
||
break
|
||
}else{
|
||
// let mmnode = mkpnode.children[mkpnode.children.length - 1]
|
||
// let mmnodesc:kapaiSc = mmnode.getComponent(kapaiSc)
|
||
// if(mmnodesc.kaNum == selectNodeArr[0].getComponent(kapaiSc).kaNum &&
|
||
// (selectNodeArr.length + mkpnode.children.length)<=10 && this.dizuoState[mm] == 1){
|
||
// let moveindex = 0
|
||
// for (let ind = selectNodeArr.length; ind > 0; ind--) {
|
||
// const element = selectNodeArr[ind-1];
|
||
// let deltime = selectNodeArr.length*0.1 - 0.1*moveindex
|
||
// this.moveKaPai(element, mkpnode, deltime)
|
||
// moveindex ++
|
||
// }
|
||
// break
|
||
// }
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 按钮点击事件
|
||
* @param t
|
||
* @param e
|
||
*/
|
||
btnClickCallBack(t, e){
|
||
if(e == 'fapai'){
|
||
this.fapaiOperate()
|
||
}else if(e == 'hecheng'){
|
||
this.checkHeCheng()
|
||
}else if(e == 'xipai'){
|
||
TrackingManager.send(TrackingType.Shuffle);
|
||
|
||
var self = this
|
||
AdsApiMgr.Instance.motivational_Video_Show(()=>{
|
||
self.xipaiOperate()
|
||
}, ()=>{})
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 发牌操作
|
||
*/
|
||
fapaiOperate(){
|
||
this.kapaiReset()
|
||
|
||
//先检测那些地方能发牌 能发几张
|
||
let datearr = []
|
||
for (let index = 0; index < this.dizuoState.length; index++) {
|
||
if(this.dizuoState[index] == 1){
|
||
let di = cc.find('di'+index, this.dizuo)
|
||
let kapainode = cc.find('kapainode', di)
|
||
if(this.maxKaPaiNum > kapainode.children.length){
|
||
let arr = [index, this.maxKaPaiNum - kapainode.children.length]
|
||
datearr.push(arr)
|
||
}
|
||
}
|
||
}
|
||
|
||
if(datearr.length == 0){ //所有的位置都不可发牌
|
||
|
||
}else{
|
||
AudioManager.playEffect(soundName.fapai)
|
||
let fapaijiedianshu = 0 //发牌的节点数量
|
||
if(datearr.length >= 5){ //多余或者等于4个 ,挑选4个节点发牌
|
||
fapaijiedianshu = Utils.getRangeRandom(5, datearr.length) //5
|
||
//console.log('打印发牌点', fapaijiedianshu)
|
||
}else{ //全发
|
||
fapaijiedianshu = datearr.length
|
||
}
|
||
let randarr = Utils.getRandomValueDif(0, datearr.length-1, fapaijiedianshu)
|
||
for (let index = 0; index < randarr.length; index++) {
|
||
const element = randarr[index];
|
||
let shuju = datearr[element]
|
||
|
||
let id = shuju[0] //节点id
|
||
let num = shuju[1] //能发几张牌
|
||
let di = cc.find('di'+id, this.dizuo)
|
||
let kapainode = cc.find('kapainode', di)
|
||
|
||
if(num == 1 || num == 2){ //1个
|
||
let leixing = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
for (let index = 0; index < num; index++) {
|
||
this.addNewKaPai(kapainode, leixing, true)
|
||
PlayData.Instance.storageGameDate[4][id].push(leixing)
|
||
}
|
||
}else if( num == 3 || num == 4 || num == 5){
|
||
let randshu = Utils.getRangeRandom(2, 3)
|
||
let leixing0 = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
let leixing1 = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
let leixing = 0
|
||
let wenhao = !1
|
||
|
||
if(randshu == 2){
|
||
let leixing = leixing0
|
||
for (let ind = 0; ind < randshu; ind++) {
|
||
this.addNewKaPai(kapainode, leixing, true)
|
||
PlayData.Instance.storageGameDate[4][id].push(leixing)
|
||
}
|
||
}else if(randshu == 3){
|
||
let randgailv = Utils.getRangeRandom(1,this.weizhigailv)
|
||
for (let ind = 0; ind < randshu; ind++) {
|
||
wenhao = !1
|
||
if(randshu < 2){
|
||
if(PlayData.Instance.guanqia >= 1){
|
||
if(randgailv == 1){
|
||
leixing = 0
|
||
wenhao = randshu == 1
|
||
}else{
|
||
leixing = leixing0
|
||
}
|
||
}else{
|
||
leixing = leixing0
|
||
}
|
||
|
||
this.addNewKaPai(kapainode, leixing, true, wenhao)
|
||
|
||
PlayData.Instance.storageGameDate[4][id].push(leixing)
|
||
}else{
|
||
leixing = leixing1
|
||
this.addNewKaPai(kapainode, leixing, true)
|
||
PlayData.Instance.storageGameDate[4][id].push(leixing)
|
||
}
|
||
}
|
||
}
|
||
}else if(num > 5){
|
||
let randshu = Utils.getRangeRandom(2, 5)
|
||
if(randshu == 1){
|
||
let leixing = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
for (let ind = 0; ind < 2; ind++) {
|
||
this.addNewKaPai(kapainode, leixing, true)
|
||
PlayData.Instance.storageGameDate[4][id].push(leixing)
|
||
}
|
||
}else if(randshu == 2){
|
||
for (let mm = 0; mm < 2; mm++) {
|
||
let leixing = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
for (let nn = 0; nn < 2; nn++) {
|
||
this.addNewKaPai(kapainode, leixing, true)
|
||
PlayData.Instance.storageGameDate[4][id].push(leixing)
|
||
}
|
||
}
|
||
}else if(randshu == 3){
|
||
let leixing = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
for (let ind = 0; ind < 3; ind++) {
|
||
this.addNewKaPai(kapainode, leixing, true)
|
||
PlayData.Instance.storageGameDate[4][id].push(leixing)
|
||
}
|
||
}else if(randshu == 4 || randshu == 5){
|
||
let leixing0 = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
let leixing1 = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
let leixing = 0
|
||
let wenhao = !1
|
||
let randgailv = Utils.getRangeRandom(1,this.weizhigailv)
|
||
for (let index = 0; index < randshu; index++) {
|
||
wenhao = !1
|
||
if(index <2){
|
||
if(PlayData.Instance.guanqia >= 1){
|
||
if(randgailv == 1){
|
||
leixing = 0
|
||
wenhao = index == 1
|
||
}else{
|
||
leixing = leixing0
|
||
}
|
||
}else{
|
||
leixing = leixing0
|
||
}
|
||
//leixing = leixing0
|
||
}else{
|
||
leixing = leixing1
|
||
}
|
||
|
||
this.addNewKaPai(kapainode, leixing, true, wenhao)
|
||
|
||
PlayData.Instance.storageGameDate[4][id].push(leixing)
|
||
}
|
||
|
||
}else if(randshu == 6){
|
||
let gailv = Utils.getRangeRandom(0,1)
|
||
if(gailv == 0){
|
||
let leixing0 = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
let leixing1 = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
let leixing = 0
|
||
let wenhao = !1
|
||
let randgailv = Utils.getRangeRandom(1,this.weizhigailv)
|
||
for (let index = 0; index < randshu; index++) {
|
||
wenhao = !1
|
||
if(index <3){
|
||
if(PlayData.Instance.guanqia >= 1){
|
||
if(randgailv == 1){
|
||
leixing = 0
|
||
wenhao = index == 2
|
||
}else{
|
||
leixing = leixing0
|
||
}
|
||
}else{
|
||
leixing = leixing0
|
||
}
|
||
//leixing = leixing0
|
||
}else{
|
||
leixing = leixing1
|
||
}
|
||
|
||
this.addNewKaPai(kapainode, leixing, true, wenhao)
|
||
|
||
PlayData.Instance.storageGameDate[4][id].push(leixing)
|
||
}
|
||
}else{
|
||
let leixing0 = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
let leixing1 = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
let leixing2 = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
let leixing = 0
|
||
let wenhao = !1
|
||
let randgailv = Utils.getRangeRandom(1,this.weizhigailv)
|
||
for (let index = 0; index < randshu; index++) {
|
||
wenhao = !1
|
||
if(index <2){
|
||
if(PlayData.Instance.guanqia >= 1){
|
||
if(randgailv == 1){
|
||
leixing = 0
|
||
wenhao = index == 1
|
||
}else{
|
||
leixing = leixing0
|
||
}
|
||
}else{
|
||
leixing = leixing0
|
||
}
|
||
//leixing = leixing0
|
||
}else if(2 == index || index == 3){
|
||
leixing = leixing1
|
||
}
|
||
else{
|
||
leixing = leixing2
|
||
}
|
||
|
||
this.addNewKaPai(kapainode, leixing, true, wenhao)
|
||
|
||
PlayData.Instance.storageGameDate[4][id].push(leixing)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
this.storageCheckOutData()
|
||
}
|
||
|
||
this.scheduleOnce(()=>{
|
||
this.checkNeedXiPai()
|
||
}, 0.4)
|
||
}
|
||
|
||
/**
|
||
* 检测合成
|
||
*/
|
||
checkHeCheng(){
|
||
this.kapaiReset()
|
||
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)
|
||
if(kapainode.children.length >= this.maxKaPaiNum){
|
||
let nextnum = 0
|
||
let tongse = !0
|
||
let lastnode = kapainode.children[kapainode.children.length - 1]
|
||
let lastnodesc:kapaiSc = lastnode.getComponent(kapaiSc)
|
||
|
||
for (let ind = 0; ind <kapainode.children.length; ind++) {
|
||
const element = kapainode.children[ind];
|
||
let elsc:kapaiSc = element.getComponent(kapaiSc)
|
||
if(elsc.kaNum != lastnodesc.kaNum){
|
||
tongse = !1
|
||
break
|
||
}
|
||
}
|
||
//同色 合成新的
|
||
if(tongse == !0){
|
||
nextnum = lastnodesc.kaNum + 1
|
||
let yanchiindex = 0
|
||
for (let kk = kapainode.children.length; kk > 0; kk--) {
|
||
let zinode = kapainode.children[kk-1]
|
||
|
||
cc.tween(zinode)
|
||
.delay(0.03*yanchiindex)
|
||
.removeSelf()
|
||
.start()
|
||
.tag(kk)
|
||
yanchiindex++
|
||
|
||
}
|
||
PlayData.Instance.storageGameDate[4][index] = []
|
||
this.scheduleOnce(()=>{ //新的
|
||
let randshu = 2 //Utils.getRangeRandom(1,2)
|
||
for (let mm = 0; mm < randshu; mm++) {
|
||
this.addNewKaPai(kapainode, nextnum, false)
|
||
PlayData.Instance.storageGameDate[4][index].push(nextnum)
|
||
}
|
||
this.storageCheckOutData()
|
||
let mubiaolevelnum = this.levelbarSc.levelnum[this.levelbarSc.jindu]
|
||
//console.log('打印目标', mubiaolevelnum, nextnum)
|
||
if(nextnum == mubiaolevelnum){
|
||
this.upRankData(nextnum)
|
||
let jiesuoid = this.levelbarSc.jindu + 5
|
||
this.scheduleOnce(()=>{
|
||
this.dizuoState[jiesuoid] = 1 //达成要求 可以解锁下一个格子
|
||
let di = cc.find('di'+jiesuoid, this.dizuo)
|
||
let suo = cc.find('suo', di)
|
||
cc.tween(suo)
|
||
.to(0.3, {opacity:0})
|
||
.start()
|
||
AudioManager.playEffect(soundName.kaikacao)
|
||
},0.5)
|
||
this.levelNum ++
|
||
this.levelbarSc.jindu++
|
||
PlayData.Instance.storageGameDate[1] = this.levelbarSc.jindu
|
||
this.storageCheckOutData()
|
||
//console.log('新的', this.levelbarSc.jindu,this.levelNum)
|
||
this.levelbarSc.updateLevelBar()
|
||
if(this.levelbarSc.jindu == 5){
|
||
console.log('达到通关条件')
|
||
this.notouch.active = !0
|
||
this.scheduleOnce(()=>{
|
||
let newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.NumLevelUpPanel])
|
||
newnode.parent = cc.director.getScene()
|
||
let sc = newnode.getComponent(NumLevelUpPanelSc)
|
||
sc.showPanel(1)
|
||
sc.setGameSc(this)
|
||
|
||
PlayData.Instance.guanqia++
|
||
PlayData.Instance.storageGameDate = [
|
||
PlayData.Instance.guanqia, //关卡数
|
||
0, //当前进度
|
||
9, //临时解锁卡槽的位置
|
||
[0,0,0], //临时卡槽的状态
|
||
[] //每个底座卡牌的数据
|
||
]
|
||
this.storageCheckOutData()
|
||
|
||
}, 0.5)
|
||
}else{
|
||
this.scheduleOnce(()=>{
|
||
let newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.NumLevelUpPanel])
|
||
newnode.parent = cc.director.getScene()
|
||
let sc = newnode.getComponent(NumLevelUpPanelSc)
|
||
sc.showPanel(0)
|
||
}, 0.5)
|
||
}
|
||
}
|
||
let dizuo = kapainode.parent
|
||
cc.find('selectkuang', dizuo).active = !1
|
||
this.checkNeedXiPai()
|
||
}, 0.35)
|
||
|
||
AudioManager.playEffect(soundName.hecheng)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 下一关
|
||
*/
|
||
nextCheck(){
|
||
let t = cc.tween
|
||
t(this.node)
|
||
.parallel(
|
||
t().to(0.5, {x:-1000}),
|
||
t().call(()=>{cc.game.emit('addnewgame')})
|
||
)
|
||
.removeSelf()
|
||
.start()
|
||
}
|
||
|
||
/**
|
||
* 检测是否需要洗牌操作
|
||
*/
|
||
checkNeedXiPai(){
|
||
let open1 = 0
|
||
let open2 = 0
|
||
for (let index = 0; index < this.dizuoState.length; index++) {
|
||
const ele = this.dizuoState[index];
|
||
let di = cc.find('di'+index, this.dizuo)
|
||
//cc.find('selectkuang', di).active = !1
|
||
let kapainode = cc.find('kapainode', di)
|
||
if(this.dizuoState[index] == 1){
|
||
open1 ++
|
||
if(kapainode.children.length > 5){
|
||
open2 ++
|
||
}
|
||
}
|
||
}
|
||
this.xipaiBtn.active = (open1-open2) == 0
|
||
}
|
||
|
||
/**
|
||
* 洗牌操作
|
||
*/
|
||
xipaiOperate(){
|
||
AudioManager.playEffect(soundName.xipai)
|
||
this.xipaiBtn.active = !1
|
||
for (let index = 0; index < this.dizuoState.length; index++) {
|
||
const ele = this.dizuoState[index];
|
||
let di = cc.find('di'+index, this.dizuo)
|
||
cc.find('selectkuang', di).active = !1
|
||
let kapainode = cc.find('kapainode', di)
|
||
|
||
//kapainode.removeAllChildren()
|
||
//cc.find('selectkuang', di).active = !1
|
||
|
||
//this.allNodeArr[index] = []
|
||
|
||
if(this.dizuoState[index] == 1){
|
||
let childrenarr = kapainode.children
|
||
|
||
while(childrenarr.length > 0){
|
||
let nodesc:kapaiSc = childrenarr[0].getComponent(kapaiSc)
|
||
|
||
if(nodesc.kaNum == 0){
|
||
let leixing = Utils.getRangeRandom(this.mixlevelNum, this.levelNum - 2)
|
||
nodesc.setKaNum(leixing)
|
||
}
|
||
let newpos0 = nodesc.node.parent.convertToWorldSpaceAR(nodesc.node.position)
|
||
let newpos1 = this.moveNode.convertToNodeSpaceAR(newpos0) //this.moveNode 是个过渡节点 保障移动的节点在最上层
|
||
nodesc.node.position = newpos1
|
||
nodesc.node.parent = this.moveNode
|
||
cc.tween(nodesc.node)
|
||
.to(0.2, {position:cc.v3(0,0,0)})
|
||
.start()
|
||
}
|
||
}
|
||
}
|
||
this.scheduleOnce(()=>{
|
||
let allnode = this.moveNode.children
|
||
let index = 0
|
||
PlayData.Instance.storageGameDate[4] = [[],[],[],[],[],[],[],[],[],[],[],[]]
|
||
while(allnode.length > 0){
|
||
index ++
|
||
const ele = allnode[0];
|
||
let elesc = ele.getComponent(kapaiSc)
|
||
let num = elesc.kaNum-PlayData.Instance.guanqia*6
|
||
let kapainode = cc.find('di' + (num-1) + '/kapainode', this.dizuo)
|
||
let newpos0 = ele.parent.convertToWorldSpaceAR(ele.position)
|
||
let newpos1 = kapainode.convertToNodeSpaceAR(newpos0)
|
||
ele.position = newpos1
|
||
ele.parent = kapainode
|
||
cc.find('di' + (num-1) + '/selectkuang' , this.dizuo).active = kapainode.children.length >= 10
|
||
|
||
if(kapainode.children.length > 10){
|
||
ele.destroy()
|
||
}else{
|
||
PlayData.Instance.storageGameDate[4][num-1].push(elesc.kaNum)
|
||
cc.tween(ele)
|
||
.to(0.2, {position:cc.v3(0,this.posY[kapainode.children.length-1],0)})
|
||
.start()
|
||
}
|
||
}
|
||
//console.log('打印卡牌数据', PlayData.Instance.storageGameDate)
|
||
this.storageCheckOutData()
|
||
}, 0.3)
|
||
}
|
||
|
||
/**
|
||
* 移动卡牌
|
||
* @param znode
|
||
* @param nodeparent
|
||
* @param deltime
|
||
*/
|
||
moveKaPai(znode, nodeparent, deltime){
|
||
|
||
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 newpos22 = cc.v2(0, this.posY[nodeparent.children.length-1])
|
||
let newpos2 = nodeparent.convertToWorldSpaceAR(newpos22)
|
||
let newpos3 = this.moveNode.convertToNodeSpaceAR(newpos2)
|
||
let newpos4 = cc.v3(newpos3.x,newpos3.y,0)
|
||
cc.tween(znode)
|
||
.delay(deltime)
|
||
.to(0.12,{position:newpos4})
|
||
.call(()=>{
|
||
AudioManager.playEffect(soundName.moveka)
|
||
znode.parent = nodeparent
|
||
znode.position = cc.v3(0, this.posY[nodeparent.children.length-1], 0)
|
||
//console.log('打印卡牌的数量', nodeparent.children.length)
|
||
if(nodeparent.children.length >= this.maxKaPaiNum){
|
||
//console.log('卡槽满10')
|
||
let tongse = !0
|
||
let lastnode = nodeparent.children[nodeparent.children.length - 1]
|
||
let lastnodesc:kapaiSc = lastnode.getComponent(kapaiSc)
|
||
|
||
for (let index = 0; index <nodeparent.children.length; index++) {
|
||
const element = nodeparent.children[index];
|
||
let elsc:kapaiSc = element.getComponent(kapaiSc)
|
||
if(elsc.kaNum != lastnodesc.kaNum){
|
||
tongse = !1
|
||
break
|
||
}
|
||
}
|
||
//同色
|
||
if(tongse == !0){
|
||
let dizuo = nodeparent.parent
|
||
cc.find('selectkuang', dizuo).active = !0
|
||
}else{
|
||
let dizuo = nodeparent.parent
|
||
cc.find('selectkuang', dizuo).active = !1
|
||
}
|
||
|
||
}
|
||
})
|
||
.start()
|
||
}
|
||
|
||
/**
|
||
* 添加新牌
|
||
* @param parentnode 父节点
|
||
* @param kanum 卡牌num
|
||
*/
|
||
addNewKaPai(parentnode, kanum, isfapai = false, wenhao?){
|
||
//console.log('是否是发牌', isfapai)
|
||
let newnode:cc.Node = cc.instantiate(this.kapaiPre)
|
||
newnode.parent = parentnode
|
||
let kapaisc = newnode.getComponent(kapaiSc)
|
||
kapaisc.setKaNum(kanum)
|
||
if(wenhao == !0){
|
||
kapaisc.showWenHao()
|
||
}
|
||
|
||
//console.log('打印wenhao', wenhao)
|
||
|
||
if(isfapai == !0){
|
||
newnode.y = -cc.winSize.height/2 - parentnode.parent.y
|
||
cc.tween(newnode)
|
||
.to(0.2, {y:this.posY[parentnode.children.length-1]})
|
||
.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 <parentnode.children.length; index++) {
|
||
const element = parentnode.children[index];
|
||
let elsc:kapaiSc = element.getComponent(kapaiSc)
|
||
if(elsc.kaNum != lastnodesc.kaNum){
|
||
tongse = !1
|
||
break
|
||
}
|
||
}
|
||
//同色
|
||
if(tongse == !0){
|
||
let dizuo = parentnode.parent
|
||
cc.find('selectkuang', dizuo).active = !0
|
||
}else{
|
||
let dizuo = parentnode.parent
|
||
cc.find('selectkuang', dizuo).active = !1
|
||
}
|
||
}
|
||
})
|
||
.start()
|
||
}else{ //合成产生新牌
|
||
newnode.y = this.posY[parentnode.children.length-1]
|
||
newnode.opacity = 0
|
||
newnode.scale = 0
|
||
cc.tween(newnode)
|
||
.to(0.1,{opacity:255, scale:1})
|
||
.start()
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 检测是否有问号
|
||
*/
|
||
checkWenHao(kapainode){
|
||
|
||
let pname:string = kapainode.parent.name
|
||
let strr = pname.split('di')
|
||
let id = Number(strr[1])
|
||
|
||
//console.log('检测卡牌node', kapainode.children, id)
|
||
let childrennode = kapainode.children
|
||
let selectarr = []
|
||
if(childrennode.length > 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)
|
||
PlayData.Instance.storageGameDate[4][id].pop()
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//console.log('打印0号', selectarr)
|
||
|
||
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(leixing)
|
||
sc.node.scale = 0
|
||
cc.tween(sc.node)
|
||
.to(0.1, {scale:1})
|
||
.start()
|
||
PlayData.Instance.storageGameDate[4][id].push(leixing)
|
||
}
|
||
|
||
if(selectarr.length > 0){
|
||
this.storageCheckOutData()
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 存储关卡数据
|
||
*/
|
||
storageCheckOutData(){
|
||
gameStorage.Instance.setCheckOutData(PlayData.Instance.storageGameDate)
|
||
}
|
||
|
||
/**
|
||
* 上传排行榜数据
|
||
*/
|
||
upRankData(num){
|
||
let highscore = gameStorage.Instance.getHightScore()
|
||
if(Number(num) > highscore){
|
||
gameStorage.Instance.setHightScore(Number(num))
|
||
AdsApiMgr.Instance.setImRankData_Num(String(num))
|
||
}
|
||
}
|
||
|
||
// update (dt) {}
|
||
|
||
}
|