少年修仙传客户端代码仓库
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
using vnxbqy.UI;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;
using System.Linq;
using System;
 
public class TreasureLuckyDrawBehavior : MonoBehaviour
{
    [SerializeField] List<ButtonEx> btnTreasureTagList = new List<ButtonEx>();
    [SerializeField] List<ButtonEx> btnTreasureTagFakeList = new List<ButtonEx>(); //为了实现遮挡效果做的假按钮,实际点击btnTreasureTagList
    [SerializeField] List<ImageEx> imgTreasureTagList = new List<ImageEx>();
    [SerializeField] List<TextEx> txtTreasureTagList = new List<TextEx>();
    [SerializeField] TextEx txtGuaranteCount;
    [SerializeField] ButtonEx btnOneGo;
    [SerializeField] TextEx txtOneGo;
    [SerializeField] ImageEx imgOneIcon;
    [SerializeField] TextEx txtOneCount;
    [SerializeField] TextEx txtOneFree;
    [SerializeField] ButtonEx btnManyGo;
    [SerializeField] TextEx txtManyGo;
    [SerializeField] ImageEx imgManyIcon;
    [SerializeField] TextEx txtManyCount;
    [SerializeField] Button btnSkip;
    [SerializeField] Image imgSkip;
    [SerializeField] RichText txtTip;
    [SerializeField] UIEffect uiEffect;
    [SerializeField] TextEx todayMaxText;
    const int MaxTreasureTypeTabCount = 4;
    int type;
    HappyXBModel XBModel { get { return ModelCenter.Instance.GetModel<HappyXBModel>(); } }
    RoleParticularModel model { get { return ModelCenter.Instance.GetModelEx<RoleParticularModel>(); } }
    PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
    StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
    public void Display(int type)
    {
        this.type = type;
        XBTypeInfo typeInfo = XBModel.GetXBInfoByType(type);
        if (typeInfo == null)
        {
            typeInfo = new XBTypeInfo()
            {
                xbType = type,
                luckValue = 0,
                freeCountToday = 0,
                treasureCount = 0,
            };
        }
        var funcSet = XBModel.GetXBFuncSet(type);
        bool isHaveFree = XBModel.IsHaveFreeXB(type);
        int toolCnt0 = playerPack.GetItemCountByID(PackType.Item, funcSet.costToolIds[0]);
        int toolCnt1 = playerPack.GetItemCountByID(PackType.Item, funcSet.costToolIds[1]);
        int luckValue = typeInfo.luckValue;
        var config = TreasureSetConfig.Get(type);
        int fullLuck = config.FullLucky;
        int onceLucky = config.OnceLucky;
        int guaranteCount = (fullLuck - luckValue) / onceLucky;
        ShowTreasureTagBtn();
        txtOneFree.SetActive(isHaveFree);
        imgOneIcon.SetActive(!isHaveFree);
        txtOneCount.SetActive(!isHaveFree);
        RefreshSkipUI();
        TreasurePavilionModel.Instance.UpdateLuckyDrawRedpoint();
        txtGuaranteCount.text = Language.Get("TreasurePavilion05", guaranteCount);
        txtOneGo.text = Language.Get("HappyXB101", funcSet.xbNums[0]);
        txtManyGo.text = Language.Get("HappyXB101", funcSet.xbNums[1]);
        txtOneCount.text = StringUtility.Contact(toolCnt0, "/", funcSet.xbNums[0]);
        txtManyCount.text = StringUtility.Contact(toolCnt1, "/", funcSet.xbNums[1]);
        txtTip.text = Language.Get("TreasurePavilion07", Language.Get("TreasurePavilion06"));
        ItemConfig itemConfig1 = ItemConfig.Get(funcSet.costToolIds[0]);
        ItemConfig itemConfig2 = ItemConfig.Get(funcSet.costToolIds[1]);
        if (itemConfig1 != null)
        {
            imgOneIcon.SetSprite(itemConfig1.IconKey);
        }
        if (itemConfig2 != null)
        {
            imgManyIcon.SetSprite(itemConfig2.IconKey);
        }
 
        todayMaxText.text = Language.Get("TreasureCntTodayMax", config.DailyMaxCount);
    }
    void ShowTreasureTagBtn()
    {
        int[] xbIDArr = TreasurePavilionModel.Instance.xbIDArr;
        var luckyDrawFuncIDDict = TreasurePavilionModel.Instance.luckyDrawFuncIDDict;
        var keyList = luckyDrawFuncIDDict.Keys.ToList();
        for (int i = 0; i < MaxTreasureTypeTabCount; i++)
        {
            if (i < xbIDArr.Length)
            {
                if (!luckyDrawFuncIDDict.ContainsKey(xbIDArr[i]))
                    continue;
                if (!FuncOpen.Instance.IsFuncOpen(luckyDrawFuncIDDict[xbIDArr[i]]))
                    continue;
                btnTreasureTagList[i].SetActiveIL(true);
                btnTreasureTagFakeList[i].SetActiveIL(true);
                imgTreasureTagList[i].SetActiveIL(TreasurePavilionModel.Instance.xbIndex == i);
                txtTreasureTagList[i].GetComponent<TextEx>().text = Language.Get("TreasureTypeTabTitle_" + i);
            }
            else
            {
                btnTreasureTagList[i].SetActiveIL(false);
                btnTreasureTagFakeList[i].SetActiveIL(false);
            }
        }
    }
    private void RefreshSkipUI()
    {
        imgSkip.SetActive(XBModel.isJumpGubaoXB);
    }
    private void RefreshXBResult()
    {
        if (XBModel.isJumpGubaoXB)
        {
            TreasurePavilionModel.Instance.isEffectPlaying = false;
            WindowCenter.Instance.Open<HappyXBGetItemWin>();
        }
        else
        {
            uiEffect.Play();
        }
    }
    void Awake()
    {
        btnSkip.SetListener(() =>
        {
            XBModel.isJumpGubaoXB = !XBModel.isJumpGubaoXB;
            RefreshSkipUI();
        });
 
        for (int i = 0; i < btnTreasureTagList.Count; i++)
        {
            int index = i;
            int[] xbIDArr = TreasurePavilionModel.Instance.xbIDArr;
            btnTreasureTagList[i].SetListener(() =>
            {
                if (index < xbIDArr.Length)
                {
                    TreasurePavilionModel.Instance.xbIndex = index;
 
                    if (index == 0)
                    {
                        XBModel.title = HappXBTitle.Gubao1;
                    }
                    else if (index == 1)
                    {
                        XBModel.title = HappXBTitle.Gubao2;
                    }
                    else if (index == 2)
                    {
                        XBModel.title = HappXBTitle.Gubao3;
                    }
                    else if (index == 3)
                    {
                        XBModel.title = HappXBTitle.Gubao4;
                    }
                    Display(type);
                }
 
            });
        }
 
        btnOneGo.SetListener(() =>
        {
            if (TreasurePavilionModel.Instance.isEffectPlaying)
                return;
 
            var config = TreasureSetConfig.Get(type);
            if (XBModel.GetXBInfoByType(type).treasureCountToday + config.TreasureCountList[0] > config.DailyMaxCount)
            {
                SysNotifyMgr.Instance.ShowTip("XBTodayMax");
                return;
            }
 
 
            TreasurePavilionModel.Instance.isEffectPlaying = true;
 
            if (XBModel.IsHaveFreeXB(type))
            {
                XBModel.SendXBQuest(type, 0, 1);
            }
            else
            {
                var funcSet = XBModel.GetXBFuncSet(type);
                if (XBModel.IsHaveOneXBTool(type))
                {
                    XBModel.SendXBQuest(type, 0, 2);
                }
                else
                {
                    TreasurePavilionModel.Instance.isEffectPlaying = false;
                    int moneyType = XBModel.XBCostTypeDict[type];
                    int costToolCount = funcSet.costToolNums[0];
                    int xbOneMoney = TreasureSetConfig.Get(type).CostMoneyList[0];
 
                    if (UIHelper.GetMoneyCnt(moneyType) >= (ulong)xbOneMoney)
                    {
                        storeModel.UseMoneyCheck(xbOneMoney, () =>
                        {
                            TreasurePavilionModel.Instance.isEffectPlaying = true;
                            XBModel.SendXBQuest(type, 0, 0);
                        }, 4, fullTip: Language.Get("TreasurePavilion08", xbOneMoney, moneyType, funcSet.costToolIds[0], costToolCount));
                    }
                    else
                    {
                        SysNotifyMgr.Instance.ShowTip("LackMoney", moneyType);
                    }
                }
            }
        });
 
        btnManyGo.SetListener(() =>
        {
            if (TreasurePavilionModel.Instance.isEffectPlaying)
                return;
 
            var config = TreasureSetConfig.Get(type);
            if (XBModel.GetXBInfoByType(type).treasureCountToday + config.TreasureCountList[1] > config.DailyMaxCount)
            {
                SysNotifyMgr.Instance.ShowTip("XBTodayMax");
                return;
            }
 
            TreasurePavilionModel.Instance.isEffectPlaying = true;
            var funcSet = XBModel.GetXBFuncSet(type);
            int toolCnt = 0;
            int needToolCnt = 0;
            int needMoney = 0;
            if (XBModel.IsHaveManyXBToolEx(type, out toolCnt, out needToolCnt, out needMoney))
            {
                if (toolCnt >= needToolCnt)
                {
                    XBModel.CheckXBManyLimit(0, type, 2);
                    return;
                }
            }
 
            TreasurePavilionModel.Instance.isEffectPlaying = false;
            int moneyType = XBModel.XBCostTypeDict[type];
            int xbManyMoney = needMoney == 0 ? funcSet.xbPrices[1] : needMoney;
 
            if (UIHelper.GetMoneyCnt(moneyType) >= (ulong)xbManyMoney)
            {
                storeModel.UseMoneyCheck(xbManyMoney, () =>
                {
                    TreasurePavilionModel.Instance.isEffectPlaying = true;
                    XBModel.SendXBQuest(type, 1, toolCnt > 0 ? 2 : 0);
                }, 4, fullTip: Language.Get("TreasurePavilion08", xbManyMoney, moneyType, funcSet.costToolIds[1], needToolCnt - toolCnt));
            }
            else
            {
                SysNotifyMgr.Instance.ShowTip("LackMoney", moneyType);
            }
 
        });
    }
 
    void OnEnable()
    {
        XBModel.RefreshXBResultAct += RefreshXBResult;
        XBModel.RefreshXBTypeInfoAct += RefreshXBTypeInfo;
        uiEffect.OnComplete += OnCompleted;
    }
 
    void OnDisable()
    {
 
        XBModel.RefreshXBResultAct -= RefreshXBResult;
        XBModel.RefreshXBTypeInfoAct -= RefreshXBTypeInfo;
        uiEffect.OnComplete -= OnCompleted;
    }
 
    private void RefreshXBTypeInfo()
    {
        Display(type);
    }
 
    public void OnCompleted()
    {
        TreasurePavilionModel.Instance.isEffectPlaying = false;
        WindowCenter.Instance.Open<HappyXBGetItemWin>();
    }
 
    public void Open()
    {
        gameObject.SetActive(true);
    }
 
    public void Close()
    {
        gameObject.SetActive(false);
    }
}