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 = 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; } }