少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
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
using System.Collections.Generic;
using System.Linq;
using vnxbqy.UI;
 
public class ZhanLingHActBuyModel : Model
{
    public int zhanLingType;        //高级战令类型
    public int showGiftType;        //1 普通战令礼包 2 高级战令礼包
    public int nowNeedValue;
 
    public Dictionary<int, List<int>> ctgIdDictH = new Dictionary<int, List<int>>();
    public Dictionary<int, List<int>> ctgIdDict = new Dictionary<int, List<int>>();
 
    public override void Init()
    {
        ctgIdDict = GeneralDefine.ZhanLingCtgIdDict;
        ctgIdDictH = GeneralDefine.ZhanLingCtgIdHDict;
    }
 
    public override void UnInit()
    {
    }
 
    public void ShowZhanLingHBuy(int zhanLingType, int showGiftType, int nowNeedValue)
    {
        this.zhanLingType = zhanLingType;
        this.showGiftType = showGiftType;
        this.nowNeedValue = nowNeedValue;
        if (!WindowCenter.Instance.IsOpen<ZhanLingHActBuyWin>())
            WindowCenter.Instance.Open<ZhanLingHActBuyWin>();
    }
 
    public int GetCtgID()
    {
        int ctgid = 0;
        if (showGiftType == 1)
        {
            ctgid = ctgIdDict[zhanLingType][0];
        }
        else if (showGiftType == 2)
        {
            ctgid = ctgIdDictH[zhanLingType][0];
        }
        return ctgid;
    }
 
    //获取购买后所有等级的奖励
    public List<Item> GetGiftAllItem()
    {
        List<int> collectList = new List<int>();
        var dict = ILZhanlingConfig.GetTypeToIDDict(zhanLingType);
        var arr = dict.Keys.ToArray();
        for (int i = 0; i < arr.Length; i++)
        {
            int needValue = arr[i];
            int zhanLingId = dict[needValue];
            collectList.Add(zhanLingId);
        }
        return CollectItems(collectList);
    }
 
    //获取购买后当前等级的奖励
    public List<Item> GetGiftNowItem()
    {
        List<int> collectList = new List<int>();
        var dict = ILZhanlingConfig.GetTypeToIDDict(zhanLingType);
        var arr = dict.Keys.ToArray();
        for (int i = 0; i < arr.Length; i++)
        {
            int needValue = arr[i];
            int zhanLingId = dict[needValue];
            if (needValue > nowNeedValue)
                break;
            collectList.Add(zhanLingId);
        }
        return CollectItems(collectList);
    }
 
    private List<Item> CollectItems(List<int> collectList)
    {
        //<物品ID,物品数量>
        Dictionary<int, int> resultDict = new Dictionary<int, int>();
        for (int i = 0; i < collectList.Count; i++)
        {
            int zhanLingId = collectList[i];
            int[][] itemArr = GetItemArr(zhanLingId, showGiftType);
            if (itemArr.IsNullOrEmpty())
                continue;
 
            for (int j = 0; j < itemArr.Length; j++)
            {
                int itemID = itemArr[j][0];
                int count = itemArr[j][1];
                if (resultDict.ContainsKey(itemID))
                {
                    resultDict[itemID] += count;
                }
                else
                {
                    resultDict[itemID] = count;
                }
            }
        }
        List<Item> result = GetItemListByDict(resultDict);
        result.Sort(Cmp);
        return result;
    }
 
    private int[][] GetItemArr(int zhanLingId, int showGiftType)
    {
        if (!ILZhanlingConfig.Has(zhanLingId))
            return new int[][] { };
 
        if (showGiftType == 1)
        {
            return ILZhanlingConfig.Get(zhanLingId).ZLRewardItemList;
        }
        else if (showGiftType == 2)
        {
            return ILZhanlingConfig.Get(zhanLingId).ZLRewardItemListH;
        }
        else
        {
            return new int[][] { };
        }
    }
 
    //将传入的<物品ID,物品数量>字典转成List<Item>
    private List<Item> GetItemListByDict(Dictionary<int, int> dict)
    {
        List<Item> result = new List<Item>();
        var arr = dict.Keys.ToArray();
        for (int i = 0; i < arr.Length; i++)
        {
            int itemID = arr[i];
            int count = dict[itemID];
            result.Add(new Item(itemID, count));
        }
        return result;
    }
 
    private int Cmp(Item a, Item b)
    {
        int count1 = a.count;
        int count2 = b.count;
        int quality1 = ItemConfig.Get(a.id).ItemColor;
        int quality2 = ItemConfig.Get(b.id).ItemColor;
 
        //品质高的排在前面
        if (quality1 != quality2)
        {
            return quality2.CompareTo(quality1);
        }
 
        // 品质相同时,数量少的排在前面
        if (count1 != count2)
        {
            return count1.CompareTo(count2);
        }
 
        // 如果品质和数量都相同,保持原有顺序
        return 0;
    }
}