少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-12 041b77f011062b5bab5216cf1b9e650e8e3e188d
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
using Snxxz.UI;
using System.Collections.Generic;
using UnityEngine;
using System;
 
public class GuardRun : SMB_Base
{
    private Vector3 m_NextPosition;
    private Vector3 m_LastPosition;
    private SFXController m_SFXController;
    private float m_Time;
    private float m_Duration = 0;
    private float m_PickUpTime = 0;
    private float m_PickUpDelayTime = 1.0f;
    private List<int> dropItems = new List<int>();
 
    private GA_Guard guard;
 
    GuardModel model
    {
        get { return ModelCenter.Instance.GetModel<GuardModel>(); }
    }
 
    protected override void OnEnter(GActor owner, Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        base.OnEnter(owner, animator, stateInfo, layerIndex);
        guard = owner as GA_Guard;
        if (guard == null)
        {
            return;
        }
        if (m_SFXController == null)
        {
            var mountPoint = guard.Root.GetChildTransformDeeply(GAStaticDefine.MountPointBoneName);
            m_SFXController = SFXPlayUtility.Instance.PlayBattleEffect(guard.pickEffectIds[1], owner);
            if (m_SFXController != null)
            {
                m_SFXController.duration = 0;
                m_SFXController.transform.SetParent(mountPoint);
                m_SFXController.transform.localPosition = Vector3.zero;
            }
        }
        else
        {
            m_SFXController.SetActive(true);
        }
 
        m_Time = 0;
        switch (guard.guardState)
        {
            case GA_Guard.GuardState.Track:
                break;
            case GA_Guard.GuardState.Dance:
                break;
            case GA_Guard.GuardState.Inter:
                {
                    if (guard.targetPlayer == null)
                    {
                        return;
                    }
                    m_NextPosition = guard.targetPlayer.Root.position.SetY(0);
                    m_LastPosition = guard.Root.position;
                    guard.Forward = m_NextPosition - guard.Root.position;
                    m_Duration = Vector3.Distance(m_NextPosition, guard.Root.position) / model.speed;
                }
                break;
            case GA_Guard.GuardState.PickUp:
                {
                    OnPickUpEnter();
                }
                break;
        }
    }
 
    public void OnPickUpEnter()
    {
        m_PickUpTime = 0.0f;
        DTC0702_tagDropItemDisappear.OnDropItemDisapperEvent -= OnDropItemDisapperEvent;
        DTC0702_tagDropItemDisappear.OnDropItemDisapperEvent += OnDropItemDisapperEvent;
        OnDropItemDisapperEvent();
    }
 
    private void OnDropItemDisapperEvent()
    {
        if (guard == null)
        {
            return;
        }
        dropItems.Clear();
        DropItemManager.TryGetGuardPickUpItem(guard.Root.position, ref dropItems);
        dropItems.Sort(Compare);
        RequestDropItem();
    }
 
    protected override void OnExit(GActor owner, Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        base.OnExit(owner, animator, stateInfo, layerIndex);
        ReleaseSFX();
        DTC0702_tagDropItemDisappear.OnDropItemDisapperEvent -= OnDropItemDisapperEvent;
        guard = null;
    }
 
    protected override void OnUpdate(GActor owner, Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        base.OnUpdate(owner, animator, stateInfo, layerIndex);
        if (owner == null || guard == null)
        {
            return;
        }
        var hero = guard.targetPlayer;
        if (guard.targetPlayer == null)
        {
            return;
        }
        switch (guard.guardState)
        {
            case GA_Guard.GuardState.Idle:
                break;
            case GA_Guard.GuardState.Track:
                {
                    var targetPosition = hero.Root.position;
                    if (MathUtility.CalDistance(guard.Root.position, targetPosition) > model.impendRange * model.impendRange)
                    {
                        guard.Root.LookAt(new Vector3(targetPosition.x, targetPosition.y + model.height, targetPosition.z));
                        guard.Root.Translate(Vector3.forward * hero.ActorInfo.moveSpeed * Time.deltaTime);
                    }
                    else
                    {
                        guard.Idle();
                    }
                }
                break;
            case GA_Guard.GuardState.Dance:
                {
                    var targetPosition = hero.Root.position;
                    m_NextPosition = targetPosition + hero.Root.right.normalized * 0.6f - hero.Forward * 0.3f;
                    m_NextPosition.y = targetPosition.y + model.height;
                    var dis = Vector3.Distance(m_NextPosition, guard.Root.position);
                    if (dis > 0.1f)
                    {
                        guard.Forward = m_NextPosition - guard.Root.position;
                        var deltapos = Vector3.Lerp(guard.Root.position, m_NextPosition, hero.ActorInfo.moveSpeed * Time.deltaTime);
                        guard.Root.position = deltapos;
                    }
                    else
                    {
                        guard.Forward = hero.Forward;
                        guard.NextAction = GA_Guard.GuardAction_Dance2;
                    }
                }
                break;
            case GA_Guard.GuardState.Inter:
                {
                    m_Time += Time.deltaTime;
                    guard.Root.position = Vector3.Lerp(m_LastPosition, m_NextPosition, Mathf.Min(1, m_Time / m_Duration));
                    if (m_Time >= m_Duration)
                    {
                        ReleaseSFX();
                        (owner as GA_Guard).Disappear();
                    }
                }
                break;
            case GA_Guard.GuardState.PickUp:
                {
                    m_PickUpTime += Time.deltaTime;
                    if (guard.Root.position != m_NextPosition)
                    {
                        m_Time += Time.deltaTime;
                        guard.Root.position = Vector3.Lerp(m_LastPosition, m_NextPosition, Mathf.Min(1, m_Time / m_Duration));
                        if (m_Time >= m_Duration)
                        {
                            RequestDropItem();
                            DropItemManager.CheckGuardPickUpItem(guard.Root.position);
                        }
                    }
                    else
                    {
                        RequestDropItem();
                    }
                }
                break;
        }
    }
 
    int Compare(int x, int y)
    {
        Vector3 xpos;
        Vector3 ypos;
        DropItemManager.TryGetDropPositionFromInstanceId(x, out xpos);
        DropItemManager.TryGetDropPositionFromInstanceId(y, out ypos);
        float xdis = Vector3.Distance(xpos, m_NextPosition);
        float ydis = Vector3.Distance(ypos, m_NextPosition);
        return -xdis.CompareTo(ydis);
    }
 
    void RequestDropItem()
    {
        m_Time = 0;
        if (dropItems.Count == 0)
        {
            guard.guardState = GA_Guard.GuardState.Track;
            return;
        }
        m_LastPosition = guard.Root.position;
        if (guard.targetPlayer == null)
        {
            return;
        }
        if (DropItemManager.TryGetDropPositionFromInstanceId(dropItems[0], out m_NextPosition))
        {
            m_NextPosition.y = guard.targetPlayer.Root.position.y + model.height;
            guard.Forward = m_NextPosition - m_LastPosition;
        }
        if (dropItems.Count > 0 && Vector3.Distance(guard.Root.position, m_NextPosition) < 0.1f
            && m_PickUpTime >= m_PickUpDelayTime)
        {
            m_PickUpTime = 0.0f;
            DropItemManager.CheckGuardPickUpItem(guard.Root.position);
        }
        m_Duration = Vector3.Distance(m_LastPosition, m_NextPosition) / model.speed;
    }
 
    void ReleaseSFX()
    {
        if (m_SFXController != null)
        {
            SFXPlayUtility.Instance.Release(m_SFXController);
            m_SFXController = null;
        }
    }
}