少年修仙传客户端代码仓库
Client_PangDeRong
2018-10-31 3f83a4148e6ee91d72c7d70a45bf80c14cd688fb
System/Compose/New/ComposeWinModel.cs
@@ -10,8 +10,7 @@
{
    private Dictionary<int, Dictionary<int, List<ItemCompoundConfig>>> firstTypeDict = null;
    private Dictionary<int, List<ItemCompoundConfig>> secondTypeDict = null;
    private Dictionary<int, List<int>> composeJobLimitDict = new Dictionary<int, List<int>>();
    private FuncConfigConfig addonsFormulaModel;
    public event Action ResetModelEvent;
    SelectEquipModel _selectModel;
    SelectEquipModel selectModel
@@ -36,23 +35,8 @@
    public override void Init()
    {
        addonsFormulaModel = Config.Instance.Get<FuncConfigConfig>("ComposeAddonsFormula");
        composeJobLimitDict.Clear();
        FuncConfigConfig funcConfig = Config.Instance.Get<FuncConfigConfig>("ComposeJobLimit");
        JsonData limitData = JsonMapper.ToObject(funcConfig.Numerical1);
        foreach(var job in limitData.Keys)
        {
            List<int> idlist = new List<int>();
            composeJobLimitDict.Add(int.Parse(job),idlist);
            if(limitData[job].IsArray)
            {
                for(int i= 0; i < limitData[job].Count; i++)
                {
                    int id = int.Parse(limitData[job][i].ToString());
                    idlist.Add(id);
                }
            }
        }
        ParseFuncConfig();
        ParseItemComoundConfig();
    }
    public override void UnInit()
@@ -76,6 +60,7 @@
        playerPack.RefreshItemCountAct += OnItemCntRefresh;
        PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= PlayerLvUpdate;
        PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerLvUpdate;
        UpdateComposeDataByLevel();
    }
    public void ResetModel()
