少年修仙传客户端代码仓库
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, October 17, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using System;
 
namespace vnxbqy.UI
{
 
    public struct TheirTeam
    {
        public int mapId;
        public int mapEx;//如果mapex 是-1 ,那么意味着是所有分线的集合。
        public bool matching;
        public int captainer;
        public string captainerName;
        public int realm;
        public int memberCount;
        public int levelMin;
        public int levelMax;
 
        public TheirTeam(HB904_tagGCSceneTeamRefresh.tagGCSceneTeam _serverInfo)
        {
            this.mapId = TeamModel.CURRENTMAP_MISSION;
            this.mapEx = -1;
            this.matching = false;
            this.captainer = (int)_serverInfo.PlayerID;
            this.captainerName = _serverInfo.PlayerName;
            this.realm = _serverInfo.RealmLV;
            this.memberCount = _serverInfo.MemberCount;
            this.levelMin = _serverInfo.ReqMinLV;
            this.levelMax = _serverInfo.ReqMaxLV;
        }
 
        public TheirTeam(int _mapId, int _mapEx, bool _matching, HB909_tagGCTagMapTeamList.tagGCTagMapTeam _serverInfo)
        {
            this.mapId = _mapId;
            this.mapEx = _mapEx;
            this.matching = _matching;
            this.captainer = (int)_serverInfo.PlayerID;
            this.captainerName = _serverInfo.PlayerName;
            this.realm = _serverInfo.RealmLV;
            this.memberCount = _serverInfo.MemberCount;
            this.levelMin = _serverInfo.ReqMinLV;
            this.levelMax = _serverInfo.ReqMaxLV;
        }
 
        public static int Sort(TheirTeam lhs, TheirTeam rhs)
        {
            return lhs.memberCount < 4 && lhs.memberCount > rhs.memberCount ? -1 : 1;
        }
 
    }
 
    public class MyTeam
    {
        int m_TeamId;
        public int teamId {
            get { return inTeam ? m_TeamId : 0; }
            set { m_TeamId = value; }
        }
 
        TeamMission m_Mission = new TeamMission(TeamModel.CURRENTMAP_MISSION, 0);
        public TeamMission mission {
            get {
                return m_Mission;
            }
            set {
 
                if (m_Mission != value)
                {
                    m_Mission = value;
                    if (autoPrepare.auto && autoPrepare.cancelWhenTargetChange)
                    {
                        autoPrepare.CancelAutoPrepare();
                    }
                }
            }
        }
 
        int m_LevelMin = 1;
        public int levelMin {
            get {
                return m_LevelMin;
            }
            set {
                m_LevelMin = value;
            }
        }
 
        int m_LevelMax = 1;
        public int levelMax {
            get {
                return m_LevelMax;
            }
            set {
                m_LevelMax = value;
            }
        }
 
        List<Teammate> members = new List<Teammate>();
        public int memberCount {
            get { return members.Count; }
        }
 
        public int nearByCount {
            get {
                var count = 0;
                for (int i = 0; i < members.Count; i++)
                {
                    var member = members[i];
                    if (member.id != PlayerDatas.Instance.baseData.PlayerID
                        && member.mapId == PlayerDatas.Instance.baseData.MapID)
                    {
                        count++;
                    }
                }
 
                return count;
            }
        }
 
        public bool inTeam {
            get { return memberCount > 0; }
        }
 
        public bool iamCaptainer {
            get {
                if (memberCount > 0)
                {
                    Teammate mate;
                    var playerId = (int)PlayerDatas.Instance.baseData.PlayerID;
                    if (TryGetMemberByPlayerId(playerId, out mate))
                    {
                        return mate.isCaptainer;
                    }
                }
                return false;
            }
        }
 
        List<TeamPrepare> prepareStates = new List<TeamPrepare>();
 
        public TeamAutoPrepare autoPrepare = new TeamAutoPrepare();
 
        public MyTeam()
        {
            levelMax = GeneralDefine.playerMaxLevel;
        }
 
        public bool TryGetMember(int _index, out Teammate _mate)
        {
            if (members.Count > _index)
            {
                _mate = members[_index];
                return true;
            }
 
            _mate = default(Teammate);
            return false;
        }
 
