消消方块阵换皮表情
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

121 lines
4.5 KiB

import { _decorator, Component, Node, sp, Sprite } from 'cc';
import { GEvent } from 'db://assets/mx/module/event/GEvent';
import { ObstacleType } from '../MapObstacle';
const { ccclass, property } = _decorator;
@ccclass('chuifengjiSchedule')
export class chuifengjiSchedule extends Component {
chixuTime = 0 //持续时间
chixuInterval = 0 //间隔时间开始
chixuTimeFix = 0 //持续时间固定值
chixuIntervalFix = 0 //间隔时间固定值
curState = 'jiangeTime' //当前状态 0 间隔时间 1 持续时间
//chixuTime 持续时间 当前状态是吹风机工作时间 不可以移动
//jiangeTime 间隔时间 当前状态是吹风机冷却时间 可以移动
prochui:Sprite = null //工作进度条
projing:Sprite = null //不工作进度条
choukaSpine: sp.Skeleton = null
fuzhiValue = false
protected onDisable(): void {
console.log('chuifengjiSchedule onDisable')
this.unscheduleAllCallbacks()
}
onEnable() {
this.choukaSpine = this.node.getChildByName('anim').getComponent(sp.Skeleton)
this.choukaSpine.setAnimation(0, '静止', true)
this.prochui = this.node.getChildByName('prochui').getComponent(Sprite)
this.projing = this.node.getChildByName('projing').getComponent(Sprite)
//初始化持续时间和间隔时间
let arr = gg.game.CurentBattle.getObstaclesByType(ObstacleType.)
if(arr.length > 0){
console.log('吹风机存在',arr[0].MechanismData)
if(!this.fuzhiValue){
this.chixuTime = 0
let cd = arr[0].MechanismData.cd.split('|')
let duration = arr[0].MechanismData.duration.split('|')
if (gg.game.CurentBattle.IsReplica) {
this.chixuTimeFix = Number(duration[0])
this.chixuInterval = Number(cd[0])
this.chixuIntervalFix = Number(cd[0])
}else{
this.chixuTimeFix = Number(duration[0])
this.chixuInterval = Number(cd[1])
this.chixuIntervalFix = Number(cd[1])
}
console.log('持续时间固定值',this.chixuTimeFix)
console.log('间隔时间',this.chixuInterval)
console.log('间隔时间固定值',this.chixuIntervalFix)
this.fuzhiValue = true
}
}
this.curState = 'jiangeTime'
this.schedule(this.updateChuiFeng, 1)
}
updateChuiFeng(dt: number){
if (!gg.game.CurentBattle.canUpdateFrame()) return;
const scaled = dt * gg.game.CurentBattle.TimeScale;
//发送chuifengji事件
if(this.curState == 'jiangeTime'){
this.chixuInterval += scaled
this.projing.fillRange = (this.chixuInterval / this.chixuIntervalFix)
if(this.chixuInterval >= this.chixuIntervalFix){
this.chixuInterval = 0
//开始持续时间
this.chixuTime = 0
this.curState = 'chixuTime'
let isCanMove = this.getIsCanMove()
GEvent.Ins.emit(GEvent.ChuifengjiEvent, isCanMove)
//console.log('当前状态是吹风机工作时间 不可以移动')
this.prochui.fillRange = 1
this.projing.fillRange = 1
this.prochui.node.active = true
this.projing.node.active = false
this.choukaSpine.setAnimation(0, '吹风', true)
}
}else if(this.curState == 'chixuTime'){
this.chixuTime += scaled
this.prochui.fillRange = 1-(this.chixuTime / this.chixuTimeFix)
if(this.chixuTime >= this.chixuTimeFix){
this.chixuTime = 0
//开始间隔时间
this.chixuInterval = 0
this.curState = 'jiangeTime'
this.choukaSpine.setAnimation(0, '静止', true)
//console.log('当前状态是吹风机冷却时间可以移动')
let isCanMove = this.getIsCanMove()
this.prochui.fillRange = 1
this.projing.fillRange = 0
this.prochui.node.active = false
this.projing.node.active = true
GEvent.Ins.emit(GEvent.ChuifengjiEvent, isCanMove)
}
}
//GEvent.Ins.emit(GEvent.ChuifengjiEvent)
}
getIsCanMove(){
return this.curState == 'jiangeTime'
}
}