少年修仙传客户端代码仓库
client_Wu Xijin
2019-04-16 fc714208ff3a320c3bb52bddd5ea3d91f647a206
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
using Snxxz.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class ClientHazyDemonKingStage : DungeonStage
{
    static readonly Vector3 playerBornPosition = new Vector3(10, 6.38f, 6.67f);
    static readonly Vector3 bossBornPosition = new Vector3(8.35f, 6.37f, 9.7f);
 
    static GA_NpcClientFightBoss clientFightBoss = null;
 
    float totalTime = 20f;
    float timer = 0f;
    DateTime playerAtkTime = DateTime.Now;
    Clock pickItemClock = null;
 
    float stepTimer = 0f;
 
    float existTime = 10f;
 
    bool pickAllDropItem = false;
 
    int itemCount = 0;
 
    Step m_Step = Step.Fight;
    Step step
    {
        get { return m_Step; }
        set
        {
            if (m_Step != value)
            {
                m_Step = value;
                switch (m_Step)
                {
                    case Step.Fight:
                        stepTimer = 0f;
                        break;
                    case Step.PickItem:
                        stepTimer = 5f;
                        break;
                    case Step.Settle:
                        stepTimer = 0f;
                        break;
                    case Step.Exit:
                        stepTimer = 0f;
                        break;
                }
            }
        }
    }
 
    HazyDemonKingModel model { get { return ModelCenter.Instance.GetModel<HazyDemonKingModel>(); } }
    HazyRegionModel hazyRegionModel { get { return ModelCenter.Instance.GetModel<HazyRegionModel>(); } }
    DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
 
    public override void Initialize()
    {
        base.Initialize();
 
        timer = 0f;
        playerAtkTime = DateTime.MinValue;
        m_Step = Step.None;
        pickAllDropItem = false;
        itemCount = 0;
 
        DTC0403_tagPlayerLoginLoadOK.mapInitOkEvent += OnReconnected;
        AttackHandler.OnAttackTarget += OnPlayerAttack;
        ClientDungeonStageUtility.onReceiveCustomDropItme += OnReceiveCustomDropItme;
        dungeonModel.onDungeonResultEvent += OnDungeonResultEvent;
        ClientDropItemUtility.OnItemPickup += OnItemPickup;
    }
 
    protected override void OnStageLoadFinish()
    {
        base.OnStageLoadFinish();
 
        InitializePlayer();
        InitializeBoss();
 
        step = Step.Fight;
    }
 
    public static uint GetClientBossSid()
    {
        if (clientFightBoss != null)
        {
            return clientFightBoss.ServerInstID;
        }
        return 0;
    }
 
    void InitializePlayer()
    {
        var hero = PlayerDatas.Instance.hero;
        hero.Pos = playerBornPosition;
        CameraController.Instance.Apply();
    }
 
    void InitializeBoss()
    {
        if (clientFightBoss != null)
        {
            clientFightBoss.ActorInfo.serverDie = true;
            GAMgr.Instance.ServerDie(clientFightBoss.ServerInstID);
            GAMgr.Instance.Release(clientFightBoss);
            clientFightBoss = null;
        }
 
        var config = HazyRegionConfig.Get(hazyRegionModel.processingIncidentId);
        var npcId = NPCConfig.Get(config.npcId);
 
        clientFightBoss = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightBoss>((uint)config.npcId, E_ActorGroup.Enemy);
        clientFightBoss.Pos = bossBornPosition;
        clientFightBoss.LockTargetSID = PlayerDatas.Instance.PlayerId;
    }
 
    private void OnPlayerAttack(uint _attackerId, uint _victimId, byte _type, uint _damage)
    {
        if (clientFightBoss == null)
        {
            return;
        }
 
        if (_victimId == clientFightBoss.ServerInstID)
        {
            var progress = Mathf.Clamp01(1 - timer / totalTime);
            var hp = (ulong)(clientFightBoss.ActorInfo.RealMaxHp * progress);
 
            TargetBriefInfo.OnRefreshBossLifeBar(_victimId, clientFightBoss.NpcConfig.NPCID,
                hp, clientFightBoss.ActorInfo.RealMaxHp);
 
            playerAtkTime = DateTime.Now;
        }
    }
 
    private void OnReceiveCustomDropItme(HB214_tagMCCuntomFBPrizeInfo package)
    {
        step = Step.PickItem;
        if (package.PrizeItemCount <= 0)
        {
            pickAllDropItem = true;
        }
        else
        {
            itemCount = package.PrizeItemCount;
            int[] items = new int[itemCount];
            for (int i = 0; i < itemCount; i++)
            {
                items[i] = (int)package.PrizeItemIDList[i];
            }
            ClientDropItemUtility.Instance.Drop(bossBornPosition, items);
 
            dungeonModel.UpdateCoolDown(DungeonCoolDownType.PickUpTime, 30 * 1000);
 
            if (pickItemClock != null)
            {
                Clock.Stop(pickItemClock);
                pickItemClock = null;
            }
            pickItemClock = Clock.AlarmAfter(30, OnPickUpItemLimit);
        }
    }
 
    void OnPickUpItemLimit()
    {
        pickAllDropItem = true;
    }
 
    private void OnItemPickup(int itemId)
    {
        itemCount--;
        if (itemCount == 0)
        {
            pickAllDropItem = true;
        }
    }
 
    private void OnDungeonResultEvent()
    {
        step = Step.Settle;
        dungeonModel.UpdateCoolDown(DungeonCoolDownType.LeaveMap, 10 * 1000);
    }
 
    protected override void OnUpdate()
    {
        base.OnUpdate();
 
        if (timer < totalTime)
        {
            if ((DateTime.Now - playerAtkTime).TotalSeconds < 1f)
            {
                timer += Time.deltaTime;
                if (timer >= totalTime)
                {
                    OnBossDie();
                }
            }
        }
 
        switch (step)
        {
            case Step.Fight:
                if (clientFightBoss == null)
                {
                    stepTimer += Time.deltaTime;
                    if (stepTimer > 5f)
                    {
                        stepTimer = 0f;
                        RequestDropItem();
                    }
                }
                break;
            case Step.PickItem:
                if (pickAllDropItem)
                {
                    stepTimer += Time.deltaTime;
                    if (stepTimer >= 5f)
                    {
                        RequestSettle();
                        stepTimer = 0f;
                    }
                }
                break;
            case Step.Settle:
                stepTimer += Time.deltaTime;
                if (stepTimer >= existTime)
                {
                    step = Step.Exit;
                    model.RequestExitClientDungeon();
                }
                break;
        }
    }
 
    void OnBossDie()
    {
        if (clientFightBoss != null)
        {
            clientFightBoss.ActorInfo.serverDie = true;
            GAMgr.Instance.ServerDie(clientFightBoss.ServerInstID);
            clientFightBoss.Die();
            clientFightBoss = null;
        }
 
        RequestDropItem();
    }
 
    void RequestDropItem()
    {
        var incidentId = hazyRegionModel.processingIncidentId;
        var config = HazyRegionConfig.Get(incidentId);
        ClientDungeonStageUtility.RequestClientDropItem(config.dungeonId, config.lineId);
    }
 
    void RequestSettle()
    {
        var incidentId = hazyRegionModel.processingIncidentId;
        var config = HazyRegionConfig.Get(incidentId);
        ClientDungeonStageUtility.RequestSettleClientDungeon(config.dungeonId, config.lineId);
    }
 
    private void OnReconnected()
    {
        var incidentId = hazyRegionModel.processingIncidentId;
        var config = HazyRegionConfig.Get(incidentId);
        ClientDungeonStageUtility.RequestStartClientDungeon(config.dungeonId, config.lineId);
    }
 
    public override void UnInitialize()
    {
        base.UnInitialize();
 
        if (clientFightBoss != null)
        {
            clientFightBoss.ActorInfo.serverDie = true;
            GAMgr.Instance.ServerDie(clientFightBoss.ServerInstID);
            GAMgr.Instance.Release(clientFightBoss);
            clientFightBoss = null;
        }
 
        if (pickItemClock != null)
        {
            Clock.Stop(pickItemClock);
            pickItemClock = null;
        }
 
        DTC0403_tagPlayerLoginLoadOK.mapInitOkEvent -= OnReconnected;
        AttackHandler.OnAttackTarget -= OnPlayerAttack;
        ClientDungeonStageUtility.onReceiveCustomDropItme -= OnReceiveCustomDropItme;
        dungeonModel.onDungeonResultEvent -= OnDungeonResultEvent;
        ClientDropItemUtility.OnItemPickup -= OnItemPickup;
    }
 
#if UNITY_EDITOR
    private void OnGUI()
    {
        if (GUILayout.Button("Exit"))
        {
            model.RequestExitClientDungeon();
        }
    }
#endif
 
    public enum Step
    {
        None,
        Fight,
        PickItem,
        Settle,
        Exit
    }
}