少年修仙传客户端代码仓库
hch
3 小时以前 600733c8f592cb9e65f2b7a3e110ac1d686e6bfe
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
using System.Collections.Generic;
using UnityEngine;
 
public class JiaPlayerController
{
    public enum E_BehaviourType
    {
        MoveBeTweenNpc,
        MaxType,
        Fight
    }
 
    public struct JiaPlayerData
    {
        public int job;
        public string name;
        public int clothes;
        public int weapon;
        public int sedcondary;
        public E_BehaviourType behaviourType;
    }
 
    private float m_Duration;
 
    public bool IsDone;
    private GA_JiaPlayer m_Player;
    public E_BehaviourType BehaviourType { get; private set; }
    public float m_WaitingTime = 0;
    public float m_RandomIdelTime = 0;
    private float m_DurationEscapeTime;
 
    public void Init(JiaPlayerData data)
    {
        IsDone = false;
        var _playerData = new GActorPlayerBase.PlayerInfo();
        _playerData.name = data.name;
        _playerData.job = (byte)data.job;
        var _equipList = new List<GActorPlayerBase.CEquipInfo>();
        if (ItemConfig.Has(data.clothes))
        {
            _equipList.Add(new GActorPlayerBase.CEquipInfo()
            {
                id = data.clothes,
                place = ItemConfig.Get(data.clothes).EquipPlace
            });
        }
        if (ItemConfig.Has(data.weapon))
        {
            _equipList.Add(new GActorPlayerBase.CEquipInfo()
            {
                id = data.clothes,
                place = ItemConfig.Get(data.clothes).EquipPlace
            });
        }
        if (ItemConfig.Has(data.sedcondary))
        {
            _equipList.Add(new GActorPlayerBase.CEquipInfo()
            {
                id = data.clothes,
                place = ItemConfig.Get(data.clothes).EquipPlace
            });
        }
        _playerData.itemDatas = _equipList.ToArray();
        _equipList.Clear();
        _equipList = null;
 
        m_DurationEscapeTime = 0;
        m_Duration = JiaPlayerManager.EachPlayerLastTime;
 
        BehaviourType = data.behaviourType;
        // 从已经刷出的NPC中随机出生位置
        Vector3 _bornPos = GetRandomNpcPosition();
 
        var _randomDir = new Vector3(Random.Range(-1f, -.3f), 0, Random.Range(-.9f, .9f));
        if (Random.Range(1, 3) == 1)
        {
            _randomDir = new Vector3(Random.Range(.3f, 1f), 0, Random.Range(-.9f, .9f));
        }
        
        _bornPos = _bornPos + _randomDir;
        GActor.TryGetValidPos(_bornPos, ref _bornPos);
 
        m_Player = GAMgr.Instance.ReqClntPlayer<GA_JiaPlayer>(_playerData, E_ActorGroup.Player);
        m_Player.InitBornPos((ushort)(_bornPos.x * 2), (ushort)(_bornPos.z * 2));
    }
 
    public void UnInit()
    {
        if (m_Player != null)
        {
            GAMgr.Instance.Release(m_Player);
            m_Player = null;
        }
    }
 
    private byte m_Step = 0;
 
    public void Update()
    {
        if (BehaviourType == E_BehaviourType.MoveBeTweenNpc)
        {
            if (m_Player != null)
            {
                switch (m_Step)
                {
                    case 0:
                        if (m_Player.IsIdle())
                        {
                            m_WaitingTime = Time.time + Random.Range(3f, 5f);
                            m_Step = 1;
                        }
                        else
                        {
                            m_Step = 2;
                        }
                        break;
                    case 1:// 等待站立的随机时间结束
                        if (Time.time > m_WaitingTime)
                        {
                            Vector3 _nextPosition = Vector3.zero;
                            bool fight = false;
                            int moveWay = Random.Range(0, 3);
                            if (moveWay == 1)
                            {
                                fight = true;
                                _nextPosition = GetFightNpcPosition();
                            }
                            else if (moveWay == 2)
                                _nextPosition = GetRandomNpcPosition();
                            else
                                _nextPosition = GetCloserNpcPosition();
 
                            if (_nextPosition == Vector3.zero)
                            {
                                fight = false;
                                _nextPosition = GetCloserNpcPosition();
                            }
 
                            if (_nextPosition == Vector3.zero)
                            {
                                m_Step = 0;
                            }
                            else
                            {
                                m_Player.MoveToPosition(_nextPosition, 1);
                                if (fight) BehaviourType = E_BehaviourType.Fight;
                                m_Step = 2;
                            }
                        }
                        break;
                    case 2:
                        if (m_Player.IsIdle())
                        {
                            m_Step = 0;
                        }
                        break;
                }
            }
        }
        else if (BehaviourType == E_BehaviourType.Fight)
        {
            if (m_Player != null)
            {
                if (m_Player.IsIdle())
                {
                    if (!m_Player.PlaySkill())
                        BehaviourType = E_BehaviourType.MoveBeTweenNpc;
                }
            }
        }
 
        m_DurationEscapeTime += Time.deltaTime;
        if(m_DurationEscapeTime > m_Duration || m_Player.Pos.x == 10000)
        {
            IsDone = true;
        }
    }
 
 
    private Vector3 GetRandomNpcPosition()
    {
        var _list = GAMgr.Instance.GetTypeList(E_ActorClassType.NpcFunc);
        if (_list == null || _list.Count == 0)
        {
            _list = GAMgr.Instance.GetTypeList(E_ActorClassType.NpcFightNorm);
            if (_list == null || _list.Count == 0)
                return Vector3.zero;
        }
 
        var _random = Random.Range(0, _list.Count);
        return _list[_random].Pos;
    }
 
    private Vector3 GetFightNpcPosition()
    {
        var _list = GAMgr.Instance.GetTypeList(E_ActorClassType.NpcFightNorm);
        if (_list == null || _list.Count == 0)
            return Vector3.zero;
 
        var _random = Random.Range(0, _list.Count);
        return _list[_random].Pos;
    }
 
    private Vector3 GetCloserNpcPosition()
    {
        var _mapID = PlayerDatas.Instance.baseData.MapID;
        var _mapNpcs = mapnpcConfig.GetNpcList(_mapID);
        var _list = new List<int>(_mapNpcs.Keys);
        /*
        _list.Sort((n1, n2) =>
        {
            var _d1 = MathUtility.DistanceSqrtXZ(PlayerDatas.Instance.hero.Pos,
                _mapNpcs[n1]);
            var _d2 = MathUtility.DistanceSqrtXZ(PlayerDatas.Instance.hero.Pos,
                _mapNpcs[n1]);
            return _d2 < _d1 ? -1 : 1;
        });
 
        for (int i = 0; i < _list.Count; ++i)
        {
            if (_list[i] != currentMoveToNpc)
            {
                currentMoveToNpc = _list[i];
                return _mapNpcs[_list[i]];
            }
        }
        */
        if (_list == null || _list.Count == 0)
        {
            return Vector3.zero;
        }
        var _random = Random.Range(0, _list.Count);
        return _mapNpcs[_list[_random]];
    }
 
    
}