refactor(HeroAtkSystem): 重构伤害计算逻辑以提高可维护性

将原有的伤害计算逻辑拆分为更清晰的步骤,引入applyPR方法统一处理伤害加成和抗性计算
根据技能类型(DType)应用对应的元素伤害计算
使用防御和魔防的百分比减免公式替代原有的固定值减免
This commit is contained in:
2025-11-21 10:28:14 +08:00
parent 58fa6527ee
commit 2dc43b5b81

View File

@@ -2,7 +2,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
import { FacSet } from "../common/config/GameSet"; import { FacSet } from "../common/config/GameSet";
import { Attrs } from "../common/config/HeroAttrs"; import { Attrs } from "../common/config/HeroAttrs";
import { FightSet } from "../common/config/GameSet"; import { FightSet } from "../common/config/GameSet";
import { SkillSet } from "../common/config/SkillSet"; import { SkillSet, DType } from "../common/config/SkillSet";
import { HeroAttrsComp } from "./HeroAttrsComp"; import { HeroAttrsComp } from "./HeroAttrsComp";
import { HeroViewComp } from "./HeroViewComp"; import { HeroViewComp } from "./HeroViewComp";
import { DamageQueueComp, DamageEvent, DamageQueueHelper } from "./DamageQueueComp"; import { DamageQueueComp, DamageEvent, DamageQueueHelper } from "./DamageQueueComp";
@@ -220,21 +220,33 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
if (!sConf) return 0; if (!sConf) return 0;
let apBase = (sConf.ap||0)*CAttrs[Attrs.AP]/100; let apBase = (sConf.ap||0)*CAttrs[Attrs.AP]/100;
let mapBase = (sConf.map||0)*CAttrs[Attrs.MAP]/100; let mapBase = (sConf.map||0)*CAttrs[Attrs.MAP]/100;
let apAfter = Math.max(0, Math.floor(apBase - (TAttrs[Attrs.DEF]||0))); const def = (TAttrs[Attrs.DEF]||0);
let mapAfter = Math.max(0, Math.floor(mapBase - (TAttrs[Attrs.MDEF]||0))); const mdef = (TAttrs[Attrs.MDEF]||0);
mapAfter = Math.floor(mapAfter * (1 - ((TAttrs[Attrs.MAGIC_RES]||0)/100))); const apRed = def / (def + FightSet.DEF_C);
let total = apAfter + mapAfter; const mapRed = mdef / (mdef + FightSet.MDEF_C);
if (sConf.elem){ let apAfter = Math.floor(apBase * (1 - apRed));
const iceR = sConf.elem.ice||0; let mapAfter = Math.floor(mapBase * (1 - mapRed));
if (iceR) total += Math.floor(total * iceR/100 * (1 + ((CAttrs[Attrs.ICE_POWER]||0)/100)) * (1 - ((TAttrs[Attrs.ICE_RES]||0)/100))); apAfter = this.applyPR(apAfter, CAttrs[Attrs.PHYS_POWER]||0, TAttrs[Attrs.PHYS_RES]||0);
const fireR = sConf.elem.fire||0; mapAfter = this.applyPR(mapAfter, CAttrs[Attrs.MAGIC_POWER]||0, TAttrs[Attrs.MAGIC_RES]||0);
if (fireR) total += Math.floor(total * fireR/100 * (1 + ((CAttrs[Attrs.FIRE_POWER]||0)/100)) * (1 - ((TAttrs[Attrs.FIRE_RES]||0)/100))); switch (sConf.DType) {
const windR = sConf.elem.wind||0; case DType.ICE:
if (windR) total += Math.floor(total * windR/100 * (1 + ((CAttrs[Attrs.WIND_POWER]||0)/100)) * (1 - ((TAttrs[Attrs.WIND_RES]||0)/100))); mapAfter = this.applyPR(mapAfter, CAttrs[Attrs.ICE_POWER]||0, TAttrs[Attrs.ICE_RES]||0);
break;
case DType.FIRE:
mapAfter = this.applyPR(mapAfter, CAttrs[Attrs.FIRE_POWER]||0, TAttrs[Attrs.FIRE_RES]||0);
break;
case DType.WIND:
mapAfter = this.applyPR(mapAfter, CAttrs[Attrs.WIND_POWER]||0, TAttrs[Attrs.WIND_RES]||0);
break;
} }
let total = apAfter + mapAfter;
total = Math.floor(total * (1 - ((TAttrs[Attrs.DAMAGE_REDUCTION]||0)/100))); total = Math.floor(total * (1 - ((TAttrs[Attrs.DAMAGE_REDUCTION]||0)/100)));
return Math.max(0,total); return Math.max(0,total);
} }
private applyPR(base: number, power: number, res: number): number {
return Math.floor(base * (1 + (power/100)) * (1 - (res/100)));
}
/** /**
* 处理角色死亡 * 处理角色死亡
* *