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.
224 lines
8.1 KiB
224 lines
8.1 KiB
|
3 weeks ago
|
import { _decorator, Component, Node } from 'cc';
|
||
|
|
import { ChapterNewPlayTypeEnum, IColdFireProperty } from '../../../game/ChapterPlayTypes';
|
||
|
|
import { GEvent } from 'db://assets/mx/module/event/GEvent';
|
||
|
|
import { ObstacleType } from '../MapObstacle';
|
||
|
|
const { ccclass, property } = _decorator;
|
||
|
|
|
||
|
|
/*
|
||
|
|
* 新机制寒冬
|
||
|
|
初始化是0
|
||
|
|
每波次-10
|
||
|
|
-20开始出现冰霜效果1
|
||
|
|
-50开始出现冰霜效果2
|
||
|
|
-70开始出现冰霜效果3
|
||
|
|
|
||
|
|
-50开始掉血出现掉血特效,每秒掉血10
|
||
|
|
-70开始掉血每秒掉血20
|
||
|
|
|
||
|
|
|
||
|
|
一个火炉障碍物增加20度
|
||
|
|
*/
|
||
|
|
@ccclass('newMechanismCold')
|
||
|
|
export class newMechanismCold extends Component {
|
||
|
|
timeInterval = 0 //时间间隔
|
||
|
|
maxTimeLimit = 0 //次数限制
|
||
|
|
subTemperatureArr: number[] = [] //波次温度下降
|
||
|
|
subHpByTemperatureArr: number[] = [] //到达特定的温度血量开始减少每秒 开始有变化
|
||
|
|
subHpArr: number[] = [] //血量开始减少每秒
|
||
|
|
startTemperature = 0 //初始温度
|
||
|
|
//波次时间
|
||
|
|
waveTime = 0
|
||
|
|
curWaveNum = 0 //当前波次
|
||
|
|
IColdFirePropertyData: IColdFireProperty = null
|
||
|
|
lastColdStage = 0 //上一次的寒冷阶段
|
||
|
|
isNeedSubHp = false //是否需要掉血
|
||
|
|
subHp = 0//扣血
|
||
|
|
addTemperatureNum = 0//配置获取
|
||
|
|
|
||
|
|
protected onEnable(): void {
|
||
|
|
GEvent.Ins.on(GEvent.ExitEdit, this.onExitEdit, this)
|
||
|
|
}
|
||
|
|
|
||
|
|
protected onDisable(): void {
|
||
|
|
GEvent.Ins.off(GEvent.ExitEdit, this.onExitEdit, this)
|
||
|
|
}
|
||
|
|
|
||
|
|
onExitEdit(){
|
||
|
|
//获取火炉障碍物
|
||
|
|
// let arr = gg.game.CurentBattle.getObstaclesByType(ObstacleType.火炉)
|
||
|
|
// let addLeng = 0
|
||
|
|
// if(arr.length == 0){
|
||
|
|
// this.addTemperatureNum = 0
|
||
|
|
// addLeng = 0
|
||
|
|
// }else{
|
||
|
|
|
||
|
|
// // let ObstacleNode = arr[0].ObstacleNode
|
||
|
|
// // if(!ObstacleNode['addTemperature']){
|
||
|
|
// // addLeng++
|
||
|
|
// // ObstacleNode['addTemperature'] = true
|
||
|
|
// // }
|
||
|
|
// for(let item of arr){
|
||
|
|
// let ObstacleNode = item.ObstacleNode
|
||
|
|
// if(!ObstacleNode['addTemperature']){
|
||
|
|
// addLeng++
|
||
|
|
// ObstacleNode['addTemperature'] = true
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// if(this.addTemperatureNum == 0){
|
||
|
|
// let MechanismData = arr[0].MechanismData
|
||
|
|
// let par1 = MechanismData.par1
|
||
|
|
// //判断是不是副本
|
||
|
|
// if (gg.game.CurentBattle.IsReplica) {
|
||
|
|
// let str = par1.split('|')
|
||
|
|
// this.addTemperatureNum = Number(str[1])
|
||
|
|
// }else{
|
||
|
|
// let str = par1.split('|')
|
||
|
|
// this.addTemperatureNum = Number(str[0])
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
|
||
|
|
// //增加的温度数值
|
||
|
|
// console.log('addTemperatureNum', this.addTemperatureNum)
|
||
|
|
|
||
|
|
|
||
|
|
// }
|
||
|
|
//this.addTemperature(arr,addLeng)
|
||
|
|
}
|
||
|
|
|
||
|
|
start() {
|
||
|
|
this.IColdFirePropertyData = gg.data.project.getChapterNewPlayInfo(ChapterNewPlayTypeEnum.ColdFire)
|
||
|
|
// let curWaveNum = gg.game.CurentBattle.CurentWaveNum //当前波次
|
||
|
|
// console.log('newMechanismCold', this.IColdFirePropertyData)
|
||
|
|
this.startTemperature = this.IColdFirePropertyData.startTemperature
|
||
|
|
// gg.game.CurentBattle.CurentTemperature = this.startTemperature
|
||
|
|
// console.log('CurentTemperature', gg.game.CurentBattle.CurentTemperature)
|
||
|
|
GEvent.Ins.emit(GEvent.CurentTemperatureChange, false)
|
||
|
|
|
||
|
|
this.timeInterval = this.IColdFirePropertyData.timeInterval
|
||
|
|
this.maxTimeLimit = this.IColdFirePropertyData.subTemperatureArr.length
|
||
|
|
this.subTemperatureArr = this.IColdFirePropertyData.subTemperatureArr
|
||
|
|
|
||
|
|
this.subHpByTemperatureArr = this.IColdFirePropertyData.subHpByTemperatureArr //-20,-50,-70
|
||
|
|
this.subHpArr = this.IColdFirePropertyData.subHpArr //0,10,20
|
||
|
|
//开启定时器一秒钟更新温度
|
||
|
|
this.schedule(this.updateTemperature, 1)
|
||
|
|
|
||
|
|
|
||
|
|
this.onColdStageChange(0)
|
||
|
|
}
|
||
|
|
|
||
|
|
private getColdStage(temp: number, limits: number[]): number {
|
||
|
|
let stage = 0;
|
||
|
|
for (const limit of limits) {
|
||
|
|
if (temp <= limit) {
|
||
|
|
stage++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return stage;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
addTemperature(arr,addLeng:number) {
|
||
|
|
//增加温度
|
||
|
|
|
||
|
|
let add = this.addTemperatureNum*addLeng
|
||
|
|
this.startTemperature += add
|
||
|
|
const stage = this.getColdStage(this.startTemperature, this.subHpByTemperatureArr);
|
||
|
|
|
||
|
|
// gg.game.CurentBattle.CurentTemperature = this.startTemperature
|
||
|
|
GEvent.Ins.emit(GEvent.CurentTemperatureChange, stage >= 2)
|
||
|
|
|
||
|
|
if (stage !== this.lastColdStage) {
|
||
|
|
this.onColdStageChange(stage);
|
||
|
|
this.lastColdStage = stage;
|
||
|
|
this.subHp = this.subHpArr[stage - 1]
|
||
|
|
}
|
||
|
|
this.handleContinuousColdEffect(this.lastColdStage);
|
||
|
|
|
||
|
|
}
|
||
|
|
updateTemperature(dt: number) {
|
||
|
|
|
||
|
|
if (!gg.game.CurentBattle.canUpdateFrame()) return;
|
||
|
|
|
||
|
|
this.waveTime += dt * gg.game.CurentBattle.TimeScale;
|
||
|
|
if (this.waveTime >= this.timeInterval) {
|
||
|
|
this.waveTime = 0
|
||
|
|
this.curWaveNum++
|
||
|
|
if (this.curWaveNum > this.subTemperatureArr.length) {
|
||
|
|
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
//更新温度
|
||
|
|
let subTemperature = this.subTemperatureArr[this.curWaveNum - 1]
|
||
|
|
//降温度
|
||
|
|
this.startTemperature -= Math.abs(subTemperature)
|
||
|
|
|
||
|
|
// console.log(`温度变更:${this.startTemperature}`)
|
||
|
|
|
||
|
|
const stage = this.getColdStage(this.startTemperature, this.subHpByTemperatureArr);
|
||
|
|
// gg.game.CurentBattle.CurentTemperature = this.startTemperature
|
||
|
|
GEvent.Ins.emit(GEvent.CurentTemperatureChange, stage >= 2)
|
||
|
|
|
||
|
|
// console.log(`温度阶段:${stage}`)
|
||
|
|
|
||
|
|
//检查this.startTemperature在 this.subHpByTemperatureArr的那个阶段,如果没有找到就是不需要扣血
|
||
|
|
if (stage !== this.lastColdStage) {
|
||
|
|
this.onColdStageChange(stage);
|
||
|
|
this.lastColdStage = stage;
|
||
|
|
this.subHp = this.subHpArr[stage - 1]
|
||
|
|
}
|
||
|
|
//this.isNeedSubHp =
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
this.handleContinuousColdEffect(this.lastColdStage, true);
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
handleContinuousColdEffect(stage: number, useBattleTimeScale = false) {
|
||
|
|
//this.subHp
|
||
|
|
if (this.subHp > 0) {
|
||
|
|
//掉血(周期伤害随战斗倍速;事件触发的单次调用不乘倍速)
|
||
|
|
const dmg = useBattleTimeScale ? this.subHp * gg.game.CurentBattle.TimeScale : this.subHp;
|
||
|
|
// console.log(`掉血:${dmg}`)
|
||
|
|
gg.game.CurentBattle.subWallHp(dmg)
|
||
|
|
GEvent.Ins.emit(GEvent.playerHit)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private onColdStageChange(stage: number) {
|
||
|
|
// console.log(`温度阶段变更:${stage}`);
|
||
|
|
if(stage == 0){
|
||
|
|
this.node.getChildByName('冰霜效果1').active = false
|
||
|
|
this.node.getChildByName('冰霜效果2').active = false
|
||
|
|
this.node.getChildByName('冰霜效果3').active = false
|
||
|
|
this.node.getChildByName('掉血').active = false
|
||
|
|
}else if (stage == 1) {
|
||
|
|
// 播放 冰霜效果 1 动画
|
||
|
|
this.node.getChildByName('冰霜效果1').active = true
|
||
|
|
this.node.getChildByName('冰霜效果2').active = false
|
||
|
|
this.node.getChildByName('冰霜效果3').active = false
|
||
|
|
this.node.getChildByName('掉血').active = false
|
||
|
|
} else if (stage === 2) {
|
||
|
|
// 播放 冰霜效果 2 动画
|
||
|
|
|
||
|
|
this.node.getChildByName('冰霜效果1').active = false
|
||
|
|
this.node.getChildByName('冰霜效果2').active = true
|
||
|
|
this.node.getChildByName('冰霜效果3').active = false
|
||
|
|
this.node.getChildByName('掉血').active = true
|
||
|
|
} else if (stage === 3) {
|
||
|
|
// 播放 冰霜效果 3 动画
|
||
|
|
this.node.getChildByName('冰霜效果1').active = false
|
||
|
|
this.node.getChildByName('冰霜效果2').active = false
|
||
|
|
this.node.getChildByName('冰霜效果3').active = true
|
||
|
|
this.node.getChildByName('掉血').active = true
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|