From 2c574cd0433bb84e297d60c547b866fbb8ac2fd7 Mon Sep 17 00:00:00 2001
From: client_linchunjie <461730578@qq.com>
Date: 星期一, 22 四月 2019 17:45:16 +0800
Subject: [PATCH] 3335 去掉旧炼丹代码,添加炼丹红点逻辑

---
 System/Alchemy/AlchemyModel.cs |  271 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 270 insertions(+), 1 deletions(-)

diff --git a/System/Alchemy/AlchemyModel.cs b/System/Alchemy/AlchemyModel.cs
index 18c9077..3b72641 100644
--- a/System/Alchemy/AlchemyModel.cs
+++ b/System/Alchemy/AlchemyModel.cs
@@ -13,6 +13,15 @@
         Dictionary<int, AlchemyDrugUseLimit> m_AlchemyDrugUseLimits = new Dictionary<int, AlchemyDrugUseLimit>();
         List<int> m_AlchemyDrugs = new List<int>();
         List<int> m_AlchemyDrugQualitys = new List<int>();
+        List<int> m_AssociationItems = new List<int>();
+
+        public readonly Redpoint redpoint = new Redpoint(MainRedDot.RedPoint_key, 110);
+        public readonly Redpoint alchemyDrugRedpoint1 = new Redpoint(110, 11001);
+        public readonly Redpoint alchemyDrugRedpoint2 = new Redpoint(110, 11002);
+        Dictionary<int, Dictionary<int, Redpoint>> alchemyQualityRedpoints = new Dictionary<int, Dictionary<int, Redpoint>>();
+        Dictionary<int, AlchemyRedpoint> alchemyRedpoints = new Dictionary<int, AlchemyRedpoint>();
+
+        public static int redpointIndex = 110010000;
 
         int m_SelectQuality = 0;
         public int selectQuality
@@ -56,6 +65,8 @@
 
         public bool isServerPrepare { get; private set; }
 
+        Clock m_AlchemingClock = null;
+
         public event Action selectQualityRefresh;
         public event Action selectAlchemyRefresh;
         public event Action alchemyStateRefresh;
@@ -65,6 +76,10 @@
 
         public override void Init()
         {
+            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
+            PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshEvent;
+            packModel.refreshItemCountEvent += RefreshItemCountEvent;
+
             ParseConfig();
         }
 
@@ -83,10 +98,38 @@
         public void OnPlayerLoginOk()
         {
             isServerPrepare = true;
+            CheckRedpoint();
         }
 
         public override void UnInit()
         {
+            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
+            PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshEvent;
+            packModel.refreshItemCountEvent -= RefreshItemCountEvent;
+        }
+
+        private void RefreshItemCountEvent(PackType packType, int arg2, int itemId)
+        {
+            if (m_AssociationItems.Contains(itemId))
+            {
+                CheckRedpoint();
+            }
+        }
+
+        private void PlayerDataRefreshEvent(PlayerDataType dataType)
+        {
+            if (dataType == PlayerDataType.LuckValue)
+            {
+                CheckRedpoint();
+            }
+        }
+
+        private void OnFuncStateChangeEvent(int id)
+        {
+            if (id == (int)FuncOpenEnum.BlastFurnace)
+            {
+                CheckRedpoint();
+            }
         }
 
         void ParseConfig()
@@ -148,8 +191,19 @@
                             id = key,
                             count = dict[key],
                         });
+
+                        if (!m_AssociationItems.Contains(key))
+                        {
+                            m_AssociationItems.Add(key);
+                        }
+                    }
+
+                    if (!m_AssociationItems.Contains(config.LearnNeedItemID))
+                    {
+                        m_AssociationItems.Add(config.LearnNeedItemID);
                     }
                 }
+
             }
 
             {
@@ -169,6 +223,32 @@
                 }
 
                 m_AlchemyDrugQualitys.Sort();
+            }
+
+            var qualitys = AlchemyConfig.GetAlchemyQualities((int)AlchemyType.Normal);
+            alchemyQualityRedpoints.Add((int)AlchemyType.Normal, new Dictionary<int, Redpoint>());
+            foreach (var quality in qualitys)
+            {
+                var qualityRedpoint = new Redpoint(alchemyDrugRedpoint1.id, redpointIndex++); ;
+                alchemyQualityRedpoints[(int)AlchemyType.Normal].Add(quality, qualityRedpoint);
+                var alchemys = AlchemyConfig.GetAlchemies((int)AlchemyType.Normal, quality);
+                foreach (var id in alchemys)
+                {
+                    alchemyRedpoints.Add(id, new AlchemyRedpoint(qualityRedpoint.id));
+                }
+            }
+
+            qualitys = AlchemyConfig.GetAlchemyQualities((int)AlchemyType.Fairy);
+            alchemyQualityRedpoints.Add((int)AlchemyType.Fairy, new Dictionary<int, Redpoint>());
+            foreach (var quality in qualitys)
+            {
+                var qualityRedpoint = new Redpoint(alchemyDrugRedpoint2.id, redpointIndex++); ;
+                alchemyQualityRedpoints[(int)AlchemyType.Fairy].Add(quality, qualityRedpoint);
+                var alchemys = AlchemyConfig.GetAlchemies((int)AlchemyType.Fairy, quality);
+                foreach (var id in alchemys)
+                {
+                    alchemyRedpoints.Add(id, new AlchemyRedpoint(qualityRedpoint.id));
+                }
             }
         }
 