        public int GetIndexOfMember(int _playerId)
        {
            for (int i = 0; i < members.Count; i++)
            {
                if (members[i].id == _playerId)
                {
                    return i;
                }
            }
 
            return -1;
        }
 
        public bool TryGetMemberByPlayerId(int _playerId, out Teammate _mate)
        {
            for (int i = 0; i < members.Count; i++)
            {
                if (members[i].id == _playerId)
                {
                    _mate = members[i];
                    return true;
                }
            }
 
            _mate = default(Teammate);
            return false;
        }
 
        public void UpdateMembers(List<Teammate> _mates)
        {
            var oldCaptainer = memberCount > 0 ? members[0].id : 0;
            var oldInTeam = inTeam;
            members.Clear();
            members.AddRange(_mates);
            members.Sort(Teammate.SortCompare);
 
            var newInTeam = inTeam;
 
            if (!oldInTeam && inTeam)
            {
                autoPrepare.CancelAutoPrepare();
            }
 
            var newCaptainer = memberCount > 0 ? members[0].id : 0;
            if ((oldCaptainer != 0 || newCaptainer != 0) && oldCaptainer != newCaptainer)
            {
                if (autoPrepare.auto && autoPrepare.cancelWhenCaptainerChange)
                {
                    autoPrepare.CancelAutoPrepare();
                }
            }
        }
 
        public int GetOnlineMemberCount()
        {
            var onlineCount = 0;
            for (int i = 0; i < members.Count; i++)
            {
                if (members[i].online)
                {
                    onlineCount++;
                }
            }
            return onlineCount;
        }
 
        public void ClearMembers()
        {
            members.Clear();
        }
 
        public int GetAnyNearByMember()
        {
            for (int i = 0; i < members.Count; i++)
            {
                var mapId = PlayerDatas.Instance.baseData.MapID;
                var lineId = PlayerDatas.Instance.baseData.FBID;
                if (members[i].mapId == mapId && members[i].lineId == lineId)
                {
                    return members[i].id;
                }
            }
 
            return 0;
        }
 
    }
 
    public class Teammate
    {
        public int id;
        public bool isCaptainer;
        public string mateName;
        public int realm;
        public int job;
        public int face;
        public int facePic;
        public int jobLevel;
        public int level;
        public int mapId;
        public int lineId;
        public bool online;
 
        public Teammate()
        {
 
        }
 
        public Teammate(HB902_tagGCTeamMemberInfo.tagGCTeamMember _serverInfo)
        {
            this.id = (int)_serverInfo.PlayerID;
            this.isCaptainer = _serverInfo.MemberLV == 2;
            this.mateName = _serverInfo.Name;
            this.realm = _serverInfo.RealmLV;
            this.job = _serverInfo.Job;
            this.face = (int)_serverInfo.Face;
            this.facePic = (int)_serverInfo.FacePic;
            this.jobLevel = _serverInfo.JobLevel;
            this.level = _serverInfo.LV;
            this.lineId = _serverInfo.LineID;
            this.online = _serverInfo.PlayerState == 1;
            this.mapId = (int)_serverInfo.MapID;
        }
 
        public void UpdateMate(HB902_tagGCTeamMemberInfo.tagGCTeamMember _serverInfo)
        {
            this.id = (int)_serverInfo.PlayerID;
            this.isCaptainer = _serverInfo.MemberLV == 2;
            this.mateName = _serverInfo.Name;
            this.realm = _serverInfo.RealmLV;
            this.job = _serverInfo.Job;
            this.face = (int)_serverInfo.Face;
            this.facePic = (int)_serverInfo.FacePic;
            this.jobLevel = _serverInfo.JobLevel;
            this.level = _serverInfo.LV;
            this.lineId = _serverInfo.LineID;
            this.online = _serverInfo.PlayerState == 1;
            this.mapId = (int)_serverInfo.MapID;
        }
 
        public void UpdateMap(H0913_tagTeamMemberChangeMap _serverInfo)
        {
            this.mapId = (int)_serverInfo.MapID;
            this.lineId = _serverInfo.LineID;
        }
 
