refactor(skill): 重构技能数据结构并支持技能等级
- 将 HeroAttrsComp 中的技能数组和独立 CD 映射重构为统一的 HSkillInfo 对象记录 - 在 SDataCom 中新增 skill_lv 字段,并在 Skill 加载时传入技能等级 - 更新 Hero 和 Monster 初始化逻辑以适配新的技能数据结构 - 修改 SCastSystem 以传递技能等级并影响技能效果 - 更新 heroSet 配置,将 skills 字段类型改为 Record<number, HSkillInfo>
This commit is contained in:
@@ -79,8 +79,12 @@ export class Hero extends ecs.Entity {
|
||||
model.ap = hero.ap*model.lv;
|
||||
model.hp= model.hp_max = hero.hp*model.lv;
|
||||
model.speed = hero.speed;
|
||||
model.setSkills(hero.skills, hero.cds);
|
||||
model.skill_lvs=hero.slvs
|
||||
model.skills = {};
|
||||
for (const key in hero.skills) {
|
||||
const skill = hero.skills[key];
|
||||
if (!skill) continue;
|
||||
model.skills[skill.uuid] = { ...skill, ccd: skill.cd };
|
||||
}
|
||||
model.updateSkillDistanceCache();
|
||||
|
||||
// 初始化 buff/debuff 系统
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { Attrs } from "../common/config/HeroAttrs";
|
||||
import { BuffConf } from "../common/config/SkillSet";
|
||||
import { HeroDisVal, HType } from "../common/config/heroSet";
|
||||
import { HeroDisVal, HSkillInfo, HType } from "../common/config/heroSet";
|
||||
import { mLogger } from "../common/Logger";
|
||||
import { Timer } from "db://oops-framework/core/common/timer/Timer";
|
||||
import { FightSet } from "../common/config/GameSet";
|
||||
@@ -26,10 +26,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
shield_max: number = 0; // 最大护盾值
|
||||
|
||||
// ==================== 攻击属性 (补充) ====================
|
||||
skills: number[] = [];
|
||||
skill_max_cds: Record<number, number> = {};
|
||||
skill_cds: Record<number, number> = {};
|
||||
skill_lvs:Record<number, number> = {};
|
||||
skills: Record<number, HSkillInfo> = {};
|
||||
// ==================== 特殊属性 ====================
|
||||
critical: number = 0; // 暴击率
|
||||
freeze_chance: number = 0; // 冰冻概率
|
||||
@@ -159,72 +156,57 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
this.dirty_shield = true;
|
||||
}
|
||||
updateCD(dt: number){
|
||||
for (const skillId of this.skills) {
|
||||
const maxCd = this.skill_max_cds[skillId] ?? 0;
|
||||
if (maxCd <= 0) {
|
||||
this.skill_cds[skillId] = 0;
|
||||
for (const key in this.skills) {
|
||||
const skill = this.skills[key];
|
||||
if (!skill) continue;
|
||||
if (skill.cd <= 0) {
|
||||
skill.ccd = 0;
|
||||
continue;
|
||||
}
|
||||
const currentCd = this.skill_cds[skillId] ?? maxCd;
|
||||
if (currentCd >= maxCd) {
|
||||
this.skill_cds[skillId] = maxCd;
|
||||
if (skill.ccd >= skill.cd) {
|
||||
skill.ccd = skill.cd;
|
||||
continue;
|
||||
}
|
||||
this.skill_cds[skillId] = Math.min(maxCd, currentCd + dt);
|
||||
skill.ccd = Math.min(skill.cd, skill.ccd + dt);
|
||||
}
|
||||
}
|
||||
isFrost(): boolean {
|
||||
return this.frost_end_time > 0
|
||||
}
|
||||
setSkills(skills: number[], cds: number[]) {
|
||||
this.skills = [];
|
||||
this.skill_max_cds = {};
|
||||
this.skill_cds = {};
|
||||
if (!skills) return;
|
||||
const len = skills.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const skillId = skills[i];
|
||||
if (!skillId) continue;
|
||||
const cd = cds[i] ?? cds[0] ?? 0;
|
||||
const maxCd = Math.max(0, cd);
|
||||
this.skills.push(skillId);
|
||||
this.skill_max_cds[skillId] = maxCd;
|
||||
this.skill_cds[skillId] = maxCd;
|
||||
}
|
||||
getSkillLevel(skillId: number): number {
|
||||
if (!skillId) return 1;
|
||||
return this.skills[skillId]?.lv ?? 1;
|
||||
}
|
||||
|
||||
getSkillIds(): number[] {
|
||||
return [...this.skills];
|
||||
return Object.values(this.skills).map(skill => skill.uuid);
|
||||
}
|
||||
|
||||
isSkillReady(skillId: number): boolean {
|
||||
if (!skillId) return false;
|
||||
const maxCd = this.skill_max_cds[skillId] ?? 0;
|
||||
if (maxCd <= 0) return true;
|
||||
const currentCd = this.skill_cds[skillId] ?? maxCd;
|
||||
return currentCd >= maxCd;
|
||||
const skill = this.skills[skillId];
|
||||
if (!skill) return false;
|
||||
if (skill.cd <= 0) return true;
|
||||
return skill.ccd >= skill.cd;
|
||||
}
|
||||
|
||||
triggerSkillCD(skillId: number) {
|
||||
if (!skillId) return;
|
||||
const maxCd = this.skill_max_cds[skillId] ?? 0;
|
||||
if (maxCd <= 0) {
|
||||
this.skill_cds[skillId] = 0;
|
||||
return;
|
||||
}
|
||||
this.skill_cds[skillId] = 0;
|
||||
const skill = this.skills[skillId];
|
||||
if (!skill) return;
|
||||
skill.ccd = 0;
|
||||
}
|
||||
|
||||
getSkillCdProgress(skillId: number): number {
|
||||
if (!skillId) return 1;
|
||||
const maxCd = this.skill_max_cds[skillId] ?? 0;
|
||||
if (maxCd <= 0) return 1;
|
||||
const currentCd = this.skill_cds[skillId] ?? maxCd;
|
||||
return Math.max(0, Math.min(1, currentCd / maxCd));
|
||||
const skill = this.skills[skillId];
|
||||
if (!skill || skill.cd <= 0) return 1;
|
||||
return Math.max(0, Math.min(1, skill.ccd / skill.cd));
|
||||
}
|
||||
|
||||
getDisplaySkillCdProgress(): number {
|
||||
const displaySkillId = this.skills[1] ?? this.skills[0] ?? 0;
|
||||
const skillIds = this.getSkillIds();
|
||||
const displaySkillId = skillIds[1] ?? skillIds[0] ?? 0;
|
||||
return this.getSkillCdProgress(displaySkillId);
|
||||
}
|
||||
|
||||
@@ -282,9 +264,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
this.shield_max = 0;
|
||||
|
||||
// 重置新增属性
|
||||
this.skills = [];
|
||||
this.skill_max_cds = {};
|
||||
this.skill_cds = {};
|
||||
this.skills = {};
|
||||
this.critical = 0;
|
||||
this.freeze_chance = 0;
|
||||
this.back_chance = 0;
|
||||
|
||||
@@ -141,7 +141,12 @@ export class Monster extends ecs.Entity {
|
||||
if(!model.is_boss){
|
||||
model.is_kalami = true;
|
||||
}
|
||||
model.setSkills(hero.skills, hero.cds);
|
||||
model.skills = {};
|
||||
for (const key in hero.skills) {
|
||||
const skill = hero.skills[key];
|
||||
if (!skill) continue;
|
||||
model.skills[skill.uuid] = { ...skill, ccd: skill.cd };
|
||||
}
|
||||
model.updateSkillDistanceCache();
|
||||
//根据刷怪控制脚本对ap和hp进行加强
|
||||
|
||||
|
||||
@@ -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