@@ -201,6 +281,23 @@
         public bool TryGetAlchemyUseLimit(int id,out AlchemyDrugUseLimit drugUseLimit)
         {
             return m_AlchemyDrugUseLimits.TryGetValue(id, out drugUseLimit);
+        }
+
+        public int GetAlchemyRedpointId(int id)
+        {
+            return alchemyRedpoints.ContainsKey(id) ? alchemyRedpoints[id].redpoint.id : 0;
+        }
+
+        public int GetQualityRedpointId(int alchemyType, int quality)
+        {
+            if (alchemyQualityRedpoints.ContainsKey(alchemyType))
+            {
+                if (alchemyQualityRedpoints[alchemyType].ContainsKey(quality))
+                {
+                    return alchemyQualityRedpoints[alchemyType][quality].id;
+                }
+            }
+            return 0;
         }
 
         public float GetAlchemySuccRate(int alchemyId)
@@ -307,8 +404,9 @@
             return true;
         }
 
-        public bool IsStoveAlcheming(AlchemyType alchemyType)
+        public bool IsStoveAlcheming(AlchemyType alchemyType, out Int2 alchemyPosition)
         {
+            alchemyPosition = default(Int2);
             var qualities = AlchemyConfig.GetAlchemyQualities((int)alchemyType);
             foreach (var quality in qualities)
             {
@@ -318,6 +416,8 @@
                     var state = GetStoveState(alchemyId);
                     if (state != 0)
                     {
+                        alchemyPosition.x = quality;
+                        alchemyPosition.y = alchemyId;
                         return true;
                     }
                 }
@@ -327,10 +427,33 @@
 
         public void ReceivePackage(HA3BF_tagMCPlayerStoveMsg package)
         {
+            var seconds = 0;
+
             for (int i = 0; i < package.StoveCnt; i++)
             {
                 var data = package.InfoList[i];
                 m_AlchemyTimes[(int)data.AlchemyID] = data.StartTime;
+
+                if (data.StartTime > 0)
+                {
+                    var config = AlchemyConfig.Get((int)data.AlchemyID);
+                    var time = TimeUtility.GetTime(data.StartTime);
+                    var _seconds = (int)(TimeUtility.ServerNow - time).TotalSeconds;
+                    if (_seconds < config.NeedTime && config.NeedTime - _seconds > seconds)
+                    {
+                        seconds = config.NeedTime - _seconds;
+                    }
+                }
+            }
+
+            if (m_AlchemingClock != null)
+            {
+                Clock.Stop(m_AlchemingClock);
+                m_AlchemingClock = null;
+            }
+            if (seconds > 0)
+            {
+                m_AlchemingClock = Clock.AlarmAfter(seconds, CheckRedpoint);
             }
 
             stoveLevel = package.StoveLV;
@@ -351,6 +474,8 @@
                     }
                 }
             }
