refactor(hero): 移除多余的日志输出并简化代码逻辑

本次提交清理了多个英雄相关组件中的调试日志,同时简化了条件判断写法:
1.  将多行if判断简化为单行return形式
2.  删除HeroViewComp中护盾特效相关的冗余日志和节点查找逻辑
3.  优化absorbShield和add_shield等方法的代码可读性
This commit is contained in:
panFD
2026-09-04 00:07:36 +08:00
parent 0a3efafbd5
commit 539c30b366
5 changed files with 9 additions and 40 deletions

View File

@@ -518,16 +518,12 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
}
private absorbShield(TAttrsComp: HeroAttrsComp, damage: number): { remainingDamage: number, absorbedDamage: number } {
mLogger.log(this.debugMode, 'HeroAtkSystem', `absorbShield: ${TAttrsComp.hero_name}, shield=${TAttrsComp.shield}, damage=${damage}`);
if (TAttrsComp.shield <= 0) {
mLogger.log(this.debugMode, 'HeroAtkSystem', `absorbShield: shield <= 0, no absorb`);
return { remainingDamage: damage, absorbedDamage: 0 };
}
const absorbed = Math.min(TAttrsComp.shield, damage);
const oldShield = TAttrsComp.shield;
TAttrsComp.shield = Math.max(0, TAttrsComp.shield - absorbed);
TAttrsComp.dirty_shield = true;
mLogger.log(this.debugMode, 'HeroAtkSystem', `absorbShield: ${TAttrsComp.hero_name}, absorbed=${absorbed}, shield ${Math.floor(oldShield)} -> ${Math.floor(TAttrsComp.shield)}, dirty_shield=true`);
return { remainingDamage: damage - absorbed, absorbedDamage: absorbed };
}

View File

@@ -154,14 +154,10 @@ export class HeroAttrsComp extends ecs.Comp {
add_shield(value: number) {
const oldShield = this.shield;
const addValue = Math.max(0, Math.floor(value));
if (addValue <= 0) {
mLogger.log(this.debugMode, 'HeroAttrs', `add_shield: addValue=${addValue} <= 0, skip`);
return;
}
if (addValue <= 0) return;
this.shield += addValue;
if (this.shield < 0) this.shield = 0;
this.dirty_shield = true; // 标记护盾需要更新
mLogger.log(this.debugMode, 'HeroAttrs', `add_shield: ${this.hero_name}, old=${Math.floor(oldShield)}, add=${addValue}, new=${Math.floor(this.shield)}, dirty_shield=true`);
}
add_hp_max(value: number) {
this.hp_max += value

View File

@@ -137,16 +137,11 @@ export class HeroTopBarComp extends CCComp {
/** 更新护盾数值条(显示具体数值,无上限) */
public shieldShow(shield: number = 0): void {
if (!this.shieldProgressBar) {
console.log('[HeroTopBarComp] shieldShow: shieldProgressBar is null');
return;
}
if (!this.shieldProgressBar) return;
// 护盾条直接显示具体数值,progress 固定为 1(满条显示)
this.shieldProgressBar.progress = 1;
// 护盾节点显隐
const shouldActive = shield > 0;
console.log(`[HeroTopBarComp] shieldShow: shield=${shield}, active=${shouldActive}, node=${this.shieldProgressBar.node.name}`);
this.shieldProgressBar.node.active = shouldActive;
this.shieldProgressBar.node.active = shield > 0;
}
/**

View File

@@ -140,11 +140,9 @@ export class HeroViewComp extends CCComp {
if (this.model.dirty_shield) {
mLogger.log(this.debugMode, 'HeroViewComp', `update dirty_shield: shield=${this.model.shield}, calling shieldShow`);
this.topBar.shieldShow(this.model.shield);
// 护盾耗尽时隐藏护盾特效
if (this.model.shield <= 0) {
mLogger.log(this.debugMode, 'HeroViewComp', `update dirty_shield: shield <= 0, hiding shield fx`);
this.hideShieldFx();
}
this.model.dirty_shield = false;
@@ -319,39 +317,25 @@ export class HeroViewComp extends CCComp {
private shieldFxNode: Node | null = null;
add_shield(shield: number) {
mLogger.log(this.debugMode, 'HeroViewComp', `add_shield called, shield=${shield}, model.shield=${this.model?.shield}, model exists=${!!this.model}`);
// 护盾数据更新由 Model 层处理,这里只负责视图表现
if (this.model && this.model.shield > 0) {
this.topBar.shieldShow(this.model.shield);
this.showShieldFx();
mLogger.log(this.debugMode, 'HeroViewComp', `add_shield: showing shield fx, model.shield=${this.model.shield}`);
} else {
mLogger.log(this.debugMode, 'HeroViewComp', `add_shield: skipped, model.shield=${this.model?.shield}`);
}
}
/** 显示护盾常驻特效(使用 this.node 下已放置的 shielded 节点) */
/** 显示护盾常驻特效(动态加载并挂载到 this.node 下) */
private showShieldFx() {
if (!this.shieldFxNode) {
this.shieldFxNode = this.node.getChildByName("shielded");
mLogger.log(this.debugMode, 'HeroViewComp', `showShieldFx: found shielded node=${!!this.shieldFxNode}`);
}
if (this.shieldFxNode && !this.shieldFxNode.active) {
this.shieldFxNode.active = true;
mLogger.log(this.debugMode, 'HeroViewComp', `showShieldFx: activated shielded node`);
} else {
mLogger.log(this.debugMode, 'HeroViewComp', `showShieldFx: shielded node already active or not found, active=${this.shieldFxNode?.active}`);
}
if (this.shieldFxNode && this.shieldFxNode.isValid) return;
this.shieldFxNode = this.createFxNode("game/skill/buff/shielded", this.node, undefined);
}
/** 隐藏护盾常驻特效 */
private hideShieldFx() {
if (this.shieldFxNode && this.shieldFxNode.active) {
this.shieldFxNode.active = false;
mLogger.log(this.debugMode, 'HeroViewComp', `hideShieldFx: deactivated shielded node`);
} else {
mLogger.log(this.debugMode, 'HeroViewComp', `hideShieldFx: shielded node not active or not found, active=${this.shieldFxNode?.active}`);
if (this.shieldFxNode && this.shieldFxNode.isValid) {
this.shieldFxNode.destroy();
}
this.shieldFxNode = null;
}
health(hp: number = 0) {

View File

@@ -539,9 +539,7 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
} else if (kind === SkillKind.Shield && sAp !== 0) {
// 护盾值 = ap% × 施法者最终最大生命(getFinalHpMax 含驻场光环与计时 buff 加成)
const addShield = Math.max(0, Math.floor(_cAttrsComp.getFinalHpMax() * sAp / 100));
mLogger.log(this.debugMode, 'SCastSystem', `applyActualFriendlyEffect Shield: caster=${_cAttrsComp.hero_name}, target=${model.hero_name}, casterHpMax=${_cAttrsComp.getFinalHpMax()}, sAp=${sAp}, addShield=${addShield}, targetOldShield=${model.shield}`);
model.add_shield(addShield);
mLogger.log(this.debugMode, 'SCastSystem', `applyActualFriendlyEffect Shield: after add_shield, targetNewShield=${model.shield}, dirty_shield=${model.dirty_shield}`);
}
if (config.buff_type !== undefined) {