import { _decorator, Component, Node } from 'cc'; import { oops } from 'db://oops-framework/core/Oops'; import { GameEvent } from '../common/config/GameEvent'; import { geDebuffNum, getBuffNum, BuffAttr, DebuffAttr } from '../common/config/SkillSet'; const { ccclass, property } = _decorator; @ccclass('FightConComp') export class FightConComp extends Component { hero=getBuffNum() ally=getBuffNum() enemy=getBuffNum() friend=getBuffNum() hero_debuff=geDebuffNum() ally_debuff=geDebuffNum() enemy_debuff=geDebuffNum() friend_debuff=geDebuffNum() //注意临时buff和debuff 每种buff的值 必须都一样 多种值 战斗处理复杂 暂时放弃 temp_hero_buff = this.getInitTempDebuff(); temp_ally_buff = this.getInitTempDebuff(); temp_enemy_buff = this.getInitTempDebuff(); temp_friend_buff = this.getInitTempDebuff(); temp_hero_debuff = this.getInitTempBuffDebuff(); temp_ally_debuff = this.getInitTempBuffDebuff(); temp_enemy_debuff = this.getInitTempBuffDebuff(); temp_friend_debuff = this.getInitTempBuffDebuff(); onLoad(){ // console.log("fight con start") oops.message.on(GameEvent.EquipChange,this.equip_change,this) oops.message.on(GameEvent.FightReady,this.fight_ready,this) } private equip_change(e:GameEvent,equip:any){ this.hero=equip.hero this.ally=equip.ally this.enemy=equip.enemy this.friend=equip.friend } private fight_ready(e:GameEvent){ this.hero=this.ally=this.enemy=this.friend=getBuffNum() this.hero_debuff=this.ally_debuff=this.enemy_debuff=this.friend_debuff=geDebuffNum() this.clearAllTempBuffs() // console.log("临时英雄buff:",this.temp_hero_buff) // console.log("临时英雄debuff:",this.temp_hero_debuff) // console.log("临时全部buff:",this.temp_ally_buff) // console.log("临时全部debuff:",this.temp_ally_debuff) // console.log("临时敌方buff:",this.temp_enemy_buff) // console.log("临时敌方debuff:",this.temp_enemy_debuff) // console.log("临时友军buff:",this.temp_friend_buff) // console.log("临时友军debuff:",this.temp_friend_debuff) } // 添加临时buff addTempBuff(target: 'hero'|'ally'|'enemy'|'friend', buffId: number, value: number, count: number) { const key = `temp_${target}_buff`; if (!this[key][buffId]) { this[key][buffId] = { value, count }; } else { this[key][buffId].value += value; this[key][buffId].count += count; } } // 触发一次buff效果后减少次数 triggerTempBuff(target: 'hero'|'ally'|'enemy'|'friend', buffId: number) { const key = `temp_${target}_buff`; if (this[key][buffId]) { this[key][buffId].count -= 1; if (this[key][buffId].count <= 0) { delete this[key][buffId]; } } } // 初始化所有buff/debuff为0 private getInitTempBuffDebuff() { const obj = {}; for (const key in BuffAttr) { if (!isNaN(Number(key))) { obj[Number(key)] = { value: 0, count: 0 }; } } return obj; } private getInitTempDebuff() { const obj = {}; for (const key in DebuffAttr) { if (!isNaN(Number(key))) { obj[Number(key)] = { value: 0, count: 0 }; } } return obj; } private clearAllTempBuffs() { this.temp_hero_buff = this.temp_ally_buff = this.temp_enemy_buff = this.temp_friend_buff = this.getInitTempBuffDebuff(); this.temp_hero_debuff = this.temp_ally_debuff = this.temp_enemy_debuff = this.temp_friend_debuff = this.getInitTempDebuff(); } update(deltaTime: number) { } }