refactor(skill): 重构伤害计算逻辑
- 删除SkillEnt.ts及其meta文件,简化技能实体管理 - 将SDataCom重命名为更清晰的DmgDataCom和SDataCom - 重构伤害计算系统,增加命中检测和伤害类型处理 - 优化技能碰撞检测逻辑,支持范围伤害和数量限制
This commit is contained in:
@@ -3,6 +3,7 @@ import { FacSet } from "../common/config/BoxSet";
|
||||
import { Attrs } from "../common/config/HeroAttrs";
|
||||
import { FightSet } from "../common/config/Mission";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { DmgDataCom } from "../skill/SDataCom";
|
||||
import { HeroAttrsComp } from "./HeroAttrsComp";
|
||||
import { HeroViewComp } from "./HeroViewComp";
|
||||
|
||||
@@ -14,8 +15,12 @@ export class HeroAtkComp extends ecs.Comp {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/** 业务层业务逻辑处理对象 */
|
||||
interface FDData{
|
||||
damage:number,
|
||||
isCrit:boolean,
|
||||
isDodge:boolean,
|
||||
}
|
||||
/** 业务层业务逻辑处理对象 伤害处理系统 */
|
||||
@ecs.register('HeroAtkSystem')
|
||||
export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate, ecs.IEntityEnterSystem {
|
||||
|
||||
@@ -25,7 +30,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
* 过滤器:只处理拥有 HeroAttrsComp 的实体
|
||||
*/
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(HeroAttrsComp);
|
||||
return ecs.allOf(HeroAttrsComp,DmgDataCom);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,9 +38,11 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
*/
|
||||
entityEnter(e: ecs.Entity): void {
|
||||
const model = e.get(HeroAttrsComp);
|
||||
if (!model) return;
|
||||
|
||||
console.log(`[HeroBattleSystem] 英雄进入战斗系统: ${model.hero_name} (uuid: ${model.hero_uuid})`);
|
||||
const dmgData=e.get(DmgDataCom)
|
||||
if (!model || !dmgData) return;
|
||||
let FDData = this.doAttack(e,dmgData)
|
||||
e.remove(DmgDataCom)
|
||||
console.log(`[HeroAtkSystem] 英雄${model.hero_name} (uuid: ${model.hero_uuid}) 受到伤害 ${FDData.damage},技能ID ${dmgData.s_uuid}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,13 +53,19 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
* @param skillId 技能ID
|
||||
* @returns 实际造成的伤害
|
||||
*/
|
||||
public doAttack(target: ecs.Entity, remainingDamage: number, attackerAttrs: any, skillId: number): number {
|
||||
public doAttack(target: ecs.Entity,dmgData:DmgDataCom): FDData {
|
||||
const targetModel = target.get(HeroAttrsComp);
|
||||
const targetView = target.get(HeroViewComp);
|
||||
if (!targetModel || targetModel.is_dead) return 0;
|
||||
let reDate:FDData={
|
||||
damage:0,
|
||||
isCrit:false,
|
||||
isDodge:false,
|
||||
}
|
||||
if (!targetModel || targetModel.is_dead) return reDate;
|
||||
|
||||
// 获取技能配置
|
||||
const skillConf = SkillSet[skillId];
|
||||
const skillConf = SkillSet[dmgData.s_uuid];
|
||||
if (!skillConf) return reDate;
|
||||
|
||||
// 触发被攻击事件
|
||||
this.onAttacked(target);
|
||||
@@ -60,15 +73,17 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
// 闪避判定
|
||||
if (this.checkDodge(targetModel)) {
|
||||
// TODO: 触发闪避视图表现
|
||||
return 0;
|
||||
reDate.isDodge=true;
|
||||
return reDate;
|
||||
}
|
||||
|
||||
// 暴击判定
|
||||
const isCrit = this.checkCrit(attackerAttrs[Attrs.CRITICAL]);
|
||||
let damage = remainingDamage;
|
||||
const isCrit = this.checkCrit(targetModel.Attrs[Attrs.CRITICAL]);
|
||||
let damage = this.dmgCount(dmgData.Attrs,dmgData.s_uuid);
|
||||
|
||||
if (isCrit) {
|
||||
damage = Math.floor(damage * (1 + (FightSet.CRIT_DAMAGE + attackerAttrs[Attrs.CRITICAL_DMG]) / 100));
|
||||
damage = Math.floor(damage * (1 + (FightSet.CRIT_DAMAGE + targetModel.Attrs[Attrs.CRITICAL_DMG]) / 100));
|
||||
reDate.isCrit=true;
|
||||
}
|
||||
|
||||
// 伤害计算(考虑易伤等debuff)
|
||||
@@ -77,7 +92,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
// 护盾吸收
|
||||
damage = this.absorbShield(targetModel, damage);
|
||||
|
||||
if (damage <= 0) return 0;
|
||||
if (damage <= 0) return reDate;
|
||||
|
||||
// 应用伤害到数据层
|
||||
targetModel.hp -= damage;
|
||||
@@ -85,7 +100,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
|
||||
// ✅ 触发视图层表现(伤害数字、受击动画、后退)
|
||||
if (targetView) {
|
||||
targetView.do_atked(damage, isCrit, skillId);
|
||||
targetView.do_atked(damage, isCrit, dmgData.s_uuid);
|
||||
}
|
||||
|
||||
// 检查死亡
|
||||
@@ -101,9 +116,16 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
console.log(`[HeroAtkSystem] ${targetModel.hero_name} 受到 ${damage} 点伤害 (暴击: ${isCrit})`);
|
||||
}
|
||||
|
||||
return damage;
|
||||
reDate.damage=damage;
|
||||
return reDate;
|
||||
}
|
||||
//伤害计算,暂时简单计算
|
||||
private dmgCount(Attrs:any,s_uuid){
|
||||
let sConf = SkillSet[s_uuid];
|
||||
if (!sConf) return 0;
|
||||
let AP = sConf.ap*Attrs[Attrs.AP];
|
||||
return AP;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理角色死亡
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user