From 74f26f60deac8fc1bb1f93ad26412f9a7e4a281d Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期日, 31 八月 2025 11:33:33 +0800
Subject: [PATCH] 50 【主界面】核心主体 - 战斗按钮逻辑

---
 Main/System/Main/AutoFightModel.cs                  |   41 ++++
 Main/Component/UI/Decorate/Tweens/FillTween.cs.meta |   11 +
 Main/System/Battle/BattleManager.cs                 |    2 
 Main/System/Battle/Skill/SkillBase.cs               |    2 
 Main/System/Main/MainWin.cs                         |  123 ++++++++++++++
 Main/Component/UI/Decorate/Tweens/FillTween.cs      |  227 ++++++++++++++++++++++++++++
 Main/System/Battle/BattleField/StoryBattleField.cs  |    9 
 Main/System/Team/TeamBase.cs                        |   37 ++++
 8 files changed, 438 insertions(+), 14 deletions(-)

diff --git a/Main/Component/UI/Decorate/Tweens/FillTween.cs b/Main/Component/UI/Decorate/Tweens/FillTween.cs
new file mode 100644
index 0000000..7b6d54c
--- /dev/null
+++ b/Main/Component/UI/Decorate/Tweens/FillTween.cs
@@ -0,0 +1,227 @@
+锘�//--------------------------------------------------------
+//    [Author]:           鐜╀釜娓告垙
+//    [  Date ]:           Thursday, September 14, 2017
+//--------------------------------------------------------
+using UnityEngine;
+using System.Collections;
+using UnityEngine.UI;
+using System;
+
+
+public class FillTween : MonoBehaviour
+{
+    public TweenCurve curve;
+    [Range(0, 1)]
+    public float from;
+    [Range(0, 1)]
+    public float to;
+    public float delay = 0f;
+    public float duration = 1f;
+    public Trigger trigger = Trigger.Manual;
+    public WrapMode wrapMode;
+    public bool reversal;
+
+    Image m_Image;
+    public Image image {
+        get {
+            return m_Image ?? (m_Image = this.GetComponent<Image>());
+        }
+    }
+
+    protected float accumulatedTime;
+    protected float curveLength;
+    protected bool doTween = false;
+
+    Action onPlayEndCallBack;
+
+    public void SetStartState()
+    {
+        image.fillAmount = from;
+    }
+
+    public void SetEndState()
+    {
+        image.fillAmount = to;
+    }
+
+    public void Play()
+    {
+        onPlayEndCallBack = null;
+        reversal = false;
+        StopAllCoroutines();
+        if (this.gameObject.activeInHierarchy)
+        {
+            SetStartState();
+            StartCoroutine("Co_StartTween");
+        }
+    }
+
+    public void Play(bool _reversal)
+    {
+        onPlayEndCallBack = null;
+        reversal = _reversal;
+        StopAllCoroutines();
+        if (this.gameObject.activeInHierarchy)
+        {
+            if (_reversal)
+            {
+                SetEndState();
+            }
+            else
+            {
+                SetStartState();
+            }
+
+            StartCoroutine("Co_StartTween");
+        }
+    }
+
+    public void Play(Action _callBack)
+    {
+        onPlayEndCallBack = _callBack;
+        reversal = false;
+        StopAllCoroutines();
+        if (this.gameObject.activeInHierarchy)
+        {
+            SetStartState();
+            StartCoroutine("Co_StartTween");
+        }
+    }
+
+    public void Stop()
+    {
+        doTween = false;
+        accumulatedTime = 0f;
+        StopAllCoroutines();
+        SetStartState();
+    }
+
+
+    void Start()
+    {
+        if (trigger == Trigger.Start)
+        {
+            SetStartState();
+            StartCoroutine("Co_StartTween");
+        }
+    }
+
+    protected virtual void OnEnable()
+    {
+        if (trigger == Trigger.Enable)
+        {
+            SetStartState();
+            StartCoroutine("Co_StartTween");
+        }
+    }
+
+    protected virtual void OnDisable()
+    {
+        doTween = false;
+        accumulatedTime = 0f;
+        StopAllCoroutines();
+    }
+
+    void LateUpdate()
+    {
+        if (doTween && duration > 0.001f)
+        {
+            accumulatedTime += Time.deltaTime;
+            UpdateFill();
+        }
+    }
+
+    IEnumerator Co_StartTween()
+    {
+        if (delay < 0f)
+        {
+            Debug.LogError("Delaytime should not be less than zero!");
+            yield break;
+        }
+        if (duration < 0.001f)
+        {
+            Debug.LogError("Duration should not be less than zero!");
+            yield break;
+        }
+
+        if (curve.keys.Length < 2)
+        {
+            Debug.LogError("涓嶆纭殑鏇茬嚎!");
+            yield break;
+        }
+
+        doTween = false;
+        OnPrepare();
+        yield return new WaitForSeconds(delay);
+        curveLength = curve.keys[curve.keys.Length - 1].time - curve.keys[0].time;
+        doTween = true;
+        accumulatedTime = 0f;
+    }
+
+    protected void UpdateFill()
+    {
+        float t = 0f;
+        switch (wrapMode)
+        {
+            case WrapMode.Once:
+                t = (accumulatedTime / duration) * curveLength;
+                break;
+            case WrapMode.Loop:
+                t = Mathf.Repeat((accumulatedTime / duration) * curveLength, 1);
+                break;
+            case WrapMode.PingPong:
+                t = Mathf.PingPong((accumulatedTime / duration) * curveLength, 1);
+                break;
+        }
+
+        var value = curve.Evaluate(reversal ? curveLength - t : t);
+        image.fillAmount = Mathf.LerpUnclamped(from, to, value);
+
+        switch (wrapMode)
+        {
+            case WrapMode.Once:
+                if (t > curveLength && doTween)
+                {
+                    OnOnceEnd();
+                    doTween = false;
+                }
+                break;
+        }
+    }
+
+    protected virtual void OnPrepare()
+    {
+
+    }
+
+    protected virtual void OnOnceEnd()
+    {
+        if (onPlayEndCallBack != null)
+        {
+            onPlayEndCallBack();
+            onPlayEndCallBack = null;
+        }
+    }
+
+    protected virtual void UpdateVector3()
+    {
+
+    }
+
+    public enum Trigger
+    {
+        Manual,
+        Start,
+        Enable,
+    }
+
+    public enum WrapMode
+    {
+        Once,
+        Loop,
+        PingPong,
+    }
+
+}
+
+
diff --git a/Main/Component/UI/Decorate/Tweens/FillTween.cs.meta b/Main/Component/UI/Decorate/Tweens/FillTween.cs.meta
new file mode 100644
index 0000000..57cca33
--- /dev/null
+++ b/Main/Component/UI/Decorate/Tweens/FillTween.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 47996afe725479248881d409acb960ac
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Main/System/Battle/BattleField/StoryBattleField.cs b/Main/System/Battle/BattleField/StoryBattleField.cs
index 0ae28ef..c71bf05 100644
--- a/Main/System/Battle/BattleField/StoryBattleField.cs
+++ b/Main/System/Battle/BattleField/StoryBattleField.cs
@@ -244,9 +244,10 @@
                 }
             }
         }
