修复 伤害错误
This commit is contained in:
@@ -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) {
|
private applySkillEffect(caster: ecs.Entity, target: ecs.Entity, config: typeof SkillSet[keyof typeof SkillSet],skillEntity:ecs.Entity) {
|
||||||
const casterView = caster.get(HeroViewComp);
|
const casterView = caster.get(HeroViewComp);
|
||||||
const targetView = target.get(HeroViewComp);
|
|
||||||
|
|
||||||
// 直接计算伤害(包含防御减免)
|
|
||||||
const damageResult = this.calculateDamage(caster, target, config);
|
|
||||||
|
|
||||||
// 播放技能特效
|
// 播放技能特效
|
||||||
casterView.playSkillEffect(config.uuid);
|
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() {
|
public clear_timer() {
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ export class SkillSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
|||||||
if(this.checkSkill(skill)){
|
if(this.checkSkill(skill)){
|
||||||
if(skill.atk_count < 1){
|
if(skill.atk_count < 1){
|
||||||
skill.atk_count++;
|
skill.atk_count++;
|
||||||
console.log("技能命中目标",skill.target.hero_name);
|
// console.log("技能命中目标",skill.caster,skill.target,SkillSet[skill.s_uuid]);
|
||||||
this.applySkillEffect(skill.caster,skill.target,SkillSet[skill.s_uuid],skill);
|
this.applySkillEffect(skill.caster,skill.target,SkillSet[skill.s_uuid]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.processDamageQueue();
|
this.processDamageQueue();
|
||||||
@@ -63,10 +63,9 @@ export class SkillSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
|||||||
return isInRange;
|
return isInRange;
|
||||||
}
|
}
|
||||||
/** 应用技能效果 */
|
/** 应用技能效果 */
|
||||||
private applySkillEffect(casterView:HeroViewComp, targetView: HeroViewComp, config: typeof SkillSet[keyof typeof SkillSet],skill:SkillCom) {
|
private applySkillEffect(casterView:HeroViewComp, targetView: HeroViewComp, config: typeof SkillSet[keyof typeof SkillSet]) {
|
||||||
|
|
||||||
// 直接计算伤害(包含防御减免)
|
// 直接计算伤害(包含防御减免)
|
||||||
const damageResult = this.calculateDamage(casterView, casterView, config);
|
const damageResult = this.calculateDamage(casterView, targetView, config);
|
||||||
// 将施法者传入applyDamage方法
|
// 将施法者传入applyDamage方法
|
||||||
this.applyDamage(targetView,damageResult);
|
this.applyDamage(targetView,damageResult);
|
||||||
// 播放技能特效
|
// 播放技能特效
|
||||||
@@ -83,24 +82,11 @@ private calculateDamage(caster: HeroViewComp, target: HeroViewComp, config: type
|
|||||||
ignoreDefense: false,
|
ignoreDefense: false,
|
||||||
canCrit: true,
|
canCrit: true,
|
||||||
}
|
}
|
||||||
|
let final = caster.ap * config.ap / 100;
|
||||||
// 计算延迟时间
|
|
||||||
if (config.AnimType === AnimType.parabolic) {
|
|
||||||
const sourcePos = caster.node.position;
|
|
||||||
const targetPos = target.node.position;
|
|
||||||
// 计算距离除以速度得到时间
|
|
||||||
const distance = Math.abs(targetPos.x - sourcePos.x);
|
|
||||||
result.delay = distance / config.speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
const sourceView = caster;
|
|
||||||
let final = sourceView.ap * config.ap / 100;
|
|
||||||
|
|
||||||
// 伤害浮动(±10%)
|
// 伤害浮动(±10%)
|
||||||
const damageFloat = 0.9 + Math.random() * 0.2; // 0.9~1.1
|
const damageFloat = 0.9 + Math.random() * 0.2; // 0.9~1.1
|
||||||
final *= damageFloat;
|
final *= damageFloat;
|
||||||
final = Math.round(final);
|
final = Math.round(final);
|
||||||
|
|
||||||
result.value = Math.max(1, final); // 确保最小伤害为1
|
result.value = Math.max(1, final); // 确保最小伤害为1
|
||||||
result.isCrit = false;
|
result.isCrit = false;
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ export class Skill extends ecs.Entity {
|
|||||||
console.log("加载预制体:",startPos,targetPos)
|
console.log("加载预制体:",startPos,targetPos)
|
||||||
// 添加技能组件
|
// 添加技能组件
|
||||||
const skillComp = node.getComponent(SkillCom); // 初始化技能参数
|
const skillComp = node.getComponent(SkillCom); // 初始化技能参数
|
||||||
|
skillComp.s_uuid = uuid;
|
||||||
skillComp.animType = config.AnimType;
|
skillComp.animType = config.AnimType;
|
||||||
skillComp.endType = config.endType;
|
skillComp.endType = config.endType;
|
||||||
skillComp.speed = config.speed;
|
skillComp.speed = config.speed;
|
||||||
|
|||||||
Reference in New Issue
Block a user