From 3f08266d9437cc544cc4f256d7229bbbde084bf8 Mon Sep 17 00:00:00 2001
From: client_linchunjie <461730578@qq.com>
Date: 星期一, 08 十月 2018 17:59:39 +0800
Subject: [PATCH] 4047 【前端】【主干】【1.0.18】法宝潜力红点最优解优化

---
 System/Treasure/TreasureData.cs           |   19 ++++
 System/Treasure/TreasureModel.cs          |  145 +++++++++++++++++++++++++++++++-----
 System/Treasure/TreasureLevelUpWin.cs     |   15 +++
 System/Treasure/TreasurePotentialPanel.cs |   29 ++++++-
 4 files changed, 182 insertions(+), 26 deletions(-)

diff --git a/System/Treasure/TreasureData.cs b/System/Treasure/TreasureData.cs
index 2f0d824..06b418a 100644
--- a/System/Treasure/TreasureData.cs
+++ b/System/Treasure/TreasureData.cs
@@ -83,6 +83,8 @@
             get; private set;
         }
 
+        public int autoSelectPotential { get; set; }
+
         Dictionary<int, List<TreasurePotential>> jobToPotentials = new Dictionary<int, List<TreasurePotential>>();
 
         public List<TreasurePotential> potentials
@@ -197,6 +199,23 @@
             }
         }
 
+        public TreasurePotential GetPotentialByIndex(int index)
+        {
+            if (potentials == null)
+            {
+                return null;
+            }
+            else
+            {
+                if (index >= 0 && index < potentials.Count)
+                {
+                    return potentials[index];
+                }
+
+                return null;
+            }
+        }
+
         public void UpdatePotentialLevel(int _potentialId, int _level)
         {
             for (int i = 0; i < potentials.Count; i++)
diff --git a/System/Treasure/TreasureLevelUpWin.cs b/System/Treasure/TreasureLevelUpWin.cs
index d4e4c9e..5b70a10 100644
--- a/System/Treasure/TreasureLevelUpWin.cs
+++ b/System/Treasure/TreasureLevelUpWin.cs
@@ -58,6 +58,8 @@
         [SerializeField] FairyTreasureCollectPanel m_TreasureFairyBehaviour;
 
         [SerializeField] RectTransform m_ContainerSelect;
+        [SerializeField] Image m_LeftRedpoint;
+        [SerializeField] Image m_RightRedpoint;
         [SerializeField] Button m_LeftBtn;
         [SerializeField] Button m_RightBtn;
         [SerializeField] Button m_BackBtn;
@@ -342,6 +344,11 @@
             m_RightBtn.gameObject.SetActive(_leftRifht != null);
             _leftRifht = Config.Instance.Get<TreasureConfig>(model.selectedTreasure - 1);
             m_LeftBtn.gameObject.SetActive(_leftRifht != null);
+            var skillLevelUpRedpointTreasure = model.GetSkillLevelUpRedpointTreasure();
+            m_LeftRedpoint.gameObject.SetActive(skillLevelUpRedpointTreasure != 0
+                && model.selectedTreasure > skillLevelUpRedpointTreasure && model.currentCategory == TreasureCategory.Human);
+            m_RightRedpoint.gameObject.SetActive(skillLevelUpRedpointTreasure != 0
+                && model.selectedTreasure < skillLevelUpRedpointTreasure && model.currentCategory == TreasureCategory.Human);
         }
 
         private void HideHuman()
@@ -1196,6 +1203,14 @@
                     UpdateLevelUpSfx(false);
                 }
             }
+            if (_id == TreasureModel.CATEGORY_REDPOINTIDS[(int)TreasureCategory.Human - 1])
+            {
+                var skillLevelUpRedpointTreasure = model.GetSkillLevelUpRedpointTreasure();
+                m_LeftRedpoint.gameObject.SetActive(skillLevelUpRedpointTreasure != 0
+                    && model.selectedTreasure > skillLevelUpRedpointTreasure && model.currentCategory == TreasureCategory.Human);
+                m_RightRedpoint.gameObject.SetActive(skillLevelUpRedpointTreasure != 0
+                    && model.selectedTreasure < skillLevelUpRedpointTreasure && model.currentCategory == TreasureCategory.Human);
+            }
         }
 
         protected override void LateUpdate()
diff --git a/System/Treasure/TreasureModel.cs b/System/Treasure/TreasureModel.cs
index d03a72e..c2a6a3e 100644
--- a/System/Treasure/TreasureModel.cs
+++ b/System/Treasure/TreasureModel.cs
@@ -662,10 +662,7 @@
                     {
                         potentialLevelChangeEvent(key, config.SkillTypeID);
                     }
