From f5fe35d36be0576053f754bd70a6086f774dc6d8 Mon Sep 17 00:00:00 2001 From: panw Date: Fri, 7 Feb 2025 15:36:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20=E8=8B=B1=E9=9B=84?= =?UTF-8?q?=E4=B8=8D=E5=9C=A8=E5=8A=A8=E4=B8=80=E4=B8=AAx=E7=82=B9,?= =?UTF-8?q?=E5=92=8C=20=E4=BC=A4=E5=AE=B3=E9=98=9F=E5=88=97=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/ecs/position/BattleMoveSystem.ts | 66 ++++++++++++++++++- assets/script/game/hero/HeroViewComp.ts | 58 ++++++++++++---- 2 files changed, 108 insertions(+), 16 deletions(-) diff --git a/assets/script/game/common/ecs/position/BattleMoveSystem.ts b/assets/script/game/common/ecs/position/BattleMoveSystem.ts index 0b5d9ae6..87015421 100644 --- a/assets/script/game/common/ecs/position/BattleMoveSystem.ts +++ b/assets/script/game/common/ecs/position/BattleMoveSystem.ts @@ -2,11 +2,13 @@ import { HeroViewComp } from "../../../hero/HeroViewComp"; import { BattleMoveComp } from "./BattleMoveComp"; import { ecs } from "../../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { smc } from "../../SingletonModuleComp"; +import { BoxSet } from "../../config/BoxSet"; @ecs.register('BattleMoveSystem') export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate { filter(): ecs.IMatcher { return ecs.allOf(BattleMoveComp, HeroViewComp); + } update(e: ecs.Entity) { @@ -16,9 +18,13 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU if (!move.moving) return; // 检测攻击范围内是否有敌人 - const shouldStop = this.checkEnemiesInRange(e, view.dis); + // 检测友方碰撞和敌方攻击范围 + const alliesStop = this.checkAlliesInProximity(e); + const enemiesStop = this.checkEnemiesInRange(e, view.dis); + const shouldStop = alliesStop || enemiesStop; view.is_atking = shouldStop; - // 同步攻击状态 + + // 同步状态 if (!shouldStop) { if(view.is_stop||view.is_dead) return //停止移动或者死亡不移动 // 计算移动量 @@ -51,6 +57,60 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU newX >= move.targetX; } + /** 检测友方单位碰撞 */ + private checkAlliesInProximity(entity: ecs.Entity): boolean { + const current = entity.get(HeroViewComp); + const currentPos = current.node.position; + const SAFE_DISTANCE = 30; // 安全距离 + + // 查找同阵营同类型的所有友军(包括当前单位) + const allAllies = ecs.query(ecs.allOf(HeroViewComp)).filter(e => { + const other = e.get(HeroViewComp); + return (e === entity || ( + other.fac === current.fac && + other.type === current.type + )); + }); + + // 按uuid从小到大排序 + const sortedAllies = allAllies.sort((a, b) => { + return a.get(HeroViewComp).hero_uuid - b.get(HeroViewComp).hero_uuid; + }); + + // 找到当前单位在排序中的位置 + const currentIndex = sortedAllies.findIndex(e => e === entity); + + // 设置渲染顺序 + if (current.is_boss) { + // boss显示在最上层 + current.node.setSiblingIndex(999); + } else { + // 非boss单位,uuid越小的显示在下层(索引越小) + current.node.setSiblingIndex(currentIndex); + } + + // 如果是uuid最小的单位,直接移动 + if (currentIndex === 0) { + current.is_stop_temp = false; + return false; + } + + // 获取前一个单位(uuid比当前小的最近单位) + const prevUnit = sortedAllies[currentIndex - 1]; + const prevView = prevUnit.get(HeroViewComp); + const distToPrev = Math.abs(currentPos.x - prevView.node.position.x); + + // 如果与前一个单位距离小于安全距离,则停止 + if (distToPrev < SAFE_DISTANCE) { + current.is_stop_temp = true; + return true; + } + + // 如果与前一个单位距离大于安全距离,则移动 + current.is_stop_temp = false; + return false; + } + /** 检测攻击范围内敌人 */ private checkEnemiesInRange(entity: ecs.Entity, range: number): boolean { const currentPos = entity.get(HeroViewComp).node.position; @@ -74,4 +134,4 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU } }); } -} \ No newline at end of file +} diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index d98f8874..9dd87350 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -108,6 +108,15 @@ export class HeroViewComp extends CCComp { ice_cd: number = 0; //冰冻倒计时 dir_y:number = 0; speek_time:number = 0; + is_stop_temp:boolean = false;i + + private damageQueue: Array<{ + damage: number, + isCrit: boolean, + delay: number + }> = []; + private isProcessingDamage: boolean = false; + private damageInterval: number = 0.2; // 伤害数字显示间隔 onLoad() { this.as = this.getComponent(HeroSpine); @@ -147,6 +156,8 @@ export class HeroViewComp extends CCComp { this.at += dt; this.in_stop(dt); + // 处理伤害队列 + this.processDamageQueue(); } get isActive() { return this.ent.has(HeroViewComp) && this.node?.isValid; @@ -357,20 +368,41 @@ export class HeroViewComp extends CCComp { /** 显示伤害数字 */ showDamage(damage: number, isCrit: boolean) { - this.BUFFCOMP.in_atked() - // this.as.atked(); + this.damageQueue.push({ + damage, + isCrit, + delay: this.damageInterval + }); + } + + /** 处理伤害队列 */ + private processDamageQueue() { + if (this.isProcessingDamage || this.damageQueue.length === 0) return; + + this.isProcessingDamage = true; + const damageInfo = this.damageQueue.shift()!; + + this.showDamageImmediate(damageInfo.damage, damageInfo.isCrit); + + // 设置延时处理下一个伤害 + this.scheduleOnce(() => { + this.isProcessingDamage = false; + }, this.damageInterval); + } + + /** 立即显示伤害效果 */ + private showDamageImmediate(damage: number, isCrit: boolean) { + this.BUFFCOMP.in_atked(); this.atked_count++; - this.exp_add(this.uaexp) - this.power_add(this.uapw) - if(isCrit){ - this.BUFFCOMP.tooltip(4,damage.toFixed(0),damage) - console.log("暴击伤害:"+damage) - - - }else{ - this.BUFFCOMP.tooltip(1,damage.toFixed(0),damage) - console.log("普通伤害:"+damage) + this.exp_add(this.uaexp); + this.power_add(this.uapw); + + if (isCrit) { + this.BUFFCOMP.tooltip(4, damage.toFixed(0), damage); + console.log("暴击伤害:" + damage); + } else { + this.BUFFCOMP.tooltip(1, damage.toFixed(0), damage); + console.log("普通伤害:" + damage); } - } } \ No newline at end of file