修复 伤害错误

This commit is contained in:
2025-03-26 16:57:15 +08:00
parent 8b33abb973
commit 63e182e214
3 changed files with 6 additions and 56 deletions

View File

@@ -121,46 +121,9 @@ export class HeroSkillSystem extends ecs.ComblockSystem implements ecs.ISystemUp
/** 应用技能效果 */
private applySkillEffect(caster: ecs.Entity, target: ecs.Entity, config: typeof SkillSet[keyof typeof SkillSet],skillEntity:ecs.Entity) {
const casterView = caster.get(HeroViewComp);
const targetView = target.get(HeroViewComp);
// 直接计算伤害(包含防御减免)
const damageResult = this.calculateDamage(caster, target, config);
// 播放技能特效
casterView.playSkillEffect(config.uuid);
console.log(`${casterView.hero_name}${targetView.hero_name} 造成 ${damageResult.value}伤害`);
}
private calculateDamage(caster: ecs.Entity, target: ecs.Entity, config: typeof SkillSet[keyof typeof SkillSet]) {
const result = {
value: 0,
isCrit: false,
isDodged: false,
delay: 0.3, // 默认延迟
ignoreDefense: false,
canCrit: true,
}
// 计算延迟时间
if (config.AnimType === AnimType.parabolic) {
const sourcePos = caster.get(HeroViewComp).node.position;
const targetPos = target.get(HeroViewComp).node.position;
// 计算距离除以速度得到时间
const distance = Math.abs(targetPos.x - sourcePos.x);
result.delay = distance / config.speed;
}
const sourceView = caster.get(HeroViewComp);
let final = sourceView.ap * config.ap / 100;
// 伤害浮动±10%
const damageFloat = 0.9 + Math.random() * 0.2; // 0.9~1.1
final *= damageFloat;
final = Math.round(final);
result.value = Math.max(1, final); // 确保最小伤害为1
result.isCrit = false;
return result;
}
public clear_timer() {