hch
2026-02-06 2b3fe1175765e0df62caba9dc160c0dbfefb0a8a
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
using System;
using LitJson;
 
using System.Collections.Generic;
using UnityEngine;
 
/// <summary>
/// 宝箱功能 + 获取奖励界面
/// </summary>
public class BoxGetItemModel : GameSystemManager<BoxGetItemModel>
{
 
 
    public override void Init()
    {
    }
 
 
    #region 处理服务器数据
 
    
 
    //获得奖励展示
    public void ReceiveAwardNotify(HA801_tagMCGiveAwardInfo netPack)
    {
        var eventName = UIHelper.ServerStringTrim(netPack.EventName);
 
 
        if (string.IsNullOrEmpty(eventName))
        {
            Debug.Log("获得物品展示 无事件名");
            return;
        }
 
        List<Item> showItems = new List<Item>();
 
        if (netPack.Exp != 0 || netPack.ExpPoint != 0)
        {
            long expValue = netPack.Exp + netPack.ExpPoint * Constants.ExpPointValue;
            showItems.Add(new Item(GeneralDefine.expDisplayId, expValue));
        }
        if (netPack.MoneyList.Length != 0)
        {
            for (int i = 0; i < netPack.MoneyLen; i++)
            {
                var moneyType = netPack.MoneyList[i].MoneyType;
                if (GeneralDefine.MoneyDisplayModel.ContainsKey(moneyType) && netPack.MoneyList[i].MoneyValue != 0)
                {
                    showItems.Add(new Item(GeneralDefine.MoneyDisplayModel[moneyType], netPack.MoneyList[i].MoneyValue));
                }
 
            }
        }
 
        bool isMergeItem = true;
        //约定IsBind=10 为古宝额外增加
        if (netPack.ItemList.Length != 0)
        {
            for (int i = 0; i < netPack.ItemLen; i++)
            {
                showItems.Add(new Item((int)netPack.ItemList[i].ItemID,
                netPack.ItemList[i].Count + netPack.ItemList[i].CountEx * Constants.ExpPointValue,
                netPack.ItemList[i].IsBind));
                if (isMergeItem && netPack.ItemList[i].IsBind >= 10)
                {
                    isMergeItem = false;
                }
            }
        }
 
 
        string info = string.Empty;
        if (LanguageConfig.HasKey("commonShowAwardEvents_" + eventName))
            info = Language.Get("commonShowAwardEvents_" + eventName);
 
        if (showItems.Count == 0)
            return;
 
        ItemLogicUtility.Instance.ShowGetItem(showItems, eventName, isMergeItem:isMergeItem);
    }
 
 
 
    #endregion
 
   
 
    //宝箱预览物品 (随机获得)
    public List<Item> GetBoxItems(int boxID)
    {
        List<Item> itemIDs = new List<Item>();
 
        if (ChestsAwardConfig.GetBoxType(boxID) == 0)
        {
            return itemIDs;
        }
 
        var config = ChestsAwardConfig.GetChestsAwardByID(boxID);
 
        if (!string.IsNullOrEmpty(config.SelectList))
        {
            var selectlistDict = ConfigParse.GetDic<int, int>(config.SelectList);
            foreach (var item in selectlistDict)
            {
                itemIDs.Add(new Item(item.Key, item.Value));
            }
        }
 
        if (!string.IsNullOrEmpty(config.FixedItem))
        {
            var itemListDict = ConfigParse.GetDic<int, int>(config.FixedItem);
            foreach (var item in itemListDict)
            {
                itemIDs.Add(new Item(item.Key, item.Value));
            }
        }
 
        if (!string.IsNullOrEmpty(config.Probability1))
        {
            var arr = JsonMapper.ToObject(config.Probability1);
 
            for (int i = 0; i < arr.Count; i++)
            {
                itemIDs.Add(new Item(int.Parse(arr[i][1][0].ToString()), long.Parse(arr[i][1][1].ToString())));
            }
        }
 
        if (!string.IsNullOrEmpty(config.Probability2))
        {
            var arr = JsonMapper.ToObject(config.Probability2);
 
            for (int i = 0; i < arr.Count; i++)
            {
                itemIDs.Add(new Item(int.Parse(arr[i][1][0].ToString()), long.Parse(arr[i][1][1].ToString())));
            }
        }
 
        return itemIDs;
    }
 
 
 
    #region 自选物品宝箱
 
    //<物品ID,数量>  用户选中物品字典
    public Dictionary<int, ChooseItems> userChooseItemDict = new Dictionary<int, ChooseItems>();
    public Action countChangeAction;    //数量发生变化
 
    public bool IsSelectItemByID(int boxId)
    {
        ChestsAwardConfig awardConfig = ChestsAwardConfig.GetChestsAwardByID(boxId);
        if (string.IsNullOrEmpty(awardConfig.SelectList))
        {
            return false;
        }
        return true;
    }
 
    public int[][] GetSelectItemsByID(int boxId)
    {
        ChestsAwardConfig awardConfig = ChestsAwardConfig.GetChestsAwardByID(boxId);
        if (string.IsNullOrEmpty(awardConfig.SelectList))
        {
            return null;
        }
        var arr = ConfigParse.GetArray2<int>(awardConfig.SelectList);
        Array.Sort(arr, SortShowItem);
        return arr;
    }
 
