少年修仙传客户端代码仓库
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
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
 
 
public class StageLoad : SingletonMonobehaviour<StageLoad>
{
    StageLoadProcessor stageLoadProcessor;
    public float progress
    {
        get
        {
            if (stageLoadProcessor != null)
            {
                return stageLoadProcessor.progress;
            }
            else
            {
                return 0f;
            }
        }
    }
 
    Stage m_CurrentStage;
    public Stage currentStage
    {
        get { return m_CurrentStage; }
        set { m_CurrentStage = value; }
    }
 
    public Stage.E_StageType stageType
    {
        get
        {
            return (currentStage != null && currentStage is DungeonStage) ? Stage.E_StageType.Dungeon : Stage.E_StageType.MainCity;
        }
    }
 
    public event Action<int> onStartStageLoadingEvent;
    public UnityAction onStageLoadFinish;
 
    StageLoadCommand currentCommand;
    Queue<StageLoadCommand> commands = new Queue<StageLoadCommand>();
 
    bool server0109Ok_Main = false;
    bool server0109Ok_CrossServer;
 
    float loadStartTime = 0f;
    public bool isLoading { get; private set; }
    public bool isLoadingScene;
 
    public int mapIdRecord { get; private set; }
    public int lineIdRecord { get; private set; }
 
    public void PushSceneLoadCommand(StageLoadCommand command)
    {
        if (!isLoading && commands.Count == 0)
        {
            currentCommand = command;
            currentCommand.fromMapId = mapIdRecord;
            currentCommand.fromLineId = lineIdRecord;
            ExcuteCommand(currentCommand);
        }
        else
        {
            commands.Enqueue(command);
        }
    }
 
    private void ExcuteCommand(StageLoadCommand command)
    {
        var tasks = new Queue<StageLoadProcessor.StageLoadTask>();
        var needLoadResource = true;
        if (command.needLoadResource)
        {
            if (command.fromMapId != command.toMapId)
            {
                needLoadResource = true;
            }
            else
            {
                var config1 = MapResourcesConfig.GetConfig(MapUtility.GetDataMapId(command.fromMapId), command.fromLineId);
                var config2 = MapResourcesConfig.GetConfig(MapUtility.GetDataMapId(command.toMapId), command.toLineId);
                if (config1 == null || config2 == null)
                {
                    needLoadResource = true;
                }
                else
                {
                    needLoadResource = config1.MapResources != config2.MapResources;
                }
            }
        }
        else
        {
            needLoadResource = false;
        }
 
        var assetValid = AssetVersionUtility.IsSceneAssetValid(command.toMapId, command.toLineId);
        if (!assetValid)
        {
            tasks.Enqueue(new StageLoadProcessor.Wait0109Task(command));
            if (command.serverType == ServerType.Main)
            {
                tasks.Enqueue(new StageLoadProcessor.WaitLoginCompleteTask(command));
            }
            tasks.Enqueue(new StageLoadProcessor.WaitSecondsTask(command, 1));
            tasks.Enqueue(new StageLoadProcessor.ReturnToNoviceVillageTask(command));
        }
        else
        {
            if (needLoadResource)
            {
                tasks.Enqueue(new StageLoadProcessor.PreProcessTask(command));
                if (command.isClientLoadMap && command.toMapId != 3)
                {
                    tasks.Enqueue(new StageLoadProcessor.WaitSecondsTask(command, 0.5f));
                }
                tasks.Enqueue(new StageLoadProcessor.UnLoadAndGCTask(command));
            }
 
            if (needLoadResource && command.needEmpty)
            {
                tasks.Enqueue(new StageLoadProcessor.LoadEmptyTask(command));
            }
 
            if (needLoadResource)
            {
                tasks.Enqueue(new StageLoadProcessor.LoadNewSceneTask(command));
                isLoadingScene = true;
            }
 
            if (!command.isClientLoadMap)
            {
                tasks.Enqueue(new StageLoadProcessor.Wait0109Task(command));
                if (command.serverType == ServerType.Main)
                {
                    tasks.Enqueue(new StageLoadProcessor.WaitLoginCompleteTask(command));
                }
            }
 
            if (needLoadResource)
            {
                tasks.Enqueue(new StageLoadProcessor.PostProcessTask(command));
            }
        }
 
        UpdateServerFlag(command.serverType, false);
 
        var gameObject = new GameObject("StageLoadProcessor");
        DontDestroyOnLoad(gameObject);
        stageLoadProcessor = gameObject.AddComponent<StageLoadProcessor>();
        stageLoadProcessor.Begin(tasks);
 
        StageLoadTimeOutCatcher.Begin(command.toMapId);
        WindowCenter.Instance.Close<MainInterfaceWin>();
        loadStartTime = Time.time;
        isLoading = true;
    }
 
