少年修仙传客户端代码仓库
hch
3 天以前 600733c8f592cb9e65f2b7a3e110ac1d686e6bfe
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
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using UnityEngine.UI;
using System.Linq;
using LitJson;
 
//天帝礼包 - 独立入口
public class GodKingGiftModel : ILModel<GodKingGiftModel>
{
    public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_JCHD;
    public const int activityID = 99;   //不能与精彩活动ID重复,独立入口
    public const Operation operationType = Operation.default22; //天帝礼包
    public ILOpenServerActivityProxy activity;
 
    public Redpoint redpoint = new Redpoint(MainRedPoint.TDLBRedPoint);
 
    public byte ResetCount;    // 本次活动已重置次数
    public IL_HAA61_tagMCActGodGiftPlayerInfo.tagMCActGodGiftAwardItem[] AwardItemList;    // 本次奖池已抽中物品列表
 
    public event Action OnPlayerInfoEvent;
 
    //奖池库类型
    public event Action OnSelectUpdate;
    int m_SelectType = 0;
    public int selectType
    {
        get { return m_SelectType; }
        set
        {
            if (m_SelectType != value)
            {
                m_SelectType = value;
                OnSelectUpdate?.Invoke();
            }
        }
    }
 
    public IL_HAA60_tagMCActGodGiftInfo.tagMCActGodGiftItem[] itemsLib; //当前要展示的可选物品
 
    public struct GodKingGiftItem
    {
        public byte itemNum;        // 物品在本库中的编号
        public uint itemID;
        public ushort itemCount;
        public byte libType;    //奖池类型
    }
 
    //已选中的奖池物品(未确认),按选择的顺序倒序显示
    public List<GodKingGiftItem> selectedItems = new List<GodKingGiftItem>();
    //正在抽奖中的物品 AA61中为抽中物品,对比不相交部分就是未抽中
    public List<GodKingGiftItem> godKingItems = new List<GodKingGiftItem>();
    public int newItemIndex;
    public int awardShowSetp = 0;   //-1 默认正常显示 0 点按钮开始 1 开始物品聚集转圈 2 物品转圈结束  回到0刷新界面 显示得奖界面
 
    public int SelectLimitedCnt = 0;   //选满多少个才可以确认奖池
    public event Action OnSelectItemEvent;
 
    protected override void Init()
    {
        activity = new ILOpenServerActivityProxy(IsOpen, IsAdvance, priorityOpen);
        OpenServerActivityCenter.Instance.Register(activityID, activity, activityType);
 
        GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
        ILOperationTimeHepler.Instance.operationTimeUpdateEvent += operationTimeUpdateEvent;
    }
 
    protected override void UnInit()
    {
        GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
        ILOperationTimeHepler.Instance.operationTimeUpdateEvent -= operationTimeUpdateEvent;
    }
 
    public bool IsOpen()
    {
        return OperationTimeHepler.Instance.SatisfyOpenCondition(operationType);
    }
 
    public bool IsAdvance()
    {
        return false;
    }
 
    public bool priorityOpen()
    {
        //红点
        return redpoint.state == RedPointState.Simple;
    }
 
 
    public void OnPlayerLoginOk()
    {
        
    }
 
    public void OnBeforePlayerDataInitialize()
    {
        selectedItems.Clear();
        godKingItems.Clear();
        awardShowSetp = -1;
    }
 
 
    private void operationTimeUpdateEvent(Operation type)
    {
        if (type == operationType)
        {
            OperationBase operationBase;
            if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
            {
                return;
            }
            OperationGodKingGift operation = operationBase as OperationGodKingGift;
 
            if (operation.IsAwardPoolOK != 0 && WindowCenter.Instance.IsOpen("GodKingGiftWin"))
            {
                WindowCenter.Instance.CloseIL<GodKingGiftWin>();
                WindowCenter.Instance.OpenIL<GodKingRandomGiftWin>();
            }
            else if (operation.IsAwardPoolOK == 0 && WindowCenter.Instance.IsOpen("GodKingRandomGiftWin"))
            {
                WindowCenter.Instance.CloseIL<GodKingRandomGiftWin>();
                WindowCenter.Instance.OpenIL<GodKingGiftWin>();
            }
            UpdateRedpoint();
        }
    }
 
    //免费次数未用(包含了奖池未选择的情况)
    void UpdateRedpoint()
    {
        redpoint.state = RedPointState.None;
        OperationBase operationBase;
        if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
        {
            return;
        }
        OperationGodKingGift operation = operationBase as OperationGodKingGift;
        if (operation.IsAwardPoolOK == 0)
        {
            redpoint.state = RedPointState.Simple;
            return;
        }
        else if (AwardItemList != null && operation.CostMoneyValueList[Math.Min(AwardItemList.Length, operation.CostMoneyValueList.Length - 1)] == 0)
        {
            redpoint.state = RedPointState.Simple;
        }
 
    }
 
