少年修仙传客户端代码仓库
hch
2025-03-03 28785d6ddf9c08e49527ede9405c7b6c93c6ed32
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
using vnxbqy.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class ClientDungeonStageUtility
{
 
    public static bool isClientDungeon { get; private set; }
    public static ushort clientMapId { get; private set; }
    public static Dungeon dungeonInfo { get; set; }
 
    static int clientErrorSymbolMapId = 0;
 
    static Action<Dungeon, bool> clientCustomDungeonResult;
 
    static CrossServerOneVsOneModel crossServerOneVsOneModel { get { return ModelCenter.Instance.GetModel<CrossServerOneVsOneModel>(); } }
 
    public static void Init()
    {
        DTC0102_tagCDBPlayer.switchAccountEvent += Reset;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
        StageLoad.Instance.onStageLoadFinish += OnStageLoadFinish;
    }
 
    public static void SetClientDungeon(bool value, ushort mapId)
    {
        isClientDungeon = value;
        clientMapId = mapId;
    }
 
    public static void RequestStartClientDungeon(int mapId, int lineId, Action<Dungeon, bool> callBack)
    {
        clientCustomDungeonResult = callBack;
 
        dungeonInfo = new Dungeon()
        {
            mapId = mapId,
            lineId = lineId,
        };
 
        if (ClientSceneManager.Instance.IsClientFightMode)
        {
            ClientSceneManager.Instance.ExitClientFightMode();
        }
        //个人boss有概率出现开始和结束倒计时同时出现,这里调用一次ResetBufData待观察
        ModelCenter.Instance.GetModel<DungeonModel>().ResetBufData();
 
        var pak = new CA231_tagCMClientStartCustomScene();
        pak.MapID = (uint)mapId;
        pak.FuncLineID = (ushort)lineId;
        GameNetSystem.Instance.SendInfo(pak);
    }
 
    public static void RequestExitClientDungeon()
    {
        var pak = new CA233_tagCMClientExitCustomScene();
        GameNetSystem.Instance.SendInfo(pak);
    }
 
    public static void ReceiveStartCustomDungeonResult(HB216_tagMCStartCustomSceneResult package)
    {
        if (package.MapID == dungeonInfo.mapId
            && package.FuncLineID == dungeonInfo.lineId)
        {
            if (clientCustomDungeonResult != null)
            {
                clientCustomDungeonResult(dungeonInfo, package.Result == 1);
            }
        }
        clientCustomDungeonResult = null;
    }
 
    public static void GotoNormalClientDungeon(int clientMapId, int mapId, int lineId)
    {
        if (!AssetSource.sceneFromEditor)
        {
            var assetValid = AssetVersionUtility.IsSceneAssetValid(mapId, lineId);
            if (!assetValid)
            {
                InGameDownLoad.Instance.TryDownLoad(InGameDownLoad.Dominant.Whole);
                return;
            }
        }
 
        RequestStartClientDungeon(mapId, lineId, (dungeonInfo, isOk) =>
        {
            if (!isOk)
            {
                return;
            }
 
            var hero = PlayerDatas.Instance.hero;
            if (hero != null)
            {
                hero.StopAll();
            }
 
            MapTransferUtility.Instance.Clear();
 
            SetClientDungeon(true, (ushort)clientMapId);
            StageLoad.Instance.PushSceneLoadCommand(new StageLoad.StageLoadCommand()
            {
                toMapId = clientMapId,
                toLineId = 0,
                needEmpty = true,
                needLoadResource = true,
                serverType = ServerType.Main,
                isClientLoadMap = true
            });
 
            var _hero = PlayerDatas.Instance.hero;
            if (_hero != null)
            {
                GA_Hero.recordServerPos = new Vector3((int)(_hero.Pos.x * 2), 0, (int)(_hero.Pos.z * 2));
            }
            PlayerDatas.Instance.baseData.mainServerMapIdRecord = PlayerDatas.Instance.baseData.MapID;
            PlayerDatas.Instance.baseData.MapID = (ushort)clientMapId;
        });
    }
 
    public static void ExitNormalClientDungeon()
    {
        SetClientDungeon(false, 0);
        PlayerDatas.Instance.extersion.pkState = 0;
        ModelCenter.Instance.GetModel<DungeonModel>().ResetBufData();
 
        PlayerDatas.Instance.baseData.MapID = PlayerDatas.Instance.baseData.mainServerMapIdRecord;
        StageLoad.Instance.PushSceneLoadCommand(new StageLoad.StageLoadCommand()
        {
            toMapId = PlayerDatas.Instance.baseData.MapID,
            toLineId = 0,
            needEmpty = true,
            needLoadResource = true,
            serverType = ServerType.Main,
            isClientLoadMap = true,
            refreshPlayerDatas = true,
            exitClientMap = true,
        });
    }
 
    public static int GetClientMapId(int mapId)
    {
        switch (mapId)
        {
            case HazyDemonKingModel.DATAMAP:
            case HazyDemonKingModel.CROSSSERVERDATAMAP:
                return HazyDemonKingModel.CLIENTDATAMAP;
            case HazyGrassModel.REIKI_DATAMAP:
                return HazyGrassModel.REIKI_CLIENTDATAMAP;
            case HazyGrassModel.FAIRY_DATAMAP:
                return HazyGrassModel.FAIRY_CLIENTDATAMAP;
            case PersonalBossModel.PERSONALBOSS_MAPID:
            case HazyRegionModel.PRECIOUS_CLIENTDATAMAP:
            case TreasureModel.CLIENTDATAMAP:
            case ClientGuardDungeon.DATAMAPID:
                return mapId;
            default:
                return mapId;
        }
    }
 
    private static void OnPlayerLoginOk()
    {
        if (isClientDungeon)
        {
            RequestStartClientDungeon(dungeonInfo.mapId, dungeonInfo.lineId, (dungeonInfo, isOk) =>
            {
                if (!isOk)
                {
                    if (StageLoad.Instance.isLoading)
                    {
                        clientErrorSymbolMapId = dungeonInfo.mapId;
                        return;
                    }
                    if (isClientDungeon)
                    {
                        ExitNormalClientDungeon();
                    }
                }
            });
        }
    }
 
    private static void OnStageLoadFinish()
    {
        if (clientErrorSymbolMapId != 0)
        {
            if (isClientDungeon && dungeonInfo.mapId == clientErrorSymbolMapId)
            {
                ExitNormalClientDungeon();
            }
        }
 
        clientErrorSymbolMapId = 0;
    }
 
    private static void Reset()
    {
        isClientDungeon = false;
        clientMapId = 0;
    }
}