-                    if (FuncOpen.Instance.IsFuncOpen(82))
-                    {
-                        UpdateSkillLevelUpRedpoint(treasure.id);
-                    }
+                    UpdateSkillLevelUpRedpoints();
                     break;
                 }
             }
@@ -819,14 +816,102 @@
 
         private void UpdateSkillLevelUpRedpoints()
         {
+            var list = GetTreasureCategory(TreasureCategory.Human);
+            for (int i = 0; i < list.Count; i++)
+            {
+                var id = list[i];
+                if (treasures[id].skillLevelUpRedpoint != null)
+                {
+                    treasures[id].skillLevelUpRedpoint.state = RedPointState.None;
+                }
+            }
             var functionOpen = FuncOpen.Instance.IsFuncOpen(82);
             if (functionOpen)
             {
-                foreach (var id in treasures.Keys)
+                for (int k = 0; k < 3; k++)
                 {
-                    UpdateSkillLevelUpRedpoint(id);
+                    for (int i = 0; i < list.Count; i++)
+                    {
+                        var treasure = treasures[list[i]];
+                        if (k < treasure.potentials.Count)
+                        {
+                            var potential = treasure.potentials[k];
+                            Item item;
+                            if (SatisfyLevelUpUnlock(list[i], k)
+                                && SatisyPotentialLevelUp(list[i], potential.id, out item))
+                            {
+                                treasure.skillLevelUpRedpoint.state = RedPointState.Simple;
+                                treasure.autoSelectPotential = k;
+                                return;
+                            }
+                        }
+                    }
+                }
+                int minCostTreasure = 0;
+                int minCostPotentialIndex = 0;
+                int minCostItemColor = 0;
+                int minCostItemCount = 0;
+                bool step = false;
+                for (int i = 0; i < list.Count; i++)
+                {
+                    var treasure = treasures[list[i]];
+                    if (treasure.state != TreasureState.Collected || !treasure.IsHighestStage)
+                    {
+                        continue;
+                    }
+                    for (int k = 0; k < treasure.potentials.Count; k++)
+                    {
+                        Item item;
+                        if (SatisyPotentialLevelUp(treasure.id, treasure.potentials[k].id, out item))
+                        {
+                            if (item.id != 0)
+                            {
+                                var itemConfig = Config.Instance.Get<ItemConfig>(item.id);
+                                var itemColor = itemConfig.ItemColor;
+                                if (minCostItemColor == 0 || itemColor < minCostItemColor ||
+                                    (itemColor == minCostItemColor && minCostItemCount < item.count))
+                                {
+                                    minCostItemColor = itemColor;
+                                    minCostItemCount = item.count;
+                                    minCostTreasure = treasure.id;
+                                    minCostPotentialIndex = k;
+                                }
+                            }
+                            else
+                            {
+                                minCostTreasure = treasure.id;
+                                minCostPotentialIndex = k;
+                                step = true;
+                                break;
+                            }
+                        }
+                    }
+                    if (step)
+                    {
+                        break;
+                    }
+                }
+                if (minCostTreasure != 0)
+                {
+                    treasures[minCostTreasure].skillLevelUpRedpoint.state = RedPointState.Simple;
+                    treasures[minCostTreasure].autoSelectPotential = minCostPotentialIndex;
                 }
             }
+        }
+
+        public int GetSkillLevelUpRedpointTreasure()
+        {
+            var list = GetTreasureCategory(TreasureCategory.Human);
+            for (int i = 0; i < list.Count; i++)
+            {
+                var treasure = treasures[list[i]];
+                if (treasure.skillLevelUpRedpoint != null &&
+                    treasure.skillLevelUpRedpoint.state == RedPointState.Simple)
+                {
+                    return list[i];
+                }
+            }
+            return 0;
         }
 
         private void UpdateAchievementRedpoints()
@@ -927,34 +1012,47 @@
             WindowCenter.Instance.Open<TreasureNewGotWin>();
         }
 