@@ -86,14 +71,234 @@
        }
    }
    private void PlayerLvUpdate(PlayerDataRefresh type)
    {
        if (type != PlayerDataRefresh.LV) return;
        UpdateComposeDataByLevel();
        SetComposeTypeRed();
        RefreshComposeRed();
    }
    #region 解析本地数据
    private FuncConfigConfig addonsFormulaModel;
    private Dictionary<int, List<int>> composeJobLimitDict = new Dictionary<int, List<int>>();
    public void ParseFuncConfig()
    {
        addonsFormulaModel = Config.Instance.Get<FuncConfigConfig>("ComposeAddonsFormula");
        composeJobLimitDict.Clear();
        FuncConfigConfig funcConfig = Config.Instance.Get<FuncConfigConfig>("ComposeJobLimit");
        JsonData limitData = JsonMapper.ToObject(funcConfig.Numerical1);
        foreach (var job in limitData.Keys)
        {
            List<int> idlist = new List<int>();
            composeJobLimitDict.Add(int.Parse(job), idlist);
            if (limitData[job].IsArray)
            {
                for (int i = 0; i < limitData[job].Count; i++)
                {
                    int id = int.Parse(limitData[job][i].ToString());
                    idlist.Add(id);
                }
            }
        }
    }
    public Dictionary<int, ComposeFirstTypeData> composeDataDict = new Dictionary<int, ComposeFirstTypeData>();
    public void ParseItemComoundConfig()
    {
        composeDataDict.Clear();
        List<ItemCompoundConfig> itemCompounds = Config.Instance.GetAllValues<ItemCompoundConfig>();
        for(int i = 0; i < itemCompounds.Count; i++)
        {
            AddComposeData(itemCompounds[i],composeDataDict);
        }
    }
    public void AddComposeData(ItemCompoundConfig itemCompound, Dictionary<int, ComposeFirstTypeData> keyValues)
    {
        if (itemCompound == null) return;
        if (!keyValues.ContainsKey(itemCompound.firstType))
        {
            var firstData = new ComposeFirstTypeData();
            firstData.firstType = itemCompound.firstType;
            firstData.secondTypeDict = new Dictionary<int, ComposeSecondTypeData>();
            ComposeSecondTypeData secondData = new ComposeSecondTypeData();
            secondData.secondType = itemCompound.secondType;
            secondData.thirdTypeDict = new Dictionary<int, List<ComposeThirdTypeData>>();
            List<ComposeThirdTypeData> thirdTypeDatas = new List<ComposeThirdTypeData>();
            ComposeThirdTypeData thirdData = new ComposeThirdTypeData();
            thirdData.thirdType = itemCompound.thirdType;
            thirdData.itemCompound = itemCompound;
            thirdTypeDatas.Add(thirdData);
            firstData.secondTypeDict.Add(secondData.secondType, secondData);
            secondData.thirdTypeDict.Add(thirdData.thirdType, thirdTypeDatas);
            keyValues.Add(firstData.firstType, firstData);
        }
        else
        {
            ComposeSecondTypeData secondData = new ComposeSecondTypeData();
            secondData.secondType = itemCompound.secondType;
            var secondTypeDict = keyValues[itemCompound.firstType].secondTypeDict;
            if (!secondTypeDict.ContainsKey(secondData.secondType))
            {
                secondTypeDict.Add(secondData.secondType, secondData);
                secondData.thirdTypeDict = new Dictionary<int, List<ComposeThirdTypeData>>();
                List<ComposeThirdTypeData> thirdTypeDatas = new List<ComposeThirdTypeData>();
                ComposeThirdTypeData thirdData = new ComposeThirdTypeData();
                thirdData.thirdType = itemCompound.thirdType;
                thirdData.itemCompound = itemCompound;
                thirdTypeDatas.Add(thirdData);
                secondData.thirdTypeDict.Add(thirdData.thirdType, thirdTypeDatas);
            }
            else
            {
                ComposeThirdTypeData thirdData = new ComposeThirdTypeData();
                thirdData.thirdType = itemCompound.thirdType;
                thirdData.itemCompound = itemCompound;
                var thirdTypeDict = secondTypeDict[secondData.secondType].thirdTypeDict;
                if (!thirdTypeDict.ContainsKey(thirdData.thirdType))
                {
                    List<ComposeThirdTypeData> thirdTypeDatas = new List<ComposeThirdTypeData>();
                    thirdTypeDatas.Add(thirdData);
                    thirdTypeDict.Add(thirdData.thirdType, thirdTypeDatas);
                }
                else
                {
                    thirdTypeDict[thirdData.thirdType].Add(thirdData);
                }
            }
        }
    }
    public class ComposeFirstTypeData
    {
        public int firstType;
        public Dictionary<int,ComposeSecondTypeData> secondTypeDict = null;
    }
    public class ComposeSecondTypeData
    {
        public int secondType;
        public Dictionary<int,List<ComposeThirdTypeData>> thirdTypeDict= null;
    }
    public class ComposeThirdTypeData
    {
        public int thirdType;
        public ItemCompoundConfig itemCompound = null;
    }
    #endregion
    #region 数据变动
    public Dictionary<int, ComposeFirstTypeData> composeOpenDataDict = new Dictionary<int, ComposeFirstTypeData>();
    public void UpdateComposeDataByLevel()
    {
        composeOpenDataDict.Clear();
        int playerLv = PlayerDatas.Instance.baseData.LV;
        foreach (var first in composeDataDict.Keys)
        {
            var secondTypeDict = composeDataDict[first].secondTypeDict;
            foreach (var second in secondTypeDict.Keys)
            {
                var thirdTypeDict = secondTypeDict[second].thirdTypeDict;
                foreach (var third in thirdTypeDict.Keys)
                {
                    for(int i = 0; i < thirdTypeDict[third].Count; i++)
                    {
                        var thirdData = thirdTypeDict[third][i];
                        if(playerLv >= thirdData.itemCompound.levelNeed
                            ||(thirdData.itemCompound.trailerLevel != 0 && playerLv >= thirdData.itemCompound.trailerLevel))
                        {
                            AddComposeData(thirdData.itemCompound, composeOpenDataDict);
                        }
                    }
                }
            }
        }
    }
    public bool TryGetFirstTypeData(int firstType,out ComposeFirstTypeData firstTypeData)
    {
        firstTypeData = null;
        return composeDataDict.TryGetValue(firstType,out firstTypeData);
    }
    public bool TryGetSecondTypeData(int firstType,int secondType,out ComposeSecondTypeData secondTypeData)
    {
        ComposeFirstTypeData firstTypeData = null;
        secondTypeData = null;
        bool isFirst = TryGetFirstTypeData(firstType,out firstTypeData);
        if(isFirst)
        {
           return firstTypeData.secondTypeDict.TryGetValue(secondType,out secondTypeData);
        }
        return false;
    }
    public bool TryGetThirdTypeData(int firstType, int secondType, int thirdType, out List<ComposeThirdTypeData> thirdTypeDatas)
    {
        ComposeSecondTypeData secondTypeData = null;
        thirdTypeDatas = null;
        bool isSecond = TryGetSecondTypeData(firstType, secondType, out secondTypeData);
        if (isSecond)
        {
            return secondTypeData.thirdTypeDict.TryGetValue(thirdType, out thirdTypeDatas);
        }
        return false;
    }
    public bool TryGetThirdTypeData(int firstType, int secondType,int thirdType,out ComposeThirdTypeData thirdTypeData)
    {
        ComposeSecondTypeData secondTypeData = null;
        thirdTypeData = null;
        bool isSecond = TryGetSecondTypeData(firstType,secondType ,out secondTypeData);
        if (isSecond)
        {
            List<ComposeThirdTypeData> thirdTypeDatas = null;
            bool isThird = secondTypeData.thirdTypeDict.TryGetValue(thirdType, out thirdTypeDatas);
            if(isThird)
            {
                thirdTypeData = thirdTypeDatas[0];
                return true;
            }
        }
        return false;
    }
    public ItemCompoundConfig CurComposeModel { get; private set; }
    public void SetCurComposeModel(ItemCompoundConfig compoundModel)
    {
        CurComposeModel = compoundModel;
    }
    public event Action<int> UpdateThirdTypeEvent;
    public void UpdateThirdType(int thirdType)
    {
        if (UpdateThirdTypeEvent != null)
        {
            UpdateThirdTypeEvent(thirdType);
        }
    }
    public event Action<int> UpdateSecondTypeEvent;
    public void UpdateSecondType(int secondType)
    {
        if (UpdateSecondTypeEvent != null)
        {
            UpdateSecondTypeEvent(secondType);
        }
    }
    public bool TryGetIncreaseRateItemIndex(ItemCompoundConfig itemCompound,bool IsIncrease, out List<int> indexlist)
    {
        indexlist = null;
        if (!IsIncrease || itemCompound == null) return false;
        SinglePackModel singlePack = playerPack.GetSinglePackModel(PackType.rptItem);
        int[] increases = itemCompound.successRateIncrease;
        indexlist = singlePack.ItemIndexlist(increases[0], increases[1]);
        return true;
    }
    #endregion
    public bool IsComposeJobLimit(int composeId)
    {
@@ -137,6 +342,18 @@
        return modellist;
    }
    public bool IsTrailerByLevel(ItemCompoundConfig itemCompound)
    {
        if (itemCompound.trailerLevel <= 0) return false;
        int playerLv = PlayerDatas.Instance.baseData.LV;
        if(playerLv >= itemCompound.trailerLevel && playerLv < itemCompound.levelNeed)
        {
            return true;
        }
        return false;
    }
    public int GetTicketId(int firstType, int secondType, int thirdType)
    {
        var itemId = 0;
@@ -149,16 +366,10 @@
            _secondTypeDict.TryGetValue(thirdType, out modellist);
            if (modellist != null && modellist.Count > 0)
            {
                int.TryParse(modellist[0].makeID, out itemId);
                itemId = modellist[0].makeID[0];
            }
        }
        return itemId;
    }
    public ItemCompoundConfig CurComposeModel { get; private set; }
    public void SetCurComposeModel(ItemCompoundConfig compoundModel)
    {
        CurComposeModel = compoundModel;
    }
    public bool IsEnoughUnfixedMat(ItemCompoundConfig compoundModel)
