少年修仙传客户端代码仓库
Client_PangDeRong
2018-10-15 a619ed5c25fe6c47580c7f16a024e2dc8531a311
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
using UnityEngine;
using UnityEngine.UI;
using EnhancedUI.EnhancedScroller;
using TableConfig;
using System;
 
namespace Snxxz.UI
{
    public class FlashSaleItemCell : ScrollerUI
    {
        [SerializeField] CommonItemBaisc itemBaisc;
        [SerializeField] Text originalPrice;
        [SerializeField] Image originalMoneyIcon;
        [SerializeField] Text presentPrice;
        [SerializeField] Image presentMoneyIcon;
        [SerializeField] Image stateImg;
        [SerializeField] Button flashSaleBtn;
        [SerializeField] Text btnStateText;
        [SerializeField] Text fullServerRemainNum;
 
        public const int RefreshFullServerBuyType = 8;
 
        FlashRushToBuyModel rushToBuyModel { get { return ModelCenter.Instance.GetModel<FlashRushToBuyModel>(); } }
        StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
        HeavenBattleModel battleModel { get { return ModelCenter.Instance.GetModel<HeavenBattleModel>(); } }
        ItemTipsModel tipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
 
        OperationFlashRushToBuy.FlashSaleItem saleItem;
        int buyState = -1;
        private void OnEnable()
        {
            battleModel.RefreshGameRecInfoAct += UpdateFullServerBuy;
            storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
            rushToBuyModel.UpdateAllAppointmentEvent += UpdateAllAppointmentInfo;
            rushToBuyModel.UpdateAppointmentEvent += UpdateAppointmentInfo;
        }
 
        private void OnDisable()
        {
            storeModel.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
            battleModel.RefreshGameRecInfoAct -= UpdateFullServerBuy;
            rushToBuyModel.UpdateAllAppointmentEvent -= UpdateAllAppointmentInfo;
            rushToBuyModel.UpdateAppointmentEvent -= UpdateAppointmentInfo;
        }
 
        public override void Refresh(CellView cell)
        {
            if (rushToBuyModel.presentFlashShop == null) return;
 
            saleItem = rushToBuyModel.presentFlashShop.items[cell.index];
            ItemCellModel cellModel = new ItemCellModel(saleItem.itemId,true,(ulong)saleItem.itemCount,saleItem.isBind);
            itemBaisc.Init(cellModel);
            itemBaisc.cellBtn.RemoveAllListeners();
            itemBaisc.cellBtn.AddListener(()=>
            {
                ItemAttrData attrData = new ItemAttrData(saleItem.itemId,true, (ulong)saleItem.itemCount, -1,saleItem.isBind);
                tipsModel.SetItemTipsModel(attrData);
            });
            originalMoneyIcon.SetIconWithMoneyType(saleItem.moneyType);
            presentMoneyIcon.SetIconWithMoneyType(saleItem.moneyType);
            originalPrice.text = saleItem.moneyOriginal.ToString();
            presentPrice.text = saleItem.moneyNumber.ToString();
            UpdateSaleItem();
            UpdateSaleItemSellState();
        }
 
        private void RefreshBuyShopLimitEvent()
        {
            UpdateSaleItemSellState();
        }
 
        private void UpdateFullServerBuy(int type)
        {
            if (type != RefreshFullServerBuyType) return;
            UpdateSaleItemSellState();
        }
 
 
        private void UpdateAllAppointmentInfo()
        {
            UpdateSaleItem();
        }
 
        private void UpdateAppointmentInfo(int shopGuid)
        {
            if (saleItem == null || shopGuid != saleItem.shopGuid) return;
            UpdateSaleItem();
        }
 
        private void UpdateSaleItem()
        {
            if (rushToBuyModel.presentFlashShop == null) return;
 
            StoreConfig storeConfig = Config.Instance.Get<StoreConfig>(saleItem.shopId);
            flashSaleBtn.RemoveAllListeners();
            var operation = rushToBuyModel.GetOperationFlashRushToBuy();
            int seconds = 0;
            buyState = operation.GetBuyTimeState(TimeUtility.ServerNow,rushToBuyModel.presentFlashShop.dayIndex,
                rushToBuyModel.presentFlashShop.timeIndex,out seconds);
 
            switch(buyState)
            {
                case -1:
                    if(saleItem.isAppointment == 0)
                    {
                        btnStateText.text = "预约";
                        flashSaleBtn.AddListener(() => { rushToBuyModel.SendFlashSaleAppointment(saleItem.shopGuid, 1); });
                    }
                    else
                    {
                        btnStateText.text = "取消预约";
                        flashSaleBtn.AddListener(() => { rushToBuyModel.SendFlashSaleAppointment(saleItem.shopGuid, 0); });
                    }
                    break;
                case 0:
                    btnStateText.text = "秒杀";
                    flashSaleBtn.AddListener(() => { storeModel.SendBuyShopItem(storeConfig,saleItem.itemCount); });
                    break;
            }
        }
 
        private void UpdateSaleItemSellState()
        {
            int fullSeverRemain = 0;
            int sellState = GetSellSate(out fullSeverRemain);
            fullServerRemainNum.text = fullSeverRemain.ToString();
            switch (sellState)
            {
                case 0:
                    stateImg.gameObject.SetActive(false);
                    flashSaleBtn.gameObject.SetActive(true);
                    break;
                case 1:
                    stateImg.gameObject.SetActive(true);
                    flashSaleBtn.gameObject.SetActive(false);
                    break;
                case 2:
                    stateImg.gameObject.SetActive(true);
                    flashSaleBtn.gameObject.SetActive(false);
                    break;
            }
 
        }
        /// <summary>
        /// 0 秒杀 1 已买到 2 已抢光
        /// </summary>
        /// <returns></returns>
        private int GetSellSate(out int fullRemainNum)
        {
            fullRemainNum = 0;
    
            var buyInfo = storeModel.GetBuyShopLimit((uint)saleItem.shopId);
            var buyCount = 0;
            var fullServerInfo = rushToBuyModel.GetFullServerInfo();
            if(buyState != -1)
            {
                if (fullServerInfo != null && fullServerInfo.Value1 == saleItem.shopId)
                {
                    fullRemainNum = saleItem.fullServerLimitNum - fullServerInfo.Value2;
                }
                else
                {
                    fullRemainNum = saleItem.fullServerLimitNum;
                }
                if (buyInfo != null)
                {
                    buyCount = buyInfo.BuyCnt;
                }
                if (buyCount >= saleItem.limitNum)
                {
                    return 1;
                }
 
                if (fullRemainNum <= 0)
                {
                    return 2;
                }
            }
            else
            {
                fullRemainNum = saleItem.fullServerLimitNum;
            }
            return 0;
        }
    }
}