少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-19 2fb0f9761ef9789ce068fbe26d2e4c7af1148ec0
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
using System;
using LitJson;
 
using System.Collections.Generic;
 
namespace Snxxz.UI
{
    [XLua.LuaCallCSharp]
    public class BoxGetItemModel : Model,IBeforePlayerDataInitialize
    {
        public string guid { get; private set; }
        public int itemId { get; private set;}
        public BoxShowType showType { get; private set; }
        PlayerPackModel _playerPack;
        PlayerPackModel playerPack
        {
            get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
        }
 
        public Dictionary<int, int> selectDict;
 
        public override void Init()
        {
 
        }
 
        void IBeforePlayerDataInitialize.OnBeforePlayerDataInitialize()
        {
            showType = BoxShowType.NoShow;
            selectDict = null;
            guid = "";
            getItems = null;
            getCoinsType = 0;
            getCoinsCnt = 0;
        }
 
        #region 处理服务器数据
 
        public BoxGetItemInfo[] getItems { get; private set;}
        public int getCoinsType { get; private set; }
        public long getCoinsCnt { get; private set; }
        public event Action<int,int,BoxGetItemInfo[]> RefreshGetItemAct;
        public void SetGetBoxItemInfo(HA810_tagMCNotifyUseItemGetItem boxItemInfo)
        {
            getItems = JsonMapper.ToObject<BoxGetItemInfo[]>(boxItemInfo.GetItemData);
            getCoinsType = boxItemInfo.MoneyType;
            getCoinsCnt = boxItemInfo.MoneyCount;
            if(!NewBieCenter.Instance.inGuiding)
            {
                switch (showType)
                {
                    case BoxShowType.NoramalShow:
                        if (!WindowCenter.Instance.IsOpen<BoxGetItemWin>())
                        {
                            WindowCenter.Instance.Open<BoxGetItemWin>();
                        }
                        break;
                    case BoxShowType.PrefectShow:
                        if (!WindowCenter.Instance.IsOpen<BoxGetItemWin>())
                        {
                            WindowCenter.Instance.Open<BoxGetItemWin>();
                        }
                        break;
                }
            }
         
            if (RefreshGetItemAct != null)
            {
                RefreshGetItemAct((int)boxItemInfo.UseItemID,(int)boxItemInfo.UseCount,getItems);
            }
 
 
        }
 
        public int GetUseCntByID(int itemId)
        {
            return playerPack.GetDayUseCntByID(itemId);
        }
 
        #endregion
 
        public void SetModel(string guid,int itemId)
        {
            ChestsConfig chestsConfig = ChestsConfig.Get(itemId);
            this.guid = guid;
            this.itemId = itemId;
            if (guid == "" || chestsConfig == null) return;
 
            ItemConfig boxConfig = ItemConfig.Get(itemId);
            if(PlayerDatas.Instance.baseData.LV < boxConfig.UseLV)
            {
                ServerTipDetails.DisplayNormalTip(Language.Get("MakeUseItem101",boxConfig.UseLV));
                return;
            }
 
            CheckBoxShowType(chestsConfig.OpenShow, guid);
        }
 
        public void CheckOpenBoxCondi(string guid, int itemId,int useCnt = 1)
        {
            ChestsConfig chestsConfig = ChestsConfig.Get(itemId);
            if (chestsConfig == null) return;
 
            ItemConfig boxConfig = ItemConfig.Get(itemId);
 
            if (chestsConfig.ExpendItemID != 0)
            {
                ItemConfig itemConfig = ItemConfig.Get(chestsConfig.ExpendItemID);
                ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("OpenBoxTool", itemConfig.ItemName), (bool isOk) =>
                {
                    if (isOk)
                    {
                        if (!IsEnoughTools(chestsConfig.ExpendItemID, chestsConfig.ExpendCount*useCnt))
                        {
                            SysNotifyMgr.Instance.ShowTip("OpenBoxToolNoEnough", itemConfig.ItemName);
                            return;
                        }
                        else
                        {
                            CheckOpenMoney(chestsConfig, boxConfig,useCnt);
                        }
                    }
                });
            }
            else
            {
                CheckOpenMoney(chestsConfig, boxConfig,useCnt);
            }
        }
 
