refactor(skill): 优化技能系统实现和配置

- 删除未使用的ECS元文件和组件
- 修复技能视图和移动逻辑,添加调试日志
- 调整技能预制体配置和动画参数
- 简化技能加载和方向处理逻辑
- 新增技能6002并更新英雄配置
- 统一受击特效路径命名
This commit is contained in:
2025-10-31 16:42:57 +08:00
parent 65b1eebd84
commit 028a175df4
18 changed files with 200 additions and 558 deletions

View File

@@ -1,448 +0,0 @@
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { Vec3 } from "cc";
/**
* ==================== 伤害事件组件 ====================
*
* 用途:
* - 记录伤害事件的详细信息
* - 支持多种伤害类型和效果
* - 被伤害处理系统使用
*/
@ecs.register('DamageEvent')
export class DamageEventComp extends ecs.Comp {
/** 伤害值 */
damage: number = 0;
/** 伤害类型 */
damageType: number = 0; // 0: 物理, 1: 魔法, 2: 真实, 3: 治疗
/** 伤害来源实体ID */
sourceEntityId: number = 0;
/** 目标实体ID */
targetEntityId: number = 0;
/** 技能ID */
skillId: number = 0;
/** 伤害位置 */
position: Vec3 = new Vec3();
/** 是否暴击 */
isCritical: boolean = false;
/** 暴击倍率 */
criticalMultiplier: number = 2.0;
/** 伤害减免 */
damageReduction: number = 0;
/** 护甲穿透 */
armorPenetration: number = 0;
/** 魔法抗性穿透 */
magicPenetration: number = 0;
/** 伤害标签 */
damageTags: string[] = [];
/** 附加效果 */
effects: DamageEffectData[] = [];
/** 是否已处理 */
processed: boolean = false;
/** 创建时间 */
createTime: number = 0;
/** 额外数据 */
extraData: any = null;
reset() {
this.damage = 0;
this.damageType = 0;
this.sourceEntityId = 0;
this.targetEntityId = 0;
this.skillId = 0;
this.position.set(0, 0, 0);
this.isCritical = false;
this.criticalMultiplier = 2.0;
this.damageReduction = 0;
this.armorPenetration = 0;
this.magicPenetration = 0;
this.damageTags = [];
this.effects = [];
this.processed = false;
this.createTime = 0;
this.extraData = null;
}
/**
* 初始化伤害事件
*/
initialize(damage: number, damageType: number, sourceId: number, targetId: number, skillId: number, position: Vec3): void {
this.damage = damage;
this.damageType = damageType;
this.sourceEntityId = sourceId;
this.targetEntityId = targetId;
this.skillId = skillId;
this.position.set(position);
this.createTime = Date.now();
this.processed = false;
}
/**
* 添加伤害标签
*/
addTag(tag: string): void {
if (!this.damageTags.includes(tag)) {
this.damageTags.push(tag);
}
}
/**
* 检查是否包含标签
*/
hasTag(tag: string): boolean {
return this.damageTags.includes(tag);
}
/**
* 添加附加效果
*/
addEffect(effect: DamageEffectData): void {
this.effects.push(effect);
}
/**
* 计算最终伤害
*/
calculateFinalDamage(targetArmor: number, targetMagicResist: number): number {
let finalDamage = this.damage;
// 应用暴击
if (this.isCritical) {
finalDamage *= this.criticalMultiplier;
}
// 应用护甲和魔抗
if (this.damageType === 0) { // 物理伤害
const effectiveArmor = Math.max(0, targetArmor - this.armorPenetration);
const damageMultiplier = 100 / (100 + effectiveArmor);
finalDamage *= damageMultiplier;
} else if (this.damageType === 1) { // 魔法伤害
const effectiveMagicResist = Math.max(0, targetMagicResist - this.magicPenetration);
const damageMultiplier = 100 / (100 + effectiveMagicResist);
finalDamage *= damageMultiplier;
}
// 真实伤害和治疗不受护甲影响
// 应用伤害减免
finalDamage *= (1 - this.damageReduction);
return Math.max(0, finalDamage);
}
}
/**
* ==================== 伤害效果数据 ====================
*
* 用途:
* - 定义伤害附加的各种效果
* - 如眩晕、减速、燃烧等
*/
export class DamageEffectData {
/** 效果类型 */
effectType: number = 0; // 0: 眩晕, 1: 减速, 2: 燃烧, 3: 冰冻, 4: 中毒
/** 效果持续时间 */
duration: number = 0;
/** 效果强度 */
intensity: number = 0;
/** 效果参数 */
params: any = null;
constructor(type: number, duration: number, intensity: number = 1, params: any = null) {
this.effectType = type;
this.duration = duration;
this.intensity = intensity;
this.params = params;
}
}
/**
* ==================== 治疗事件组件 ====================
*
* 用途:
* - 记录治疗事件的详细信息
* - 支持多种治疗类型
* - 被治疗处理系统使用
*/
@ecs.register('HealEvent')
export class HealEventComp extends ecs.Comp {
/** 治疗值 */
healAmount: number = 0;
/** 治疗类型 */
healType: number = 0; // 0: 瞬间治疗, 1: 持续治疗, 2: 护盾
/** 治疗来源实体ID */
sourceEntityId: number = 0;
/** 目标实体ID */
targetEntityId: number = 0;
/** 技能ID */
skillId: number = 0;
/** 治疗位置 */
position: Vec3 = new Vec3();
/** 是否暴击治疗 */
isCritical: boolean = false;
/** 暴击倍率 */
criticalMultiplier: number = 1.5;
/** 治疗加成 */
healBonus: number = 0;
/** 是否已处理 */
processed: boolean = false;
/** 创建时间 */
createTime: number = 0;
reset() {
this.healAmount = 0;
this.healType = 0;
this.sourceEntityId = 0;
this.targetEntityId = 0;
this.skillId = 0;
this.position.set(0, 0, 0);
this.isCritical = false;
this.criticalMultiplier = 1.5;
this.healBonus = 0;
this.processed = false;
this.createTime = 0;
}
/**
* 计算最终治疗量
*/
calculateFinalHeal(): number {
let finalHeal = this.healAmount;
// 应用暴击
if (this.isCritical) {
finalHeal *= this.criticalMultiplier;
}
// 应用治疗加成
finalHeal *= (1 + this.healBonus);
return Math.max(0, finalHeal);
}
}
/**
* ==================== 状态效果组件 ====================
*
* 用途:
* - 管理角色身上的各种状态效果
* - 如BUFF、DEBUFF等
* - 支持叠加和刷新
*/
@ecs.register('StatusEffect')
export class StatusEffectComp extends ecs.Comp {
/** 效果ID */
effectId: number = 0;
/** 效果类型 */
effectType: number = 0;
/** 效果名称 */
name: string = "";
/** 剩余持续时间 */
remainingDuration: number = 0;
/** 总持续时间 */
totalDuration: number = 0;
/** 效果强度 */
intensity: number = 1;
/** 叠加层数 */
stackCount: number = 1;
/** 最大叠加层数 */
maxStacks: number = 1;
/** 来源实体ID */
sourceEntityId: number = 0;
/** 技能ID */
skillId: number = 0;
/** 是否为BUFF */
isBuff: boolean = true;
/** 是否可驱散 */
canDispel: boolean = true;
/** 效果参数 */
params: any = null;
/** 图标路径 */
iconPath: string = "";
reset() {
this.effectId = 0;
this.effectType = 0;
this.name = "";
this.remainingDuration = 0;
this.totalDuration = 0;
this.intensity = 1;
this.stackCount = 1;
this.maxStacks = 1;
this.sourceEntityId = 0;
this.skillId = 0;
this.isBuff = true;
this.canDispel = true;
this.params = null;
this.iconPath = "";
}
/**
* 更新效果持续时间
*/
updateDuration(deltaTime: number): boolean {
this.remainingDuration -= deltaTime;
return this.remainingDuration > 0;
}
/**
* 刷新效果持续时间
*/
refreshDuration(): void {
this.remainingDuration = this.totalDuration;
}
/**
* 增加叠加层数
*/
addStack(count: number = 1): void {
this.stackCount = Math.min(this.maxStacks, this.stackCount + count);
}
/**
* 减少叠加层数
*/
removeStack(count: number = 1): void {
this.stackCount = Math.max(0, this.stackCount - count);
}
/**
* 获取效果进度 (0-1)
*/
getProgress(): number {
if (this.totalDuration <= 0) return 1;
return Math.max(0, 1 - (this.remainingDuration / this.totalDuration));
}
}
/**
* ==================== 伤害统计组件 ====================
*
* 用途:
* - 统计伤害数据
* - 用于战斗分析和显示
*/
@ecs.register('DamageStats')
export class DamageStatsComp extends ecs.Comp {
/** 总伤害输出 */
totalDamageDealt: number = 0;
/** 总伤害承受 */
totalDamageTaken: number = 0;
/** 总治疗量 */
totalHealingDone: number = 0;
/** 暴击次数 */
criticalHits: number = 0;
/** 总攻击次数 */
totalAttacks: number = 0;
/** 击杀数 */
kills: number = 0;
/** 死亡数 */
deaths: number = 0;
/** 技能使用统计 */
skillUsageStats: Map<number, number> = new Map();
reset() {
this.totalDamageDealt = 0;
this.totalDamageTaken = 0;
this.totalHealingDone = 0;
this.criticalHits = 0;
this.totalAttacks = 0;
this.kills = 0;
this.deaths = 0;
this.skillUsageStats.clear();
}
/**
* 记录伤害输出
*/
recordDamageDealt(damage: number, isCritical: boolean = false): void {
this.totalDamageDealt += damage;
this.totalAttacks++;
if (isCritical) {
this.criticalHits++;
}
}
/**
* 记录伤害承受
*/
recordDamageTaken(damage: number): void {
this.totalDamageTaken += damage;
}
/**
* 记录治疗
*/
recordHealing(healing: number): void {
this.totalHealingDone += healing;
}
/**
* 记录技能使用
*/
recordSkillUsage(skillId: number): void {
const currentCount = this.skillUsageStats.get(skillId) || 0;
this.skillUsageStats.set(skillId, currentCount + 1);
}
/**
* 获取暴击率
*/
getCriticalRate(): number {
return this.totalAttacks > 0 ? this.criticalHits / this.totalAttacks : 0;
}
/**
* 获取平均伤害
*/
getAverageDamage(): number {
return this.totalAttacks > 0 ? this.totalDamageDealt / this.totalAttacks : 0;
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "92032577-e289-43f6-92f3-6d99c7ec4ce8",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -61,6 +61,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
isCrit:false,
isDodge:false,
}
console.log("[HeroAtkSystem] doAttack",target,dmgData)
if (!targetModel || targetModel.is_dead) return reDate;
// 获取技能配置

View File

@@ -171,7 +171,7 @@ export class HeroViewComp extends CCComp {
/** 受击特效 */
private in_atked(anm: string = "atked", scale: number = 1) {
var path = "game/skill/boom/" + anm;
var path = "game/skill/end/" + anm;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.setScale(node.scale.x * scale, node.scale.y);
@@ -297,6 +297,7 @@ export class HeroViewComp extends CCComp {
let SConf=SkillSet[s_uuid]
this.back()
this.showDamage(damage, isCrit, SConf.AtkedName); // 暴击状态由战斗系统内部处理
console.log("[HeroViewComp] do_atked",damage,isCrit,SConf.AtkedName)
}
//后退
back(){

View File

@@ -115,7 +115,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
}, delay);
const heroAttrs = casterEntity.get(HeroAttrsComp);
console.log(`[SACastSystem] ${heroAttrs?.hero_name ?? '未知'} 施放技能: ${config.name}`);
// console.log(`[SACastSystem] ${heroAttrs?.hero_name ?? '未知'} 施放技能: ${config.name}`);
}
/**
@@ -149,7 +149,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
const startPos = caster.node.position.clone();
const targetPos = targets[0]; // 使用第一个目标位置
console.log(`[SACastSystem]: ${s_uuid}, 起始位置: ${startPos}, 目标位置: ${targetPos}`);
// console.log(`[SACastSystem]: ${s_uuid}, 起始位置: ${startPos}, 目标位置: ${targetPos}`);
// 加载技能实体(包括预制体、组件初始化等)
skill.load(startPos, parent, s_uuid, targetPos, caster);