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.
 
 
 
 

168 lines
5.9 KiB

import { _decorator, Component, Label, Node, Tween, tween } from 'cc';
import { GEvent } from 'db://assets/mx/module/event/GEvent';
import { ChapterNewPlayTypeEnum } from '../../../game/ChapterPlayTypes';
import { UIID } from '../../../game/ConfigRes';
import { TableNames } from '../../../game/ConfigTableData';
import { MapObstacle } from '../MapObstacle';
import { Monster } from '../Monster';
const { ccclass, property } = _decorator;
/**冰箱 */
@ccclass('iceBox')
export class iceBox extends Component {
mapObstacleCom: MapObstacle;
//工作时间
workTime = 10
workTimeFix = 10 //固定工作时间
pauseWorkTime = 5//暂停工作时间
pauseWorkTimeFix = 5 //固定暂停工作时间
explodeRadius = 100 //减速半径
reduceTime = 2 //减速时间
reduceSpeed = 5000 //减速速度 除以10000
isXiufuFinish = true //是否修复完成
priceNum = 0 //修复价格
curState = 'work' //默认先开启工作状态
config: Record<string, unknown> = null;
zawConfig: Record<string, unknown> = null;
protected onEnable(): void {
//注册按钮监听
this.node.on(Node.EventType.TOUCH_END, this.onClickEnd, this);
//监听修复完成
GEvent.Ins.on(GEvent.XiufuFinish, this.onXiufuFinish, this);
}
onXiufuFinish(xiufuNode) {
if (xiufuNode == this.node) {
// this.mapObstacleCom.Grid.isBroken = false //不是破损
this.isXiufuFinish = true
this.workTime = 0
this.curState = 'work'
this.refreshBtn()
}
}
onClickEnd() {
if (this.mapObstacleCom) {
// if (this.mapObstacleCom.Grid.isBroken) {
// gg.ui.openPanel(UIID.xiufuBox, {
// data: {
// priceNum: this.priceNum,
// xiufuNode: this.node,
// config: this.config,
// zawConfig: this.zawConfig,
// mapObstacle: this.mapObstacleCom,
// }
// });
// } else {
// //修复状态,点击无反应
// return
// }
}
}
protected onDisable(): void {
//移除按钮监听
this.node.off(Node.EventType.TOUCH_END, this.onClickEnd, this);
//移除修复完成监听
GEvent.Ins.off(GEvent.XiufuFinish, this.onXiufuFinish, this);
}
start() {
this.config = null;
this.zawConfig = null;
//this.moneyLab.string = '+'+this.addMoney.toString()
if (this.node.parent) {
let mapObstacleCom = this.node.parent.getComponent(MapObstacle);
if (mapObstacleCom) {
this.mapObstacleCom = mapObstacleCom;
// console.log('获取当前的mapObstacleCom组件成功');
if (gg.data.project.getGridIsRepair(gg.game.CurentBattle.MapId, this.mapObstacleCom.Grid.Index) == 1) {
// this.mapObstacleCom.Grid.isBroken = false;
}
// this.isXiufuFinish = !this.mapObstacleCom.Grid.isBroken;
this.refreshBtn()
if (this.isXiufuFinish) {
this.curState = 'work'
this.workTime = 0
}
}
} else {
this.isXiufuFinish = true
this.curState = 'work'
this.workTime = 0
this.refreshBtn()
}
//console.log(this.node,'招财猫节点');
this.schedule(this.workSchdule, 1)
}
workSchdule(dt: number) {
if (!gg.game.CurentBattle.canUpdateFrame()) return;
if (!this.isXiufuFinish) {
return
}
const scaled = dt * gg.game.CurentBattle.TimeScale;
if (this.curState == 'work') {
this.workTime += scaled
if (this.workTime >= this.workTimeFix) {
this.curState = 'pauseWorkTime'
this.pauseWorkTime = 0
this.refreshBtn()
} else {
//检测是不是有怪物被减速了
let bombMonsters = gg.game.CurentBattle.MonsterSpawner.getMonstersInArea(this.node.worldPosition, this.explodeRadius);
// console.log('冰霜区域内有怪物??==', bombMonsters.length)
// bombMonsters.forEach((monsterNode) => {
// // 已有冰霜计时(BuffIceSchedule)则不再 reset,避免反复刷新减速时长
// if (monsterNode.getComponent(BuffIceSchedule)) {
// monsterNode.getComponent(Monster)?.resetIceBuff(this.reduceTime, this.reduceSpeed, false);
// return;
// }
// monsterNode.getComponent(Monster)?.resetIceBuff(this.reduceTime, this.reduceSpeed, true);
// });
}
} else if (this.curState == 'pauseWorkTime') {
this.pauseWorkTime += scaled
if (this.pauseWorkTime >= this.pauseWorkTimeFix) {
this.curState = 'work'
this.workTime = 0
this.refreshBtn()
}
}
}
refreshBtn() {
if (this.isXiufuFinish) {
if (this.curState == 'work') {
this.node.getChildByName('破损').active = false
this.node.getChildByName('修复').active = false
this.node.getChildByName('打开').active = true
} else {
this.node.getChildByName('破损').active = false
this.node.getChildByName('修复').active = true
this.node.getChildByName('打开').active = false
}
} else {
this.node.getChildByName('破损').active = true
this.node.getChildByName('修复').active = false
this.node.getChildByName('打开').active = false
}
}
}