    int SortShowItem(int[] a, int[] b)
    {
        var itemConfig1 = ItemConfig.Get(a[0]);
        var itemConfig2 = ItemConfig.Get(b[0]);
        int quality1 = itemConfig1.ItemColor;
        int quality2 = itemConfig2.ItemColor;
        //品质高的排在前面
        if (quality1 != quality2)
            return quality2.CompareTo(quality1);
        return itemConfig1.ID - itemConfig2.ID;
    }
 
    /// <summary>
    /// 选择自选物品数量
    /// </summary>
    /// <param name="itemId">被选择物品的ID</param>
    /// <param name="guid">宝箱的GUID</param>
    /// <param name="extra"></param>
    /// <param name="changeCnt">加减数量</param>
    public void IncreaseUserChooseItemCount(int itemId, string guid, int extra, int changeCnt)
    {
        if (userChooseItemDict.ContainsKey(itemId))
        {
            userChooseItemDict[itemId].guid = guid;
            userChooseItemDict[itemId].useCnt = userChooseItemDict[itemId].useCnt + changeCnt;
            userChooseItemDict[itemId].extra = extra;
        }
        else
        {
            userChooseItemDict[itemId] = new ChooseItems() { guid = guid, useCnt = 1, extra = extra };
        }
        countChangeAction?.Invoke();
    }
 
 
    //当前选择材料总数量
    public int GetNowChooseItemCount()
    {
        int total = 0;
        if (userChooseItemDict == null && userChooseItemDict.Count == 0)
            return 0;
        List<int> list = new List<int>(userChooseItemDict.Keys);
        for (int i = 0; i < list.Count; i++)
            total += userChooseItemDict[list[i]].useCnt;
        return total;
    }
 
 
 
    public bool TrySendUse()
    {
        CA323_tagCMUseItems.tagCMUseItemsSelect[] chooseItemList = GetSendList(userChooseItemDict, out List<ChooseItems> resultChooseItemDict, out string guid, out int count);
        //一个材料也没选
        if (chooseItemList.Length < 1)
        {
            SysNotifyMgr.Instance.ShowTip("ChooseItems01");
            return false;
        }
 
        var itemModel = PackManager.Instance.GetItemByGuid(guid);
        if (itemModel == null)
            return false;
 
        for (int i = 0; i < resultChooseItemDict.Count; i++)
        {
            var item = PackManager.Instance.GetItemByGuid(resultChooseItemDict[i].guid);
            if (item == null)
                return false;
 
            var error = 0;
            if (!ItemLogicUtility.Instance.CanUseItem(resultChooseItemDict[i].guid, resultChooseItemDict[i].useCnt, out error))
            {
                switch (error)
                {
                    case 1:
                        SysNotifyMgr.Instance.ShowTip("EverydayUseLimit");
                        break;
                    case 2:
                        SysNotifyMgr.Instance.ShowTip("UseCntLimit");
                        break;
                    case 3:
                        SysNotifyMgr.Instance.ShowTip("GeRen_chenxin_749572");
                        break;
                    default:
                        break;
                }
                return false;
            }
        }
 
        var useItem = new CA323_tagCMUseItems();
        useItem.ItemIndex = (byte)itemModel.gridIndex;
        useItem.UseCnt = (ushort)count;
        useItem.ExData = (uint)0;
        useItem.SelectCount = (byte)chooseItemList.Length;
        useItem.SelectList = chooseItemList;
        GameNetSystem.Instance.SendInfo(useItem); 
        return true;
    }
 
  
 
    CA323_tagCMUseItems.tagCMUseItemsSelect[] GetSendList(Dictionary<int, ChooseItems> userChooseItemDict, out List<ChooseItems> resultChooseItemDict, out string guid, out int count)
    {
        guid = string.Empty;
        count = 0;
        resultChooseItemDict = new List<ChooseItems> { };
        List<int> list = new List<int>(userChooseItemDict.Keys);
        List<ChooseItems> result = new List<ChooseItems>();
        for (int i = 0; i < list.Count; i++)
        {
            int itemId = list[i];
            ChooseItems chooseItems = userChooseItemDict[itemId];
            if (!ItemConfig.HasKey(itemId))
                continue;
            if (chooseItems == null || chooseItems.useCnt <= 0)
                continue;
            count += chooseItems.useCnt;
            result.Add(chooseItems);
        }
        resultChooseItemDict = result;
        if (!result.IsNullOrEmpty())
            guid = result[0].guid;
 
        List<CA323_tagCMUseItems.tagCMUseItemsSelect> tagCMUseItemsSelects = new List<CA323_tagCMUseItems.tagCMUseItemsSelect>();
        for (int i = 0; i < result.Count; i++)
        {
            CA323_tagCMUseItems.tagCMUseItemsSelect temp = new CA323_tagCMUseItems.tagCMUseItemsSelect();
            temp.SelectID = (uint)result[i].extra;
            temp.SelectCnt = (ushort)result[i].useCnt;
            tagCMUseItemsSelects.Add(temp);
        }
 
        return tagCMUseItemsSelects.ToArray();
    }
 
    public void ClearAll()
    {
        userChooseItemDict.Clear();
    }
 
 
 
 
 
    #endregion
 
 
    
}
 
 
 
public class ChooseItems
{
    public string guid;
    public int useCnt;
    public int extra;
}