refactor(护盾): 移除 shield_max 属性并简化护盾逻辑
护盾系统不再需要维护最大护盾值,因为护盾层数已有明确上限(FightSet.SHIELD_MAX)。 移除 HeroAttrs 枚举、HeroAttrsComp 组件、HeroAtkSystem 和 HeroViewComp 中所有对 shield_max 的引用和操作。 现在护盾层数直接受 SHIELD_MAX 限制,视图层仅需当前护盾值即可显示。
This commit is contained in:
@@ -14,7 +14,6 @@ export enum Attrs {
|
||||
speed = "speed", // 基础移动速度
|
||||
dis = "dis", // 基础距离
|
||||
shield = "shield", // 当前护盾
|
||||
shield_max = "shield_max", // 最大护盾值
|
||||
|
||||
// ==================== 攻击属性 ====================
|
||||
a_cd = "a_cd", // 攻击计时
|
||||
|
||||
@@ -327,7 +327,6 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
TAttrsComp.shield = Math.max(0, TAttrsComp.shield - 1);
|
||||
if (TAttrsComp.shield <= 0) {
|
||||
TAttrsComp.shield = 0;
|
||||
TAttrsComp.shield_max = 0;
|
||||
}
|
||||
TAttrsComp.dirty_shield = true;
|
||||
mLogger.log(this.debugMode, 'HeroAtkSystem', ` 护盾抵挡1次伤害,剩余次数 ${TAttrsComp.shield}`);
|
||||
|
||||
@@ -24,7 +24,6 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
speed: number = 100; // 基础移动速度
|
||||
dis: number = 100; // 基础距离
|
||||
shield: number = 0; // 当前护盾
|
||||
shield_max: number = 0; // 最大护盾值
|
||||
|
||||
// ==================== 攻击属性 (补充) ====================
|
||||
skills: Record<number, HSkillInfo> = {};
|
||||
@@ -97,9 +96,8 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
const addValue = Math.max(0, Math.floor(value));
|
||||
if (addValue <= 0) return;
|
||||
this.shield += addValue;
|
||||
this.shield_max += addValue;
|
||||
this.shield = Math.min(this.shield, FightSet.SHIELD_MAX); // 限制护盾最大层数
|
||||
if (this.shield < 0) this.shield = 0;
|
||||
if (this.shield_max < 0) this.shield_max = 0;
|
||||
this.dirty_shield = true; // 标记护盾需要更新
|
||||
if (this.debugMode) {
|
||||
mLogger.log(this.debugMode, 'HeroAttrs', ` 护盾次数变更: ${this.hero_name}, 变化=${addValue}, ${Math.floor(oldShield)} -> ${Math.floor(this.shield)}`);
|
||||
@@ -229,7 +227,6 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
this.speed = 100;
|
||||
this.dis = 100;
|
||||
this.shield = 0;
|
||||
this.shield_max = 0;
|
||||
|
||||
// 重置新增属性
|
||||
this.skills = {};
|
||||
|
||||
@@ -156,7 +156,7 @@ export class HeroViewComp extends CCComp {
|
||||
|
||||
|
||||
if (this.model.dirty_shield) {
|
||||
this.show_shield(this.model.shield, this.model.shield_max);
|
||||
this.show_shield(this.model.shield);
|
||||
this.model.dirty_shield = false;
|
||||
}
|
||||
}
|
||||
@@ -166,10 +166,9 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
|
||||
/** 显示护盾 */
|
||||
private show_shield(shield: number = 0, shield_max: number = 0) {
|
||||
private show_shield(shield: number = 0) {
|
||||
this.lastBarUpdateTime = Date.now() / 1000;
|
||||
this.node.getChildByName("shielded").active = shield > 0;
|
||||
void shield_max;
|
||||
}
|
||||
|
||||
/** 显示血量 */
|
||||
@@ -370,7 +369,7 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
add_shield(shield:number){
|
||||
// 护盾数据更新由 Model 层处理,这里只负责视图表现
|
||||
if(this.model && this.model.shield>0) this.show_shield(this.model.shield, this.model.shield_max);
|
||||
if(this.model && this.model.shield>0) this.show_shield(this.model.shield);
|
||||
}
|
||||
|
||||
health(hp: number = 0) {
|
||||
|
||||
Reference in New Issue
Block a user