style: 格式化代码并修复代码风格问题

本次提交主要对HeroAttrsComp和HeroViewComp两个文件进行了代码风格统一优化:
1. 统一变量声明的空格规范,修复类型标注前后的空格问题
2. 修正函数参数默认值的空格格式
3. 调整空行和注释的排版一致性
4. 修复字符串类型标注的大小写问题
5. 新增等级变更脏标记和对应的UI显示逻辑
6. 优化了部分条件判断和逻辑代码的可读性
This commit is contained in:
pan
2026-07-21 16:33:52 +08:00
parent 2234b9021d
commit 5d55f3bdb1
2 changed files with 193 additions and 170 deletions

View File

@@ -13,7 +13,7 @@ export class HeroAttrsComp extends ecs.Comp {
private static readonly percentRateThreshold = 1; private static readonly percentRateThreshold = 1;
private static readonly minAttackCd = 0.05; private static readonly minAttackCd = 0.05;
Ebus:any=null! Ebus: any = null!
// ==================== 角色基础信息 ==================== // ==================== 角色基础信息 ====================
hero_uuid: number = 1001; hero_uuid: number = 1001;
hero_name: string = "hero"; hero_name: string = "hero";
@@ -42,7 +42,7 @@ export class HeroAttrsComp extends ecs.Comp {
[SkillTriggerType.FEnd]?: { s_uuid: number; t_num: number; overrides?: SkillOverrides }[]; [SkillTriggerType.FEnd]?: { s_uuid: number; t_num: number; overrides?: SkillOverrides }[];
[SkillTriggerType.Atking]?: { s_uuid: number; t_num: number; overrides?: SkillOverrides }[]; [SkillTriggerType.Atking]?: { s_uuid: number; t_num: number; overrides?: SkillOverrides }[];
[SkillTriggerType.Atked]?: { s_uuid: number; t_num: number; overrides?: SkillOverrides }[]; [SkillTriggerType.Atked]?: { s_uuid: number; t_num: number; overrides?: SkillOverrides }[];
[SkillTriggerType.Revive]?: {s_uuid: number, r_num: number, upr: number}; [SkillTriggerType.Revive]?: { s_uuid: number, r_num: number, upr: number };
// ==================== 特殊属性 ==================== // ==================== 特殊属性 ====================
critical: number = 0; // 暴击率 critical: number = 0; // 暴击率
@@ -70,6 +70,7 @@ export class HeroAttrsComp extends ecs.Comp {
// ==================== 脏标签标记 ==================== // ==================== 脏标签标记 ====================
dirty_hp: boolean = false; // 血量变更标记 dirty_hp: boolean = false; // 血量变更标记
dirty_shield: boolean = false; // 护盾变更标记 dirty_shield: boolean = false; // 护盾变更标记
dirty_lv: boolean = false; // 等级变更标记
// ==================== 技能距离缓存 ==================== // ==================== 技能距离缓存 ====================
maxSkillDistance: number = 0; // 最远技能攻击距离缓存受MP影响 maxSkillDistance: number = 0; // 最远技能攻击距离缓存受MP影响
@@ -92,10 +93,10 @@ export class HeroAttrsComp extends ecs.Comp {
// ==================== 计数统计 ==================== // ==================== 计数统计 ====================
atk_count: number = 0; // 攻击次数 atk_count: number = 0; // 攻击次数
atked_count: number = 0; // 被攻击次数 atked_count: number = 0; // 被攻击次数
killed_count:number=0; killed_count: number = 0;
combat_target_eid: number = -1; combat_target_eid: number = -1;
enemy_in_cast_range: boolean = false; enemy_in_cast_range: boolean = false;
start(){ start() {
} }
// ==================== BUFF 系统初始化 ==================== // ==================== BUFF 系统初始化 ====================
/** /**
@@ -108,7 +109,7 @@ export class HeroAttrsComp extends ecs.Comp {
} }
/*******************基础属性管理********************/ /*******************基础属性管理********************/
add_hp(value:number){ add_hp(value: number) {
const oldHp = this.hp; const oldHp = this.hp;
let addValue = value; let addValue = value;
this.hp += addValue; this.hp += addValue;
@@ -119,7 +120,7 @@ export class HeroAttrsComp extends ecs.Comp {
} }
return addValue; return addValue;
} }
add_shield(value:number){ add_shield(value: number) {
const oldShield = this.shield; const oldShield = this.shield;
const addValue = Math.max(0, Math.floor(value)); const addValue = Math.max(0, Math.floor(value));
if (addValue <= 0) return; if (addValue <= 0) return;
@@ -131,15 +132,15 @@ export class HeroAttrsComp extends ecs.Comp {
mLogger.log(this.debugMode, 'HeroAttrs', ` 护盾次数变更: ${this.hero_name}, 变化=${addValue}, ${Math.floor(oldShield)} -> ${Math.floor(this.shield)}`); mLogger.log(this.debugMode, 'HeroAttrs', ` 护盾次数变更: ${this.hero_name}, 变化=${addValue}, ${Math.floor(oldShield)} -> ${Math.floor(this.shield)}`);
} }
} }
add_hp_max(value:number){ add_hp_max(value: number) {
this.hp_max+=value this.hp_max += value
this.hp+=value this.hp += value
this.dirty_hp = true; // ✅ 仅标记需要更新 this.dirty_hp = true; // ✅ 仅标记需要更新
return value return value
} }
add_ap(value:number){ add_ap(value: number) {
this.ap +=value this.ap += value
return value return value
} }
@@ -163,12 +164,12 @@ export class HeroAttrsComp extends ecs.Comp {
} }
toFrost(time: number=1) { toFrost(time: number = 1) {
const frostTime = FightSet.FROST_TIME * time; const frostTime = FightSet.FROST_TIME * time;
this.frost_end_time = Math.max(this.frost_end_time, frostTime); this.frost_end_time = Math.max(this.frost_end_time, frostTime);
} }
toStun(time: number=1) { toStun(time: number = 1) {
const stunTime = FightSet.STUN_TIME * time; const stunTime = FightSet.STUN_TIME * time;
this.stun_end_time = Math.max(this.stun_end_time, stunTime); this.stun_end_time = Math.max(this.stun_end_time, stunTime);
@@ -181,7 +182,7 @@ export class HeroAttrsComp extends ecs.Comp {
} }
} }
updateCD(dt: number){ updateCD(dt: number) {
// 如果处于冰冻状态,则技能 CD 暂停刷新 // 如果处于冰冻状态,则技能 CD 暂停刷新
if (this.isFrost()) return; if (this.isFrost()) return;
@@ -423,34 +424,35 @@ export class HeroAttrsComp extends ecs.Comp {
this.atk_count = 0; this.atk_count = 0;
this.atked_count = 0; this.atked_count = 0;
this.killed_count =0; this.killed_count = 0;
this.combat_target_eid = -1; this.combat_target_eid = -1;
this.enemy_in_cast_range = false; this.enemy_in_cast_range = false;
// 重置脏标签 // 重置脏标签
this.dirty_hp = false; this.dirty_hp = false;
this.dirty_shield = false; this.dirty_shield = false;
this.dirty_lv = false;
} }
} }
@ecs.register('HeroBuffSystem') @ecs.register('HeroBuffSystem')
export class HeroBuffSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate { export class HeroBuffSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
private timer =new Timer(0.1) private timer = new Timer(0.1)
filter(): ecs.IMatcher { filter(): ecs.IMatcher {
return ecs.allOf(HeroAttrsComp); return ecs.allOf(HeroAttrsComp);
} }
update(e: ecs.Entity): void { update(e: ecs.Entity): void {
if(this.timer.update(this.dt)){ if (this.timer.update(this.dt)) {
const attrsComp = e.get(HeroAttrsComp); const attrsComp = e.get(HeroAttrsComp);
if(attrsComp.frost_end_time > 0){ if (attrsComp.frost_end_time > 0) {
attrsComp.frost_end_time -= 0.1; attrsComp.frost_end_time -= 0.1;
if(attrsComp.frost_end_time <= 0){ if (attrsComp.frost_end_time <= 0) {
attrsComp.frost_end_time = 0; attrsComp.frost_end_time = 0;
} }
} }
if(attrsComp.stun_end_time > 0){ if (attrsComp.stun_end_time > 0) {
attrsComp.stun_end_time -= 0.1; attrsComp.stun_end_time -= 0.1;
if(attrsComp.stun_end_time <= 0){ if (attrsComp.stun_end_time <= 0) {
attrsComp.stun_end_time = 0; attrsComp.stun_end_time = 0;
} }
} }

View File

@@ -1,11 +1,11 @@
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite, math, clamp, Game, tween, Tween, Color, BoxCollider2D, UITransform, UIOpacity, NodeEventType} from "cc"; import { Vec3, _decorator, v3, Collider2D, Contact2DType, Label, Node, Prefab, instantiate, ProgressBar, Component, Material, Sprite, math, clamp, Game, tween, Tween, Color, BoxCollider2D, UITransform, UIOpacity, NodeEventType } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { mLogger } from "../common/Logger"; import { mLogger } from "../common/Logger";
import { HeroSpine } from "./HeroSpine"; import { HeroSpine } from "./HeroSpine";
import { BoxSet, FacSet, FightSet, NumberFormatter, TooltipTypes } from "../common/config/GameSet"; import { BoxSet, FacSet, FightSet, NumberFormatter, TooltipTypes } from "../common/config/GameSet";
import { smc } from "../common/SingletonModuleComp"; import { smc } from "../common/SingletonModuleComp";
import { SkillSet,} from "../common/config/SkillSet"; import { SkillSet, } from "../common/config/SkillSet";
import { HeroInfo } from "../common/config/heroSet"; import { HeroInfo } from "../common/config/heroSet";
import { oops } from "db://oops-framework/core/Oops"; import { oops } from "db://oops-framework/core/Oops";
import { UIID } from "../common/config/GameUIConfig"; import { UIID } from "../common/config/GameUIConfig";
@@ -32,20 +32,21 @@ export class HeroViewComp extends CCComp {
// ==================== View 层属性(表现相关)==================== // ==================== View 层属性(表现相关)====================
as: HeroSpine = null! as: HeroSpine = null!
status:String = "" status: String = ""
scale: number = 1; // 显示方向 scale: number = 1; // 显示方向
box_group:number = BoxSet.HERO; // 碰撞组 box_group: number = BoxSet.HERO; // 碰撞组
realDeadTime:number=0.1 realDeadTime: number = 0.1
deadCD:number=0 deadCD: number = 0
monDeadTime:number=0.1 monDeadTime: number = 0.1
hp_height:number=70 hp_height: number = 70
boss_hp_height:number=120 boss_hp_height: number = 140
// 血条显示相关 // 血条显示相关
lastBarUpdateTime:number = 0; // 最后一次血条/蓝条/护盾更新时间 lastBarUpdateTime: number = 0; // 最后一次血条/蓝条/护盾更新时间
// ==================== UI 节点引用 ==================== // ==================== UI 节点引用 ====================
private top_node: Node = null!; private top_node: Node = null!;
private topOpacity: UIOpacity = null!; private topOpacity: UIOpacity = null!;
private topBasePos: Vec3 = v3(); private topBasePos: Vec3 = v3();
private lvLabel: Label | null = null; // 等级显示文本
private readonly barIdleOpacity: number = 153; private readonly barIdleOpacity: number = 153;
private readonly barActiveOpacity: number = 255; private readonly barActiveOpacity: number = 255;
private readonly idleOpacityDelay: number = 0.25; private readonly idleOpacityDelay: number = 0.25;
@@ -73,13 +74,13 @@ export class HeroViewComp extends CCComp {
onLoad() { onLoad() {
this.as = this.getComponent(HeroSpine); this.as = this.getComponent(HeroSpine);
const collider = this.node.getComponent(BoxCollider2D); const collider = this.node.getComponent(BoxCollider2D);
this.scheduleOnce(()=>{ this.scheduleOnce(() => {
if (collider) { if (collider) {
collider.enabled = true; // 先禁 collider.enabled = true; // 先禁
collider.group = this.box_group; // 设置为英雄组 collider.group = this.box_group; // 设置为英雄组
} }
},0.1) }, 0.1)
// let anm = this.node.getChildByName("anm") // let anm = this.node.getChildByName("anm")
// anm.setScale(anm.scale.x*0.8,anm.scale.y*0.8); // anm.setScale(anm.scale.x*0.8,anm.scale.y*0.8);
@@ -100,7 +101,7 @@ export class HeroViewComp extends CCComp {
} }
/** 视图层逻辑代码分离演示 */ /** 视图层逻辑代码分离演示 */
start () { start() {
this.init(); this.init();
} }
@@ -115,16 +116,19 @@ export class HeroViewComp extends CCComp {
this.initUINodes(); this.initUINodes();
/** 方向 */ /** 方向 */
this.node.setScale(this.scale*Math.abs(this.node.scale.x), 1*this.node.scale.y); // 确保 scale.x 为正后再乘方向 this.node.setScale(this.scale * Math.abs(this.node.scale.x), 1 * this.node.scale.y); // 确保 scale.x 为正后再乘方向
this.top_node.setScale(this.scale*this.top_node.scale.x,1*this.top_node.scale.y); this.top_node.setScale(this.scale * this.top_node.scale.x, 1 * this.top_node.scale.y);
/* 显示角色血*/ /* 显示角色血*/
this.top_node.getChildByName("hp").active = true; this.top_node.getChildByName("hp").active = true;
this.top_node.getChildByName("cd").active = false; this.top_node.getChildByName("cd").active = false;
this.top_node.getChildByName("shield").active = false; this.top_node.getChildByName("shield").active = false;
this.top_node.getChildByName("lv").active = false; this.top_node.getChildByName("lv").active = true;
this.top_node.active = true; this.top_node.active = true;
this.setTopBarOpacity(false); this.setTopBarOpacity(false);
// 初始化等级显示
this.lv_show();
// 🔥 重置血条 UI 显示状态 // 🔥 重置血条 UI 显示状态
if (this.model) { if (this.model) {
this.hp_show(); this.hp_show();
@@ -148,15 +152,21 @@ export class HeroViewComp extends CCComp {
this.top_node = this.node.getChildByName("top"); this.top_node = this.node.getChildByName("top");
this.topOpacity = this.top_node.getComponent(UIOpacity) || this.top_node.addComponent(UIOpacity); this.topOpacity = this.top_node.getComponent(UIOpacity) || this.top_node.addComponent(UIOpacity);
this.top_node.setPosition(0, this.hp_height, 0); this.top_node.setPosition(0, this.hp_height, 0);
if(this.model.is_boss) this.top_node.setPosition(0, this.boss_hp_height, 0); if (this.model.is_boss) this.top_node.setPosition(0, this.boss_hp_height, 0);
this.topBasePos = this.top_node.position.clone(); this.topBasePos = this.top_node.position.clone();
const hpNode = this.top_node.getChildByName("hp"); const hpNode = this.top_node.getChildByName("hp");
if(this.model.fac==FacSet.HERO){ if (this.model.fac == FacSet.HERO) {
hpNode.getChildByName("Bar").getComponent(Sprite).color=new Color("#2ECC71") hpNode.getChildByName("Bar").getComponent(Sprite).color = new Color("#2ECC71")
} }
// 确保血条等UI始终在最上层显示 // 确保血条等UI始终在最上层显示
this.top_node.setSiblingIndex(999); this.top_node.setSiblingIndex(999);
// 缓存等级显示 Labellv 节点下的 Label 子节点)
const lvNode = this.top_node.getChildByName("lv");
if (lvNode) {
this.lvLabel = lvNode.getChildByName("Label")?.getComponent(Label) ?? null;
}
} }
@@ -166,23 +176,23 @@ export class HeroViewComp extends CCComp {
* View 层每帧更新 * View 层每帧更新
* 注意:数据更新逻辑已移到 HeroAttrSystem这里只负责显示 * 注意:数据更新逻辑已移到 HeroAttrSystem这里只负责显示
*/ */
update(dt: number){ update(dt: number) {
if(!smc.mission.play ) return; if (!smc.mission.play) return;
if(smc.mission.pause) return if (smc.mission.pause) return
// 🔥 修复添加安全检查防止在实体销毁过程中访问null的model // 🔥 修复添加安全检查防止在实体销毁过程中访问null的model
if(!this.ent) return; if (!this.ent) return;
if (!this.model) return; if (!this.model) return;
this.processDamageQueue(); this.processDamageQueue();
if(this.model.is_dead){ if (this.model.is_dead) {
this.deadCD+=dt this.deadCD += dt
if(this.deadCD>=this.realDeadTime){ if (this.deadCD >= this.realDeadTime) {
this.deadCD=0 this.deadCD = 0
this.realDead() this.realDead()
} }
return return
} ; };
// ✅ 按需更新 UI脏标签模式- 只在属性变化时更新 // ✅ 按需更新 UI脏标签模式- 只在属性变化时更新
if (this.model.dirty_hp) { if (this.model.dirty_hp) {
@@ -195,10 +205,15 @@ export class HeroViewComp extends CCComp {
this.show_shield(this.model.shield); this.show_shield(this.model.shield);
this.model.dirty_shield = false; this.model.dirty_shield = false;
} }
if (this.model.dirty_lv) {
this.lv_show();
this.model.dirty_lv = false;
}
} }
public cd_show(){ public cd_show() {
return; return;
} }
/** 显示护盾 */ /** 显示护盾 */
@@ -211,8 +226,8 @@ export class HeroViewComp extends CCComp {
private hp_show() { private hp_show() {
this.lastBarUpdateTime = Date.now() / 1000; this.lastBarUpdateTime = Date.now() / 1000;
// 不再基于血量是否满来决定显示状态,只更新进度条 // 不再基于血量是否满来决定显示状态,只更新进度条
let hp=this.model.hp; let hp = this.model.hp;
let hp_max=this.model.hp_max; let hp_max = this.model.hp_max;
// mLogger.log(this.debugMode, 'HeroViewComp', "hp_show",hp,hp_max) // mLogger.log(this.debugMode, 'HeroViewComp', "hp_show",hp,hp_max)
let targetProgress = hp_max > 0 ? hp / hp_max : 0; let targetProgress = hp_max > 0 ? hp / hp_max : 0;
@@ -237,6 +252,12 @@ export class HeroViewComp extends CCComp {
return this.model.hp >= this.model.hp_max; return this.model.hp >= this.model.hp_max;
} }
/** 更新等级显示 */
private lv_show() {
if (!this.lvLabel || !this.model) return;
this.lvLabel.string = String(this.model.lv);
}
private setTopBarOpacity(isActive: boolean) { private setTopBarOpacity(isActive: boolean) {
if (!this.top_node || !this.top_node.isValid) return; if (!this.top_node || !this.top_node.isValid) return;
if (this.topOpacity) { if (this.topOpacity) {
@@ -321,7 +342,7 @@ export class HeroViewComp extends CCComp {
pos.y = pos.y + y; pos.y = pos.y + y;
Tooltip.load(pos, type, value, s_uuid, this.node); Tooltip.load(pos, type, value, s_uuid, this.node);
} }
/** 技能提示 */ /** 技能提示 */
public skill_name(value: string = "", s_uuid: number = 1001, triggerType: string = "", y: number = 50) { public skill_name(value: string = "", s_uuid: number = 1001, triggerType: string = "", y: number = 50) {
let pos = v3(0, 60); let pos = v3(0, 60);
pos.y = pos.y + y; pos.y = pos.y + y;
@@ -347,30 +368,30 @@ export class HeroViewComp extends CCComp {
shield_tip(absorbed: number) { shield_tip(absorbed: number) {
this.hp_tip(TooltipTypes.life, NumberFormatter.formatNumber(Math.max(0, Math.floor(absorbed)))); this.hp_tip(TooltipTypes.life, NumberFormatter.formatNumber(Math.max(0, Math.floor(absorbed))));
} }
public playBuff(anm: string = ""){ public playBuff(anm: string = "") {
if(anm==="") return; if (anm === "") return;
var path = "game/skill/buff/" + anm; var path = "game/skill/buff/" + anm;
this.spawnTimedFx(path, this.node, this.effectLifeTime); this.spawnTimedFx(path, this.node, this.effectLifeTime);
} }
public playReady(anm: string = ""){ public playReady(anm: string = "") {
if(anm==="") return; if (anm === "") return;
var path = "game/skill/ready/" + anm; var path = "game/skill/ready/" + anm;
this.spawnAnimEndFx(path, this.node, undefined); this.spawnAnimEndFx(path, this.node, undefined);
} }
public playOther(anm: string = ""){ public playOther(anm: string = "") {
if(anm==="") return; if (anm === "") return;
var path = "game/skill/ready/" + anm; var path = "game/skill/ready/" + anm;
// 以自身当前位置为基准,挂载到父节点,即使自身节点销毁动画也能继续播放 // 以自身当前位置为基准,挂载到父节点,即使自身节点销毁动画也能继续播放
this.spawnAnimEndFx(path, this.node.parent, this.node.position); this.spawnAnimEndFx(path, this.node.parent, this.node.position);
} }
public playEnd(anm: string = ""){ public playEnd(anm: string = "") {
if(anm==="") return; if (anm === "") return;
var path = "game/skill/end/" + anm; var path = "game/skill/end/" + anm;
this.spawnAnimEndFx(path, this.node, undefined); this.spawnAnimEndFx(path, this.node, undefined);
} }
public playAllTime(anm: string = ""){ public playAllTime(anm: string = "") {
if(anm==="") return; if (anm === "") return;
var path = "game/skill/buff/" + anm; var path = "game/skill/buff/" + anm;
// 常驻特效直接创建节点,不挂载生命周期销毁组件,随父节点(this.node)一起销毁 // 常驻特效直接创建节点,不挂载生命周期销毁组件,随父节点(this.node)一起销毁
this.createFxNode(path, this.node, undefined); this.createFxNode(path, this.node, undefined);
@@ -379,7 +400,7 @@ export class HeroViewComp extends CCComp {
private heathed() { private heathed() {
this.spawnAnimEndFx("game/skill/buff/heathed", this.node, undefined); this.spawnAnimEndFx("game/skill/buff/heathed", this.node, undefined);
} }
private deaded(){ private deaded() {
this.spawnAnimEndFx("game/skill/end/dead", this.node.parent, this.node.position); this.spawnAnimEndFx("game/skill/end/dead", this.node.parent, this.node.position);
} }
private createFxNode(path: string, parent: Node | null, worldPos?: Vec3): Node | null { private createFxNode(path: string, parent: Node | null, worldPos?: Vec3): Node | null {
@@ -414,35 +435,35 @@ export class HeroViewComp extends CCComp {
return this.ent.has(HeroViewComp) && this.node?.isValid; return this.ent.has(HeroViewComp) && this.node?.isValid;
} }
/** 状态切换(动画) */ /** 状态切换(动画) */
status_change(type:string){ status_change(type: string) {
if(this.status === type) return; if (this.status === type) return;
this.status = type; this.status = type;
if(this.model.is_dead || this.model.is_reviving) return if (this.model.is_dead || this.model.is_reviving) return
if(type === "idle"){ if (type === "idle") {
this.as.idle(); this.as.idle();
} else if(type === "move"){ } else if (type === "move") {
this.as.move(); this.as.move();
} }
} }
add_shield(shield:number){ add_shield(shield: number) {
// 护盾数据更新由 Model 层处理,这里只负责视图表现 // 护盾数据更新由 Model 层处理,这里只负责视图表现
if(this.model && this.model.shield>0) this.show_shield(this.model.shield); if (this.model && this.model.shield > 0) this.show_shield(this.model.shield);
} }
health(hp: number = 0) { health(hp: number = 0) {
// ✅ 仅显示特效和提示,不调用 hp_show() // ✅ 仅显示特效和提示,不调用 hp_show()
if(hp<=20) return; if (hp <= 20) return;
this.heathed(); this.heathed();
this.hp_tip(TooltipTypes.health, hp.toFixed(0)); this.hp_tip(TooltipTypes.health, hp.toFixed(0));
this.lastBarUpdateTime = Date.now() / 1000; this.lastBarUpdateTime = Date.now() / 1000;
} }
alive(){ alive() {
// 重置复活标记 - 必须最先重置否则status_change会被拦截 // 重置复活标记 - 必须最先重置否则status_change会被拦截
this.model.is_reviving = false; this.model.is_reviving = false;
this.model.is_dead=false this.model.is_dead = false
this.model.is_count_dead=false this.model.is_count_dead = false
this.deadCD = 0; this.deadCD = 0;
// 恢复碰撞体 // 恢复碰撞体
@@ -469,16 +490,16 @@ export class HeroViewComp extends CCComp {
* 死亡视图表现 * 死亡视图表现
* 由 HeroAtkSystem 调用,只负责视觉效果和事件通知 * 由 HeroAtkSystem 调用,只负责视觉效果和事件通知
*/ */
do_dead(){ do_dead() {
// 添加安全检查 // 添加安全检查
if (!this.model) return; if (!this.model) return;
// 防止重复触发 // 防止重复触发
if(this.model.is_count_dead) return; if (this.model.is_count_dead) return;
this.model.is_count_dead = true; // 防止重复触发,必须存在防止重复调用 this.model.is_count_dead = true; // 防止重复触发,必须存在防止重复调用
// 怪物使用0.5秒死亡时间英雄使用realDeadTime // 怪物使用0.5秒死亡时间英雄使用realDeadTime
if(this.model.fac === FacSet.MON){ if (this.model.fac === FacSet.MON) {
this.realDeadTime = this.monDeadTime; this.realDeadTime = this.monDeadTime;
} }
@@ -490,7 +511,7 @@ export class HeroViewComp extends CCComp {
this.deaded(); this.deaded();
} }
} }
realDead(){ realDead() {
// 🔥 修复添加model安全检查防止实体销毁过程中的空指针异常 // 🔥 修复添加model安全检查防止实体销毁过程中的空指针异常
if (!this.model) { if (!this.model) {
mLogger.warn(this.debugMode, 'HeroViewComp', "[HeroViewComp] realDead called but model is null, skipping"); mLogger.warn(this.debugMode, 'HeroViewComp', "[HeroViewComp] realDead called but model is null, skipping");
@@ -524,7 +545,7 @@ export class HeroViewComp extends CCComp {
}) })
.start(); .start();
} }
do_atked(damage:number,isCrit:boolean,s_uuid:number,isBack:boolean=false){ do_atked(damage: number, isCrit: boolean, s_uuid: number, isBack: boolean = false) {
// 受到攻击时更新最后更新时间 // 受到攻击时更新最后更新时间
this.activateTopBar(); this.activateTopBar();
this.lastBarUpdateTime = Date.now() / 1000; this.lastBarUpdateTime = Date.now() / 1000;
@@ -539,40 +560,40 @@ export class HeroViewComp extends CCComp {
} }
// 视图层表现 // 视图层表现
let SConf=SkillSet[s_uuid] let SConf = SkillSet[s_uuid]
const hitAnm = SConf?.DAnm|| "atked"; const hitAnm = SConf?.DAnm || "atked";
if (isBack) this.back() if (isBack) this.back()
this.in_atked(hitAnm, this.model.fac==FacSet.HERO?1:-1); this.in_atked(hitAnm, this.model.fac == FacSet.HERO ? 1 : -1);
this.showDamage(damage, isCrit); this.showDamage(damage, isCrit);
} }
private isBackingUp: boolean = false; // 🔥 添加后退状态标记 private isBackingUp: boolean = false; // 🔥 添加后退状态标记
//后退 //后退
back(distance: number = 0){ back(distance: number = 0) {
// 🔥 防止重复调用后退动画 // 🔥 防止重复调用后退动画
if (this.isBackingUp) return; if (this.isBackingUp) return;
this.isBackingUp = true; // 🔥 设置后退状态 this.isBackingUp = true; // 🔥 设置后退状态
if(this.model.fac==FacSet.MON) { if (this.model.fac == FacSet.MON) {
// 基础击退距离,加上额外的距离强化 // 基础击退距离,加上额外的距离强化
let dist = FightSet.BACK_RANG + distance; let dist = FightSet.BACK_RANG + distance;
let tx=this.node.position.x + dist; let tx = this.node.position.x + dist;
if(tx > 320) tx=320; if (tx > 320) tx = 320;
tween(this.node) tween(this.node)
.to(0.1, { position:v3(tx,this.node.position.y,0)}) .to(0.1, { position: v3(tx, this.node.position.y, 0) })
.call(() => { .call(() => {
this.isBackingUp = false; // 🔥 动画完成后重置状态 this.isBackingUp = false; // 🔥 动画完成后重置状态
}) })
.start(); .start();
} }
if(this.model.fac==FacSet.HERO) { if (this.model.fac == FacSet.HERO) {
let dist = 5 + distance; let dist = 5 + distance;
let tx=this.node.position.x - dist; let tx = this.node.position.x - dist;
if(tx < -320) tx=-320; if (tx < -320) tx = -320;
tween(this.node) tween(this.node)
.to(0.1, { position:v3(tx,this.node.position.y,0)}) .to(0.1, { position: v3(tx, this.node.position.y, 0) })
.call(() => { .call(() => {
this.isBackingUp = false; // 🔥 动画完成后重置状态 this.isBackingUp = false; // 🔥 动画完成后重置状态
}) })
@@ -582,10 +603,10 @@ export class HeroViewComp extends CCComp {
// 伤害计算和战斗逻辑已迁移到 HeroBattleSystem // 伤害计算和战斗逻辑已迁移到 HeroBattleSystem
playSkillAnm(act:string="") { playSkillAnm(act: string = "") {
mLogger.log(this.debugMode, 'HeroViewComp', '[heroview] act'+act,) mLogger.log(this.debugMode, 'HeroViewComp', '[heroview] act' + act,)
if (act==="") return; if (act === "") return;
switch(act){ switch (act) {
case "max": case "max":
this.as.max() this.as.max()
break break
@@ -649,8 +670,8 @@ export class HeroViewComp extends CCComp {
if (collider) { if (collider) {
collider.off(Contact2DType.BEGIN_CONTACT); collider.off(Contact2DType.BEGIN_CONTACT);
} }
this.deadCD=0 this.deadCD = 0
this.lastBarUpdateTime=0 this.lastBarUpdateTime = 0
this.unschedule(this.restoreBarIdleOpacity); this.unschedule(this.restoreBarIdleOpacity);
// 清理伤害队列 // 清理伤害队列