攻击次数 继续完善

This commit is contained in:
2025-06-12 10:56:12 +08:00
parent a0bd1da1ca
commit 4c0d1023a0
8 changed files with 91 additions and 53 deletions

View File

@@ -35,6 +35,7 @@ export class SkillConComp extends CCComp {
update(dt: number) {
if(!smc.mission.play||smc.mission.pause) return
this.HeroView.at += dt;
if (this.HeroView.is_atking &&this.HeroView.at > this.HeroView.cd) {
const config = SkillSet[this.HeroView.atk_skill];
if (!config) return;
@@ -44,6 +45,7 @@ export class SkillConComp extends CCComp {
}else{
count+=this.FIGHTCON.friend.ATK_COUNT+this.FIGHTCON.ally.ATK_COUNT
}
console.log(this.HeroView.hero_name+(this.HeroView.is_master?"[主]":"[从]")+"=>"+config.name+"=>"+count)
this.castSkill(config,count);
this.HeroView.at = 0;
}
@@ -75,23 +77,46 @@ export class SkillConComp extends CCComp {
}
}
private doSkill(config: typeof SkillSet[keyof typeof SkillSet],count:number=1) {
private doSkill(config: typeof SkillSet[keyof typeof SkillSet],count:number=1,angle:number=0) {
// 添加节点有效性检查
if (!this.node || !this.node.isValid || !this.HeroView || !this.HeroView.node || !this.HeroView.node.isValid) {
return;
}
const skillEntity = ecs.getEntity<Skill>(Skill);
const targets = this.selectEnemyTargets(config);
if (targets.length === 0) return;
this.scheduleOnce(()=>{
if(targets.length<=0||!this.HeroView) return
const timerId = setTimeout(() => {
// 再次检查节点有效性
if (!this.node || !this.node.isValid || !this.HeroView || !this.HeroView.node || !this.HeroView.node.isValid) {
return;
}
// 检查目标有效性
if (targets.length <= 0 || !targets[0]) return;
const targetView = targets[0].get(HeroViewComp);
if (!targetView || !targetView.node || !targetView.node.isValid) return;
skillEntity.load(
new Vec3(this.HeroView.node.position.x+BoxSet.ATK_X*this.HeroView.scale, this.HeroView.node.position.y+BoxSet.ATK_Y, 0), // 起始位置
this.HeroView.box_group, // 阵营
this.node.parent, // 父节点
config.uuid, // 技能ID
new Vec3(targets[0]?.get(HeroViewComp).node.position.x, targets[0]?.get(HeroViewComp).node.position.y, 0), // 目标位置
this.HeroView
new Vec3(this.HeroView.node.position.x + BoxSet.ATK_X * this.HeroView.scale,
this.HeroView.node.position.y + BoxSet.ATK_Y, 0),
this.node.parent,
config.uuid,
new Vec3(targetView.node.position.x, targetView.node.position.y, 0),
this.HeroView,
angle
);
},0.3)
// console.log("技能:"+config.uuid+"=>"+targets[0]?.get(HeroViewComp).hero_name);
}, 300);
count-=1
if(count>0){
let angle=10*count
this.scheduleOnce(()=>{
this.doSkill(config,count,angle)
},0.1)
}
// 保存定时器ID
this._timers[`skill_${config.uuid}`] = timerId;
}
private selectEnemyTargets(config: typeof SkillSet[keyof typeof SkillSet]): ecs.Entity[] {
@@ -144,8 +169,11 @@ export class SkillConComp extends CCComp {
}
onDestroy() {
// console.log("SkillConComp onDestroy")
// 清理所有定时器
Object.values(this._timers).forEach(clearTimeout);
this._timers = {};
// 移除事件监听
this.off(GameEvent.CastHeroSkill);
}
}