import { _decorator, Component, Node, Vec3 } 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'; import { Timer } from 'db://oops-framework/core/common/timer/Timer'; import { FightSet } from '../common/config/Mission'; import { SuperCards, SuperCardsType } from '../common/config/CardSet'; import { ecs } from 'db://oops-framework/libs/ecs/ECS'; import { Skill } from '../skills/Skill'; import { MasterModelComp } from '../hero/MasterModel'; import { HeroViewComp } from '../hero/HeroViewComp'; import { MonModelComp } from '../hero/MonModelComp'; const { ccclass, property } = _decorator; @ccclass('FightConComp') export class FightConComp extends Component { hero_buff=getBuffNum() friend_buff=getBuffNum() enemy_buff=getBuffNum() hero_debuff=geDebuffNum() friend_debuff=geDebuffNum() enemy_debuff=geDebuffNum() //注意临时buff和debuff 每种buff的值 必须都一样 多种值 战斗处理复杂 暂时放弃 temp_hero_buff = this.getInitTempBuff(); temp_friend_buff = this.getInitTempBuff(); temp_enemy_buff = this.getInitTempBuff(); temp_hero_debuff = this.getInitTempDebuff(); temp_friend_debuff = this.getInitTempDebuff(); temp_enemy_debuff = this.getInitTempDebuff(); atk_type:number=0; //装备特殊属性 friend_alive_cd:number=FightSet.FRIEND_LIVE_CD atk_add_friend_atk:number=0 atk_add_friend_hp:number=0 atk_add_glod:number=0 atk_add_master_atk:number=0 atk_add_master_hp:number=0 //卡牌特效 card_atk_add:number=0 //卡牌特效 攻击提高攻击力效果 额外添加值 card_hp_add:number=0 //卡牌特效 攻击提高生命值效果 额外添加值 aoe_queues:any[]=[] // 范围伤害技能执行队列 private aoe_timer: number = 0; // 技能执行计时器 private readonly AOE_INTERVAL: number = 0.4; // 执行间隔,单位秒 aoe_pos:Vec3=new Vec3(-280,300,0) aoe_target_pos:Vec3=new Vec3(180,0,0) buff_pos:Vec3=new Vec3(-280,100,0) debuff_pos:Vec3=new Vec3(-280,100,0) onLoad(){ // console.log("fight con start") oops.message.on(GameEvent.EquipChange,this.equip_change,this) oops.message.on(GameEvent.FightReady,this.fight_ready,this) oops.message.on(GameEvent.ChangeATK_EQUIP_SPECIAL_ATTR,this.change_equip_special_attr,this) oops.message.on(GameEvent.UseSpecialCard,this.use_special_card,this) } protected start(): void { this.friend_alive_cd=FightSet.FRIEND_LIVE_CD } change_equip_special_attr(e:GameEvent,data:any){ console.log("[FightConComp]:change_equip_special_attr",data) this.atk_add_friend_atk=data.atk_add_friend_atk+(this.card_atk_add > 0 ? this.card_atk_add:0) //装备特殊属性 英雄/伙伴 攻击力增加 this.atk_add_friend_hp=data.atk_add_friend_hp+(this.card_hp_add > 0 ? this.card_hp_add:0) //装备特殊属性 英雄/伙伴 生命值增加 this.atk_add_glod=data.atk_add_glod this.atk_add_master_atk=data.atk_add_master_atk+(this.card_atk_add > 0 ? this.card_atk_add:0) //装备特殊属性 英雄/伙伴 攻击力增加 this.atk_add_master_hp=data.atk_add_master_hp+(this.card_hp_add > 0 ? this.card_hp_add:0) //装备特殊属性 英雄/伙伴 生命值增加 this.friend_alive_cd=FightSet.FRIEND_LIVE_CD-data.friend_live_cd_less } private equip_change(e:GameEvent,equip:any){ this.hero_buff=equip.hero_buff this.friend_buff=equip.friend_buff this.hero_debuff=equip.hero_debuff this.friend_debuff=equip.friend_debuff this.enemy_debuff=equip.enemy_debuff } private fight_ready(e:GameEvent){ this.clearAlls() } // 添加临时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 getInitTempBuff() { 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 use_special_card(e:GameEvent,data:any){ console.log("[FightConComp]:use_special_card:",SuperCards[data.uuid]) switch(SuperCards[data.uuid].type){ case SuperCardsType.SPECIAL: switch(data.uuid){ case 3001: console.log("[FightConComp]:use_special_card:附魔宝典") this.card_atk_add+=SuperCards[data.uuid].value1 break case 3002: console.log("[FightConComp]:use_special_card:附魔宝典") this.card_hp_add+=SuperCards[data.uuid].value1 break } break case SuperCardsType.AOE: this.aoe_queues.push({ s_uuid:SuperCards[data.uuid].value1, count:SuperCards[data.uuid].value2, damage:SuperCards[data.uuid].value3}) break case SuperCardsType.BUFF: break case SuperCardsType.DEBUFF: break } } private aoe_skill_execute(data:any){ let skill=ecs.getEntity(Skill) let master = ecs.query(ecs.allOf(MasterModelComp)) // 检查必要参数 if (!master || master.length === 0) { console.error("[FightConComp] 未找到主角实体"); return; } let masterView = master[0].get(HeroViewComp); if (!masterView) { console.error("[FightConComp] 主角视图组件获取失败"); return; } let angle=0 let targets = this.pickRandomTarget(data.count) let target_pos= new Vec3(0,0,0) if(targets.length==0){ target_pos=this.aoe_target_pos }else{ target_pos= new Vec3(targets[0].get(HeroViewComp).node.position.x,0,0) } skill.load( this.aoe_pos, this.node, data.s_uuid, target_pos, masterView, angle, data.damage ); } /** 随机选择目标 */ private pickRandomTarget(count: number=1): ecs.Entity[] { let entities = ecs.query(ecs.allOf(MonModelComp)) const shuffled = [...entities].sort(() => 0.5 - Math.random()); return shuffled.slice(0, count); } private clearAlls() { this.hero_buff=getBuffNum() this.friend_buff=getBuffNum() this.enemy_buff=getBuffNum() this.hero_debuff=geDebuffNum() this.friend_debuff=geDebuffNum() this.enemy_debuff=geDebuffNum() this.temp_hero_buff = this.getInitTempBuff() this.temp_friend_buff = this.getInitTempBuff() this.temp_enemy_buff = this.getInitTempBuff() this.temp_hero_debuff = this.getInitTempDebuff() this.temp_friend_debuff = this.getInitTempDebuff() this.temp_enemy_debuff = this.getInitTempDebuff() this.friend_alive_cd=FightSet.FRIEND_LIVE_CD this.atk_add_friend_atk=0 this.atk_add_friend_hp=0 this.atk_add_glod=0 this.atk_add_master_atk=0 this.atk_add_master_hp=0 this.card_atk_add=0 this.card_hp_add=0 this.aoe_queues = [] // 清空技能队列 this.aoe_timer = 0 // 重置计时器 } update(deltaTime: number) { // 更新技能执行计时器 if (this.aoe_queues.length > 0) { this.aoe_timer += deltaTime; if (this.aoe_timer >= this.AOE_INTERVAL) { this.aoe_timer = 0; let skill = this.aoe_queues[0]; this.aoe_skill_execute(skill); skill.count--; if (skill.count <= 0) { this.aoe_queues.shift(); // 移除已完成的技能 } } } } }