hch
5 小时以前 cba555476b1f1b856b9211451e739d8cdce0eeba
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
 
 
public class BuyItemController : Singleton<BuyItemController>
{
 
    Dictionary<int, int> vipBuyCntDict = new Dictionary<int, int>();
 
    public bool CheckIsVipBuy(StoreConfig model, out int curVipIndex, out int nextVipIndex)
    {
        vipBuyCntDict.Clear();
        curVipIndex = -1;
        nextVipIndex = -1;
        bool isVipBuy = false;
        if (model == null) return isVipBuy;
 
        if (model.VIPLV.Length < 2)
        {
            if (model.VIPLV[0] != 0)
            {
                isVipBuy = true;
            }
            else
            {
                isVipBuy = false;
            }
        }
        else
        {
            isVipBuy = true;
        }
 
        if (isVipBuy)
        {
            for (int i = model.VIPLV.Length - 1; i > -1; i--)
            {
                vipBuyCntDict.Add(model.VIPLV[i], model.GoumaiNumber[i]);
            }
            int playerVip = PlayerDatas.Instance.baseData.VIPLv;
            for (int i = model.VIPLV.Length - 1; i > -1; i--)
            {
                if (model.VIPLV[i] > playerVip)
                {
                    nextVipIndex = i;
                }
                else if (model.VIPLV[i] <= playerVip)
                {
                    curVipIndex = i;
                    break;
                }
            }
 
        }
 
        return isVipBuy;
    }
 
    public bool CheckIsLimitBuyCnt(StoreConfig model, out int canBuyCnt, out int addBuyCnt)
    {
        canBuyCnt = 0;
        addBuyCnt = 0;
        if (model == null) return false;
 
        int[] canBuyNums = model.GoumaiNumber;
        int curVipIndex = -1;
        int nexVipIndex = -1;
        bool isVipBuy = CheckIsVipBuy(model, out curVipIndex, out nexVipIndex);
        if (isVipBuy)
        {
            if (curVipIndex != -1)
            {
                canBuyCnt = canBuyNums[curVipIndex];
            }
 
            if (nexVipIndex != -1)
            {
                addBuyCnt = canBuyNums[nexVipIndex] - canBuyCnt;
            }
            return true;
        }
        else
        {
            if (canBuyNums[0] != 0)
            {
                canBuyCnt = canBuyNums[0];
                return true;
            }
            else
            {
                return false;
            }
        }
    }
 
    public int goodId { get; private set; }
    public readonly LogicInt wannaBuyCount = new LogicInt();
 
 
    public void SetGood(int goodId)
    {
        this.goodId = goodId;
        wannaBuyCount.value = 1;
    }
 
    public void SetBuyCount(int goodId, int count)
    {
        var countLimit = GetBuyCountLimit(goodId, PlayerDatas.Instance.baseData.VIPLv);
        if (countLimit == -1)
        {
            wannaBuyCount.value = Mathf.Clamp(count, 1, 999);
        }
        else
        {
            wannaBuyCount.value = Mathf.Clamp(count, 1, countLimit);
        }
    }
 
    public bool IsVipLimitGood(int goodId)
    {
        var config = StoreConfig.Get(goodId);
        return config != null && config.VIPLV.Length > 1 && config.VIPLV[0] > 0;
    }
 
    /// <summary>
    /// 返回值为-1,表示没有vip限制,返回值为999表示已经没有下一个vip限制
    /// </summary>
    /// <param name="goodId"></param>
    /// <param name="vipLevel"></param>
    /// <returns></returns>
    public int GetNextCanbuyVipLevel(int goodId, int vipLevel)
    {
        if (!IsVipLimitGood(goodId))
        {
            return -1;
        }
 
        var config = StoreConfig.Get(goodId);
        var nextLevel = 999;
        for (int i = 0; i < config.VIPLV.Length; i++)
        {
            if (config.VIPLV[i] > vipLevel)
            {
                nextLevel = config.VIPLV[i];
                break;
            }
        }
 
        return nextLevel;
    }
 
    /// <summary>
    /// 返回值如果是-1,表示无限制
    /// </summary>
    /// <param name="goodId"></param>
    /// <returns></returns>
    public int GetBuyCountLimit(int goodId, int vipLevel)
    {
        var config = StoreConfig.Get(goodId);
        if (config.GoumaiNumber.Length == 0 || config.GoumaiNumber[0] == 0)
        {
            return -1;
        }
 
        var isVipLimitGood = config != null && config.VIPLV.Length > 1;
        var canBuy = 0;
        if (isVipLimitGood)
        {
            var index = -1;
            for (var i = config.VIPLV.Length - 1; i >= 0; i--)
            {
                if (config.VIPLV[i] <= vipLevel)
                {
                    index = i;
                    break;
                }
            }
           
            if (index != -1)
            {
                canBuy = config.GoumaiNumber[index];
            }
            else
            {
                canBuy = 0;
            }
        }
        else
        {
            canBuy = config.GoumaiNumber[0];
        }
 
        var goodLimit = StoreModel.Instance.GetBuyShopLimit((uint)goodId);
        var haveBuy = goodLimit != null ? goodLimit.BuyCnt : 0;
        return canBuy - haveBuy;
    }
 
    public bool IsSellOut(int goodId, int vipLevel)
    {
        var limitCount = GetBuyCountLimit(goodId, vipLevel);
        return limitCount != -1 && limitCount <= 0;
    }
 
    public int GetTotalPrice(int goodId, int count)
    {
        var config = StoreConfig.Get(goodId);
        return config.MoneyNumber * count;
    }
 
 
}