@@ -205,7 +416,7 @@
    Dictionary<int, Dictionary<int, int>> fixedMatIsBindDict = new Dictionary<int, Dictionary<int, int>>();  //id , isBind, count
    Dictionary<int, Dictionary<int, int>> unfixedMatIsBindDict = new Dictionary<int, Dictionary<int, int>>();
    public void SendComposeRequest(ItemCompoundConfig compoundModel, Dictionary<int, List<int>> fixedItemIndexDict,UIEffect composEffect,int composeCount = 1,int successRate = 10000)
    public void SendComposeRequest(ItemCompoundConfig compoundModel, Dictionary<int, List<int>> fixedItemIndexDict,UIEffect composEffect,int composeCount = 1,int successRate = 10000,bool isIncrease = false)
    {
        fixedMatIsBindDict.Clear();
        unfixedMatIsBindDict.Clear();
@@ -320,19 +531,19 @@
                                                        {
                                                            if (sure)
                                                            {
                                                                SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount);
                                                                SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount,isIncrease);
                                                            }
                                                        });
                                                        return;
                                                    }
                                                    else
                                                    {
                                                        SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount);
                                                        SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease);
                                                    }
                                                }
                                                else
                                                {
                                                    SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount);
                                                    SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease);
                                                }
                                            }
                                               
