Files
heros/assets/script/game/map/FightConComp.ts
2025-06-19 17:28:55 +08:00

181 lines
6.3 KiB
TypeScript

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';
import { Timer } from 'db://oops-framework/core/common/timer/Timer';
import { FightSet } from '../common/config/Mission';
import { SuperCards, SuperCardsType } from '../common/config/CardSet';
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 //卡牌特效 攻击提高生命值效果 额外添加值
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:
break
case SuperCardsType.BUFF:
break
case SuperCardsType.DEBUFF:
break
}
}
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
}
update(deltaTime: number) {
}
}