少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Sunday, January 21, 2018
//--------------------------------------------------------
using System;
using System.Collections.Generic;
 
 
namespace vnxbqy.UI
{
 
    
    public class PreciousItemGetModel : Model, IBeforePlayerDataInitialize, ISwitchAccount, IPlayerLoginOk
    {
        Dictionary<string, PreciousItem> itemStack = new Dictionary<string, PreciousItem>();
        List<string> itemGuids = new List<string>();
        List<string> itemExpGuids = new List<string>();
 
        PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
        CrossServerOneVsOneModel crossOneVsOneModel { get { return ModelCenter.Instance.GetModel<CrossServerOneVsOneModel>(); } }
 
        public PreciousItem currentShowItem { get; private set; }
        public event Action showItemRefreshEvent;
        public bool isGetNewItem { get; set; }
 
        bool isServerPrepare { get; set; }
        public override void Init()
        {
            ItemLogicUtility.Instance.GetPreciousItemEvent += OnGetPreciousItem;
            ItemLogicUtility.Instance.GetExpItemEvent += OnGetPreciousExpItem;
            playerPack.refrechPackEvent += OnPackageRefresh;
            playerPack.refreshItemCountEvent += OnPackageItemRefresh;
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
        }
 
        public override void UnInit()
        {
            ItemLogicUtility.Instance.GetPreciousItemEvent -= OnGetPreciousItem;
            ItemLogicUtility.Instance.GetExpItemEvent -= OnGetPreciousExpItem;
            playerPack.refrechPackEvent -= OnPackageRefresh;
            playerPack.refreshItemCountEvent -= OnPackageItemRefresh;
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            isGetNewItem = false;
            isServerPrepare = false;
            PlayerDatas.Instance.playerDataRefreshEvent -= RefreshRealm;
            CrossServerOneVsOnePlayerInfo.Instance.UpdateMatchNumEvent -= UpdateCrossOneVsOneMatchNum;
        }
 
        public void OnSwitchAccount()
        {
            currentShowItem = default(PreciousItem);
        }
 
 
        public void OnPlayerLoginOk()
        {
            isServerPrepare = true;
            PlayerDatas.Instance.playerDataRefreshEvent += RefreshRealm;
            CrossServerOneVsOnePlayerInfo.Instance.UpdateMatchNumEvent += UpdateCrossOneVsOneMatchNum;
        }
 
 
        public bool TryGetItem(string _guid, out PreciousItem _itemModel)
        {
            return itemStack.TryGetValue(_guid, out _itemModel);
        }
 
        public void ReportConfirmPreciousItem(PreciousItem _preciousItem)
        {
            if (string.IsNullOrEmpty(_preciousItem.guid))
            {
                return;
            }
 
            if (itemExpGuids.Contains(_preciousItem.guid))
            {
                itemExpGuids.Remove(_preciousItem.guid);
            }
 
            if (itemGuids.Contains(_preciousItem.guid))
            {
                itemGuids.Remove(_preciousItem.guid);
            }
 
            if (itemStack.ContainsKey(_preciousItem.guid))
            {
                itemStack.Remove(_preciousItem.guid);
            }
 
            RefreshCurrrentShowPreciousItem();
        }
 
        public int GetShowItemId()
        {
            if (currentShowItem == default(PreciousItem))
            {
                return 0;
            }
            else
            {
                var item = playerPack.GetItemByGuid(currentShowItem.guid);
                return item == null ? 0 : item.config.ID;
            }
        }
 
        private void UpdateCrossOneVsOneMatchNum()
        {
            if (!TryRemindMatchTick()) return;
 
            var itemModels = playerPack.GetItemsById(PackType.Item, 1506);
            if (itemModels != null && itemModels.Count > 0)
            {
                var itemModel = itemModels[0];
                var error = 0;
                var isHaveMakeNum = ItemOperateUtility.Instance.CanUseItem(itemModel.guid, 1, out error);
                if (isHaveMakeNum)
                {
                    OnGetPreciousItem(PackType.Item, itemModel.guid);
                }
            }
        }
 
        private bool TryRemindMatchTick()
        {
            if (NewBieCenter.Instance.inGuiding || !CrossServerOneVsOnePKSeason.Instance.isSatisfyMatch) return false;
            int remainNum = CrossServerOneVsOnePlayerInfo.Instance.GetDayRemainNum();
            if (remainNum > 0) return false;
            return true;
        }
 
        private void RefreshRealm(PlayerDataType type)
        {
            int realmLv = PlayerDatas.Instance.baseData.realmLevel;
            if (type != PlayerDataType.RealmLevel
                || NewBieCenter.Instance.inGuiding)
            {
                return;
            }
 
            List<ItemModel> druglist = ItemLogicUtility.Instance.GetDruglistByRealm();
            for (int i = 0; i < druglist.Count; i++)
            {
                OnGetPreciousItem(druglist[i].packType, druglist[i].guid);
            }
        }
 