        public static int SortCompare(Teammate _lhs, Teammate _rhs)
        {
            return _lhs.isCaptainer && !_rhs.isCaptainer ? -1 : 1;
        }
 
    }
 
    /// <summary>
    /// 邀请别人
    /// </summary>
    public struct TeamInvite
    {
        public int playerId;
        public string playerName;
        public int job;
        public int jobLevel;
        public int face;
        public int facePic;
        public int realm;
        public int playerLevel;
 
        public TeamInvite(HB908_tagGCRecommendNearbyPlayerList.tagGCRecommendNearbyPlayer _playerInfo)
        {
            this.playerId = (int)_playerInfo.PlayerID;
            this.playerName = _playerInfo.Name;
            this.job = _playerInfo.Job;
            this.jobLevel = 1;
            this.face = (int)_playerInfo.Face;
            this.facePic = (int)_playerInfo.FacePic;
            this.realm = _playerInfo.RealmLV;
            this.playerLevel = _playerInfo.LV;
        }
 
        public TeamInvite(PlayerFairyData.FairyMember _member)
        {
            this.playerId = (int)_member.PlayerID;
            this.playerName = _member.Name;
            this.job = _member.Job;
            this.jobLevel = 1;
            this.face = (int)_member.Face;
            this.facePic = (int)_member.FacePic;
            this.realm = _member.OfficialRank;
            this.playerLevel = _member.LV;
        }
 
        public TeamInvite(FriendPlayer _member)
        {
            this.playerId = (int)_member.PlayerID;
            this.playerName = _member.PlayerName;
            this.job = _member.Job;
            this.jobLevel = 1;
            this.face = (int)_member.Face;
            this.facePic = (int)_member.FacePic;
            this.realm = _member.RealmLV;
            this.playerLevel = _member.LV;
        }
 
    }
 
    /// <summary>
    /// 邀请函,别人邀请你发的请柬
    /// </summary>
    public struct TeamInvitation
    {
        public int playerId;
        public string playerName;
        public int level;
        public int job;
        public int jobLevel;
        public int realm;
        public TeamMission mission;
 
        public TeamInvitation(HB901_tagGCInviteJoinTeamInfo _serverInfo)
        {
            this.playerId = (int)_serverInfo.PlayerID;
            this.playerName = _serverInfo.Name;
            this.job = _serverInfo.Job;
            this.jobLevel = _serverInfo.JobLevel;
            this.realm = _serverInfo.RealmLV;
            this.level = _serverInfo.LV;
            this.mission = new TeamMission((int)_serverInfo.TagMapID, (int)_serverInfo.TagMapEx);
        }
 
    }
 
    public struct TeamApplication
    {
        public int playerId;
        public string playerName;
        public int job;
        public int jobLevel;
        public int face;
        public int facePic;
        public int realm;
        public int playerLevel;
 
        public TeamApplication(HB907_tagGCRequestJoinTeam _applicationInfo)
        {
            this.playerId = (int)_applicationInfo.PlayerID;
            this.playerName = _applicationInfo.Name;
            this.job = _applicationInfo.Job;
            this.jobLevel = _applicationInfo.JobLevel;
            this.realm = _applicationInfo.RealmLV;
            this.playerLevel = _applicationInfo.LV;
            this.face = (int)_applicationInfo.Face;
            this.facePic = (int)_applicationInfo.FacePic;
        }
 
    }
 
    public struct TeamMission
    {
        public int mapId;
        public int mapEx;
 
        public TeamMission(int _mapId, int _mapEx)
        {
            this.mapId = _mapId;
            this.mapEx = _mapEx;
        }
 
        public static bool operator ==(TeamMission _lhs, TeamMission _rhs)
        {
            return _lhs.mapId == _rhs.mapId && _lhs.mapEx == _rhs.mapEx;
        }
 
        public static bool operator !=(TeamMission _lhs, TeamMission _rhs)
        {
            return _lhs.mapId != _rhs.mapId || _lhs.mapEx != _rhs.mapEx;
        }
    }
 
    public class TeamPrepare
    {
        int m_MapId = 0;
        public int mapId {
            get { return m_MapId; }
            private set { m_MapId = value; }
        }
 