-        // else
-        // {
-        //     BattleDebug.LogError("action doesnt finish, wait a moment please");
-        // }
+        else
+        {
+            if (!AutoFightModel.Instance.isAutoAttack)
+                BattleDebug.LogError("action doesnt finish, wait a moment please");
+        }
     }
 }
\ No newline at end of file
diff --git a/Main/System/Battle/BattleManager.cs b/Main/System/Battle/BattleManager.cs
index 588112a..581419d 100644
--- a/Main/System/Battle/BattleManager.cs
+++ b/Main/System/Battle/BattleManager.cs
@@ -350,13 +350,13 @@
         if (isCreate)
         { 
             battleField = BattleFieldFactory.CreateBattleField(guid, MapID, FuncLineID, extendData, redTeamList, blueTeamList);
-            onBattleFieldCreate?.Invoke(guid, battleField);
 
             if (string.IsNullOrEmpty(guid))
             {
                 storyBattleField = (StoryBattleField)battleField;
             }
             battleFields.Add(guid, battleField);
+            onBattleFieldCreate?.Invoke(guid, battleField);
         }
 
 
diff --git a/Main/System/Battle/Skill/SkillBase.cs b/Main/System/Battle/Skill/SkillBase.cs
index 9535875..3b9b52b 100644
--- a/Main/System/Battle/Skill/SkillBase.cs
+++ b/Main/System/Battle/Skill/SkillBase.cs
@@ -93,7 +93,7 @@
 	// 1路绉诲姩鍒拌窛绂婚樀瀹逛綅缃畁鐮佺殑璺濈锛堝2鍙蜂綅锛�5鍙蜂綅锛夐噴鏀撅紙鍗虫垬鍦轰腑澶绫伙級
 	public virtual void Cast()
 	{
-		EventBroadcast.Instance.Broadcast<string, SkillConfig>(EventName.BATTLE_CAST_SKILL, battleField.guid, skillConfig);
+		EventBroadcast.Instance.Broadcast<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, battleField.guid, skillConfig, caster.teamHero);
 
 		BattleDebug.LogError(GetType().Name + " Skill Cast Start");
 		//	楂樹寒鎵�鏈夋湰娆℃妧鑳界浉鍏崇殑鐩爣
