少年修仙传客户端代码仓库
client_linchunjie
2018-09-14 a0ede150686a218c92b901b1f20aef12a9913890
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
using Snxxz.UI;
using System.Collections.Generic;
using UnityEngine;
 
public class GuardRun : SMB_Base
{
    [HideInInspector]
    public Vector3 nextPosition;
    private Vector3 lastPosition;
    private SFXController _sfXctl;
    private float m_Time;
    private float guardClosingTime = 0;
    private List<int> dropItemList = new List<int>();
    private GA_Guard guard;
    private float m_PickUpPackTime = 0;
    private float m_PickUpDelayTime = 1.0f;
 
    PlayerPackModel _playerPack;
    PlayerPackModel playerPack
    {
        get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
    }
 
    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 (_sfXctl == null)
        {
            var mountPoint = guard.Root.GetChildTransformDeeply(GAStaticDefine.MountPointBoneName);
            _sfXctl = SFXPlayUtility.Instance.PlayBattleEffect(guard.guardEffects[1], owner);
            if (_sfXctl != null)
            {
                _sfXctl.duration = 0;
                _sfXctl.transform.SetParent(mountPoint);
                _sfXctl.transform.localPosition = Vector3.zero;
            }
        }
        else
        {
            _sfXctl.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;
                    }
                    nextPosition = guard.targetPlayer.Root.position.SetY(0);
                    lastPosition = guard.Root.position;
                    guard.Forward = nextPosition - guard.Root.position;
                    guardClosingTime = Vector3.Distance(nextPosition, guard.Root.position) / guard.GuardianSpeed;
                }
                break;
            case GA_Guard.GuardState.PickUp:
                {
                    OnPickUpEnter();
                }
                break;
        }
    }
 
    public void OnPickUpEnter()
    {
        m_PickUpPackTime = 0.0f;
        DTC0702_tagDropItemDisappear.OnDropItemDisapperEvent -= OnDropItemDisapperEvent;
        DTC0702_tagDropItemDisappear.OnDropItemDisapperEvent += OnDropItemDisapperEvent;
        OnDropItemDisapperEvent();
    }
 
    private void OnDropItemDisapperEvent()
    {
        if (guard == null)
        {
            return;
        }
        dropItemList.Clear();
        DropItemManager.TryGetGuardPickUpItem(guard, ref dropItemList);
        dropItemList.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 _heroPos = hero.Root.position;
                    if (MathUtility.CalDistance(guard.Root.position, _heroPos) > guard.GuardianImpendRange * guard.GuardianImpendRange)
                    {
                        guard.Root.LookAt(new Vector3(_heroPos.x, _heroPos.y + guard.GuardianHeight, _heroPos.z));
                        guard.Root.Translate(Vector3.forward * hero.ActorInfo.moveSpeed * Time.deltaTime);
                    }
                    else
                    {
                        guard.Idle();
                    }
                }
                break;
            case GA_Guard.GuardState.Dance:
                {
                    var _heroPos = hero.Root.position;
                    nextPosition = _heroPos + hero.Root.right.normalized * 0.6f - hero.Forward * 0.3f;
                    nextPosition.y = _heroPos.y + guard.GuardianHeight;
                    var dis = Vector3.Distance(nextPosition, guard.Root.position);
                    if (dis > 0.1f)
                    {
                        guard.Forward = nextPosition - guard.Root.position;
                        var deltapos = Vector3.Lerp(guard.Root.position, 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(lastPosition, nextPosition, Mathf.Min(1, m_Time / guardClosingTime));
                    if (m_Time >= guardClosingTime)
                    {
                        ReleaseSFX();
                        (owner as GA_Guard).Disappear();
                    }
                }
                break;
            case GA_Guard.GuardState.PickUp:
                {
                    m_PickUpPackTime += Time.deltaTime;
                    if (guard.Root.position != nextPosition)
                    {
                        m_Time += Time.deltaTime;
                        guard.Root.position = Vector3.Lerp(lastPosition, nextPosition, Mathf.Min(1, m_Time / guardClosingTime));
                        if (m_Time >= guardClosingTime)
                        {
                            RequestDropItem();
                            DropItemManager.CheckGuardPickUpItem(guard);
                        }
                    }
                    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, nextPosition);
        float ydis = Vector3.Distance(ypos, nextPosition);
        return -xdis.CompareTo(ydis);
    }
 
    void RequestDropItem()
    {
        m_Time = 0;
        if (dropItemList.Count == 0)
        {
            guard.guardState = GA_Guard.GuardState.Track;
            return;
        }
        lastPosition = guard.Root.position;
        if (guard.targetPlayer == null)
        {
            return;
        }
        if (DropItemManager.TryGetDropPositionFromInstanceId(dropItemList[0], out nextPosition))
        {
            nextPosition.y = guard.targetPlayer.Root.position.y + guard.GuardianHeight;
            guard.Forward = nextPosition - lastPosition;
        }
        if (dropItemList.Count > 0 && Vector3.Distance(guard.Root.position, nextPosition) < 0.1f
            && m_PickUpPackTime >= m_PickUpDelayTime)
        {
            m_PickUpPackTime = 0.0f;
            DropItemManager.CheckGuardPickUpItem(guard);
        }
        guardClosingTime = Vector3.Distance(lastPosition, nextPosition) / guard.GuardianSpeed;
    }
 
    void ReleaseSFX()
    {
        if (_sfXctl != null)
        {
            SFXPlayUtility.Instance.Release(_sfXctl);
            _sfXctl = null;
        }
    }
}