+
+            CheckRedpoint();
 
             if (alchemyStateRefresh != null)
             {
@@ -373,6 +498,134 @@
             if (alchemyDrugUseRefresh != null)
             {
                 alchemyDrugUseRefresh();
+            }
+        }
+
+        static List<int> s_Endables = new List<int>();
+        static List<int> s_Studyables = new List<int>();
+        static List<int> s_Alchemyables = new List<int>();
+
+        static Dictionary<AlchemyType, List<int>> s_SortQualitys = new Dictionary<AlchemyType, List<int>>();
+
+        public List<int> GetSortQualitys(AlchemyType alchemyType)
+        {
+            if (!s_SortQualitys.ContainsKey(alchemyType))
+            {
+                s_SortQualitys.Add(alchemyType, new List<int>(AlchemyConfig.GetAlchemyQualities((int)alchemyType)));
+                s_SortQualitys[alchemyType].Sort(QualityCompare);
+            }
+            return s_SortQualitys[alchemyType];
+        }
+
+        private int QualityCompare(int x, int y)
+        {
+            return -x.CompareTo(y);
+        }
+
+        void CheckRedpoint()
+        {
+            s_Endables.Clear();
+            s_Studyables.Clear();
+            s_Alchemyables.Clear();
+
+            if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.BlastFurnace))
+            {
+                RefreshRedpoint();
+                return;
+            }
+
+            CheckRedpoint(AlchemyType.Normal);
+            CheckRedpoint(AlchemyType.Fairy);
+
+            RefreshRedpoint();
+        }
+
+        void CheckRedpoint(AlchemyType alchemyType)
+        {
+            Int2 position;
+            if (IsStoveAlcheming(alchemyType, out position))
+            {
+                var state = GetStoveState(position.y);
+                if (state == 2)
+                {
+                    s_Endables.Add(position.y);
+                }
+            }
+            else
+            {
+                var qualitys = AlchemyConfig.GetAlchemyQualities((int)alchemyType);
+                foreach (var quality in qualitys)
+                {
+                    var alchemys = AlchemyConfig.GetAlchemies((int)alchemyType, quality);
+                    foreach (var id in alchemys)
+                    {
+                        if (!IsGraspRecipe(id))
+                        {
+                            var config = AlchemyConfig.Get(id);
+                            var count = packModel.GetItemCountByID(PackType.Item, config.LearnNeedItemID);
+                            if (count <= 0 || stoveLevel < config.LearnNeedAlchemLV
+                                || PlayerDatas.Instance.extersion.luckValue < config.LearnNeedLuck)
+                            {
+                                continue;
+                            }
+                            s_Studyables.Add(id);
+                        }
+                    }
+                }
+
+                qualitys = GetSortQualitys(alchemyType);
+                foreach (var quality in qualitys)
+                {
+                    var alchemyable = false;
+                    var alchemys = AlchemyConfig.GetAlchemies((int)alchemyType, quality);
+                    foreach (var id in alchemys)
+                    {
+                        if (!IsGraspRecipe(id))
+                        {
+                            continue;
+                        }
+                        Item item;
+                        if (IsAlchemyEnoughMaterial(id, out item))
+                        {
+                            s_Alchemyables.Add(id);
+                            alchemyable = true;
+                        }
+                    }
+
+                    if (alchemyable)
+                    {
+                        break;
+                    }
+                }
+            }
+        }
+
+        void RefreshRedpoint()
+        {
+            var qualitys = AlchemyConfig.GetAlchemyQualities((int)AlchemyType.Normal);
+            foreach (var quality in qualitys)
+            {
+                var alchemys = AlchemyConfig.GetAlchemies((int)AlchemyType.Normal, quality);
+                foreach (var id in alchemys)
+                {
+                    var redpoint = alchemyRedpoints[id];
+                    redpoint.studyRedpoint.state = s_Studyables.Contains(id) ? RedPointState.Simple : RedPointState.None;
+                    redpoint.endRedpoint.state = s_Endables.Contains(id) ? RedPointState.Simple : RedPointState.None;
+                    redpoint.alchemyRedpoint.state = s_Alchemyables.Contains(id) ? RedPointState.Simple : RedPointState.None;
+                }
+            }
+
+            qualitys = AlchemyConfig.GetAlchemyQualities((int)AlchemyType.Fairy);
+            foreach (var quality in qualitys)
+            {
+                var alchemys = AlchemyConfig.GetAlchemies((int)AlchemyType.Fairy, quality);
+                foreach (var id in alchemys)
+                {
+                    var redpoint = alchemyRedpoints[id];
+                    redpoint.studyRedpoint.state = s_Studyables.Contains(id) ? RedPointState.Simple : RedPointState.None;
+                    redpoint.endRedpoint.state = s_Endables.Contains(id) ? RedPointState.Simple : RedPointState.None;
+                    redpoint.alchemyRedpoint.state = s_Alchemyables.Contains(id) ? RedPointState.Simple : RedPointState.None;
+                }
             }
         }
     }
@@ -497,5 +750,21 @@
             return 0;
         }
     }
+
+    public class AlchemyRedpoint
+    {
+        public readonly Redpoint redpoint;
+        public readonly Redpoint studyRedpoint;
+        public readonly Redpoint endRedpoint;
+        public readonly Redpoint alchemyRedpoint;
+
+        public AlchemyRedpoint(int baseId)
+        {
+            redpoint = new Redpoint(baseId, AlchemyModel.redpointIndex++);
+            studyRedpoint = new Redpoint(redpoint.id, AlchemyModel.redpointIndex++);
+            endRedpoint = new Redpoint(redpoint.id, AlchemyModel.redpointIndex++);
+            alchemyRedpoint = new Redpoint(redpoint.id, AlchemyModel.redpointIndex++);
+        }
+    }
 }
 

--
Gitblit v1.8.0