diff --git a/Main/System/Main/AutoFightModel.cs b/Main/System/Main/AutoFightModel.cs
index 5f2fc5f..c0b1c8d 100644
--- a/Main/System/Main/AutoFightModel.cs
+++ b/Main/System/Main/AutoFightModel.cs
@@ -76,7 +76,9 @@
     {
         ParseConfig();
         DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
+        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += BeforePlayerInit;
         BattleManager.Instance.onBattleFieldCreate += OnCreateBattleField;
+        EventBroadcast.Instance.AddListener<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, OnSkillCast);
 
     }
 
@@ -84,6 +86,7 @@
     {
         DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
         BattleManager.Instance.onBattleFieldCreate -= OnCreateBattleField;
+        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= BeforePlayerInit;
 
     }
 
@@ -99,6 +102,12 @@
     void OnPlayerLoginOk()
     {
         //鐧诲綍鏃舵湁瑁呭鐨勫鐞�
+    }
+
+    void BeforePlayerInit()
+    {
+        fightingHeroSkinID = 0;
+        heroGuid = "";
     }
 
     public void SaveAutoFightSetting()
@@ -150,7 +159,7 @@
 
     }
 
-    #region 鎴樻枟
+    #region 涓荤嚎鎴樻枟锛堣嚜鍔ㄥ拰鎵嬪姩锛�
 
     public void StartFight()
     {
@@ -163,7 +172,7 @@
             return;
         }
 
-        if (UIHelper.GetMoneyCnt(41) < PlayerDatas.Instance.baseData.UseHarmerCount)
+        if (!ItemLogicUtility.CheckCurrencyCount(41, PlayerDatas.Instance.baseData.UseHarmerCount, 2))
         {
             if (storyBattleField.GetBattleMode() != BattleMode.Stop)
                 storyBattleField.HaveRest();
@@ -190,14 +199,40 @@
 
     }
 
+
     void ChangeBattleModeEvent(BattleMode _battleMode)
     {
         if (_battleMode == BattleMode.Stop)
         {
             isAutoAttack = false;
         }
+        OnFightEvent?.Invoke(false);
     }
-    
+
+    public int fightingHeroSkinID;  //褰撳墠鎴樻枟鐨勮嫳闆勭毊鑲D
+    public string heroGuid;
+    public event Action<bool> OnFightEvent; //鏄惁鎴樻枟閫氱煡
+
+
+    /// <summary>
+    /// 鎶�鑳介噴鏀� 閫氱煡UI澶勭悊
+    /// </summary>
+    /// <param name="guid">绌轰负涓荤嚎</param>
+    /// <param name="skillConfig">鐢ㄤ簬鎬掓皵绛夋樉绀�</param>
+    /// <param name="teamHero">鎴樻枟涓殑姝﹀皢</param>
+    void OnSkillCast(string guid, SkillConfig skillConfig, TeamHero teamHero)
+    {
+        if (!string.IsNullOrEmpty(guid))
+            return;
+
+
+        if (teamHero.NPCID != 0)
+            return;
+        fightingHeroSkinID = teamHero.SkinID;
+        heroGuid = teamHero.guid;
+        OnFightEvent?.Invoke(true);
+    }
+
     #endregion
 
 
diff --git a/Main/System/Main/MainWin.cs b/Main/System/Main/MainWin.cs
index f88f5cd..1423613 100644
--- a/Main/System/Main/MainWin.cs
+++ b/Main/System/Main/MainWin.cs
@@ -15,12 +15,23 @@
     [SerializeField] Text powerText;
     [SerializeField] OfficialTitleCell officialRankText;
 
