少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Wednesday, November 01, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
 
    public class DungeonBuyTimesWin : Window
    {
        [SerializeField] Button m_Close;
        [SerializeField] Text m_DungeonName;
        [SerializeField] Text m_TodayBuyTimes;
        [SerializeField] Text m_CostRemind;
        [SerializeField] RectTransform m_ContainerVipUp;
        [SerializeField] Text m_VipUpRemind;
        [SerializeField] RectTransform m_ContainerBuylimit;
        [SerializeField] Button m_BuyTimes;
        [SerializeField] Button m_GotoRecharge;
 
        DungeonRecord dungeonRecord;
        string costFormula = string.Empty;
 
        DungeonModel model { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
        VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
 
        protected override void BindController()
        {
 
        }
 
        protected override void AddListeners()
        {
            m_Close.onClick.AddListener(CloseClick);
            m_BuyTimes.onClick.AddListener(BuyTimes);
            m_GotoRecharge.onClick.AddListener(GotoRecharge);
        }
 
        protected override void OnPreOpen()
        {
            PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
            vipModel.OnVipTimeEvent += OnVipTimeEvent;
            model.updateDungeonBuyCnt += UpdateDungeonBuyCnt;
            if (model.TryGetRecord(model.currentDungeon.mapId, out dungeonRecord))
            {
                Display();
            }
            else
            {
                CloseImmediately();
            }
        }
 
        protected override void OnAfterOpen()
        {
 
        }
 
        protected override void OnPreClose()
        {
            PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
            vipModel.OnVipTimeEvent -= OnVipTimeEvent;
            model.updateDungeonBuyCnt -= UpdateDungeonBuyCnt;
        }
 
        protected override void OnAfterClose()
        {
        }
 
        private void OnVipTimeEvent()
        {
            Display();
        }
 
        private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType)
        {
            if (refreshType == PlayerDataType.VIPLv)
            {
                Display();
            }
        }
 
        private void UpdateDungeonBuyCnt()
        {
            Display();
        }
 
        void Display()
        {
            var openTimeConfig = DungeonOpenTimeConfig.Get(model.currentDungeon.mapId);
 
            m_DungeonName.text = openTimeConfig.FBName;
 
            int defaultTimes = VipPrivilegeConfig.GetVipPrivilegeData((VipPrivilegeType)openTimeConfig.BuyTimesID, 0);
            int vipBuyTimes = vipModel.GetVipPrivilegeCnt((VipPrivilegeType)openTimeConfig.BuyTimesID) - defaultTimes;
            var totalTimes = defaultTimes + vipBuyTimes;
            var surplusTimes = totalTimes - dungeonRecord.buyTimes;
            var canBuyTimes = defaultTimes > dungeonRecord.buyTimes || surplusTimes > 0;
 
            var surplusTimeDisplay = UIHelper.AppendColor(surplusTimes > 0 ? TextColType.Green : TextColType.Red, surplusTimes.ToString(), true);
 
            m_TodayBuyTimes.text = Language.Get("TimesBuyLanguage1", surplusTimeDisplay, totalTimes);
            int nextVipLv = vipModel.GetPrivilegeVipLv((VipPrivilegeType)openTimeConfig.BuyTimesID, totalTimes);
 
            var currentVipLv = PlayerDatas.Instance.baseData.VIPLv;
            int vipHasTimesLv = vipModel.GetPrivilegeVipLv((VipPrivilegeType)openTimeConfig.BuyTimesID, defaultTimes);
 
            bool displayUp = (currentVipLv >= vipHasTimesLv && nextVipLv != -1) || (currentVipLv < vipHasTimesLv && surplusTimes == 0 && nextVipLv != -1);
            m_ContainerVipUp.SetActive(displayUp);
            m_GotoRecharge.SetActive(nextVipLv != -1 && !canBuyTimes);
 
            if (displayUp)
            {
                var _buyTimes = VipPrivilegeConfig.GetVipPrivilegeData((VipPrivilegeType)openTimeConfig.BuyTimesID, nextVipLv);
                var upTimes = _buyTimes - totalTimes;
                m_VipUpRemind.text = Language.Get("TimesBuyLanguage2", nextVipLv, upTimes);
            }
            if (model.TryGetBuyCountCost(model.currentDungeon.mapId, out costFormula))
            {
                Equation.Instance.Clear();
                Equation.Instance.AddKeyValue("hasBuyCnt", dungeonRecord.buyTimes);
                int _cost = Equation.Instance.Eval<int>(costFormula);
                m_CostRemind.text = Language.Get("TimesBuyLanguage3", _cost);
            }
 
            m_BuyTimes.SetActive(canBuyTimes);
            m_GotoRecharge.SetActive(!canBuyTimes && nextVipLv != -1);
            m_ContainerBuylimit.SetActive(!canBuyTimes && nextVipLv == -1);
        }
 
        private void BuyTimes()
        {
            if (!CheckSpecialDungeon())
            {
                return;
            }
            Equation.Instance.Clear();
            Equation.Instance.AddKeyValue("hasBuyCnt", dungeonRecord.buyTimes);
            model.TryGetBuyCountCost(model.currentDungeon.mapId, out costFormula);
            int _cost = Equation.Instance.Eval<int>(costFormula);
            if (PlayerDatas.Instance.baseData.diamond >= _cost)
            {
                model.RequestBuyEnterCount(model.currentDungeon.mapId);
            }
            else
            {
                if (VersionConfig.Get().isBanShu)
                {
                    SysNotifyMgr.Instance.ShowTip("GoldErr");
                    return;
                }
 
                WindowCenter.Instance.Open<RechargeTipWin>();
            }
        }
 
        private bool CheckSpecialDungeon()
        {
            if (DemonJarModel.DATA_MAPID == model.currentDungeon.mapId)
            {
                var _totalTimes = model.GetTotalTimes(DemonJarModel.DATA_MAPID);
                var _enterTimes = model.GetEnterTimes(DemonJarModel.DATA_MAPID);
                if ((_totalTimes - _enterTimes) >= DemonJarModel.TOTALTIME_LIMIT)
                {
                    ServerTipDetails.DisplayNormalTip(Language.Get("DemonJar18"));
                    return false;
                }
            }
            else if (JadeDynastyBossModel.JADEDYNASTY_MAP == model.currentDungeon.mapId)
            {
                var _totalTimes = model.GetTotalTimes(JadeDynastyBossModel.JADEDYNASTY_MAP);
                var _enterTimes = model.GetEnterTimes(JadeDynastyBossModel.JADEDYNASTY_MAP);
                var jadeDynastyBossModel = ModelCenter.Instance.GetModel<JadeDynastyBossModel>();
                if ((_totalTimes - _enterTimes) >= jadeDynastyBossModel.challengeLimitCount)
                {
                    ServerTipDetails.DisplayNormalTip(Language.Get("DemonJar18"));
                    return false;
                }
                var mapId = PlayerDatas.Instance.baseData.MapID;
                var dataMapId = model.GetDataMapIdByMapId(mapId);
                if (dataMapId == JadeDynastyBossModel.JADEDYNASTY_MAP)
                {
                    SysNotifyMgr.Instance.ShowTip("JadeDynastyBossBuyTimesError");
                    return false;
                }
            }
            return true;
        }
 
        private void GotoRecharge()
        {
            WindowCenter.Instance.Close<FindPreciousFrameWin>();
            WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.VipRechargeFunc1);
        }
    }
 
}