From 3bd7f56906e31e8fe0072108c9d4652707b51de8 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期二, 21 十月 2025 17:59:00 +0800
Subject: [PATCH] 125 战斗 战斗UI

---
 Main/System/Battle/BattleObject/BattleObject.cs |  199 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 159 insertions(+), 40 deletions(-)

diff --git a/Main/System/Battle/BattleObject/BattleObject.cs b/Main/System/Battle/BattleObject/BattleObject.cs
index e094fb1..89714c3 100644
--- a/Main/System/Battle/BattleObject/BattleObject.cs
+++ b/Main/System/Battle/BattleObject/BattleObject.cs
@@ -32,13 +32,13 @@
 
     public BattleObjectBuffMgr buffMgr;
 
+    public BattleObjectLayerMgr layerMgr;
+
     public int ObjID { get; set; }
 
     public BattleCamp Camp { get; protected set; }
 
     public TeamHero teamHero { get; protected set; }
-
-    // public BuffMgr buffMgr;
 
     public MotionBase motionBase;
 
@@ -51,6 +51,7 @@
     protected BattleDrops battleDrops;
 
     private RectTransform m_heroRectTrans;
+
 
     public RectTransform heroRectTrans
     {
@@ -68,9 +69,8 @@
 
     protected Renderer[] renderers;
 
-    public Transform effectNode;
-
     private List<HB405_tagMCAddExp> hB405_tagMCAddExps = new List<HB405_tagMCAddExp>();
+    public BattleHeroInfoBar heroInfoBar;
 
     public BattleObject(BattleField _battleField)
     {
@@ -83,19 +83,33 @@
         teamHero = _teamHero;
         Camp = _camp;
         motionBase = new MotionBase();
-        motionBase.Init(heroGo.GetComponentInChildren<SkeletonGraphic>(true));
-        motionBase.onAnimationComplete += OnAnimationComplete;
+        motionBase.Init(heroGo.GetComponentInChildren<SkeletonAnimation>(true));
         buffMgr = new BattleObjectBuffMgr();
         buffMgr.Init(this);
 
-        renderers = heroGo.GetComponentsInChildren<Renderer>(true);
-    }
+        layerMgr = new BattleObjectLayerMgr();
+        layerMgr.Init(this);
 
+        renderers = heroGo.GetComponentsInChildren<Renderer>(true);
+
+        heroInfoBar = heroGo.GetComponentInChildren<BattleHeroInfoBar>(true);
+        heroInfoBar.SetBattleObject(this);
+
+        //  鏍规嵁闃佃惀缈昏浆琛�鏉�
+        var heroInfoBarScale = heroInfoBar.transform.localScale;
+        heroInfoBarScale.x *= Camp == BattleCamp.Red ? 1 : -1;
+        heroInfoBar.transform.localScale = heroInfoBarScale;
+
+        heroInfoBar.SetActive(true);
+        SetFront();
+    }
 
 
     public virtual void Run()
     {
         motionBase.Run();
+        heroInfoBar.Run();
+        buffMgr.Run();
     }
 
     public virtual void Pause()
@@ -110,7 +124,6 @@
 
     public virtual void Destroy()
     {
-        motionBase.onAnimationComplete -= OnAnimationComplete;
 
         motionBase.Release();
         motionBase = null;
@@ -129,16 +142,45 @@
         switch ((PlayerDataType)_refreshInfo.RefreshType)
         {
             case PlayerDataType.HP:
+                long toHp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
+                heroInfoBar.UpdateHP(teamHero.curHp, toHp, teamHero.maxHp);
                 teamHero.curHp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
                 break;
             case PlayerDataType.MaxHP:
                 teamHero.maxHp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
+                heroInfoBar.UpdateHP(teamHero.curHp, teamHero.curHp, teamHero.maxHp);
                 break;
             case PlayerDataType.XP:
+                long toXp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
+                heroInfoBar.UpdateXP(teamHero.rage, toXp, 100);
                 teamHero.rage = (int)GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
                 break;
             default:
-                BattleDebug.LogError("BattleObject.ObjInfoRefresh 鍑虹幇鎰忓绫诲瀷 " + _refreshInfo.RefreshType.ToString());
+                Debug.LogError("BattleObject.ObjInfoRefresh 鍑虹幇鎰忓绫诲瀷 " + _refreshInfo.RefreshType.ToString());
+                break;
+        }
+    }
+
+    public void ObjPropertyRefreshView(HB418_tagSCObjPropertyRefreshView vNetData)
+    {
+        switch ((PlayerDataType)vNetData.RefreshType)
+        {
+            case PlayerDataType.HP:
+                long toHp = GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
+                heroInfoBar.UpdateHP(teamHero.curHp, toHp, teamHero.maxHp);
+                teamHero.curHp = GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
+                break;
+            case PlayerDataType.MaxHP:
+                teamHero.maxHp = GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
+                heroInfoBar.UpdateHP(teamHero.curHp, teamHero.curHp, teamHero.maxHp);
+                break;
+            case PlayerDataType.XP:
+                long toXp = GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
+                heroInfoBar.UpdateXP(teamHero.rage, toXp, 100);
+                teamHero.rage = (int)GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
+                break;
+            default:
+                Debug.LogError("BattleObject.ObjPropertyRefreshView 鍑虹幇鎰忓绫诲瀷 " + vNetData.RefreshType.ToString());
                 break;
         }
     }