        private void OnGetPreciousItem(PackType type, string guid)
        {
            var preciousItem = new PreciousItem(type, guid);
            if (!itemGuids.Contains(guid))
            {
                itemGuids.Add(guid);
            }
 
            itemStack[guid] = preciousItem;
 
            RefreshCurrrentShowPreciousItem();
        }
 
        private void OnGetPreciousExpItem(PackType type, string guid)
        {
            var preciousItem = new PreciousItem(type, guid);
            if (!itemExpGuids.Contains(guid))
            {
                itemExpGuids.Add(guid);
            }
 
            itemStack[guid] = preciousItem;
 
            RefreshCurrrentShowPreciousItem();
        }
 
        private void OnPackageRefresh(PackType _type)
        {
            if (_type != PackType.Item)
            {
                return;
            }
 
            RefreshCurrrentShowPreciousItem();
        }
 
        private void OnPackageItemRefresh(PackType _type, int _index, int _itemId)
        {
            OnPackageRefresh(_type);
        }
 
        private void OnFuncStateChangeEvent(int id)
        {
            if (id == (int)FuncOpenEnum.BlastFurnace && FuncOpen.Instance.IsFuncOpen(id))
            {
                if (isServerPrepare)
                {
                    RecommandAlchemyStudyItems();
                    RecommandAlchemyDrugs();
                }
            }
        }
 
        private bool FindLatestItem(out PreciousItem _item)
        {
            string guid;
            if (itemExpGuids.Count == 0)
            {
                if (itemGuids.Count == 0)
                {
                    _item = default(PreciousItem);
                    return false;
                }
                else
                    guid = itemGuids[itemGuids.Count - 1];
 
            }
            else
                guid = itemExpGuids[itemExpGuids.Count - 1];
 
 
            _item = itemStack[guid];
            return true;
        }
 
        private void RecommandAlchemyDrugs()
        {
            var items = playerPack.GetItems(PackType.Item, new SinglePack.FilterParams());
            if (items != null)
            {
                foreach (var item in items)
                {
                    var config = AttrFruitConfig.Get(item.itemId);
                    if (config != null && config.FuncID == 2)
                    {
                        ItemLogicUtility.Instance.RecommendItem(item);
                    }
                }
            }
        }
 
        private void RecommandAlchemyStudyItems()
        {
            var items = playerPack.GetItems(PackType.Item, new SinglePack.FilterParams()
            {
                itemTypes = new List<int>() { 55 },
            });
            if (items != null)
            {
                foreach (var item in items)
                {
                    ItemLogicUtility.Instance.RecommendItem(item);
                }
            }
        }
 
        private void Trim()
        {
            for (int i = itemExpGuids.Count - 1; i >= 0; i--)
            {
                var item = itemStack[itemExpGuids[i]];
                if (playerPack.GetItemByGuid(item.guid) == null
                    || playerPack.GetItemByGuid(item.guid).packType != PackType.Item)
                {
                    itemExpGuids.RemoveAt(i);
                }
            }
 
            for (int i = itemGuids.Count - 1; i >= 0; i--)
            {
                var item = itemStack[itemGuids[i]];
                if (playerPack.GetItemByGuid(item.guid) == null
                    || playerPack.GetItemByGuid(item.guid).packType != PackType.Item)
                {
                    itemGuids.RemoveAt(i);
                }
            }
        }
 
        private void RefreshCurrrentShowPreciousItem()
        {
            Trim();
 
            PreciousItem tempItem;
            if (FindLatestItem(out tempItem))
            {
                if (tempItem != currentShowItem)
                {
                    currentShowItem = tempItem;
                }
            }
            else
            {
                currentShowItem = default(PreciousItem);
            }
 
            if (showItemRefreshEvent != null)
            {
                isGetNewItem = true;
                showItemRefreshEvent();
            }
        }
 
        public bool ShowPreciousItemAble()
        {
            var mapId = PlayerDatas.Instance.baseData.MapID;
            var lineId = PlayerDatas.Instance.baseData.dungeonLineId;
            var dungeonId = dungeonModel.GetDungeonId(dungeonModel.GetDataMapIdByMapId(mapId), lineId);
            if (dungeonId == 0)
            {
                return true;
            }
            else
            {
                var config = DungeonConfig.Get(dungeonId);
                return config.ShowNewItemTip == 1;
            }
        }
 
        public struct PreciousItem
        {
            public PackType packType;
            public string guid;
 
            public PreciousItem(PackType _packType, string _guid)
            {
                this.packType = _packType;
                this.guid = _guid;
            }
 
            public static bool operator ==(PreciousItem _lhs, PreciousItem _rhs)
            {
                return _lhs.packType == _rhs.packType && _lhs.guid == _rhs.guid;
            }
 
            public static bool operator !=(PreciousItem _lhs, PreciousItem _rhs)
            {
                return _lhs.packType != _rhs.packType || _lhs.guid != _rhs.guid;
            }
 
 
        }
 
    }
 
}