        int m_MapEx;
        public int mapEx {
            get { return m_MapEx; }
            private set { m_MapEx = value; }
        }
 
        public Dictionary<int, TeammatePrepareState> playerStates = new Dictionary<int, TeammatePrepareState>();
 
        bool m_IsError = false;
        public bool isError {
            get { return m_IsError; }
            private set {
                m_IsError = value;
            }
        }
 
        public bool isPreparing {
            get {
                return !IsAllOk() && !isError && !IsReject();
            }
        }
 
        public TeamPrepare()
        {
        }
 
        public void UpdatePrepareState(HB911_tagGCTeamEnterFBPrepare _serverInfo)
        {
            this.mapId = (int)_serverInfo.TagMapID;
            this.mapEx = (int)_serverInfo.TagMapEx;
            this.isError = _serverInfo.IsPrepareErr == 1;
            playerStates.Clear();
            for (int i = 0; i < _serverInfo.MemStateList.Length; i++)
            {
                var playerState = _serverInfo.MemStateList[i];
                playerStates[(int)playerState.PlayerID] = (TeammatePrepareState)(playerState.PrepareState);
            }
        }
 
        public TeammatePrepareState GetPlayerPrepareSate(int _playerId)
        {
            if (playerStates.ContainsKey(_playerId))
            {
                return playerStates[_playerId];
            }
            else
            {
                return TeammatePrepareState.UnPrepared;
            }
        }
 
        public bool OnlyCaptainerPrepared(int _captainerId)
        {
            var okCount = 0;
            var captainerOk = false;
            foreach (var key in playerStates.Keys)
            {
                if (playerStates[key] == TeammatePrepareState.Prepared)
                {
                    okCount++;
                }
                if (key == _captainerId)
                {
                    captainerOk = playerStates[key] == TeammatePrepareState.Prepared;
                }
            }
 
            return okCount == 1 && captainerOk;
        }
 
        public bool IsReject()
        {
            foreach (var key in playerStates.Keys)
            {
                if (playerStates[key] == TeammatePrepareState.Rejected)
                {
                    return true;
                }
            }
 
            return false;
        }
 
        public bool IsAllOk()
        {
            foreach (var key in playerStates.Keys)
            {
                if (playerStates[key] != TeammatePrepareState.Prepared)
                {
                    return false;
                }
            }
 
            return true;
        }
 
    }
 
    public struct TeamTargetPreference
    {
        public int minLevel;
        public int maxLevel;
 
        public TeamTargetPreference(int _minLevel, int _maxLevel)
        {
            this.minLevel = _minLevel;
            this.maxLevel = _maxLevel;
        }
 
    }
 
    public class TeamAutoPrepare
    {
        bool m_Auto = false;
        public bool auto {
            get { return m_Auto; }
            private set {
                if (m_Auto != value)
                {
                    m_Auto = value;
                    if (autoPrepareChangeEvent != null)
                    {
                        autoPrepareChangeEvent();
                    }
                }
            }
        }
 
        public int mapId { get; private set; }
        public int mapEx { get; private set; }
 
        bool m_CancelWhenTargetChange = true;
        public bool cancelWhenTargetChange {
            get { return m_CancelWhenTargetChange; }
        }
 
        bool m_CancelWhenCaptainerChange = false;
        public bool cancelWhenCaptainerChange {
            get { return m_CancelWhenCaptainerChange; }
        }
 
        public event Action autoPrepareChangeEvent;
 
        public void CancelAutoPrepare()
        {
            this.mapId = 0;
            this.mapEx = 0;
            this.m_CancelWhenCaptainerChange = false;
            this.m_CancelWhenTargetChange = true;
            this.auto = false;
        }
 
        public void SetAutoPreapare(int mapId, int mapEx, bool cancelWhenTargetChange, bool cancelWhenCaptainerChange)
        {
            this.mapId = mapId;
            this.mapEx = mapEx;
            this.m_CancelWhenTargetChange = cancelWhenTargetChange;
            this.m_CancelWhenCaptainerChange = cancelWhenCaptainerChange;
            this.auto = true;
        }
 
    }
 
}