@@ -226,60 +268,113 @@
         return true;
     }
 
-    public virtual void Hurt(List<long> damageValues, long _totalDamage, uint attackType)
+    public virtual void Hurt(List<long> damageValues, long _totalDamage,
+        HB427_tagSCUseSkill.tagSCUseSkillHurt hurt, SkillConfig skillConfig, int hitIndex,
+        BattleDrops battleDrops, HB422_tagMCTurnFightObjDead deadPack)
     {
-        PopDamage(teamHero.curHp, damageValues, attackType);
+        bool isLastHit = hitIndex >= skillConfig.DamageDivide.Length - 1;
+        bool firstHit = hitIndex == 0;
+        BattleDmgInfo dmgInfo = PopDamage(damageValues, _totalDamage, hurt, skillConfig, isLastHit);
 
-        motionBase.PlayAnimation(MotionName.hit, false);
 
-        //  鎵h
-        teamHero.curHp -= _totalDamage;
+        //  杩欓噷
+        if (dmgInfo.IsType(DamageType.Dodge))
+        {
+            if (isLastHit)
+            {
+                DodgeFinishAction dodgeFinish = new DodgeFinishAction(battleField, this);
+                battleField.recordPlayer.InsertRecord(dodgeFinish);
+            }
+
+            if (firstHit)
+            {
+                OnDodgeBegin();
+            }
+        }
+
+        bool isFatalAttack = (null != deadPack) && isLastHit;
+
+        if (isFatalAttack)
+        {
+            if (null != battleDrops)
+            {
+                PushDropItems(battleDrops);
+            }
+            battleField.OnObjsDead(new List<HB422_tagMCTurnFightObjDead>() { deadPack });
+            
+        }
+        else
+        {
+            if ((dmgInfo.IsType(DamageType.Damage) || dmgInfo.IsRealdamage()))
+            {
+                motionBase.PlayAnimation(MotionName.hit, false);
+            }
+        }
+
+
     }
 
+    public void SuckHp(uint suckHP, SkillConfig skillConfig)
+    {
+        teamHero.curHp = Math.Min(teamHero.maxHp, teamHero.curHp + (int)suckHP);
+    }
+
+    public void HurtByReflect(uint bounceHP, SkillConfig skillConfig)
+    {
+        teamHero.curHp = Math.Max(0, teamHero.curHp - (int)bounceHP);
+    }
+
+
+    const float pingpongTime = 0.4f;
     //  闂伩寮�濮�
     public virtual void OnDodgeBegin()
     {
-        float pingpongTime = 0.2f;
         RectTransform rectTrans = heroRectTrans;
-        var tween = rectTrans.DOAnchorPos(new Vector3(-50, 50, 0), pingpongTime)
+        var tween = rectTrans.DOAnchorPos(new Vector3(-30, 0, 0), pingpongTime)
             .SetEase(Ease.OutCubic);
+
+        motionBase.ShowIllusionShadow(true);
+
+        tween.onComplete += () =>
+        {
+            motionBase.ShowIllusionShadow(false);
+        };
 
         battleField.battleTweenMgr.OnPlayTween(tween);
     }
 
     //  闂伩缁撴潫