    public void ReportComplete(int mapId, int lineId, bool record)
    {
        if (record)
        {
            mapIdRecord = mapId;
            lineIdRecord = lineId;
        }
 
        isLoading = false;
        StageLoadTimeOutCatcher.Stop();
 
        if (stageLoadProcessor != null)
        {
            DestroyImmediate(stageLoadProcessor.gameObject);
            stageLoadProcessor = null;
        }
    }
 
    public void UpdateServerFlag(ServerType serverType, bool ok)
    {
        if (ok)
        {
            if (currentCommand != null && !currentCommand.isClientLoadMap && !currentCommand.serverFlag0109)
            {
                currentCommand.serverFlag0109 = true;
            }
            else
            {
                foreach (var command in commands)
                {
                    if (command.serverType == serverType && !command.serverFlag0109)
                    {
                        command.serverFlag0109 = true;
                        break;
                    }
                }
            }
        }
 
        switch (serverType)
        {
            case ServerType.Main:
                server0109Ok_Main = ok;
                break;
            case ServerType.CrossSever:
                server0109Ok_CrossServer = ok;
                break;
            default:
                break;
        }
    }
 
    public void BroadcastStageLoadStartEvent(int mapId)
    {
        try
        {
            if (onStartStageLoadingEvent != null)
            {
                onStartStageLoadingEvent(mapId);
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex);
        }
 
    }
 
    public void BroadcastStageLoadEndEvent()
    {
        try
        {
            if (onStageLoadFinish != null)
            {
                onStageLoadFinish();
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex);
        }
 
    }
 
    void Update()
    {
        if (!isLoading && commands.Count > 0)
        {
            currentCommand = commands.Dequeue();
            currentCommand.fromMapId = mapIdRecord;
            currentCommand.fromLineId = lineIdRecord;
            ExcuteCommand(currentCommand);
        }
 
        if (isLoading)
        {
            if (Time.time - loadStartTime > 25f)
            {
                if (stageLoadProcessor != null)
                {
                    DestroyImmediate(stageLoadProcessor.gameObject);
                    stageLoadProcessor = null;
                }
 
                currentCommand = null;
                isLoading = false;
                commands.Clear();
                StageLoadTimeOutCatcher.ReportLoadingOverTime();
                GameNetSystem.Instance.Reconnect();
            }
        }
    }
 
    public class StageLoadCommand
    {
        public int fromMapId;
        public int fromLineId;
        public int toMapId;
        public int toLineId;
 
        public bool needEmpty;
        public ServerType serverType;
        public bool isClientLoadMap;
        public bool needLoadResource;
        public bool refreshPlayerDatas;
        public bool exitClientMap;
 
        public bool serverFlag0109 = false;
    }
 
    public bool IsServerPrepareOk(ServerType socketType)
    {
        switch (socketType)
        {
            case ServerType.Main:
                return server0109Ok_Main;
            case ServerType.CrossSever:
                return server0109Ok_CrossServer;
            default:
                return false;
        }
    }
 
    int m_InitHeroStep = -1;
    public int initHeroStep { get { return m_InitHeroStep; } }
 
