少年修仙传客户端代码仓库
hch
4 天以前 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
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using UnityEngine.UI;
using System.Linq;
using LitJson;
using UnityEngine;
 
//买1送5活动
public class Buy1Free5Model : ILModel<Buy1Free5Model>
{
    public ILOpenServerActivityProxy activity;
 
    public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_Activity1;
    public const int activityID = 4;
    public const Operation operationType = Operation.default25;
 
    public Redpoint redpoint = new Redpoint(MainRedPoint.RechargeGenerousGiftWinRedpoint,MainRedPoint.buy1Free5Redpoint);
    public Redpoint leftRedpoint = new Redpoint(MainRedPoint.buy1Free5Redpoint*10 + 2);
    public Redpoint rightRedpoint = new Redpoint(MainRedPoint.buy1Free5Redpoint*10 + 1);
    public event Action UpdateFreeGiftEvent;
 
    public List<int> freeGiftStates = new List<int>();
    public int selectCTGIDIndex = 0;    //界面切页
 
    VipModel vipModel { get { return ModelCenter.Instance.GetModelEx<VipModel>(); } }
 
    protected override void Init()
    {
        ILOperationTimeHepler.Instance.operationTimeUpdateEvent += OperationEvent;
        GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
        vipModel.rechargeCountEvent += OnRechargeEvent;
        activity = new ILOpenServerActivityProxy(IsOpen, IsAdvance, priorityOpen);
        OpenServerActivityCenter.Instance.Register(activityID, activity, activityType);
 
    }
 
    protected override void UnInit()
    {
        ILOperationTimeHepler.Instance.operationTimeUpdateEvent -= OperationEvent;
        GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
        vipModel.rechargeCountEvent -= OnRechargeEvent;
    }
 
    public bool IsOpen()
    {
        return OperationTimeHepler.Instance.SatisfyOpenCondition(operationType);
    }
 
    public bool IsAdvance()
    {
        return false;
    }
 
    public bool priorityOpen()
    {
        return false;
    }
 
 
 
    public void OnBeforePlayerDataInitialize()
    {
        freeGiftStates.Clear();
    }
 
    private void OperationEvent(Operation opType)
    {
        if (opType == operationType)
        {
            UpdateRedpoint();
        }
    }
 
 
    #region 服务端数据
    public uint ActNum { get; private set; } //累充类型 对应界面
    public void UpdateFreeGiftState(IL_HAA66_tagMCActBuyOnePlayerInfo package)
    {
        freeGiftStates.Clear();
        OperationBase operationBase;
        if (OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
        {
            OperationBuy1Free5 operation = operationBase as OperationBuy1Free5;
            if (operation.ActNum != package.ActNum)
            {
                return;
            }
            ActNum = package.ActNum;
            for (int i = 0; i < package.FreeRecordList.Length; i++)
            {
                freeGiftStates.Add((int)package.FreeRecordList[i]);
            }
            UpdateFreeGiftEvent?.Invoke();
            UpdateRedpoint();
        }
    }
 
    #endregion
 
    //购买后可免费领取5份礼包
    //0 未购买 1 可领取 2 已领取
    //ctgIDIndex 充值档位索引 freeIndex 免费礼包索引
    public int GetFreeGiftState(int ctgIDIndex, int ctgID, int freeIndex)
    {
        VipModel.RechargeCount rechargeCount;
        vipModel.TryGetRechargeCount(ctgID, out rechargeCount);
        if (rechargeCount.todayCount == 0)
            return 0;
 
        if (ctgIDIndex >= freeGiftStates.Count)
        {
            //有充值记录 但是没有领取记录
            return 1;
        }
        //按二进制位判断是否可领取
        if ((freeGiftStates[ctgIDIndex] & (1 << freeIndex)) != 0)
        {
            return 2;
        }
        return 1;
    }
 
    void OnRechargeEvent(int id)
    {
        if (!IsOpen())
            return;
        UpdateRedpoint();
    }
 
 
 
    public void UpdateRedpoint()
    {
        redpoint.state = RedPointState.None;
        OperationBase operationBase;
        if (OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
        {
            OperationBuy1Free5 operation = operationBase as OperationBuy1Free5;
            if (operation.ActNum != ActNum)
            {
                return;
            }
            //key一定是从0开始的
            for (int i = 0; i < operation.indexToCTGIDDict.Keys.Count; i++)
            {
                int ctgID = operation.indexToCTGIDDict[i];
                var itemList = operation.CTGIDToFreeDict[ctgID];
                for (int j = 0; j < itemList.Count; j++)
                {
                    if (GetFreeGiftState(i, ctgID, j) == 1)
                    {
                        redpoint.state = RedPointState.Simple;
                        return;
                    }
                }
            }
        }
    }
 
    public void UpdateLRRedpoint()
    {
        leftRedpoint.state = RedPointState.None;
        rightRedpoint.state = RedPointState.None;
        OperationBase operationBase;
        if (OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
        {
            OperationBuy1Free5 operation = operationBase as OperationBuy1Free5;
            if (operation.ActNum != ActNum)
            {
                return;
            }
            for (int i = 0; i < operation.indexToCTGIDDict.Keys.Count; i++)
            {
                int ctgID = operation.indexToCTGIDDict[i];
                var itemList = operation.CTGIDToFreeDict[ctgID];
                for (int j = 0; j < itemList.Count; j++)
                {
                    if (GetFreeGiftState(i, ctgID, j) == 1)
                    {
                        if (i < selectCTGIDIndex)
                        {
                            leftRedpoint.state = RedPointState.Simple;
                            break;
                        }
                        if (i > selectCTGIDIndex)
                        {
                            rightRedpoint.state = RedPointState.Simple;
                            break;
                        }
                    }
                }
            }
        }
    }
}