refactor(skill): 重构技能数据结构并支持技能等级
- 将 HeroAttrsComp 中的技能数组和独立 CD 映射重构为统一的 HSkillInfo 对象记录 - 在 SDataCom 中新增 skill_lv 字段,并在 Skill 加载时传入技能等级 - 更新 Hero 和 Monster 初始化逻辑以适配新的技能数据结构 - 修改 SCastSystem 以传递技能等级并影响技能效果 - 更新 heroSet 配置,将 skills 字段类型改为 Record<number, HSkillInfo>
This commit is contained in:
@@ -23,7 +23,7 @@ import { HType } from "../common/config/heroSet";
|
||||
@ecs.register('SCastSystem')
|
||||
export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
|
||||
debugMode: boolean = false; // 是否启用调试模式
|
||||
private readonly emptyCastPlan = { skillId: 0, isFriendly: false, targetPos: null as Vec3 | null, targetEids: [] as number[] };
|
||||
private readonly emptyCastPlan = { skillId: 0, skillLv: 1, isFriendly: false, targetPos: null as Vec3 | null, targetEids: [] as number[] };
|
||||
private readonly meleeCastRange = 64;
|
||||
private heroMatcher: ecs.IMatcher | null = null;
|
||||
private getHeroMatcher(): ecs.IMatcher {
|
||||
@@ -52,7 +52,7 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
this.castSkill(castPlan, heroAttrs, heroView);
|
||||
}
|
||||
|
||||
private pickCastSkill(heroAttrs: HeroAttrsComp, heroView: HeroViewComp): { skillId: number; isFriendly: boolean; targetPos: Vec3 | null; targetEids: number[] } {
|
||||
private pickCastSkill(heroAttrs: HeroAttrsComp, heroView: HeroViewComp): { skillId: number; skillLv: number; isFriendly: boolean; targetPos: Vec3 | null; targetEids: number[] } {
|
||||
const type = heroAttrs.type as HType;
|
||||
const maxRange = this.resolveMaxCastRange(heroAttrs, type);
|
||||
const target = this.findNearestEnemyInRange(heroAttrs, heroView, maxRange);
|
||||
@@ -63,26 +63,28 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
const config = SkillSet[s_uuid];
|
||||
if (!config) continue;
|
||||
if (!heroAttrs.isSkillReady(s_uuid)) continue;
|
||||
const skillLv = heroAttrs.getSkillLevel(s_uuid);
|
||||
if (this.isSelfSkill(config.TGroup)) {
|
||||
if (typeof selfEid !== "number") continue;
|
||||
return { skillId: s_uuid, isFriendly: true, targetPos: null, targetEids: [selfEid] };
|
||||
return { skillId: s_uuid, skillLv, isFriendly: true, targetPos: null, targetEids: [selfEid] };
|
||||
}
|
||||
if (this.isFriendlySkill(config.TGroup)) {
|
||||
const includeSelf = config.TGroup === TGroup.Ally;
|
||||
const friendlyEids = this.collectFriendlyTargetEids(heroAttrs.fac, selfEid, includeSelf);
|
||||
if (friendlyEids.length === 0) continue;
|
||||
return { skillId: s_uuid, isFriendly: true, targetPos: null, targetEids: friendlyEids };
|
||||
return { skillId: s_uuid, skillLv, isFriendly: true, targetPos: null, targetEids: friendlyEids };
|
||||
}
|
||||
if (!target || !heroView.node || !target.node) continue;
|
||||
const targetPos = this.resolveEnemyCastTargetPos(config, heroAttrs, heroView, target, maxRange);
|
||||
if (!targetPos) continue;
|
||||
return { skillId: s_uuid, isFriendly: false, targetPos, targetEids: [] };
|
||||
return { skillId: s_uuid, skillLv, isFriendly: false, targetPos, targetEids: [] };
|
||||
}
|
||||
return this.emptyCastPlan;
|
||||
}
|
||||
|
||||
private castSkill(castPlan: { skillId: number; isFriendly: boolean; targetPos: Vec3 | null; targetEids: number[] }, heroAttrs: HeroAttrsComp, heroView: HeroViewComp) {
|
||||
private castSkill(castPlan: { skillId: number; skillLv: number; isFriendly: boolean; targetPos: Vec3 | null; targetEids: number[] }, heroAttrs: HeroAttrsComp, heroView: HeroViewComp) {
|
||||
const s_uuid = castPlan.skillId;
|
||||
const skillLv = castPlan.skillLv;
|
||||
const config = SkillSet[s_uuid];
|
||||
if (!config) return;
|
||||
//播放前摇技能动画
|
||||
@@ -100,11 +102,11 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
if (castPlan.isFriendly) {
|
||||
const friendlyTargets = this.resolveFriendlyTargets(castPlan.targetEids, heroAttrs.fac);
|
||||
if (friendlyTargets.length === 0) return;
|
||||
this.applyPrimaryEffect(s_uuid, config, heroView,heroAttrs, friendlyTargets, null);
|
||||
this.applyPrimaryEffect(s_uuid, skillLv, config, heroView,heroAttrs, friendlyTargets, null);
|
||||
this.applyExtraEffects(config, friendlyTargets);
|
||||
return;
|
||||
}
|
||||
this.applyPrimaryEffect(s_uuid, config, heroView,heroAttrs, [], castPlan.targetPos);
|
||||
this.applyPrimaryEffect(s_uuid, skillLv, config, heroView,heroAttrs, [], castPlan.targetPos);
|
||||
}, delay);
|
||||
heroAttrs.triggerSkillCD(s_uuid);
|
||||
}
|
||||
@@ -115,19 +117,19 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
return [...skillIds.slice(1), skillIds[0]];
|
||||
}
|
||||
|
||||
private createSkillEntity(s_uuid: number, caster: HeroViewComp,cAttrsComp: HeroAttrsComp, targetPos: Vec3) {
|
||||
private createSkillEntity(s_uuid: number, skillLv: number, caster: HeroViewComp,cAttrsComp: HeroAttrsComp, targetPos: Vec3) {
|
||||
if (!caster.node || !caster.node.isValid) return;
|
||||
const parent = caster.node.parent;
|
||||
if (!parent) return;
|
||||
const skill = ecs.getEntity<Skill>(Skill);
|
||||
skill.load(caster.node.position.clone(), parent, s_uuid, targetPos.clone(), caster,cAttrsComp, 0);
|
||||
skill.load(caster.node.position.clone(), parent, s_uuid, targetPos.clone(), caster, cAttrsComp, skillLv, 0);
|
||||
}
|
||||
|
||||
private applyPrimaryEffect(s_uuid: number, config: SkillConfig, heroView: HeroViewComp, cAttrsComp: HeroAttrsComp,targets: HeroViewComp[], targetPos: Vec3 | null) {
|
||||
private applyPrimaryEffect(s_uuid: number, skillLv: number, config: SkillConfig, heroView: HeroViewComp, cAttrsComp: HeroAttrsComp,targets: HeroViewComp[], targetPos: Vec3 | null) {
|
||||
const kind = config.kind ?? SkillKind.Damage;
|
||||
if (kind === SkillKind.Damage) {
|
||||
if (config.ap <= 0 || !targetPos) return;
|
||||
this.createSkillEntity(s_uuid, heroView,cAttrsComp, targetPos);
|
||||
this.createSkillEntity(s_uuid, skillLv, heroView,cAttrsComp, targetPos);
|
||||
return;
|
||||
}
|
||||
for (const target of targets) {
|
||||
@@ -189,7 +191,7 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
return eids;
|
||||
}
|
||||
|
||||
private hasCastTarget(castPlan: { skillId: number; isFriendly: boolean; targetPos: Vec3 | null; targetEids: number[] }): boolean {
|
||||
private hasCastTarget(castPlan: { skillId: number; skillLv: number; isFriendly: boolean; targetPos: Vec3 | null; targetEids: number[] }): boolean {
|
||||
if (castPlan.skillId === 0) return false;
|
||||
if (castPlan.isFriendly) return castPlan.targetEids.length > 0;
|
||||
return !!castPlan.targetPos;
|
||||
|
||||
Reference in New Issue
Block a user