+    //鎴樻枟鎸夐挳
+    [SerializeField] Image fightOtherWinBG; //鍒囨崲鍏朵粬鐣岄潰鐨勬樉绀�
+    [SerializeField] Image fightOtherWinWarnImg; //鍒囨崲鍏朵粬鐣岄潰 濡傛灉鏄垬鏂椾腑娉涚孩鎻愮ず
+    [SerializeField] GameObject fightBG; //鎴樻枟鐣岄潰鏄剧ず
+    [SerializeField] Image restImg; //浼戞伅鐘舵��
+    [SerializeField] GameObject fightGo; //鎴樻枟鐘舵��
+    [SerializeField] Image fightHeroImg; //鎴樻枟鏄剧ず鑻遍泟
+    [SerializeField] UIEffectPlayer fightEffect;
+    [SerializeField] FillTween cdTween;
+
+
     public Text hammerText;
 
     protected override void InitComponent()
     {
         base.InitComponent();
-        
+
         avatarCell.button.AddListener(() => { });
 
     }
@@ -29,11 +40,13 @@
     {
         UpdateCurrency();
         UpdatePlayerInfo();
+        RefreshFightBtn();
     }
 
     protected override void OnPreOpen()
     {
         PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefresh;
+        AutoFightModel.Instance.OnFightEvent += OnSkillCast;
         base.OnPreOpen();
 
         // 鍒锋柊UI
@@ -43,6 +56,7 @@
     protected override void OnPreClose()
     {
         PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefresh;
+        AutoFightModel.Instance.OnFightEvent -= OnSkillCast;
         base.OnPreClose();
     }
 
@@ -109,7 +123,7 @@
             case PlayerDataType.default26:
                 hammerText.text = UIHelper.GetMoneyCnt(41).ToString();
                 break;
-                
+
         }
 
     }
@@ -122,7 +136,7 @@
     {
         hammerText.text = UIHelper.GetMoneyCnt(41).ToString();
     }
-    
+
     /// <summary>
     /// 搴曢儴鏍囩鎸夐挳鐐瑰嚮
     /// </summary>
@@ -138,7 +152,7 @@
         }
         SelectBottomTab(index);
     }
-    
+
 
     /// <summary>
     /// 鏍规嵁鏍囩绱㈠紩鎵撳紑瀵瑰簲鐨勫瓙鐣岄潰
@@ -185,5 +199,106 @@
                 Debug.LogWarning("鏈煡鐨勬爣绛剧储寮�: " + functionOrder);
                 break;
         }
