少年修仙传客户端代码仓库
client_Wu Xijin
2019-03-05 60f616fc149c620953f468d1383f15a810f898df
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
 
namespace Snxxz.UI
{
    public class EquipStarModel : Model
    {
        public readonly LogicString selectedEquip = new LogicString();
        public readonly LogicInt equipStarLevel = new LogicInt();
        public readonly LogicInt operateMaterialIndex = new LogicInt();
        public readonly Dictionary<int, LogicString> materials = new Dictionary<int, LogicString>();
        public readonly LogicInt starUpgradeProbability = new LogicInt();
 
        Dictionary<int, EquipSetStar> equipStars = new Dictionary<int, EquipSetStar>();
        Dictionary<string, CandidateEquip> candidateEquips = new Dictionary<string, CandidateEquip>();
        Dictionary<int, int> maxStarLevels = new Dictionary<int, int>();
 
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
 
        public override void Init()
        {
            ParseConfig();
        }
 
        public override void UnInit()
        {
 
        }
 
        public void DoStarUpgrade(int level, int place, int starLevel)
        {
            if (!equipStars.ContainsKey(level))
            {
                return;
            }
 
            var maxLevel = GetMaxStarLevel(level);
            if (starLevel > maxLevel)
            {
                //已经是最大星级,无法升星
                return;
            }
 
            var config = EquipStarConfig.Get(level, place, starLevel);
            var specialMaterial = packModel.GetItemByGuid(materials[6].value);
            if (config.CostItemDict.x > 0 && (specialMaterial == null || specialMaterial.config.ID != config.CostItemDict.x))
            {
                //请放入正确的特殊材料
                return;
            }
 
            var materialIndexs = new List<ushort>();
            var materialItemIds = new List<uint>();
            foreach (var material in materials.Values)
            {
                if (!string.IsNullOrEmpty(material.value))
                {
                    var item = packModel.GetItemByGuid(material.value);
                    materialIndexs.Add((ushort)item.itemPlace);
                    materialItemIds.Add((uint)item.itemId);
                }
            }
 
            if (materialIndexs.Count < (config.CostEquipCnt + config.CostItemDict.x > 0 ? 1 : 0))
            {
                //材料不足
                return;
            }
 
            var info = new CA5C5_tagCMEquipPartStarUp();
            info.EquipPackIndex = (ushort)EquipSet.ClientPlaceToServerPlace(level, place);
            info.CostEquipIndex = materialIndexs.ToArray();
            info.CostEquipID = materialItemIds.ToArray();
            info.CostEquipCnt = (byte)materialIndexs.Count;
 
            GameNetSystem.Instance.SendInfo(info);
        }
 
        public void FiltrateCandidateEquips(int level)
        {
            candidateEquips.Clear();
            var equips = GetStarUpgradableEquips(level);
            for (var i = 0; i < equips.Count; i++)
            {
                var guid = equips[i];
                candidateEquips[guid] = new CandidateEquip(guid);
 
                if (i == 0)
                {
                    SelectTargetEquip(guid);
                }
            }
        }
 
        public void UpdateStarLevels(HA3B1_tagMCEquipPartStarInfo info)
        {
            for (var i = 0; i < info.InfoList.Length; i++)
            {
                var clientInfo = EquipSet.ServerPlaceToClientPlace(info.InfoList[i].EquipPackIndex);
                var level = clientInfo.x;
                if (equipStars.ContainsKey(level))
                {
                    equipStars[level].UpdateEquipStarLevel(clientInfo.y, info.InfoList[i].Star);
                }
            }
        }
 
        public int GetSuitLevel(int level, EquipSuitType type)
        {
            if (!equipStars.ContainsKey(level))
            {
                return 0;
            }
 
            return equipStars[level].GetSuitLevel(type);
        }
 
        private List<string> GetStarUpgradableEquips(int level)
        {
            var equipSet = equipModel.GetEquipSet(level);
            if (equipSet == null)
            {
                return null;
            }
 
            var equips = new List<string>();
            for (var i = 1; i <= 12; i++)
            {
                var equipGuid = equipSet.GetEquip(i);
                if (!string.IsNullOrEmpty(equipGuid))
                {
                    equips.Add(equipGuid);
                }
            }
 
            return equips;
        }
 
        public List<string> GetCandidateEquips()
        {
            return new List<string>(candidateEquips.Keys);
        }
 
        public CandidateEquip GetCandidateEquip(string equipGuid)
        {
            if (candidateEquips.ContainsKey(equipGuid))
            {
                return candidateEquips[equipGuid];
            }
            else
            {
                return null;
            }
        }
 