    public void UpdatePlayerInfo(IL_HAA61_tagMCActGodGiftPlayerInfo netPack)
    {
        OperationBase operationBase;
        if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
        {
            return;
        }
 
        OperationGodKingGift operation = operationBase as OperationGodKingGift;
        if (operation.ActNum != netPack.ActNum)
        {
            return;
        }
 
        ResetCount = netPack.ResetCount;
 
        //找出不同物品
        if (AwardItemList != netPack.AwardItemList && awardShowSetp == 0)
        {
            newItemIndex = -1;
            for (int i = 0; i < netPack.AwardItemList.Length; i++)
            {
                bool find = false;
                if (AwardItemList != null)
                {
                    for (int j = 0; j < AwardItemList.Length; j++)
                    {
                        if (netPack.AwardItemList[i].ItemLibType == AwardItemList[j].ItemLibType &&
                            netPack.AwardItemList[i].ItemNum == AwardItemList[j].ItemNum)
                        {
                            find = true;
                            break;
                        }
                    }
                }
 
                if (!find)
                {
                    for (int k = 0; k < godKingItems.Count; k++)
                    {
                        if (godKingItems[k].itemNum == netPack.AwardItemList[i].ItemNum
                            && godKingItems[k].libType == netPack.AwardItemList[i].ItemLibType)
                        {
                            newItemIndex = k;
                            awardShowSetp = 1;
                        }
                    }
                    break;
                }
 
            }
        }
        AwardItemList = netPack.AwardItemList;
 
        OnPlayerInfoEvent?.Invoke();
        UpdateRedpoint();
    }
 
    //根据奖池是否选择完毕来决定打开界面
    public void OpenWindow()
    {
        OperationBase operationBase;
        if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
        {
            return;
        }
 
        OperationGodKingGift operation = operationBase as OperationGodKingGift;
        if (operation.IsAwardPoolOK == 0)
        {
            WindowCenter.Instance.OpenIL<GodKingGiftWin>();
        }
        else
        {
            WindowCenter.Instance.OpenIL<GodKingRandomGiftWin>();
        }
    }
 
    //当前要展示库的可选物品
    public void RefreshItemsByType()
    {
        OperationBase operationBase;
        if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
        {
            itemsLib = null;
            return;
        }
 
        OperationGodKingGift operation = operationBase as OperationGodKingGift;
        for (int i = 0; i < operation.ItemLibList.Length; i++)
        {
            if (operation.ItemLibList[i].ItemLibType == selectType + 1)
            {
                itemsLib = operation.ItemLibList[i].GodGiftItemList;
                return;
            }
        }
 
        itemsLib = null;
    }
 
    // 指定库的已选物品数量
    public int SelectdCountByLib(int libType)
    {
        int cnt = 0;
        for (int i = 0; i < selectedItems.Count; i++)
        {
            if (selectedItems[i].libType == libType)
            {
                cnt++;
            }
        }
        return cnt;
    }
 
    public void OnSelectItem(int index, bool isAdd)
    {
        var itemInfo = itemsLib[index];
        if (isAdd)
        {
            selectedItems.Add(new GodKingGiftItem()
            {
                itemNum = itemInfo.ItemNum,
                itemID = itemInfo.ItemID,
                itemCount = itemInfo.ItemCount,
                libType = (byte)(selectType + 1),
            });
        }
        else
        {
            int delIndex = -1;
            for (int i = 0; i < selectedItems.Count; i++)
            {
                if (itemInfo.ItemNum == selectedItems[i].itemNum && selectedItems[i].libType == (selectType + 1))
                {
                    delIndex = i;
                    break;
                }
            }
            if (delIndex != -1)
            {
                selectedItems.RemoveAt(delIndex);
            }
        }
        OnSelectItemEvent?.Invoke();
    }
 
    //库对应的选择数量
    public Dictionary<int, int> libSelectCnt = new Dictionary<int, int>();
 
    public int GetMaxSelectCnt()
    {
        if (SelectLimitedCnt == 0)
        {
            libSelectCnt.Clear();
            OperationBase operationBase;
            if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
            {
                itemsLib = null;
                return SelectLimitedCnt;
            }
 
            OperationGodKingGift operation = operationBase as OperationGodKingGift;
 
            for (int i = 0; i < operation.ItemLibList.Length; i++)
            {
                SelectLimitedCnt += operation.ItemLibList[i].NeedChooseCount;
                libSelectCnt[operation.ItemLibList[i].ItemLibType] = operation.ItemLibList[i].NeedChooseCount;
            }
            return SelectLimitedCnt;
        }
 
        return SelectLimitedCnt;
    }
 
    public int GetLibSelectCnt(int libType)
    {
        return libSelectCnt[libType];
    }
 
    public int GetResetCnt()
    {
        OperationBase operationBase;
        if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
        {
            return 0;
        }
 
        OperationGodKingGift operation = operationBase as OperationGodKingGift;
 
        return operation.ResetCountMax - ResetCount;
    }
}