少年修仙传客户端代码仓库
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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Wednesday, April 10, 2019
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
 
    public class HazyDemonKingDungeonWin : Window
    {
        [SerializeField] Transform m_ContainerDungeonInfo;
        [SerializeField] CyclicScroll m_CyclicScroll;
        [SerializeField] HazyDemonKingPlayerBehaviour m_BelongToPlayer;
        [SerializeField] RectTransform m_ContainerPlayerList;
        [SerializeField] Text m_MyAtkTargetName;
 
        [SerializeField] Transform m_ContainerInvincibleBuff;
        [SerializeField] SmoothSlider m_BuffSlider;
 
        [SerializeField] Vector3[] m_PlayerListPositions;
        [SerializeField] Vector2 m_PlayerListSize;
 
 
        DateTime invincibleBuffEndTime = DateTime.Now;
        uint invincibleLastTime = 0;
 
        uint myAtkSid = 0;
 
        List<uint> playerIds = new List<uint>();
        List<uint> clonePlayerIds = new List<uint>();
 
        uint belongToPlayerId = 0;
 
        private int dungeonType
        {
            get
            {
                var incidentId = hazyRegionModel.GetIncidentId(ClientDungeonStageUtility.dungeonInfo.mapId, ClientDungeonStageUtility.dungeonInfo.lineId);
                var config = HazyRegionConfig.Get(incidentId);
                if (config != null)
                {
                    return config.dungeonType;
                }
                return 0;
            }
        }
 
        HazyDemonKingModel model { get { return ModelCenter.Instance.GetModel<HazyDemonKingModel>(); } }
        HazyRegionModel hazyRegionModel { get { return ModelCenter.Instance.GetModel<HazyRegionModel>(); } }
        DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
 
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
        }
 
        protected override void OnPreOpen()
        {
            model.onPlayerInfoRefresh += OnPlayerInfoRefresh;
            StatusMgr.onReceiveStatus += OnReceiveStatus;
            GlobalTimeEvent.Instance.secondEvent += PerSecond;
        }
 
        protected override void OnActived()
        {
            base.OnActived();
            Display();
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            m_BelongToPlayer.Dispose();
            m_CyclicScroll.Dispose();
            model.onPlayerInfoRefresh -= OnPlayerInfoRefresh;
            StatusMgr.onReceiveStatus -= OnReceiveStatus;
            GlobalTimeEvent.Instance.secondEvent -= PerSecond;
        }
 
        protected override void OnAfterClose()
        {
        }
 
        protected override void LateUpdate()
        {
            if (TimeUtility.ServerNow < invincibleBuffEndTime)
            {
                m_BuffSlider.delay = 0.2f;
                DisplayInvincibleProgress();
            }
            else
            {
                if (m_ContainerInvincibleBuff.gameObject.activeSelf)
                {
                    m_ContainerInvincibleBuff.SetActive(false);
                }
            }
        }
        #endregion
 
        void Display()
        {
            m_ContainerDungeonInfo.SetActive(dungeonType != 0);
 
            DisplayBelongTo();
            DisplayPlayers();
            DisplayMyTargetName();
            DisplayInvincibleBuff();
        }
 
        void DisplayPlayers()
        {
            if (dungeonType == 0)
            {
                return;
            }
 
            playerIds.Clear();
            clonePlayerIds.Clear();
 
            foreach (var sid in model.GetPlayerIds())
            {
                if (!model.IsExistBelongTo(sid))
                {
                    playerIds.Add(sid);
                }
            }
 
            playerIds.Sort(Compare);
            clonePlayerIds.AddRange(playerIds);
 
            m_CyclicScroll.Init(playerIds);
        }
 
        void DisplayBelongTo()
        {
            if (dungeonType == 0)
            {
                return;
            }
 
            belongToPlayerId = 0;
            foreach (var sid in model.GetPlayerIds())
            {
                if (model.IsExistBelongTo(sid))
                {
                    belongToPlayerId = sid;
                }
            }
 
            m_BelongToPlayer.Dispose();
            if (belongToPlayerId == 0)
            {
                m_BelongToPlayer.SetActive(false);
                m_ContainerPlayerList.localPosition = m_PlayerListPositions[1];
                m_ContainerPlayerList.sizeDelta = m_ContainerPlayerList.sizeDelta.SetY(m_PlayerListSize.y);
                m_CyclicScroll.rectTransform.localPosition = Vector3.zero;
                m_CyclicScroll.rectTransform.sizeDelta = m_CyclicScroll.rectTransform.sizeDelta.SetY(m_PlayerListSize.y);
                return;
            }
            m_ContainerPlayerList.sizeDelta = m_ContainerPlayerList.sizeDelta.SetY(m_PlayerListSize.x);
            m_ContainerPlayerList.localPosition = m_PlayerListPositions[0];
            m_CyclicScroll.rectTransform.localPosition = Vector3.zero;
            m_CyclicScroll.rectTransform.sizeDelta = m_CyclicScroll.rectTransform.sizeDelta.SetY(m_PlayerListSize.x);
            m_BelongToPlayer.SetActive(true);
            m_BelongToPlayer.Display(belongToPlayerId);
        }
 
        void DisplayInvincibleBuff()
        {
            bool existInvincibleBuff = false;
            Status_Base status_Base = null;
            uint serverInstId = 0;
 
            if (dungeonType != 0)
            {
                var actors = GAMgr.Instance.GetTypeList(E_ActorClassType.NpcFightBoss);
                if (actors != null && actors.Count > 0)
                {
                    serverInstId = (actors[0] as GA_NpcFightBoss).ServerInstID;
                    existInvincibleBuff = StatusMgr.Instance.IsExist(serverInstId, model.invincibleBuffId);
                }
            }
            else
            {
                serverInstId = ClientHazyDemonKingStage.GetClientBossSid();
                existInvincibleBuff = StatusMgr.Instance.IsExist(serverInstId, model.invincibleBuffId);
            }
 
 
            if (existInvincibleBuff)
            {
                status_Base = StatusMgr.Instance.Get(serverInstId, model.invincibleBuffId);
            }
 
            m_ContainerInvincibleBuff.SetActive(existInvincibleBuff);
 
            if (existInvincibleBuff && status_Base != null)
            {
                invincibleBuffEndTime = status_Base.receiveTime.AddTicks(status_Base.LastTime * TimeSpan.TicksPerMillisecond);
                invincibleLastTime = (uint)status_Base.LastTime;
            }
            m_BuffSlider.delay = 0f;
            DisplayInvincibleProgress();
        }
 
        void DisplayInvincibleProgress()
        {
            var milliSeconds = Mathf.CeilToInt((float)(invincibleBuffEndTime - TimeUtility.ServerNow).TotalMilliseconds);
            if (invincibleLastTime == 0)
            {
                invincibleLastTime = (uint)milliSeconds;
            }
            var progress = Mathf.Clamp01((float)milliSeconds / invincibleLastTime);
            m_BuffSlider.value = progress;
        }
 
        private void OnPlayerInfoRefresh()
        {
            DisplayPlayers();
        }
 
        private void OnReceiveStatus(int buffId)
        {
            if (buffId == model.invincibleBuffId)
            {
                DisplayInvincibleBuff();
            }
        }
 
        private void PerSecond()
        {
            if (dungeonType == 0)
            {
                return;
            }
 
            if (clonePlayerIds.Count > 0)
            {
                clonePlayerIds.Sort(Compare);
            }
 
            if (clonePlayerIds.Count == playerIds.Count)
            {
                for (int i = 0; i < clonePlayerIds.Count; i++)
                {
                    if (clonePlayerIds[i] != playerIds[i])
                    {
                        DisplayPlayers();
                        return;
                    }
                }
            }
 
            var _sid = model.GetPlayerAtkTarget(PlayerDatas.Instance.PlayerId);
            if (_sid != myAtkSid)
            {
                DisplayMyTargetName();
            }
 
            if (!model.IsExistBelongTo(belongToPlayerId))
            {
                foreach (var sid in model.GetPlayerIds())
                {
                    if (model.IsExistBelongTo(sid))
                    {
                        belongToPlayerId = sid;
                        DisplayBelongTo();
                        DisplayPlayers();
                        break;
                    }
                }
            }
        }
 
        void DisplayMyTargetName()
        {
            if (dungeonType == 0)
            {
                return;
            }
 
            m_MyAtkTargetName.text = string.Empty;
 
            myAtkSid = model.GetPlayerAtkTarget(PlayerDatas.Instance.PlayerId);
            var actor = GAMgr.Instance.GetBySID(myAtkSid);
 
            if (actor != null)
            {
                if (actor is GA_NpcClientFightBoss)
                {
                    m_MyAtkTargetName.text = (actor as GA_NpcClientFightBoss).NpcConfig.charName;
                }
                else if (actor is GA_NpcFightBoss)
                {
                    m_MyAtkTargetName.text = (actor as GA_NpcFightBoss).NpcConfig.charName;
                }
                else if (actor is GA_Player)
                {
                    m_MyAtkTargetName.text = UIHelper.ServerStringTrim((actor as GA_Player).ActorInfo.PlayerName);
                }
            }
        }
 
        int Compare(uint lhs, uint rhs)
        {
            bool lhs_isMySelf = lhs == PlayerDatas.Instance.PlayerId;
            bool rhs_isMySelf = rhs == PlayerDatas.Instance.PlayerId;
            if (lhs_isMySelf != rhs_isMySelf)
            {
                return lhs_isMySelf.CompareTo(rhs_isMySelf);
            }
 
            var playerId = PlayerDatas.Instance.baseData.PlayerID;
            var lhs_atkself = model.GetPlayerAtkTarget(lhs) == playerId;
            var rhs_atkself = model.GetPlayerAtkTarget(rhs) == playerId;
            if (lhs_atkself != rhs_atkself)
            {
                return -lhs_atkself.CompareTo(rhs_atkself);
            }
            return 0;
        }
    }
 
}