-    public virtual void OnDodgeEnd()
+    public virtual void OnDodgeEnd(Action _complete = null)
     {
-        float pingpongTime = 0.2f;
         RectTransform rectTrans = heroRectTrans;
 
         var tween = rectTrans.DOAnchorPos(Vector3.zero, pingpongTime)
                             .SetEase(Ease.OutCubic);
+
+        tween.onComplete += () =>
+        {
+            _complete?.Invoke();
+        };
 
         battleField.battleTweenMgr.OnPlayTween(tween);
     }
 
     public virtual void OnDeath(Action _onDeathAnimationComplete)
     {
-        BattleDebug.LogError(ObjID + " OnDeath called");
-        onDeathAnimationComplete = _onDeathAnimationComplete;
-        motionBase.PlayAnimation(MotionName.dead, false);
-    }
-
-    protected virtual void OnAnimationComplete(MotionName motionName)
-    {
-        if (motionName == MotionName.dead)
+        motionBase.PlayAnimation(MotionName.dead, false, () =>
         {
+            teamHero.isDead = true;
             OnDeadAnimationComplete();
-            onDeathAnimationComplete?.Invoke();
-            onDeathAnimationComplete = null;
-        }
+            _onDeathAnimationComplete?.Invoke();
+        });
     }
 
     protected virtual void OnDeadAnimationComplete()
     {
         //  鎴栬鐪嬬湅婧惰В鐗规晥锛� YYL TODO
         heroGo.SetActive(false);
+
+        buffMgr.RemoveAllBuff();
     }
 
     public void OnReborn(HB423_tagMCTurnFightObjReborn vNetData)
@@ -291,19 +386,26 @@
     }
 
     // 浼ゅ杩樿鐪� 鏄惁闂伩 鏆村嚮 and so on 闇�瑕佹湁涓�涓狣amageType 鏈嶅姟鍣ㄥ簲璇ヤ細缁�
-    protected virtual void PopDamage(long curHp, List<long> damageValues, uint attackType)
+    protected virtual BattleDmgInfo PopDamage(List<long> damageValues, long _totalDamage, HB427_tagSCUseSkill.tagSCUseSkillHurt hurt, SkillConfig skillConfig, bool isLastHit)
     {
-        //  鍏跺疄搴旇閫氱煡鍑哄幓缁橴I鐣岄潰瑙h�� 璁︰I鐣岄潰鑷繁鏉ユ樉绀虹殑 YYL TODO
-        //  鎾斁浼ゅ鏁板瓧
-        //  杩欓噷鍙互瀹炵幇涓�涓激瀹虫暟瀛楃殑寮瑰嚭鏁堟灉
-        //  姣斿浣跨敤涓�涓猆I缁勪欢鏉ユ樉绀轰激瀹虫暟瀛�
-        foreach (var damage in damageValues)
+        BattleDmgInfo battleDmgInfo = new BattleDmgInfo(battleField.guid, damageValues, this, hurt, skillConfig, isLastHit);
+
+        int currentHurtHp = 0;
+        for (int i = 0; i < damageValues.Count; i++)
         {
-            Debug.Log($"Damage: {damage}");
+            currentHurtHp += (int)damageValues[i];
         }
 
+        bool isRecovery = battleDmgInfo.IsType(DamageType.Recovery);
+
+        long toHp = Math.Max(0, teamHero.curHp + (isRecovery ? currentHurtHp : -currentHurtHp));
+
+        heroInfoBar.UpdateHP(teamHero.curHp, toHp, teamHero.maxHp);
+        teamHero.curHp = toHp;
+
         // YYL TODO 鏄惁闇�瑕佹寕鍦ㄥ湪鑷韩鐨刦ollow鐐逛笂
-        EventBroadcast.Instance.Broadcast(EventName.BATTLE_DAMAGE_TAKEN, battleField.guid, this, damageValues);
+        EventBroadcast.Instance.Broadcast(EventName.BATTLE_DAMAGE_TAKEN, battleDmgInfo);
+        return battleDmgInfo;
     }
 
     public RectTransform GetAliasTeamNode()
@@ -327,8 +429,11 @@
         //  浼戞伅鐘舵��
         //  澶氫竴涓獄zz鐨勪竴涓壒鏁�
         heroGo.SetActive(true);
-        motionBase.PlayAnimation(MotionName.idle, true);
+        motionBase.HaveRest();
         heroRectTrans.anchoredPosition = Vector2.zero;
+
+        heroInfoBar.SetActive(false);
+        SetFront();
     }
 
     public void PushDropItems(BattleDrops _battleDrops)
@@ -338,7 +443,7 @@
 
     public void PerformDrop()
     {
-        if (null == battleDrops)
+        if (null == battleDrops || battleDrops.dropItemPackIndex.Count == 0)
             return;
 
         EventBroadcast.Instance.Broadcast<string, BattleDrops, Action>(
@@ -350,6 +455,20 @@
         battleDrops = null;
     }
 
+    public void SetBack()
+    {
+        layerMgr.SetBack();
+    }
+
+    public void SetFront()
+    {
+        layerMgr.SetFront();
+    }
+
+    public void SetSpeedRatio(float ratio)
+    {
+        motionBase.SetSpeedRatio(ratio);
+    }
 
 
 #if UNITY_EDITOR_STOP_USING

--
Gitblit v1.8.0