少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
    public class DungeonReturnBloodBehaviour : MonoBehaviour
    {
        [SerializeField] Button m_MoneyReturnBlood;
        [SerializeField] ReturnBloodBeha m_MoneyReturnBeha;
        [SerializeField] Button m_FreeReturnBlood;
        [SerializeField] ReturnBloodBeha m_FreeReturnBeha;
 
        int mapId = 0;
 
        int moneyReturnId = 0;
        int freeReturnId = 0;
 
        DungeonUseBuffModel model
        {
            get { return ModelCenter.Instance.GetModel<DungeonUseBuffModel>(); }
        }
 
        private void Awake()
        {
            m_FreeReturnBlood.AddListener(FreeReturnBlood);
            m_MoneyReturnBlood.AddListener(MoneyReturnBlood);
        }
 
        public void Display(int mapId)
        {
            this.mapId = mapId;
 
            moneyReturnId = 0;
            freeReturnId = 0;
 
            var list = model.GetDungeonUseBuffs(mapId);
            for (int i = 0; i < list.Count; i++)
            {
                var config = DungeonUseBuffConfig.Get(list[i]);
                if (config.MoneyCnt != 0)
                {
                    moneyReturnId = list[i];
                }
                else
                {
                    freeReturnId = list[i];
                }
            }
 
            m_MoneyReturnBlood.SetActive(moneyReturnId != 0);
            if (moneyReturnId != 0)
            {
                m_MoneyReturnBeha.Display(moneyReturnId);
            }
            m_FreeReturnBlood.SetActive(freeReturnId != 0);
            if (freeReturnId != 0)
            {
                m_FreeReturnBeha.Display(freeReturnId);
            }
 
            DisplayTime();
 
            model.onUseBuffTimeRefresh += OnUseBuffTimeRefresh;
        }
 
        void DisplayTime()
        {
            if (moneyReturnId != 0)
            {
                var seconds = GetBuffSeconds(moneyReturnId);
                m_MoneyReturnBeha.SetCoolDown(seconds);
            }
 
            if (freeReturnId != 0)
            {
                var seconds = GetBuffSeconds(freeReturnId);
                m_FreeReturnBeha.SetCoolDown(seconds);
            }
        }
 
        private void LateUpdate()
        {
            if (m_FreeReturnBlood.gameObject.activeSelf)
            {
                m_FreeReturnBeha.OnUpdate();
            }
            if (m_MoneyReturnBlood.gameObject.activeSelf)
            {
                m_MoneyReturnBeha.OnUpdate();
            }
        }
 
        float GetBuffSeconds(int id)
        {
            var config = DungeonUseBuffConfig.Get(id);
            var tick = model.GetUseBuffTime(config.DataMapId, config.MoneyCnt);
            var useTime = TimeUtility.GetTime(tick);
            var seconds = Mathf.Max(0f, config.CD - (float)(TimeUtility.ServerNow - useTime).TotalSeconds);
            return seconds;
        }
 
        private void MoneyReturnBlood()
        {
            if (moneyReturnId != 0)
            {
                var config = DungeonUseBuffConfig.Get(moneyReturnId);
                var seconds = GetBuffSeconds(moneyReturnId);
                if (seconds <= 0)
                {
                    if (model.moneyCostRemind)
                    {
                        var skillConfig = SkillConfig.Get(config.BuffID);
                        ConfirmCancel.ToggleConfirmCancel(Language.Get("Mail101"),
                            Language.Get("HazyReturnBloodRemind", config.MoneyCnt, skillConfig.EffectValue11 / 100),
                            Language.Get("InspireNoMention"),
                            (bool isOk, bool toggle) =>
                            {
                                if (toggle)
                                {
                                    model.moneyCostRemind = false;
                                }
                                if (isOk)
                                {
                                    if (PlayerDatas.Instance.baseData.diamond < config.MoneyCnt)
                                    {
                                        WindowCenter.Instance.Open<RechargeTipWin>();
                                        return;
                                    }
                                    var pak = new CB10A_tagCMFBBuyBuff();
                                    pak.MapID = (uint)config.DataMapId;
                                    pak.MoneyCnt = (ushort)config.MoneyCnt;
                                    GameNetSystem.Instance.SendInfo(pak);
                                }
                            });
                    }
                    else
                    {
                        var pak = new CB10A_tagCMFBBuyBuff();
                        pak.MapID = (uint)config.DataMapId;
                        pak.MoneyCnt = (ushort)config.MoneyCnt;
                        GameNetSystem.Instance.SendInfo(pak);
                    }
                }
            }
        }
 
        private void FreeReturnBlood()
        {
            if (freeReturnId != 0)
            {
                var config = DungeonUseBuffConfig.Get(freeReturnId);
                var seconds = GetBuffSeconds(freeReturnId);
                if (seconds <= 0)
                {
                    var pak = new CB10A_tagCMFBBuyBuff();
                    pak.MapID = (uint)config.DataMapId;
                    pak.MoneyCnt = (ushort)config.MoneyCnt;
                    GameNetSystem.Instance.SendInfo(pak);
                }
            }
        }
 
        private void OnUseBuffTimeRefresh()
        {
            DisplayTime();
        }
 
        public void Dispose()
        {
            model.onUseBuffTimeRefresh -= OnUseBuffTimeRefresh;
        }
 
        [Serializable]
        public class ReturnBloodBeha
        {
            [SerializeField] Image m_Mask;
            [SerializeField] Text m_Time;
            [SerializeField] Text m_Cost;
            [SerializeField] Text m_Effect;
 
            int id = 0;
            float seconds = 0f;
 
            public void Display(int id)
            {
                this.id = id;
                var config = DungeonUseBuffConfig.Get(id);
                if (config.MoneyCnt != 0)
                {
                    m_Cost.text = config.MoneyCnt.ToString();
                }
 
                var skillConfig = SkillConfig.Get(config.BuffID);
                m_Effect.text = Language.Get("HazyReturnBlood", skillConfig.EffectValue11 / 100);
 
                m_Mask.SetActive(false);
            }
 
            public void SetCoolDown(float seconds)
            {
                this.seconds = seconds;
                if (seconds <= 0 && m_Mask.gameObject.activeSelf)
                {
                    m_Mask.SetActive(false);
                }
            }
 
            void DisplayMask()
            {
                var config = DungeonUseBuffConfig.Get(id);
                var progress = Mathf.Clamp01(seconds / config.CD);
                m_Mask.fillAmount = progress;
                if (!m_Mask.gameObject.activeSelf)
                {
                    m_Mask.SetActive(true);
                }
                m_Time.text = ((int)seconds).ToString();
            }
 
            public void OnUpdate()
            {
                if (seconds > 0f)
                {
                    seconds -= Time.deltaTime;
                    DisplayMask();
 
                    if (seconds <= 0f)
                    {
                        m_Mask.SetActive(false);
                    }
                }
            }
        }
    }
}