2 Commits

Author SHA1 Message Date
panw
52b24668c7 refactor(heroView): 优化英雄和怪物死亡处理逻辑
重构了realDead方法,统一添加死亡飞出屏幕动画,根据阵营区分处理逻辑:英雄移动到墓地,怪物动画结束后销毁
2026-05-21 16:34:09 +08:00
panw
654e39ff5b refactor(MissionHeroComp): 移除闲置的驻场技能总加成计算方法 2026-05-21 16:20:54 +08:00
7 changed files with 81 additions and 48 deletions

View File

@@ -0,0 +1,33 @@
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { FacSet } from "../common/config/GameSet";
import { HeroInfo } from "../common/config/heroSet";
import { FieldSkillSet, FieldSkillType } from "../common/config/SkillSet";
import { HeroAttrsComp } from "./HeroAttrsComp";
/**
* 驻场技能(光环属性)计算辅助类
*
* 核心职责:
* 统一管理全场存活英雄带来的全局加成属性计算。
* 解耦原先写在 HeroAttrsComp 中的静态计算逻辑,符合单一职责原则。
*/
export class FieldSkillHelper {
/** 获取指定驻场技能类型的总加成值(只计算存活的友方英雄) */
public static getFieldSkillTotalValue(type: FieldSkillType): number {
let total = 0;
ecs.query(ecs.allOf(HeroAttrsComp)).forEach((entity: ecs.Entity) => {
const model = entity.get(HeroAttrsComp);
if (!model || model.is_dead || model.fac !== FacSet.HERO) return;
const heroConfig = HeroInfo[model.hero_uuid];
if (heroConfig && heroConfig.field) {
for (const skillUuid of heroConfig.field) {
const skillConfig = FieldSkillSet[skillUuid];
if (skillConfig && skillConfig.type === type) {
total += skillConfig.value;
}
}
}
});
return total;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "140c8aaf-42b4-4f1c-880a-dd43af7588a2",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -6,6 +6,7 @@ import { FacSet, FightSet } from "../common/config/GameSet";
import { FieldSkillSet, FieldSkillType } from "../common/config/SkillSet";
import { smc } from "../common/SingletonModuleComp";
import { TalentConfig, TalentType } from "../common/config/TalentSet";
import { FieldSkillHelper } from "./FieldSkillHelper";
@ecs.register('HeroAttrs')
export class HeroAttrsComp extends ecs.Comp {
public debugMode: boolean = false;
@@ -203,7 +204,7 @@ export class HeroAttrsComp extends ecs.Comp {
/** 将驻场配置值统一换算成百分比数值,兼容 0.2 和 20 两种写法。 */
private getFieldPercentValue(type: FieldSkillType): number {
const rawValue = HeroAttrsComp.getFieldSkillTotalValue(type);
const rawValue = FieldSkillHelper.getFieldSkillTotalValue(type);
if (Math.abs(rawValue) <= HeroAttrsComp.percentRateThreshold) {
return rawValue * 100;
}
@@ -340,24 +341,7 @@ export class HeroAttrsComp extends ecs.Comp {
this.dirty_shield = false;
}
/** 获取指定驻场技能类型的总加成值(只计算存活的英雄) */
public static getFieldSkillTotalValue(type: FieldSkillType): number {
let total = 0;
ecs.query(ecs.allOf(HeroAttrsComp)).forEach((entity: ecs.Entity) => {
const model = entity.get(HeroAttrsComp);
if (!model || model.is_dead || model.fac !== FacSet.HERO) return;
const heroConfig = HeroInfo[model.hero_uuid];
if (heroConfig && heroConfig.field) {
for (const skillUuid of heroConfig.field) {
const skillConfig = FieldSkillSet[skillUuid];
if (skillConfig && skillConfig.type === type) {
total += skillConfig.value;
}
}
}
});
return total;
}
/** 获取指定天赋的加成数值 */
public static getTalentValue(talentId: TalentType): number {

View File

@@ -464,30 +464,34 @@ export class HeroViewComp extends CCComp {
mLogger.warn(this.debugMode, 'HeroViewComp', "[HeroViewComp] realDead called but model is null, skipping");
return;
}
// 根据阵营触发不同事件
if(this.model.fac === FacSet.MON){
}
if(this.model.fac === FacSet.HERO){
// 将英雄移到玩家看不到的墓地
this.node.setPosition(v3(-2000, -2000, 0));
const collider = this.node.getComponent(Collider2D);
if (collider) {
collider.enabled = false;
}
// 隐藏UI
this.top_node.active = false;
} else {
// 🔥 方案B治理性措施 - 在销毁实体前先禁用碰撞体,从源头减少"尸体"参与碰撞
const collider = this.node.getComponent(Collider2D);
if (collider) {
collider.enabled = false;
}
this.ent.destroy();
// 隐藏UI
this.top_node.active = false;
// 在销毁实体前先禁用碰撞体,从源头减少"尸体"参与碰撞
const collider = this.node.getComponent(Collider2D);
if (collider) {
collider.enabled = false;
}
// 根据阵营决定飞出方向:英雄向左(负),怪物向右(正)
let isHero = this.model.fac === FacSet.HERO;
let dirX = isHero ? -800 : 800;
// 死亡往后飞出屏幕动画
tween(this.node)
.by(0.5, { position: v3(dirX, 700, 0), angle: isHero ? 360 : -360 }, { easing: "quadOut" })
.call(() => {
this.node.angle = 0; // 重置角度
if (isHero) {
// 将英雄移到玩家看不到的墓地,留待下回合上场
this.node.setPosition(v3(-2000, -2000, 0));
} else {
// 动画结束后销毁怪物实体
this.ent.destroy();
}
})
.start();
}
do_atked(damage:number,isCrit:boolean,s_uuid:number,isBack:boolean=false){
// 受到攻击时更新最后更新时间

View File

@@ -6,6 +6,7 @@ import { FacSet } from "../common/config/GameSet";
import { FieldSkillType } from "../common/config/SkillSet";
import { TalentType } from "../common/config/TalentSet";
import { smc } from "../common/SingletonModuleComp";
import { FieldSkillHelper } from "./FieldSkillHelper";
/**
@@ -65,7 +66,7 @@ export class SkillTriggerHelper {
let triggerCount = 1;
// 仅英雄享受加成,怪物始终只触发 1 次
if (model.fac === FacSet.HERO) {
triggerCount += HeroAttrsComp.getFieldSkillTotalValue(FieldSkillType.SummonCount);
triggerCount += FieldSkillHelper.getFieldSkillTotalValue(FieldSkillType.SummonCount);
triggerCount += HeroAttrsComp.getTalentValue(TalentType.Summon);
}
triggerCount = Math.max(1, Math.floor(triggerCount)); // 确保最少触发 1 次
@@ -84,7 +85,7 @@ export class SkillTriggerHelper {
let triggerCount = 1;
if (model.fac === FacSet.HERO) {
triggerCount += HeroAttrsComp.getFieldSkillTotalValue(FieldSkillType.DeadCount);
triggerCount += FieldSkillHelper.getFieldSkillTotalValue(FieldSkillType.DeadCount);
// 【局内战绩评分系统】统计死亡触发技能生效次数(用于局后防守评分结算)
smc.vmdata.scores.dead_trigger_count += model.dead.length;
}

View File

@@ -47,6 +47,7 @@ import { Tooltip } from "../skill/Tooltip";
import { CardInitCoins } from "../common/config/CardSet";
import { Timer } from "db://oops-framework/core/common/timer/Timer";
import { FieldSkillType } from "../common/config/SkillSet";
import { FieldSkillHelper } from "../hero/FieldSkillHelper";
import { spawningEngine } from "./RogueConfig";
import { MissionEconomy } from "./MissionEconomy";
const { ccclass, property } = _decorator;
@@ -579,9 +580,9 @@ export class MissionComp extends CCComp {
private triggerHeroBattleSkills(isStart: boolean) {
let triggerCount = 1;
if (isStart) {
triggerCount += HeroAttrsComp.getFieldSkillTotalValue(FieldSkillType.StartCount);
triggerCount += FieldSkillHelper.getFieldSkillTotalValue(FieldSkillType.StartCount);
} else {
triggerCount += HeroAttrsComp.getFieldSkillTotalValue(FieldSkillType.EndCount);
triggerCount += FieldSkillHelper.getFieldSkillTotalValue(FieldSkillType.EndCount);
}
triggerCount = Math.max(1, Math.floor(triggerCount));
@@ -600,7 +601,7 @@ export class MissionComp extends CCComp {
* 战斗结束阶段治疗所有英雄包括墓地英雄恢复70%最大生命值
*/
private healAllHeroes() {
const healRateBoost = HeroAttrsComp.getFieldSkillTotalValue(FieldSkillType.WaveHeal);
const healRateBoost = FieldSkillHelper.getFieldSkillTotalValue(FieldSkillType.WaveHeal);
const finalHealRate = Math.min(1, FightSet.WAVE_HEAL_RATE + healRateBoost);
ecs.query(this.heroAttrsMatcher).forEach(entity => {

View File

@@ -5,6 +5,7 @@ import { HeroAttrsComp } from "../hero/HeroAttrsComp";
import { FieldSkillType } from "../common/config/SkillSet";
import { TalentType } from "../common/config/TalentSet";
import { FightSet } from "../common/config/GameSet";
import { FieldSkillHelper } from "../hero/FieldSkillHelper";
/**
* 局内经济统一管理类
@@ -70,7 +71,7 @@ export class MissionEconomy {
*/
static getSellGold(): number {
const baseSellGold = 1; // 基础卖出金币
const goldBoost = HeroAttrsComp.getFieldSkillTotalValue(FieldSkillType.SellGold);
const goldBoost = FieldSkillHelper.getFieldSkillTotalValue(FieldSkillType.SellGold);
let totalSellGold = baseSellGold + goldBoost;
// 应用天赋 SellBonus (增加数值)
const bonusGold = HeroAttrsComp.getTalentValue(TalentType.SellBonus);
@@ -94,7 +95,7 @@ export class MissionEconomy {
*/
static getWaveGold(baseReward: number): number {
let reward = Math.max(0, Math.floor(baseReward));
const goldBoost = HeroAttrsComp.getFieldSkillTotalValue(FieldSkillType.WaveGold);
const goldBoost = FieldSkillHelper.getFieldSkillTotalValue(FieldSkillType.WaveGold);
reward += goldBoost;
return reward;
}