refactor(hero): 优化护盾系统日志与显示逻辑

1. 新增多处护盾相关调试日志,方便追踪护盾数值变化
2. 重构HeroAttrsComp的add_shield方法,统一日志输出格式
3. 重写HeroTopBarComp的护盾显示逻辑,改为直接显示数值而非按上限比例
4. 为HeroViewComp新增护盾特效管理,实现护盾状态自动显隐
5. 清理hk1.prefab中冗余的预制体覆盖配置
This commit is contained in:
panFD
2026-09-03 23:53:37 +08:00
parent a41ff479da
commit 0a3efafbd5
6 changed files with 85 additions and 206 deletions

View File

@@ -26,34 +26,31 @@
},
{
"__id__": 22
},
{
"__id__": 34
}
],
"_active": true,
"_components": [
{
"__id__": 43
"__id__": 31
},
{
"__id__": 45
"__id__": 33
},
{
"__id__": 47
"__id__": 35
},
{
"__id__": 49
"__id__": 37
},
{
"__id__": 51
"__id__": 39
},
{
"__id__": 53
"__id__": 41
}
],
"_prefab": {
"__id__": 55
"__id__": 43
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -459,10 +456,10 @@
"__id__": 22
},
"asset": {
"__uuid__": "e1b8a315-ece3-41a2-941e-a66861753f1b",
"__uuid__": "50c3d5e4-49f8-4bd7-a15b-cda359a0ae5c",
"__expectedType__": "cc.Prefab"
},
"fileId": "c46/YsCPVOJYA4mWEpNYRx",
"fileId": "5fqU0L3/FOhKaco5UkHuWT",
"instance": {
"__id__": 24
},
@@ -470,7 +467,7 @@
},
{
"__type__": "cc.PrefabInstance",
"fileId": "3a1pwLAh1NkYnlDVrAFcnS",
"fileId": "69IAw7dThHvIlVtTfXOVMZ",
"prefabRootNode": {
"__id__": 1
},
@@ -491,12 +488,6 @@
},
{
"__id__": 30
},
{
"__id__": 31
},
{
"__id__": 33
}
],
"removedComponents": []
@@ -509,166 +500,6 @@
"propertyPath": [
"_name"
],
"value": "shielded"
},
{
"__type__": "cc.TargetInfo",
"localID": [
"c46/YsCPVOJYA4mWEpNYRx"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 26
},
"propertyPath": [
"_lpos"
],
"value": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 26
},
"propertyPath": [
"_lrot"
],
"value": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 26
},
"propertyPath": [
"_euler"
],
"value": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 26
},
"propertyPath": [
"_active"
],
"value": false
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 32
},
"propertyPath": [
"_contentSize"
],
"value": {
"__type__": "cc.Size",
"width": 120,
"height": 100
}
},
{
"__type__": "cc.TargetInfo",
"localID": [
"63NP9yq3hEUKD/OZZZ5t7x"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 26
},
"propertyPath": [
"_lscale"
],
"value": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
}
},
{
"__type__": "cc.Node",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_prefab": {
"__id__": 35
},
"__editorExtras__": {}
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 34
},
"asset": {
"__uuid__": "50c3d5e4-49f8-4bd7-a15b-cda359a0ae5c",
"__expectedType__": "cc.Prefab"
},
"fileId": "5fqU0L3/FOhKaco5UkHuWT",
"instance": {
"__id__": 36
},
"targetOverrides": null
},
{
"__type__": "cc.PrefabInstance",
"fileId": "69IAw7dThHvIlVtTfXOVMZ",
"prefabRootNode": {
"__id__": 1
},
"mountedChildren": [],
"mountedComponents": [],
"propertyOverrides": [
{
"__id__": 37
},
{
"__id__": 39
},
{
"__id__": 40
},
{
"__id__": 41
},
{
"__id__": 42
}
],
"removedComponents": []
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 38
},
"propertyPath": [
"_name"
],
"value": "top"
},
{
@@ -680,7 +511,7 @@
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 38
"__id__": 26
},
"propertyPath": [
"_lpos"
@@ -695,7 +526,7 @@
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 38
"__id__": 26
},
"propertyPath": [
"_lrot"
@@ -711,7 +542,7 @@
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 38
"__id__": 26
},
"propertyPath": [
"_euler"
@@ -726,7 +557,7 @@
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 38
"__id__": 26
},
"propertyPath": [
"_lscale"
@@ -748,7 +579,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 44
"__id__": 32
},
"_contentSize": {
"__type__": "cc.Size",
@@ -776,7 +607,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 46
"__id__": 34
},
"anm": {
"__id__": 13
@@ -797,7 +628,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 48
"__id__": 36
},
"debugMode": false,
"_id": ""
@@ -816,7 +647,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 50
"__id__": 38
},
"enabledContactListener": true,
"bullet": false,
@@ -850,7 +681,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 52
"__id__": 40
},
"tag": 0,
"_group": 4,
@@ -884,7 +715,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 54
"__id__": 42
},
"playOnLoad": false,
"_clips": [],
@@ -907,9 +738,6 @@
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": [
{
"__id__": 34
},
{
"__id__": 22
},