@@ -349,19 +560,19 @@
                                            {
                                                if (sure)
                                                {
                                                    SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount);
                                                    SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease);
                                                }
                                            });
                                            return;
                                        }
                                        else
                                        {
                                            SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount);
                                            SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease);
                                        }
                                    }
                                    else
                                    {
                                        SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount);
                                        SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease);
                                    }
                                }
                            }
@@ -377,13 +588,13 @@
                    {
                        if (isCompose)
                        {
                            SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount);
                            SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease);
                        }
                    });
            }
            else
            {
                SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount);
                SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease);
            }
        }
        else
@@ -449,7 +660,7 @@
                   {
                       if (isCompose)
                       {
                           SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount);
                           SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease);
                       }
                   });
            }
@@ -480,14 +691,14 @@
                   {
                       if (isCompose)
                       {
                           SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount);
                           SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease);
                       }
                   });
            }
        }
    }
    public void SendComposeQuest(ItemCompoundConfig compoundModel,UIEffect composEffect,byte[] unfixedIndexArray, int composeCount)
    public void SendComposeQuest(ItemCompoundConfig compoundModel,UIEffect composEffect,byte[] unfixedIndexArray, int composeCount,bool isIncrease)
    {
        composEffect.Play();
        CA303_tagCMItemCompound itemCompose = null;
@@ -501,6 +712,20 @@
        itemCompose.AddonsItemIndexCnt = (byte)selectModel.GetHaveAddSelectItem().Count;
        itemCompose.AddonsItemIndex = DictToArray(selectModel.GetHaveAddSelectItem());
        itemCompose.AddonsItemCount = addonsReduceArray;
        List<int> increaseIndexlist = null;
        TryGetIncreaseRateItemIndex(compoundModel,isIncrease,out increaseIndexlist);
        byte[] increaseRateIndexArray = null;
        if (increaseIndexlist != null)
        {
            increaseRateIndexArray = ListToArray(increaseIndexlist);
            itemCompose.RateIncreaseItemIndexCnt = (byte)increaseRateIndexArray.Length;
            itemCompose.RateIncreaseItemIndex = increaseRateIndexArray;
        }
        else
        {
            itemCompose.RateIncreaseItemIndexCnt = 0;
            itemCompose.RateIncreaseItemIndex = new byte[0];
        }
        GameNetSystem.Instance.SendInfo(itemCompose);
    }
@@ -652,6 +877,18 @@
        return itemArray;
    }
    private byte[] ListToArray(List<int> list)
    {
        byte[] itemArray = new byte[list.Count];
        int i = 0;
        for (i = 0; i < list.Count; i++)
        {
            itemArray[i] = (byte)list[i];
        }
        return itemArray;
    }
    private byte[] DictToArray(Dictionary<int, List<int>> itemDict)
    {
        int itemArrayLength = 0;
@@ -773,8 +1010,8 @@
            if (getFirstModel[secondType].ContainsKey(0))
            {
                ItemCompoundConfig compoundConfig = getFirstModel[secondType][0][0];
                int[] fixedIDs = ConfigParse.GetMultipleStr<int>(compoundConfig.itemID);
                int[] fixedCnt = ConfigParse.GetMultipleStr<int>(compoundConfig.itemCount);
                int[] fixedIDs = compoundConfig.itemID;
                int[] fixedCnt = compoundConfig.itemCount;
                for (int i = 0; i < fixedIDs.Length; i++)
                {
                    int haveCnt = playerPack.GetItemCountByID(PackType.rptItem, fixedIDs[i]);
@@ -945,7 +1182,7 @@
                List<ItemCompoundConfig> compoundlist = firstDict[3][thirdType];
                for(int i = 0; i < compoundlist.Count; i++)
                {
                    int makeID = ConfigParse.GetMultipleStr<int>(compoundlist[i].makeID)[i];
                    int makeID = compoundlist[i].makeID[i];
                    string key = StringUtility.Contact(3, 10, thirdType);
                    if (IsComposeJobLimit(makeID) && IsEnoughFixedMat(compoundlist[i]))
                    {
@@ -987,6 +1224,7 @@
    fixedItem,
    unfixedItem,
    addItem,
    IncreaseItem,
}
public enum DisplayItemArray