        public void SelectTargetEquip(string equipGuid)
        {
            selectedEquip.value = equipGuid;
            foreach (var candidate in candidateEquips.Values)
            {
                candidate.selected.value = candidate.guid == equipGuid;
            }
 
            var item = packModel.GetItemByGuid(equipGuid);
            if (item != null)
            {
                equipStarLevel.value = GetEquipStarLevel(item.config.LV, item.config.EquipPlace);
            }
        }
 
        public int GetMaxStarLevel(int level)
        {
            if (maxStarLevels.ContainsKey(level))
            {
                return maxStarLevels[level];
            }
            else
            {
                return 0;
            }
        }
 
        public int GetTotalStarLevel(int level)
        {
            if (!equipStars.ContainsKey(level))
            {
                return 0;
            }
 
            return equipStars[level].GetTotalStarLevel();
        }
 
        public int GetEquipStarLevel(int level, int place)
        {
            if (!equipStars.ContainsKey(level))
            {
                return 0;
            }
 
            return equipStars[level].GetEquipStarLevel(place);
        }
 
        public int GetEquipCountWhichStarLevelLq(int level, int standard)
        {
            if (!equipStars.ContainsKey(level))
            {
                return 0;
            }
 
            return equipStars[level].GetEquipCountWhichStarLevelLq(standard);
        }
 
        public List<ItemModel> GetMaterials(int level, int place, int starLevel)
        {
            var config = EquipStarConfig.Get(level, place, starLevel);
            if (config == null)
            {
                return null;
            }
 
            var equipGuid = equipModel.GetEquip(level,place);
            var equip = packModel.GetItemByGuid(equipGuid);
            if (equip == null)
            {
                return null;
            }
 
            var expcetMaterials = packModel.GetItems( PackType.Item, new SinglePack.FilterParams()
            {
                level = 0,
                quality = 0,
                equipType = 0,
                itemType = 0
            });
 
            for (var i = expcetMaterials.Count - 1; i >= 0; i--)
            {
                var item = expcetMaterials[i];
                if (item.config.RealmLimit != equip.config.RealmLimit)
                {
                    expcetMaterials.RemoveAt(i);
                }
                else if (!config.CostEquipPlace.Contains(item.config.EquipPlace))
                {
                    expcetMaterials.RemoveAt(i);
                }
                else if (!config.CostEquipColor.Contains(item.config.ItemColor))
                {
                    expcetMaterials.RemoveAt(i);
                }
            }
 
            for (var i = 1; i <= 6; i++)
            {
                var placedMaterialGuid = GetMaterialLogicStringByIndex(i).value;
                var materialItem = packModel.GetItemByGuid(placedMaterialGuid);
                if (materialItem != null)
                {
                    expcetMaterials.Remove(materialItem);
                }
            }
 
            return expcetMaterials;
        }
 
        public void AddMaterial(int index, string itemGuid)
        {
            GetMaterialLogicStringByIndex(index).value = itemGuid;
        }
 
        public void RemoveMaterial(int index)
        {
            GetMaterialLogicStringByIndex(index).value = string.Empty;
        }
 
        private void CalculateStarUpgradeProbability()
        {
            var probability = 0f;
            var selectedItem = packModel.GetItemByGuid(selectedEquip.value);
            var config = EquipStarConfig.Get(selectedItem.config.LV, selectedItem.config.EquipPlace, equipStarLevel.value + 1);
            var singleItemRate = (float)config.SuitTotalRate / config.CostEquipCnt;
            for (var i = 1; i <= 5; i++)
            {
                var itemGuid = GetMaterialLogicStringByIndex(i).value;
                var item = packModel.GetItemByGuid(itemGuid);
                probability += item.config.SuiteiD > 0 ? singleItemRate : singleItemRate * 0.5f;
            }
 
            starUpgradeProbability.value = Mathf.RoundToInt(probability * 100);
        }
 
        public LogicString GetMaterialLogicStringByIndex(int index)
        {
            return materials.ContainsKey(index - 1) ? materials[index - 1] : null;
        }
 
        private void ParseConfig()
        {
            var configs = EquipStarConfig.GetValues();
            foreach (var config in configs)
            {
                var currentStar = materials.ContainsKey(config.Level) ? maxStarLevels[config.Level] : 0;
                if (currentStar > config.Star)
                {
                    maxStarLevels[config.Level] = config.Star;
                }
            }
 
        }
 
    }
}