-        private void UpdateSkillLevelUpRedpoint(int _treasureId)
+        public bool SatisfyLevelUpUnlock(int treasureId, int index)
         {
-            if (treasures.ContainsKey(_treasureId))
+            if (treasures.ContainsKey(treasureId))
             {
-                var treasure = treasures[_treasureId];
-                if (treasure.skillLevelUpRedpoint == null)
-                {
-                    return;
-                }
-                var anyPointialLevelupAble = false;
+                var treasure = treasures[treasureId];
                 if (treasure.state == TreasureState.Collected && treasure.IsHighestStage)
                 {
-                    for (int i = 0; i < treasure.potentials.Count; i++)
+                    if (index >= 0 && index < treasure.potentials.Count - 1)
                     {
-                        var potential = treasure.potentials[i];
-                        if (SatisyPotentialLevelUp(treasure.id, potential.id))
+                        var potential = treasure.potentials[index];
+                        var nextPotential = treasure.potentials[index + 1];
+                        var skillConfig = Config.Instance.Get<SkillConfig>(nextPotential.id);
+                        if (skillConfig.LearnSkillReq > 0)
                         {
-                            anyPointialLevelupAble = true;
-                            break;
+                            if (potential.level < skillConfig.LearnSkillLV)
+                            {
+                                return true;
+                            }
+                        }
+                    }
+                    else if (index == treasure.potentials.Count - 1)
+                    {
+                        var potential = treasure.GetPotential(index);
+                        var config = Config.Instance.Get<SkillConfig>(potential.id);
+                        int[] _getSkillArray;
+                        if (TryGetPotentialGetSkill(config.SkillTypeID, out _getSkillArray))
+                        {
+                            if (potential.level < _getSkillArray[0])
+                            {
+                                return true;
+                            }
                         }
                     }
                 }
-                treasure.skillLevelUpRedpoint.state = anyPointialLevelupAble ? RedPointState.Simple : RedPointState.None;
             }
+            return false;
         }
 
-        public bool SatisyPotentialLevelUp(int treasureId, int potentialId)
+        public bool SatisyPotentialLevelUp(int treasureId, int potentialId, out Item item)
         {
+            item = default(Item);
             var treasure = treasures[treasureId];
             var potential = treasure.GetPotential(potentialId);
             if (potential == null)
@@ -1010,6 +1108,11 @@
                         var own = packageModel.GetItemCountByID(PackType.rptItem, itemId);
                         if (own >= treasureSkillConfig.MeterialNum2[j])
                         {
+                            item = new Item()
+                            {
+                                id = itemId,
+                                count = treasureSkillConfig.MeterialNum2[j],
+                            };
                             return true;
                         }
                     }
diff --git a/System/Treasure/TreasurePotentialPanel.cs b/System/Treasure/TreasurePotentialPanel.cs
index 5e05670..5948e7a 100644
--- a/System/Treasure/TreasurePotentialPanel.cs
+++ b/System/Treasure/TreasurePotentialPanel.cs
@@ -34,6 +34,7 @@
         [SerializeField] Button m_RemoveBook;
         [SerializeField] ImageEx m_UpgradeImage;
         [SerializeField] Button m_Upgrade;
+        [SerializeField] Image m_LevelUpRed;
 
         [SerializeField] UIEffect m_FailureEffect;
 
@@ -94,6 +95,9 @@
                         DisplayUpgradeCost();
                         DisplayGetSkill();
                         DisplaySuccessRatio();
+
+                        m_LevelUpRed.gameObject.SetActive(m_Treasure.id == model.GetSkillLevelUpRedpointTreasure()
+                             && m_Treasure.GetPotentialByIndex(m_Treasure.autoSelectPotential).id == selectedPotential);
                     }
                     else
                     {
@@ -142,14 +146,26 @@
                 }
             }
 
-            for (int i = 0; i < m_Treasure.potentials.Count; i++)
+            if (m_Treasure.skillLevelUpRedpoint.state == RedPointState.Simple)
             {
-                if (model.SatisyPotentialLevelUp(_treasure.id, m_Treasure.potentials[i].id))
+                if (m_Treasure.autoSelectPotential < m_Treasure.potentials.Count)
                 {
-                    _index = i;
-                    break;
+                    _index = m_Treasure.autoSelectPotential;
                 }
             }
+            else
+            {
+                for (int i = 0; i < m_Treasure.potentials.Count; i++)
+                {
+                    Item item;
+                    if (model.SatisyPotentialLevelUp(_treasure.id, m_Treasure.potentials[i].id, out item))
+                    {
+                        _index = i;
+                        break;
+                    }
+                }
+            }
+
 
             selectedPotential = m_Treasure.potentials[_index].id;
 
@@ -272,6 +288,8 @@
             if (m_Treasure != null && _id == m_Treasure.skillLevelUpRedpoint.id)
             {
                 DisplayAddBookRedpoint();
+                m_LevelUpRed.gameObject.SetActive(m_Treasure.id == model.GetSkillLevelUpRedpointTreasure()
+                    && m_Treasure.GetPotentialByIndex(m_Treasure.autoSelectPotential).id == selectedPotential);
             }
         }
 
@@ -615,7 +633,8 @@
                 m_AddBookRedpoint.gameObject.SetActive(false);
                 return;
             }
-            bool levelUpHighSuccess = model.SatisyPotentialLevelUp(model.selectedTreasure, model.selectedPotential);
+            Item item;
+            bool levelUpHighSuccess = model.SatisyPotentialLevelUp(model.selectedTreasure, model.selectedPotential, out item);
             m_AddBookRedpoint.gameObject.SetActive(levelUpHighSuccess);
         }
 

--
Gitblit v1.8.0