View File

@@ -518,14 +518,16 @@ 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', " 护盾值小于等于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', ` 护盾减免 ${absorbed.toFixed(1)} 点伤害,剩余护盾 ${TAttrsComp.shield.toFixed(1)}`);
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,14 @@ 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) return;
if (addValue <= 0) {
mLogger.log(this.debugMode, 'HeroAttrs', `add_shield: addValue=${addValue} <= 0, skip`);
return;
}
this.shield += addValue;
this.shield = Math.min(this.shield, FightSet.SHIELD_MAX); // 限制护盾值上限(数值减免型)
if (this.shield < 0) this.shield = 0;
this.dirty_shield = true; // 标记护盾需要更新
if (this.debugMode) {
mLogger.log(this.debugMode, 'HeroAttrs', ` 护盾值变更: ${this.hero_name}, 变化=${addValue}, ${Math.floor(oldShield)} -> ${Math.floor(this.shield)}`);
}
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

@@ -4,7 +4,7 @@ import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/modu
import { HeroAttrsComp } from "./HeroAttrsComp";
import { BuffComp } from "./BuffComp";
import { BuffList, BuffCategory, DEBUFF_ICON_MAP } from "../common/config/BuffSet";
import { FacSet, FightSet } from "../common/config/GameSet";
import { FacSet } from "../common/config/GameSet";
const { ccclass, property } = _decorator;
@@ -135,13 +135,18 @@ export class HeroTopBarComp extends CCComp {
}
}
/** 更新护盾数值条(百分比 = shield / SHIELD_MAX) */
/** 更新护盾数值条(显示具体数值,无上限) */
public shieldShow(shield: number = 0): void {
if (!this.shieldProgressBar) return;
const progress = FightSet.SHIELD_MAX > 0 ? shield / FightSet.SHIELD_MAX : 0;
this.shieldProgressBar.progress = clamp(progress, 0, 1);
if (!this.shieldProgressBar) {
console.log('[HeroTopBarComp] shieldShow: shieldProgressBar is null');
return;
}
// 护盾条直接显示具体数值,progress 固定为 1(满条显示)
this.shieldProgressBar.progress = 1;
// 护盾节点显隐
this.shieldProgressBar.node.active = shield > 0;
const shouldActive = shield > 0;
console.log(`[HeroTopBarComp] shieldShow: shield=${shield}, active=${shouldActive}, node=${this.shieldProgressBar.node.name}`);
this.shieldProgressBar.node.active = shouldActive;
}
/**

View File

@@ -140,7 +140,13 @@ 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;
}
@@ -309,9 +315,43 @@ export class HeroViewComp extends CCComp {
this.as.move();
}
}
/** 护盾常驻特效节点,避免重复创建 */
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);
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 节点) */
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}`);
}
}
/** 隐藏护盾常驻特效 */
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}`);
}
}
health(hp: number = 0) {
@@ -329,6 +369,7 @@ export class HeroViewComp extends CCComp {
this.model.is_dead = false
this.model.is_count_dead = false
this.deadCD = 0;
this.hideShieldFx();
// 恢复碰撞体
const collider = this.node.getComponent(Collider2D);
@@ -493,6 +534,7 @@ export class HeroViewComp extends CCComp {
}
reset() {
this.isCastingMax = false;
this.hideShieldFx();
// 清理残留的定时器和缓动
this.unscheduleAllCallbacks();
Tween.stopAllByTarget(this.node);

View File

@@ -539,7 +539,9 @@ 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) {