少年修仙传客户端代码仓库
client_Zxw
2018-08-13 196c1f03fe7a8908272c8127133e632d107eaef8
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Snxxz.UI
{
    public class FlashSaleModel : Model, IPlayerLoginOk, IBeforePlayerDataInitialize
    {
        StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
        public override void Init()
        {
            OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
            OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
            TimeMgr.Instance.OnDayEvent += OnDayEvent;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
        }
 
        public void OnPlayerLoginOk()
        {
            UpdateRedpoint();
        }
 
        public override void UnInit()
        {
            OperationTimeHepler.Instance.operationStartEvent -= OperationStartEvent;
            OperationTimeHepler.Instance.operationEndEvent -= OperationEndEvent;
            TimeMgr.Instance.OnDayEvent -= OnDayEvent;
        }
 
        private void OperationEndEvent(Operation type, int state)
        {
            if (type == Operation.FlashSale && state == 0)
            {
                UpdateRedpoint();
            }
        }
 
        private void OperationStartEvent(Operation type, int state)
        {
            if (type == Operation.FlashSale && state == 0)
            {
                UpdateRedpoint();
            }
        }
 
        private void OnDayEvent()
        {
            UpdateRedpoint();
        }
 
        public void SetDayRemind()
        {
            if (flashSaleRedpoint.state == RedPointState.Simple)
            {
                DayRemind.Instance.SetDayRemind(DayRemind.FLASHSALE_REDPOINT, true);
                UpdateRedpoint();
            }
        }
 
        public bool IsOpen
        {
            get
            {
                OperationBase operationBase;
                OperationTimeHepler.Instance.TryGetOperationTime(Operation.FlashSale, out operationBase);
                return operationBase != null && operationBase.SatisfyOpenCondition() && operationBase.InTime(TimeUtility.ServerNow);
            }
        }
 
        public void SendBuyFlashSale(int index, int id)
        {
            OperationBase operationBase;
            if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.FlashSale, out operationBase))
            {
                OperationFlashSale operation = operationBase as OperationFlashSale;
                if (!operation.InTime(TimeUtility.ServerNow))
                {
                    SysNotifyMgr.Instance.ShowTip("ActiveOutTime");
                    return;
                }
                var gift = operation.GetFlashSaleGift(index, id);
                if (!gift.Equals(default(OperationFlashSale.FlashSaleGift)))
                {
                    var buyInfo = storeModel.GetBuyShopLimit((uint)gift.id);
                    var buyCount = 0;
                    if (buyInfo != null)
                    {
                        buyCount = buyInfo.BuyCnt;
                    }
                    if (buyCount >= gift.limitNum)
                    {
                        return;
                    }
 
                    if (UIHelper.GetMoneyCnt(gift.moneyType) < (ulong)gift.moneyNumber)
                    {
                        switch (gift.moneyType)
                        {
                            case 1:
                                if (VersionConfig.Get().isBanShu)
                                {
                                    SysNotifyMgr.Instance.ShowTip("GoldErr");
                                    return;
                                }
                                WindowCenter.Instance.Open<RechargeTipWin>();
                                break;
                            default:
                                SysNotifyMgr.Instance.ShowTip("LackMoney", gift.moneyType);
                                break;
                        }
                        return;
                    }
                    if (gift.moneyType == 1)
                    {
                        ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
                        Language.Get("OSTimeLimitGiftConfirm", gift.moneyNumber), (bool isOk) =>
                        {
                            if (isOk)
                            {
                                C0803_tagCBuyItemList pak = new C0803_tagCBuyItemList();
                                pak.NPCID = 0;
                                pak.BuyItemIndex = (ushort)gift.id;
                                pak.BuyCount = 1;
                                GameNetSystem.Instance.SendInfo(pak);
                            }
                        });
                    }
                    else
                    {
                        C0803_tagCBuyItemList pak = new C0803_tagCBuyItemList();
                        pak.NPCID = 0;
                        pak.BuyItemIndex = (ushort)gift.id;
                        pak.BuyCount = 1;
                        GameNetSystem.Instance.SendInfo(pak);
                    }
                }
            }
            else
            {
                SysNotifyMgr.Instance.ShowTip("ActiveOutTime");
            }
 
        }
 
        public bool HasNotBuyGift()
        {
            OperationBase operationBase;
            OperationTimeHepler.Instance.TryGetOperationTime(Operation.FlashSale, out operationBase);
            if (operationBase != null && operationBase.InTime(TimeUtility.ServerNow))
            {
                OperationFlashSale operation = operationBase as OperationFlashSale;
                var index = operation.IndexOfFlashShop();
                if (index != -1 && index < operation.flashShops.Count)
                {
                    var flashShop = operation.flashShops[index];
                    for (int i = 0; i < flashShop.gifts.Length; i++)
                    {
                        var gift = flashShop.gifts[i];
                        var buyInfo = storeModel.GetBuyShopLimit((uint)gift.id);
                        if (buyInfo == null || buyInfo.BuyCnt < gift.limitNum)
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
 
        public Redpoint flashSaleRedpoint = new Redpoint(MainRedDot.REDPOINT_OPENSERVER, 20904);
        private void UpdateRedpoint()
        {
            flashSaleRedpoint.state = RedPointState.None;
            if (IsOpen && HasNotBuyGift() && !DayRemind.Instance.GetDayRemind(DayRemind.FLASHSALE_REDPOINT))
            {
                flashSaleRedpoint.state = RedPointState.Simple;
            }
        }
    }
}