From b0718b0ff46e1d337c28bb91105b67b66f93bee3 Mon Sep 17 00:00:00 2001
From: client_linchunjie <461730578@qq.com>
Date: 星期三, 17 四月 2019 10:34:02 +0800
Subject: [PATCH] 3335 缥缈仙域

---
 System/Dungeon/DungeonReturnBloodBehaviour.cs |  216 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 213 insertions(+), 3 deletions(-)

diff --git a/System/Dungeon/DungeonReturnBloodBehaviour.cs b/System/Dungeon/DungeonReturnBloodBehaviour.cs
index 6c742f7..8cf52cb 100644
--- a/System/Dungeon/DungeonReturnBloodBehaviour.cs
+++ b/System/Dungeon/DungeonReturnBloodBehaviour.cs
@@ -8,16 +8,226 @@
 {
     public class DungeonReturnBloodBehaviour : MonoBehaviour
     {
-        [SerializeField] Button m_ReturnBlood;
+        [SerializeField] Button m_MoneyReturnBlood;
+        [SerializeField] ReturnBloodBeha m_MoneyReturnBeha;
+        [SerializeField] Button m_FreeReturnBlood;
+        [SerializeField] ReturnBloodBeha m_FreeReturnBeha;
+
+        int mapId = 0;
+
+        int moneyReturnId = 0;
+        int freeReturnId = 0;
+
+        DungeonUseBuffModel model
+        {
+            get { return ModelCenter.Instance.GetModel<DungeonUseBuffModel>(); }
+        }
 
         private void Awake()
         {
-            m_ReturnBlood.AddListener(OnReturnBlood);
+            m_FreeReturnBlood.AddListener(FreeReturnBlood);
+            m_MoneyReturnBlood.AddListener(MoneyReturnBlood);
         }
 
-        private void OnReturnBlood()
+        public void Display(int mapId)
         {
+            this.mapId = mapId;
 
+            moneyReturnId = 0;
+            freeReturnId = 0;
+
+            var list = model.GetDungeonUseBuffs(mapId);
+            for (int i = 0; i < list.Count; i++)
+            {
+                var config = DungeonUseBuffConfig.Get(list[i]);
+                if (config.MoneyCnt != 0)
+                {
+                    moneyReturnId = list[i];
+                }
+                else
+                {
+                    freeReturnId = list[i];
+                }
+            }
+
+            m_MoneyReturnBlood.gameObject.SetActive(moneyReturnId != 0);
+            if (moneyReturnId != 0)
+            {
+                m_MoneyReturnBeha.Display(moneyReturnId);
+            }
+            m_FreeReturnBlood.gameObject.SetActive(freeReturnId != 0);
+            if (freeReturnId != 0)
+            {
+                m_FreeReturnBeha.Display(freeReturnId);
+            }
+
+            DisplayTime();
+
+            model.onUseBuffTimeRefresh += OnUseBuffTimeRefresh;
+        }
+
+        void DisplayTime()
+        {
+            if (moneyReturnId != 0)
+            {
+                var seconds = GetBuffSeconds(moneyReturnId);
+                m_MoneyReturnBeha.SetCoolDown(seconds);
+            }
+
+            if (freeReturnId != 0)
+            {
+                var seconds = GetBuffSeconds(freeReturnId);
+                m_FreeReturnBeha.SetCoolDown(seconds);
+            }
+        }
+
+        private void LateUpdate()
+        {
+            if (m_FreeReturnBlood.gameObject.activeSelf)
+            {
+                m_FreeReturnBeha.OnUpdate();
+            }
+            if (m_MoneyReturnBlood.gameObject.activeSelf)
+            {
+                m_MoneyReturnBeha.OnUpdate();
+            }
+        }
+
+        float GetBuffSeconds(int id)
+        {
+            var config = DungeonUseBuffConfig.Get(id);
+            var tick = model.GetUseBuffTime(config.DataMapId, config.MoneyCnt);
+            var useTime = TimeUtility.GetTime(tick);
+            var seconds = Mathf.Max(0f, config.CD - (float)(TimeUtility.ServerNow - useTime).TotalSeconds);
+            return seconds;
+        }
+
+        private void MoneyReturnBlood()
+        {
+            if (moneyReturnId != 0)
+            {
+                var config = DungeonUseBuffConfig.Get(moneyReturnId);
+                var seconds = GetBuffSeconds(moneyReturnId);
+                if (seconds <= 0)
+                {
+                    if (model.moneyCostRemind)
+                    {
+                        ConfirmCancel.ToggleConfirmCancel(Language.Get("Mail101"), Language.Get(""),
+                            Language.Get("InspireNoMention"),
+                            (bool isOk, bool toggle) =>
+                            {
+                                if (toggle)
+                                {
+                                    model.moneyCostRemind = false;
+                                }
+                                if (isOk)
+                                {
+                                    if (PlayerDatas.Instance.baseData.diamond < config.MoneyCnt)
+                                    {
+                                        WindowCenter.Instance.Open<RechargeTipWin>();
+                                        return;
+                                    }
+                                    var pak = new CB10A_tagCMFBBuyBuff();
+                                    pak.MapID = (uint)config.DataMapId;
+                                    pak.MoneyCnt = (ushort)config.MoneyCnt;
+                                    GameNetSystem.Instance.SendInfo(pak);
+                                }
+                            });
+                    }
+                    else
+                    {
+                        var pak = new CB10A_tagCMFBBuyBuff();
+                        pak.MapID = (uint)config.DataMapId;
+                        pak.MoneyCnt = (ushort)config.MoneyCnt;
+                        GameNetSystem.Instance.SendInfo(pak);
+                    }
+                }
+            }
+        }
+
+        private void FreeReturnBlood()
+        {
+            if (freeReturnId != 0)
+            {
+                var config = DungeonUseBuffConfig.Get(freeReturnId);
+                var seconds = GetBuffSeconds(freeReturnId);
+                if (seconds <= 0)
+                {
+                    var pak = new CB10A_tagCMFBBuyBuff();
+                    pak.MapID = (uint)config.DataMapId;
+                    pak.MoneyCnt = (ushort)config.MoneyCnt;
+                    GameNetSystem.Instance.SendInfo(pak);
+                }
+            }
+        }
+
+        private void OnUseBuffTimeRefresh()
+        {
+            DisplayTime();
+        }
+
+        public void Dispose()
+        {
+            model.onUseBuffTimeRefresh -= OnUseBuffTimeRefresh;
+        }
+
+        [Serializable]
+        public class ReturnBloodBeha
+        {
+            [SerializeField] Image m_Mask;
+            [SerializeField] Text m_Time;
+            [SerializeField] Text m_Cost;
+            [SerializeField] Text m_Effect;
+
+            int id = 0;
+            float seconds = 0f;
+
+            public void Display(int id)
+            {
+                this.id = id;
+                var config = DungeonUseBuffConfig.Get(id);
+                if (config.MoneyCnt != 0)
+                {
+                    m_Cost.text = config.MoneyCnt.ToString();
+                }
+
+                m_Mask.gameObject.SetActive(false);
+            }
+
+            public void SetCoolDown(float seconds)
+            {
+                this.seconds = seconds;
+                if (seconds <= 0 && m_Mask.gameObject.activeSelf)
+                {
+                    m_Mask.gameObject.SetActive(false);
+                }
+            }
+
+            void DisplayMask()
+            {
+                var config = DungeonUseBuffConfig.Get(id);
+                var progress = Mathf.Clamp01(seconds / config.CD);
+                m_Mask.fillAmount = progress;
+                if (!m_Mask.gameObject.activeSelf)
+                {
+                    m_Mask.gameObject.SetActive(true);
+                }
+                m_Time.text = ((int)seconds).ToString();
+            }
+
+            public void OnUpdate()
+            {
+                if (seconds > 0f)
+                {
+                    seconds -= Time.deltaTime;
+                    DisplayMask();
+
+                    if (seconds <= 0f)
+                    {
+                        m_Mask.gameObject.SetActive(false);
+                    }
+                }
+            }
         }
     }
 }

--
Gitblit v1.8.0