fix(战斗系统): 修复伤害数值出错问题
- 修复在DamageEvent接口和DamageQueueComp缺少ext_dmg和dmg_ratio字段问题 - 修复HeroAtkSystem的伤害计算逻辑 - 优化HeroViewComp的hp_show和mp_show方法,直接使用model数据 - 默认显示血条并增加调试日志输出 - 移除冗余的debug日志,优化伤害计算流程
This commit is contained in:
@@ -66,16 +66,9 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
if (!damageEvent) break;
|
||||
|
||||
// 处理单个伤害事件
|
||||
const FDData = this.doAttack(e, damageEvent);
|
||||
this.doAttack(e, damageEvent);
|
||||
processedCount++;
|
||||
damageQueue.processedCount++;
|
||||
|
||||
if (this.debugMode) {
|
||||
const casterName = damageEvent.caster?.ent?.get(HeroAttrsComp)?.hero_name || "未知";
|
||||
const casterUuid = damageEvent.caster?.ent?.get(HeroAttrsComp)?.hero_uuid || 0;
|
||||
console.log(`[HeroAtkSystem] 英雄${TAttrsComp.hero_name} (uuid: ${TAttrsComp.hero_uuid}) 受到 ${casterName}(uuid: ${casterUuid})的 伤害 ${FDData.damage},${FDData.isCrit?"暴击":"普通"}攻击,技能ID ${damageEvent.s_uuid}`);
|
||||
}
|
||||
|
||||
// 如果目标已死亡,停止处理后续伤害
|
||||
if (TAttrsComp.is_dead) {
|
||||
if (this.debugMode) {
|
||||
@@ -158,6 +151,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
const isCrit = this.checkChance(damageEvent.Attrs[Attrs.CRITICAL]-TAttrsComp.Attrs[Attrs.CRITICAL_RESIST]);
|
||||
// 计算基础伤害
|
||||
let damage = this.dmgCount(damageEvent,TAttrsComp);
|
||||
console.log("[HeroAtkSystem] dmgCount",damage)
|
||||
if (isCrit) {
|
||||
// 暴击伤害计算
|
||||
// 使用施法者的暴击伤害加成属性(damageEvent.Attrs 快照)
|
||||
@@ -168,12 +162,18 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
CAttrsComp?.useValueTalByAttr(Attrs.CRITICAL); // 清除施法者的暴击buff
|
||||
|
||||
}
|
||||
console.log("[HeroAtkSystem] after crit",damage)
|
||||
// 护盾吸收
|
||||
damage =Math.floor(this.absorbShield(TAttrsComp, damage))
|
||||
console.log("[HeroAtkSystem] after shield",damage)
|
||||
if (damage <= 0) return reDate;
|
||||
// 应用伤害到数据层
|
||||
TAttrsComp.hp -= damage;
|
||||
TAttrsComp.atked_count++;
|
||||
if (this.debugMode) {
|
||||
const casterName = damageEvent.caster?.ent?.get(HeroAttrsComp)?.hero_name || "未知";
|
||||
const casterUuid = damageEvent.caster?.ent?.get(HeroAttrsComp)?.hero_uuid || 0;
|
||||
console.log(`[HeroAtkSystem] 英雄${TAttrsComp.hero_name} (uuid: ${TAttrsComp.hero_uuid}) 受到 ${casterName}(uuid: ${casterUuid})的 伤害 ${damage},${isCrit?"暴击":"普通"}攻击,技能ID ${damageEvent.s_uuid}`);
|
||||
}
|
||||
//反伤判定 并应用到施法者
|
||||
this.check_thorns(TAttrsComp, caster?.ent,damage);
|
||||
// 击退判定
|
||||
@@ -198,9 +198,8 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
}
|
||||
}
|
||||
|
||||
if (this.debugMode) {
|
||||
console.log(`[HeroAtkSystem] ${TAttrsComp.hero_name} 受到 ${damage} 点伤害 (暴击: ${isCrit})`);
|
||||
}
|
||||
if (this.debugMode) console.log(`[HeroAtkSystem] ${TAttrsComp.hero_name} 受到 ${damage} 点伤害 (暴击: ${isCrit})`);
|
||||
|
||||
|
||||
reDate.damage=damage;
|
||||
return reDate;
|
||||
@@ -256,19 +255,21 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
* - 所有除法和乘法计算后都进行取整操作,确保游戏中的伤害值为整数
|
||||
* - 元素伤害只应用于魔法伤害部分
|
||||
*/
|
||||
private dmgCount(damageEvent:any,TAttrsComp:HeroAttrsComp){
|
||||
private dmgCount(damageEvent:DamageEvent,TAttrsComp:HeroAttrsComp){
|
||||
// 1. 获取技能配置 - 如果技能不存在,直接返回0伤害
|
||||
const CAttrs=damageEvent.Attrs;
|
||||
const TAttrs=TAttrsComp.Attrs;
|
||||
let sConf = SkillSet[damageEvent.s_uuid];
|
||||
if (!sConf) return 0;
|
||||
|
||||
if (this.debugMode) console.log(`[HeroAtkSystem] 伤害处理对象`,CAttrs,TAttrs);
|
||||
// 2. 计算原始物理伤害和魔法伤害
|
||||
// 物理伤害基础值 = 技能物理倍率 * (施法者物理攻击力 + 额外物理伤害) / 100 * 伤害比例
|
||||
// 物理伤害基础值 = 技能物理倍率 * (施法者物理攻击力 + 额外伤害) / 100 * 额外伤害比例
|
||||
let apBase = (sConf.ap||0)*(CAttrs[Attrs.AP]+damageEvent.ext_dmg)/100*damageEvent.dmg_ratio;
|
||||
// 魔法伤害基础值 = 技能魔法倍率 * (施法者魔法攻击力 + 额外魔法伤害) / 100 * 伤害比例
|
||||
// 魔法伤害基础值 = 技能魔法倍率 * (施法者魔法攻击力 + 额外伤害) / 100 * 额外伤害比例
|
||||
let mapBase = (sConf.map||0)*(CAttrs[Attrs.MAP]+damageEvent.ext_dmg)/100*damageEvent.dmg_ratio;
|
||||
|
||||
if (this.debugMode) console.log(`[HeroAtkSystem] 物理伤害基础值: ${apBase}, 技能ap=${sConf.ap},施法者物理攻击力: ${CAttrs[Attrs.AP]}, 魔法伤害基础值: ${mapBase}技能map=${sConf.map}
|
||||
额外伤害:${damageEvent.ext_dmg}, 额外伤害比例:${damageEvent.dmg_ratio}`);
|
||||
|
||||
// 3. 获取目标防御属性
|
||||
const def = (TAttrs[Attrs.DEF]||0); // 目标物理防御
|
||||
const mdef = (TAttrs[Attrs.MDEF]||0); // 目标魔法防御
|
||||
@@ -281,14 +282,15 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
let apAfter = Math.floor(apBase * (1 - apRed)); // 物理伤害 - 防御减免
|
||||
let mapAfter = Math.floor(mapBase * (1 - mapRed)); // 魔法伤害 - 防御减免
|
||||
|
||||
|
||||
|
||||
if (this.debugMode) console.log(`[HeroAtkSystem] 物理伤害基础值: ${apBase}, 物理伤害 - 防御减免: ${apAfter} 魔法伤害基础值: ${mapBase}, 魔法伤害 - 防御减免: ${mapAfter}`);
|
||||
|
||||
// 6. 应用物理/魔法攻击力和抗性修正
|
||||
// 物理伤害修正:基础伤害 * (1 + 物理攻击力加成%) * (1 - 目标物理抗性%)
|
||||
apAfter = this.applyPR(apAfter, CAttrs[Attrs.PHYS_POWER]||0, TAttrs[Attrs.PHYS_RES]||0);
|
||||
// 魔法伤害修正:基础伤害 * (1 + 魔法攻击力加成%) * (1 - 目标魔法抗性%)
|
||||
mapAfter = this.applyPR(mapAfter, CAttrs[Attrs.MAGIC_POWER]||0, TAttrs[Attrs.MAGIC_RES]||0);
|
||||
|
||||
if (this.debugMode) console.log(`[HeroAtkSystem] 物理伤害修正后: ${apAfter} 魔法伤害修正后: ${mapAfter} `);
|
||||
|
||||
// 7. 根据技能元素类型,应用元素属性加成和抗性修正
|
||||
switch (sConf.DType) {
|
||||
case DType.ICE:
|
||||
@@ -304,6 +306,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
mapAfter = this.applyPR(mapAfter, CAttrs[Attrs.WIND_POWER]||0, TAttrs[Attrs.WIND_RES]||0);
|
||||
break;
|
||||
}
|
||||
if (this.debugMode) console.log(`[HeroAtkSystem] 物理伤害修正后: ${apAfter} 元素伤害修正后: ${mapAfter}`);
|
||||
|
||||
// 8. 计算最终总伤害(物理伤害 + 魔法伤害)
|
||||
let total = apAfter + mapAfter;
|
||||
@@ -315,7 +318,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
total = Math.max(0,total);
|
||||
//11. 易伤减免 免伤属性免伤+天赋免伤
|
||||
total = Math.floor(total * (1 + ((DMG_INVUL-DMG_RED)/100)));
|
||||
|
||||
if (this.debugMode) console.log(`[HeroAtkSystem] 易伤减免后: ${total}`);
|
||||
return Math.max(0,total);
|
||||
}
|
||||
|
||||
@@ -461,7 +464,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
private onAttacked(entity: ecs.Entity): void {
|
||||
const TAttrsComp = entity.get(HeroAttrsComp);
|
||||
if (!TAttrsComp || TAttrsComp.is_dead) return;
|
||||
|
||||
TAttrsComp.atked_count++;
|
||||
// 这里可以添加被攻击时的特殊处理逻辑
|
||||
if (TAttrsComp.fac === FacSet.MON) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user