        public void CheckOpenMoney(ChestsConfig chestsConfig, ItemConfig boxConfig,int useCnt)
        {
            if (!IsEnoughMoney(chestsConfig.OpenMoney*useCnt))
            {
                SysNotifyMgr.Instance.ShowTip("BoxOpenCostMoney", 1);
                return;
            }
            else
            {
                if (chestsConfig.OpenMoney > 0)
                {
                    ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("OpenBoxGold", chestsConfig.OpenMoney*useCnt), (bool isOk) =>
                    {
                        if (isOk)
                        {
                            CheckOtherCondi(chestsConfig,boxConfig,useCnt);
                        }
                    });
                }
                else
                {
                    CheckOtherCondi(chestsConfig, boxConfig,useCnt);
                }
            }
        }
 
        public void CheckOtherCondi(ChestsConfig chestsConfig,ItemConfig boxConfig,int useCnt)
        {
 
            if (boxConfig.MaxSkillCnt > 0 && GetUseCntByID(itemId) >= boxConfig.MaxSkillCnt)
            {
                SysNotifyMgr.Instance.ShowTip("UseCntLimit");
                return;
            }
 
            selectDict = null;
            bool isSelectItem = IsSelectItemByID(itemId, out selectDict);
            if (isSelectItem)
            {
                if (!WindowCenter.Instance.IsOpen<ChooseItemWin>())
                {
                    WindowCenter.Instance.Open<ChooseItemWin>();
                }
                return;
            }
 
            ItemModel itemModel = playerPack.GetItemModelByGUID(guid);
            if (itemModel != null)
            {
                ItemLogicUtility.Instance.SendMakeUseQuest(itemModel.itemPlace,useCnt);
            }
        }
 
        public bool CheckOpenBoxCondition(int itemId,out bool isBox)
        {
            isBox = false;
            ChestsConfig chestsConfig = ChestsConfig.Get(itemId);
            if (chestsConfig == null) return false;
 
            isBox = true;
            bool isCanOpen = true;
            ItemConfig boxConfig = ItemConfig.Get(itemId);
            if (PlayerDatas.Instance.baseData.LV < boxConfig.UseLV)
            {
                isCanOpen = false;
                return isCanOpen;
            }
 
            if (chestsConfig.ExpendItemID != 0)
            {
                ItemConfig itemConfig = ItemConfig.Get(chestsConfig.ExpendItemID);
                if (!IsEnoughTools(chestsConfig.ExpendItemID, chestsConfig.ExpendCount))
                {
                    isCanOpen = false;
                    return isCanOpen;
                }
            }
 
            if (!IsEnoughMoney(chestsConfig.OpenMoney))
            {
                isCanOpen = false;
                return isCanOpen;
            }
 
            if (boxConfig.MaxSkillCnt > 0 && GetUseCntByID(itemId) >= boxConfig.MaxSkillCnt)
            {
                isCanOpen = false;
                return isCanOpen;
            }
 
            return isCanOpen;
        }
 
        private bool IsEnoughMoney(int moneyCnt)
        {
            ulong haveMoney = UIHelper.GetMoneyCnt(1);
            DebugEx.Log("IsEnoughMoney" + haveMoney);
            if(haveMoney >= (ulong)moneyCnt)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
        private bool IsEnoughTools(int itemId,int toolCnt)
        {
            int count = playerPack.GetItemCountByID(PackType.Item,itemId);
            if(count >= toolCnt)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
        #region 得到宝箱选择的物品
        Dictionary<int, List<int>> jobReplaceDic = new Dictionary<int, List<int>>();
        Dictionary<int, int> selectlistDict = null;
        public bool IsSelectItemByID(int boxId,out Dictionary<int,int> selectDict)
        {
            selectDict = new Dictionary<int, int>();
            jobReplaceDic.Clear();
            ChestsAwardConfig awardConfig = ChestsAwardConfig.GetChestsAwardByID(boxId);
            if(string.IsNullOrEmpty(awardConfig.SelectList))
            {
                return false;
            }
            else
            {
                selectlistDict  = ConfigParse.GetDic<int, int>(awardConfig.SelectList);
                JsonData jsonData = JsonMapper.ToObject(awardConfig.JobItem);
                if(jsonData.IsArray)
                {
                    for(int i = 0; i < jsonData.Count; i++)
                    {
                        List<int> idlist = new List<int>();
                        jobReplaceDic.Add(i,idlist);
                        if(jsonData[i].IsArray)
                        {
                            for(int j = 0;j < jsonData[i].Count; j++)
                            {
                                int itemId = int.Parse(jsonData[i][j].ToString());
                                idlist.Add(itemId);
                            }
                        }
                    }
                }
                
                foreach(var itemId in selectlistDict.Keys)
                {
                    int id = itemId; 
                    foreach(var index in jobReplaceDic.Keys)
                    {
                        if(jobReplaceDic[index].Contains(itemId))
                        {
                            int replaceIndex = PlayerDatas.Instance.baseData.Job - 1;
                            id = jobReplaceDic[index][replaceIndex];
                            break;
                        }
                    }
                    selectDict.Add(id,selectlistDict[itemId]);
                }
 
                return true;
            }
 
        }
        #endregion
 
        private void CheckBoxShowType(int openShow,string guid)
        {
            ItemModel itemModel = playerPack.GetItemModelByGUID(guid);
            if (itemModel == null) return;
 
            switch ((BoxShowType)openShow)
            {
                case BoxShowType.NoShow:
                    showType = BoxShowType.NoShow;
                    ulong maxValue = 0;
                    playerPack.IsReachUseLimit(guid, out maxValue);
                    if (itemModel.config.BatchUse != 0 && maxValue > 1)
                    {
                        BatchUseModel.Instance.SetBatchModel(itemModel.itemInfo.ItemGUID);
                        WindowCenter.Instance.Open<BatchWin>();
                        return;
                    }
                    break;
                case BoxShowType.NoramalShow:
                    showType = BoxShowType.NoramalShow;
                    break;
                case BoxShowType.PrefectShow:
                    showType = BoxShowType.PrefectShow;
                    break;
            }
            CheckOpenBoxCondi(guid, itemModel.itemId);
        }
 
 
        public override void UnInit()
        {
           
        }
 
    }
 
    public enum BoxShowType
    {
        NoShow = 0, //无展示
        NoramalShow = 1, //普通展现
        PrefectShow = 2, // 有特效+展示
    }
 
    public class BoxGetItemInfo
    {
        public int ItemID;
        public int Count;
        public int IsBind;
        public int IsSuite;
        public string UserData;
    }
}