style: 格式化代码并修复代码风格问题
本次提交主要对HeroAttrsComp和HeroViewComp两个文件进行了代码风格统一优化: 1. 统一变量声明的空格规范,修复类型标注前后的空格问题 2. 修正函数参数默认值的空格格式 3. 调整空行和注释的排版一致性 4. 修复字符串类型标注的大小写问题 5. 新增等级变更脏标记和对应的UI显示逻辑 6. 优化了部分条件判断和逻辑代码的可读性
This commit is contained in:
@@ -13,7 +13,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
private static readonly percentRateThreshold = 1;
|
||||
private static readonly minAttackCd = 0.05;
|
||||
|
||||
Ebus:any=null!
|
||||
Ebus: any = null!
|
||||
// ==================== 角色基础信息 ====================
|
||||
hero_uuid: number = 1001;
|
||||
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.Atking]?: { 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; // 暴击率
|
||||
@@ -64,20 +64,21 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
|
||||
frost_end_time: number = 0;
|
||||
stun_end_time: number = 0;
|
||||
|
||||
|
||||
boom: boolean = false; // 自爆怪
|
||||
|
||||
// ==================== 脏标签标记 ====================
|
||||
dirty_hp: boolean = false; // 血量变更标记
|
||||
dirty_shield: boolean = false; // 护盾变更标记
|
||||
dirty_lv: boolean = false; // 等级变更标记
|
||||
|
||||
// ==================== 技能距离缓存 ====================
|
||||
maxSkillDistance: number = 0; // 最远技能攻击距离(缓存,受MP影响)
|
||||
minSkillDistance: number = 0; // 最近技能攻击距离(缓存,不受MP影响,用于停止位置判断)
|
||||
|
||||
|
||||
// ==================== 阵型位置 ====================
|
||||
posIndex: number = -1;
|
||||
|
||||
|
||||
// ==================== 标记状态 ====================
|
||||
is_dead: boolean = false;
|
||||
is_count_dead: boolean = false;
|
||||
@@ -92,10 +93,10 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
// ==================== 计数统计 ====================
|
||||
atk_count: number = 0; // 攻击次数
|
||||
atked_count: number = 0; // 被攻击次数
|
||||
killed_count:number=0;
|
||||
killed_count: number = 0;
|
||||
combat_target_eid: number = -1;
|
||||
enemy_in_cast_range: boolean = false;
|
||||
start(){
|
||||
start() {
|
||||
}
|
||||
// ==================== BUFF 系统初始化 ====================
|
||||
/**
|
||||
@@ -108,7 +109,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
}
|
||||
/*******************基础属性管理********************/
|
||||
|
||||
add_hp(value:number){
|
||||
add_hp(value: number) {
|
||||
const oldHp = this.hp;
|
||||
let addValue = value;
|
||||
this.hp += addValue;
|
||||
@@ -119,7 +120,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
}
|
||||
return addValue;
|
||||
}
|
||||
add_shield(value:number){
|
||||
add_shield(value: number) {
|
||||
const oldShield = this.shield;
|
||||
const addValue = Math.max(0, Math.floor(value));
|
||||
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)}`);
|
||||
}
|
||||
}
|
||||
add_hp_max(value:number){
|
||||
this.hp_max+=value
|
||||
this.hp+=value
|
||||
add_hp_max(value: number) {
|
||||
this.hp_max += value
|
||||
this.hp += value
|
||||
this.dirty_hp = true; // ✅ 仅标记需要更新
|
||||
return value
|
||||
}
|
||||
|
||||
add_ap(value:number){
|
||||
this.ap +=value
|
||||
add_ap(value: number) {
|
||||
this.ap += value
|
||||
return value
|
||||
}
|
||||
|
||||
@@ -151,7 +152,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
add_special_attr(attr_type: Attrs, value: number) {
|
||||
// 利用枚举值(字符串)与类属性名一致的特性,动态访问并累加属性
|
||||
const key = attr_type as keyof this;
|
||||
|
||||
|
||||
// 确保目标属性存在且类型为数字,避免运行时错误
|
||||
if (typeof this[key] === 'number') {
|
||||
(this as any)[key] += value;
|
||||
@@ -163,15 +164,15 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
}
|
||||
|
||||
|
||||
toFrost(time: number=1) {
|
||||
toFrost(time: number = 1) {
|
||||
const frostTime = FightSet.FROST_TIME * time;
|
||||
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;
|
||||
this.stun_end_time = Math.max(this.stun_end_time, stunTime);
|
||||
|
||||
|
||||
// 击晕时 CD 清零
|
||||
for (const key in this.skills) {
|
||||
const skill = this.skills[key];
|
||||
@@ -180,11 +181,11 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateCD(dt: number){
|
||||
|
||||
updateCD(dt: number) {
|
||||
// 如果处于冰冻状态,则技能 CD 暂停刷新
|
||||
if (this.isFrost()) return;
|
||||
|
||||
|
||||
// 如果处于击晕状态,则技能 CD 暂停刷新(且保持清零状态)
|
||||
if (this.isStun()) {
|
||||
for (const key in this.skills) {
|
||||
@@ -195,7 +196,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (const key in this.skills) {
|
||||
const skill = this.skills[key];
|
||||
if (!skill) continue;
|
||||
@@ -344,7 +345,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
this.maxSkillDistance = maxRange;
|
||||
this.minSkillDistance = minRange;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取缓存的最远技能攻击距离
|
||||
* @returns 最远攻击距离
|
||||
@@ -352,7 +353,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
public getCachedMaxSkillDistance(): number {
|
||||
return this.maxSkillDistance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取缓存的最近技能攻击距离
|
||||
* @returns 最近攻击距离
|
||||
@@ -376,7 +377,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
this.speed = 100;
|
||||
this.dis = 100;
|
||||
this.shield = 0;
|
||||
|
||||
|
||||
// 重置新增属性
|
||||
this.skills = {};
|
||||
this.call = undefined;
|
||||
@@ -401,16 +402,16 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
this.puncture_chance = 0;
|
||||
this.wfuny = 0;
|
||||
this.boom = false;
|
||||
|
||||
|
||||
this.frost_end_time = 0;
|
||||
this.stun_end_time = 0;
|
||||
|
||||
// 重置技能距离缓存
|
||||
this.maxSkillDistance = 0;
|
||||
this.minSkillDistance = 0;
|
||||
|
||||
|
||||
this.posIndex = -1;
|
||||
|
||||
|
||||
this.is_dead = false;
|
||||
this.is_count_dead = false;
|
||||
this.is_atking = false;
|
||||
@@ -420,37 +421,38 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
this.is_friend = false;
|
||||
this.is_kalami = false;
|
||||
this.is_reviving = false;
|
||||
|
||||
|
||||
this.atk_count = 0;
|
||||
this.atked_count = 0;
|
||||
this.killed_count =0;
|
||||
this.killed_count = 0;
|
||||
this.combat_target_eid = -1;
|
||||
this.enemy_in_cast_range = false;
|
||||
// 重置脏标签
|
||||
this.dirty_hp = false;
|
||||
this.dirty_shield = false;
|
||||
this.dirty_lv = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ecs.register('HeroBuffSystem')
|
||||
export class HeroBuffSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
|
||||
private timer =new Timer(0.1)
|
||||
private timer = new Timer(0.1)
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(HeroAttrsComp);
|
||||
}
|
||||
|
||||
update(e: ecs.Entity): void {
|
||||
if(this.timer.update(this.dt)){
|
||||
if (this.timer.update(this.dt)) {
|
||||
const attrsComp = e.get(HeroAttrsComp);
|
||||
if(attrsComp.frost_end_time > 0){
|
||||
if (attrsComp.frost_end_time > 0) {
|
||||
attrsComp.frost_end_time -= 0.1;
|
||||
if(attrsComp.frost_end_time <= 0){
|
||||
if (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;
|
||||
if(attrsComp.stun_end_time <= 0){
|
||||
if (attrsComp.stun_end_time <= 0) {
|
||||
attrsComp.stun_end_time = 0;
|
||||
}
|
||||
}
|
||||
@@ -459,5 +461,5 @@ export class HeroBuffSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user