少年修仙传客户端代码仓库
client_linchunjie
2019-04-18 f624ba05077458b476f76cb8d666029a2fb56807
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Snxxz.UI
{
    public class AlchemyModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
    {
        Dictionary<int, uint> m_AlchemyTimes = new Dictionary<int, uint>();
        Dictionary<int, AlchemyCount> m_AlchemyCounts = new Dictionary<int, AlchemyCount>();
        Dictionary<int, int> m_AlchemyQualityLucks = new Dictionary<int, int>();
        Dictionary<int, List<Item>> m_AlchemyMaterials = new Dictionary<int, List<Item>>();
 
        int m_SelectQuality = 0;
        public int selectQuality
        {
            get { return m_SelectQuality; }
            set
            {
                if (m_SelectQuality != value)
                {
                    m_SelectQuality = value;
                    if (selectQualityRefresh != null)
                    {
                        selectQualityRefresh();
                    }
                }
            }
        }
 
        int m_SelectAlchemy = 0;
        public int selectAlchemy
        {
            get { return m_SelectAlchemy; }
            set
            {
                if (m_SelectAlchemy != value)
                {
                    m_SelectAlchemy = value;
                    if (selectAlchemyRefresh != null)
                    {
                        selectAlchemyRefresh();
                    }
                }
            }
        }
 
        public int stoveLevel { get; private set; }
        public int stoveExp { get; private set; }
        public string alchemySuccRate { get; private set; }
 
        public event Action selectQualityRefresh;
        public event Action selectAlchemyRefresh;
        public event Action alchemyStateRefresh;
 
        public override void Init()
        {
            ParseConfig();
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            m_AlchemyTimes.Clear();
            stoveLevel = 0;
            stoveExp = 0;
        }
 
        public void OnPlayerLoginOk()
        {
        }
 
        void ParseConfig()
        {
            {
                var configs = AlchemyCountConfig.GetValues();
                foreach (var config in configs)
                {
                    var intArray = LitJson.JsonMapper.ToObject<int[][]>(config.CntRateList);
                    var min = intArray[0][1];
                    var max = intArray[intArray.Length - 1][1];
                    if (m_AlchemyCounts.ContainsKey(config.AlchemyQuality))
                    {
                        var alchemyCount = m_AlchemyCounts[config.AlchemyQuality];
                        if (min < alchemyCount.min)
                        {
                            alchemyCount.min = min;
                            m_AlchemyCounts[config.AlchemyQuality] = alchemyCount;
                        }
                        if (max > alchemyCount.max)
                        {
                            alchemyCount.max = max;
                            m_AlchemyCounts[config.AlchemyQuality] = alchemyCount;
                        }
                    }
                    else
                    {
                        m_AlchemyCounts[config.AlchemyQuality] = new AlchemyCount()
                        {
                            min = min,
                            max = max,
                        };
                    }
                }
            }
 
            {
                var funcConfig = FuncConfigConfig.Get("alchemySuccess");
                alchemySuccRate = funcConfig.Numerical3;
 
                var json = LitJson.JsonMapper.ToObject(funcConfig.Numerical2);
                foreach (var key in json.Keys)
                {
                    var quality = int.Parse(key);
                    m_AlchemyQualityLucks.Add(quality, int.Parse(json[key].ToString()));
                }
            }
 
            {
                var configs = AlchemyConfig.GetValues();
                foreach (var config in configs)
                {
                    m_AlchemyMaterials.Add(config.ID, new List<Item>());
                    var dict = ConfigParse.GetDic<int, int>(config.Material);
                    foreach (var key in dict.Keys)
                    {
                        m_AlchemyMaterials[config.ID].Add(new Item()
                        {
                            id = key,
                            count = dict[key],
                        });
                    }
                }
            }
        }
 
        public bool TryGetAlchemyStartTime(int alchemyId, out uint tick)
        {
            return m_AlchemyTimes.TryGetValue(alchemyId, out tick);
        }
 
        public bool TryGetAlchemyCount(int alchemyId, out AlchemyCount alchemyCount)
        {
            var config = AlchemyConfig.Get(alchemyId);
            if (config == null)
            {
                alchemyCount = default(AlchemyCount);
                return false;
            }
            if (config.AlchemType == (int)AlchemyType.Fairy)
            {
                alchemyCount = AlchemyCount.one;
                return true;
            }
            return m_AlchemyCounts.TryGetValue(config.AlchemyQuality, out alchemyCount);
        }
 
        public bool TryGetAlchemyMaterials(int alchemyId, out List<Item> items)
        {
            return m_AlchemyMaterials.TryGetValue(alchemyId, out items);
        }
 
        public float GetAlchemySuccRate(int alchemyId)
        {
            var config = AlchemyConfig.Get(alchemyId);
            if (config == null)
            {
                return 0f;
            }
            if (config.AlchemType == (int)AlchemyType.Fairy)
            {
                return 10000f;
            }
            var itemConfig = ItemConfig.Get(config.AlchemItemID);
            var luckValue = PlayerDatas.Instance.extersion.luckValue;
            return GetAlchemySuccRate(stoveLevel, itemConfig.LV, luckValue);
        }
 
        public float GetAlchemySuccRate(int stoveLevel, int itemLevel, int luck)
        {
            Equation.Instance.Clear();
            Equation.Instance.AddKeyValue("alchemyLV", stoveLevel);
            Equation.Instance.AddKeyValue("alchemyQuality", itemLevel);
            Equation.Instance.AddKeyValue("curLuckValue", luck);
            var qualityNeedLuck = m_AlchemyQualityLucks.ContainsKey(itemLevel) ? m_AlchemyQualityLucks[itemLevel] : 0;
            Equation.Instance.AddKeyValue("qualityNeedLuck", qualityNeedLuck);
            return Equation.Instance.Eval<float>(alchemySuccRate);
        }
 
        public bool IsGraspRecipe(int alchemyId)
        {
            return m_AlchemyTimes.ContainsKey(alchemyId);
        }
 
        public void ReceivePackage(HA3BF_tagMCPlayerStoveMsg package)
        {
            for (int i = 0; i < package.StoveCnt; i++)
            {
                var data = package.InfoList[i];
                m_AlchemyTimes[(int)data.AlchemyID] = data.StartTime;
            }
 
            stoveLevel = package.StoveLV;
            stoveExp = (int)package.StoveExp;
 
            if (package.ItemID != 0)
            {
                if (package.ItemCnt > 0)//炼丹成功
                {
 
                }
                else//炼丹失败
                {
 
                }
            }
 
            if (alchemyStateRefresh != null)
            {
                alchemyStateRefresh();
            }
        }
 
        public override void UnInit()
        {
        }
    }
 
    public enum AlchemyType
    {
        Normal = 1,
        Fairy = 2,
    }
 
    public struct AlchemyCount
    {
        public int min;
        public int max;
 
        public static readonly AlchemyCount one = new AlchemyCount()
        {
            min = 1,
            max = 1,
        };
    }
}