+
+        RefreshFightBtn();
+    }
+
+
+    ///鎴樻枟鎸夐挳鏄剧ず瑙勫垯
+    /// 1.鍦ㄤ富绾挎垬鏂楃晫闈笅锛�
+    ///     1.1.浼戞伅鐘舵�佺殑鎸夐挳
+    ///     1.2.鎴樻枟鐘舵�佺殑鎸夐挳 锛氭樉绀轰笅涓�涓鏀诲嚮鐨勬灏嗗ご鍍忥紝鎸変綅缃『搴忔帹绠楁樉绀哄ご鍍忥紱涓ヨ皑鎯呭喌涓嬮渶鍒ゆ柇涓嬩竴涓灏嗘槸鍚﹀彲鏀诲嚮濡傝鐪╂檿绛�
+    ///         鏈夎挋鐗堬細榛樿鏄剧ず鎾斁鍏朵粬鎴樻枟鐨勭姸鎬侊紝鐪╂檿鐨勭姸鎬佺瓑姣旇緝澶氾紙澶у鏄挋鐗堟樉绀虹殑鎯呭喌锛屾牴鎹疄闄呯湅鏄惁闇�瑕侊級
+    ///         鏃犺挋鐗堬細缁撴潫涓�涓皬閫氱煡鐨勬椂鍊欙紙B425锛夊彲浠ラ噴鏀剧殑鍘绘帀钂欑増锛涙湁鎬掓皵鐨勬椂鍊欐槸鍚︾壒娈婅〃鐜帮紙寰幆鐏壒鏁堬紵锛�
+    ///         杞湀锛氱偣鍑婚噴鏀� 鎾斁鐗规晥涓旇挋鐗堣浆鍦堬紝杞湀缁撴潫鍚庢樉绀鸿挋鐗� -- 鍚屾椂涓婃柟鍗$墝鎾斁鐗规晥鍜岃浆鍦堬紵
+    /// 2.鍦ㄩ潪涓荤嚎鎴樻枟鐣岄潰涓嬶細
+    ///     1. 浼戞伅鏄剧ず鍏抽棴鐘舵�� 鏃犵壒鏁�
+    ///     2. 鎴樻枟涓紝鏄剧ず娉涚孩鐗规晥
+    /// 涓婃柟鍗$墝 鏀诲嚮鏃舵挱鏀剧壒鏁堝拰杞湀锛屾湁鎬掓皵鐨勬椂鍊欐樉绀烘�掓皵鐗规晥锛�
+
+
+    void RefreshFightBtn()
+    {
+        if (functionOrder == 0)
+        {
+            //涓诲煄鐣岄潰
+            fightOtherWinBG.SetActive(false);
+            fightBG.SetActive(true);
+
+
+            if (BattleManager.Instance.storyBattleField != null &&
+            BattleManager.Instance.storyBattleField.GetBattleMode() == BattleMode.Stop)
+            {
+                fightGo.SetActive(false);
+                restImg.SetActive(true);
+            }
+            else
+            {
+                fightGo.SetActive(true);
+                restImg.SetActive(false);
+                RefreshFightIng();
+            }
+
+        }
+        else
+        {
+            //闈炰富鍩庣晫闈�
+            fightOtherWinBG.SetActive(true);
+            fightBG.SetActive(false);
+            if (BattleManager.Instance.storyBattleField != null &&
+            BattleManager.Instance.storyBattleField.GetBattleMode() == BattleMode.Stop)
+            {
+                fightOtherWinWarnImg.SetActive(false);
+            }
+            else
+            {
+                fightOtherWinWarnImg.SetActive(true);
+            }
+        }
+    }
+
+
+    void RefreshFightIng(bool isfighting = false)
+    {
+        if (isfighting)
+        {
+            // fightEffect.playDelayTime = 50;
+            fightEffect.Play();
+            cdTween.SetStartState();
+            cdTween.Play(()=>
+            { 
+                AutoFightModel.Instance.fightingHeroSkinID = TeamManager.Instance.GetTeam(TeamType.Story).GetNextServerHero(AutoFightModel.Instance.heroGuid).SkinID;
+                fightHeroImg.SetSprite(HeroSkinConfig.Get(AutoFightModel.Instance.fightingHeroSkinID).SquareIcon);
+            });
+        }
+        else
+        {
+            fightEffect.Stop();
+            cdTween.Stop();
+            cdTween.SetEndState();
+        }
+
+        if (AutoFightModel.Instance.fightingHeroSkinID == 0)
+        {
+            AutoFightModel.Instance.fightingHeroSkinID = TeamManager.Instance.GetTeam(TeamType.Story).GetNextServerHero(AutoFightModel.Instance.heroGuid).SkinID;
+        }
+
+        fightHeroImg.SetSprite(HeroSkinConfig.Get(AutoFightModel.Instance.fightingHeroSkinID).SquareIcon);
+    }
+
+    void OnSkillCast(bool isfighting)
+    {
+
+        if (functionOrder != 0)
+            return;
+
+        if (isfighting)
+        {
+            RefreshFightIng(isfighting);
+        }
+        else
+        {
+            RefreshFightBtn();
+        }
     }
 }
\ No newline at end of file
diff --git a/Main/System/Team/TeamBase.cs b/Main/System/Team/TeamBase.cs
index b0de245..fec20d5 100644
--- a/Main/System/Team/TeamBase.cs
+++ b/Main/System/Team/TeamBase.cs
@@ -187,9 +187,10 @@
         }
         return null;
     }
+    
 
     public TeamHero GetHeroByHeroID(int heroId)
-    { 
+    {
         foreach (var hero in tempHeroes)
         {
             if (hero != null && hero.heroId == heroId)
@@ -238,6 +239,40 @@
         return false;
     }
 
+    public TeamHero GetNextServerHero(string guid)
+    {
+        if (string.IsNullOrEmpty(guid))
+        {
+            //鍙栫涓�涓�
+            foreach (var hero in serverHeroes)
+            {
+                if (hero != null)
+                {
+                    return hero;
+                }
+            }
+            return null;
+        }
+        else
+        {
+            //鍙栦笅涓�涓�
+            bool findNext = false;
+            foreach (var hero in serverHeroes)
+            {
+                if (hero != null && hero.guid == guid)
+                {
+                    findNext = true;
+                }
+                else if (findNext && hero != null)
+                {
+                    return hero;
+                }
+            }
+            //娌℃壘鍒� 鍙栫涓�涓�
+            return GetNextServerHero("");
+        }
+    }
+
     //瀹㈡埛绔粠0寮�濮嬶紝鏈嶅姟绔粠1寮�濮�
     public int GetEmptyPosition()
     {

--
Gitblit v1.8.0