少年修仙传客户端代码仓库
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
using vnxbqy.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClientPersonalBossDungeonStage : DungeonStage
{
    static readonly Vector3 s_PlayerPosition = new Vector3(16.19f, 0.825f, 7.62f);
    static readonly Vector3 s_NpcPosition = new Vector3(11.9f, 0.825f, 9.64f);
 
    static readonly float s_PlayerAngle = -70.925f;
 
    static int[] s_StepTimes = null;
 
    static Clock s_StepClock = null;
 
    Step m_Step = Step.None;
    public Step step
    {
        get { return m_Step; }
        set
        {
            if (m_Step != value)
            {
                switch (m_Step)
                {
                    case Step.Prepare:
                        OnExitPrepare();
                        break;
                    case Step.Fight:
                        OnExitFight();
                        break;
                }
 
                m_Step = value;
 
                switch (m_Step)
                {
                    case Step.Prepare:
                        OnEnterPrepare();
                        break;
                    case Step.Fight:
                        OnEnterFight();
                        break;
                    case Step.Over:
                        OnEnterOver();
                        break;
                }
            }
        }
    }
 
    static GA_NpcClientFightBoss s_ClientBoss = null;
 
    static PersonalBossModel model { get { return ModelCenter.Instance.GetModel<PersonalBossModel>(); } }
    static DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
 
    public override void Initialize()
    {
        base.Initialize();
 
        step = Step.None;
 
        var npcId = model.GetBossNpcId(ClientDungeonStageUtility.dungeonInfo.lineId);
        var config = PersonalBossConfig.Get(npcId);
        if (config != null)
        {
            var dungeonId = dungeonModel.GetDungeonId(PersonalBossModel.PERSONALBOSS_MAPID, config.lineId);
            var dungeonConfig = DungeonConfig.Get(dungeonId);
            if (dungeonConfig != null)
            {
                s_StepTimes = LitJson.JsonMapper.ToObject<int[]>(dungeonConfig.StepTime);
            }
        }
 
        dungeonModel.onDungeonResultEvent += OnDungeonResultEvent;
        PersonalEnemy.OnNpcAppear += OnNpcAppear;
    }
 
    protected override void OnStageLoadFinish()
    {
        base.OnStageLoadFinish();
 
        InitializePlayer();
 
        step = Step.Prepare;
 
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += PlayerLoginOk;
    }
 
    void InitializePlayer()
    {
        var hero = PlayerDatas.Instance.hero;
        if (hero != null)
        {
            hero.Pos = s_PlayerPosition;
            hero.Rotation = Quaternion.Euler(0, s_PlayerAngle, 0);
        }
        CameraController.Instance.Apply();
    }
 
    void OnEnterPrepare()
    {
        var seconds = s_StepTimes[0];
        dungeonModel.UpdateCoolDown(DungeonCoolDownType.WaitStart, (uint)seconds * 1000);
 
        s_StepClock = Clock.AlarmAfter(seconds, () =>
          {
              step = Step.Fight;
          });
    }
 
    void OnExitPrepare()
    {
        if (s_StepClock != null)
        {
            Clock.Stop(s_StepClock);
            s_StepClock = null;
        }
    }
 
    void OnEnterFight()
    {
        InitializeNpc();
 
        var seconds = s_StepTimes[1];
        dungeonModel.UpdateCoolDown(DungeonCoolDownType.FightStart, (uint)seconds * 1000);
 
        s_StepClock = Clock.AlarmAfter(seconds, () =>
        {
            ClientDungeonStageUtility.ExitNormalClientDungeon();
        });
    }
 
    private void OnExitFight()
    {
        if (s_StepClock != null)
        {
            Clock.Stop(s_StepClock);
            s_StepClock = null;
        }
    }
 
    private void OnEnterOver()
    {
        var seconds = s_StepTimes[2];
        dungeonModel.UpdateCoolDown(DungeonCoolDownType.LeaveMap, (uint)seconds * 1000);
        s_StepClock = Clock.AlarmAfter(seconds, () =>
        {
            ClientDungeonStageUtility.ExitNormalClientDungeon();
        });
    }
 
    void InitializeNpc()
    {
        uint hp = 0;
        uint hpEx = 0;
        var position = s_NpcPosition;
        if (s_ClientBoss != null)
        {
            hp = (uint)(s_ClientBoss.ActorInfo.Hp % Constants.ExpPointValue);
            hpEx = (uint)(s_ClientBoss.ActorInfo.Hp / Constants.ExpPointValue);
            position = s_ClientBoss.Pos;
            PersonalEnemy.Release(s_ClientBoss);
        }
 
        var npcId = model.GetBossNpcId(ClientDungeonStageUtility.dungeonInfo.lineId);
        PersonalEnemy.Create((uint)npcId, E_ActorGroup.Enemy, position, hp, hpEx);
    }
 
    private void OnDungeonResultEvent()
    {
        step = Step.Over;
    }
 
    private void PlayerLoginOk()
    {
        if (step < Step.Over)
        {
            InitializeNpc();
        }
    }
 
    public override void UnInitialize()
    {
        base.UnInitialize();
 
        dungeonModel.onDungeonResultEvent -= OnDungeonResultEvent;
        PersonalEnemy.OnNpcAppear -= OnNpcAppear;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= PlayerLoginOk;
 
        if (s_ClientBoss != null)
        {
            s_ClientBoss = null;
        }
 
        if (s_StepClock != null)
        {
            Clock.Stop(s_StepClock);
            s_StepClock = null;
        }
    }
 
    private void OnNpcAppear(GA_NpcClientFightNorm _npc)
    {
        if (_npc != null && _npc is GA_NpcClientFightBoss)
        {
            s_ClientBoss = _npc as GA_NpcClientFightBoss;
        }
    }
 
#if UNITY_EDITOR
    private void OnGUI()
    {
        if (GUILayout.Button("Exit"))
        {
            ClientDungeonStageUtility.ExitNormalClientDungeon();
        }
    }
#endif
 
    public enum Step
    {
        None,
        Prepare,
        Fight,
        Over,
    }
}