    public void InitHero()
    {
        m_InitHeroStep = 0;
 
        // 初始化摄像机
        if (!CameraController.Instance)
        {
            var prefab = UnityEngine.Object.Instantiate(BuiltInLoader.LoadPrefab("GameCamera"));
            CameraController.Instance.SetcamerePrefab(prefab);
            CameraController.Instance.AcceptInput = false;
            CameraController.Instance.CameraObject.enabled = false;
        }
 
        m_InitHeroStep = 1;
        var hero = PlayerDatas.Instance.hero;
        if (hero == null)
        {
            hero = GAMgr.Instance.RequestPlayer<GA_Hero>(PlayerDatas.Instance.PlayerId, E_ActorGroup.User, null);
        }
 
        m_InitHeroStep = 2;
        hero.State = E_ActorState.Idle;
        hero.ActorInfo.ResetHp((long)PlayerDatas.Instance.baseData.HP, (long)PlayerDatas.Instance.extersion.MaxHP);
        hero.CalculateMoveSpeed((ushort)PlayerDatas.Instance.extersion.SpeedValue);
        hero.CalculateAtkSpeed(PlayerDatas.Instance.extersion.battleValEx1);
        hero.InitBornPos(PlayerDatas.Instance.baseData.PosX, PlayerDatas.Instance.baseData.PosY);
        m_InitHeroStep = 3;
        CameraController.Instance.SetLookTarget(hero.Root);
        CameraController.Instance.Apply();
 
        var apperance = ModelCenter.Instance.GetModel<EquipModel>().GetAppearance();
 
        m_InitHeroStep = 4;
        if (apperance.fashionClothes != 0)
        {
            hero.SwitchClothes((uint)apperance.fashionClothes, (int)RoleEquipType.FashionClothes);
        }
        else
        {
            hero.SwitchClothes((uint)apperance.clothes);
        }
 
        m_InitHeroStep = 5;
        if (apperance.fashionWeapon != 0)
        {
            hero.SwitchWeapon((uint)apperance.fashionWeapon, (int)RoleEquipType.FashionWeapon);
        }
        else
        {
            hero.SwitchWeapon((uint)apperance.weapon);
        }
 
        m_InitHeroStep = 6;
        if (apperance.fashionSecondary != 0)
        {
            hero.SwitchSecondary((uint)apperance.fashionSecondary, (int)RoleEquipType.FashionWeapon2);
        }
        else
        {
            hero.SwitchSecondary((uint)apperance.secondary);
        }
 
        m_InitHeroStep = 7;
 
        if (apperance.wings != 0)
        {
            hero.SwitchWing((uint)apperance.wings);
        }
 
        m_InitHeroStep = 8;
        var mapConfig = MapConfig.Get(PlayerDatas.Instance.baseData.MapID);
        if (mapConfig.CanRide != 1)
        {
            hero.SwitchHorse(0);
        }
 
        m_InitHeroStep = 9;
 
        var pack = ModelCenter.Instance.GetModel<PackModel>();
        var equipIndex = EquipSet.ClientPlaceToServerPlace(new Int2(0, (int)RoleEquipType.Guard));
        var _itemModel = pack.GetItemByIndex(PackType.Equip, equipIndex);
        if (_itemModel != null && _itemModel.itemInfo != null)
        {
            hero.SwitchGuard((uint)_itemModel.itemId);
        }
 
        m_InitHeroStep = 10;
 
        hero.SyncSuitEffect(apperance.isSuit);
 
        m_InitHeroStep = 11;
        hero.IdleImmediate();
 
        hero.SetFairyLeagueHeadUp(PlayerDatas.Instance.baseData.MapID == FairyLeagueModel.FAIRY_LEAGUE_DUNGEON);
        hero.CheckAncientHeadUp();
 
        GA_Pet _pet = GAMgr.Instance.GetBySID(PlayerDatas.Instance.PlayerId * 10 + 1) as GA_Pet;
 
        if (_pet != null)
        {
            Debug.LogFormat("主角已有宠物,这里卸载掉");
            GAMgr.Instance.ServerDie(_pet.ServerInstID);
            GAMgr.Instance.Release(_pet);
        }
 
 
        if (ModelCenter.Instance.GetModel<PetModel>().PetNow != 0 && mapConfig.CanOutPet == 1)
        {
            var _package = new H0435_tagPetAppear();
            _package.PetID = PlayerDatas.Instance.PlayerId * 10 + 1;
            _package.NPCID = (uint)ModelCenter.Instance.GetModel<PetModel>().PetNow;
            _package.PlayerID = PlayerDatas.Instance.PlayerId;
            _package.PosX = (uint)(hero.Pos.x * 2);
            _package.PosX = (uint)(hero.Pos.z * 2);
 
            _pet = GAMgr.Instance.RequestNPCFight<GA_Pet>(_package.PetID, _package.NPCID, hero.Group, _package);
            hero.petSid = PlayerDatas.Instance.PlayerId * 10 + 1;
            _pet.Pos = hero.Pos;
            _pet.ActorInfo.moveSpeed = hero.ActorInfo.moveSpeed;
            _pet.ActorInfo.ownerSID = hero.ServerInstID;
        }
 
        m_InitHeroStep = 12;
        var titleId = 0;
        if (PlayerDatas.Instance.baseData.MapID != 31160)
        {
            var titelModel = ModelCenter.Instance.GetModel<TitleModel>();
            var title = titelModel.GetTitleEquip();
            titleId = title != null && titelModel.IsTitleGain(title.id) ? title.id : 0;
        }
        hero.SwitchTitle((uint)titleId);
 
        m_InitHeroStep = 13;
        // 判断buff
        if (StatusMgr.Instance.IsExist(PlayerDatas.Instance.PlayerId, StatusMgr.Instance.redNameBuffID))
        {
            hero.SwitchRedName(true);
        }
 
        hero.RequestLight();
 
        m_InitHeroStep = 14;
        PlayerDatas.Instance.hero = hero;
 
        var preLoadSkillEffects = GeneralDefine.PreloadSkillEffect[hero.JobSetup.Job - 1];
        if (preLoadSkillEffects != null && preLoadSkillEffects.Length > 0)
        {
            foreach (var _id in preLoadSkillEffects)
            {
                InstanceResourcesLoader.PreloadSkillEffect(_id);
            }
        }
 
        m_InitHeroStep = 15;
    }
 
}