少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-25 cdb0198fb8e85811ec1e06b15f36df9cbe0fdb9a
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
 
using System.Collections.Generic;
using Snxxz.UI;
 
using UnityEngine;
 
public abstract class HeroAI_Data { }
 
public abstract class HeroAI_Base
{
    public static byte stopReason = 0;
 
    private SkillModel m_SkillModel;
    private SkillModel skillModel
    {
        get { return m_SkillModel ?? (m_SkillModel = ModelCenter.Instance.GetModel<SkillModel>()); }
    }
 
    public abstract bool Condition();
    public abstract void Enter();
    public abstract void Update();
    public abstract void Exit();
    public abstract bool IsOver();
 
    protected int xpSkillID = 0;
 
    protected Skill DecideUserSkill(int[] skillList = null, int priorSkillId = -1)
    {
        GA_Hero _hero = PlayerDatas.Instance.hero;
        if (_hero == null || !_hero.CanCastSkill())
        {
            return null;
        }
 
        Skill _skill = null;
 
        if (priorSkillId >= 0)
        {
            if (CanCast(priorSkillId, true))
            {
                _skill = _hero.SkillMgr.Get(priorSkillId);
                if (_skill != null)
                {
                    return _skill;
                }
            }
        }
 
        // 判断是否需要使用加血技能
        float _curHpPer = PlayerDatas.Instance.baseData.HP * 1f / PlayerDatas.Instance.extersion.MaxHP;
        if (_curHpPer < _hero.JobSetup.HpPerUseSkill * Constants.F_DELTA)
        {
            _skill = CanCast(_hero.JobSetup.HpSkillList);
        }
 
        if (_skill != null)
        {
            return _skill;
        }
 
        // 判断是否需要使用增益技能
        _skill = CanCast(_hero.JobSetup.GainSkillList);
 
        if (_skill != null)
        {
            return _skill;
        }
 
        if (skillList == null)
        {
            // 判断是否需要使用哪个攻击技能
            _skill = CanCast(_hero.JobSetup.HangupSkillList);
        }
        else
        {
            _skill = CanCast(skillList);
        }
 
        if (_skill == null && _hero.CanCommonAtk())
        {
            int _index = _hero.nextComAtkIndex;
            if (_index == -1)
            {
                _index = 0;
            }
            int _comSkillID = _hero.GetCommonSkillID(_index);
 
            _skill = _hero.SkillMgr.Get(_comSkillID);
 
            if (_skill != null && _skill.skillInfo != null && _skill.skillInfo.config != null)
            {
                // 判断是否是被封禁的技能
                if (!StatusMgr.Instance.CanAttack(_hero.ServerInstID, _skill.skillInfo.config.SkillOfSeries))
                {
                    return _skill;
                }
            }
        }
 
        return _skill;
    }
 
    protected Skill CanCast(int[] skillList)
    {
        GA_Hero _hero = PlayerDatas.Instance.hero;
 
        int _chkSkillID = -1;
        for (int i = 0; i < skillList.Length; ++i)
        {
            _chkSkillID = skillList[i];
 
            if (CanCast(_chkSkillID))
            {
                return _hero.SkillMgr.Get(_chkSkillID);
            }
        }
 
        return null;
    }
 
    protected bool CanCastActiveUse(int skillID)
    {
        GA_Hero _hero = PlayerDatas.Instance.hero;
        // 获取英雄真实拥有的技能
        Dictionary<int, PlayerSkillData> _heroSkills = PlayerDatas.Instance.skill.GetAllSkill();
 
        if (!_heroSkills.ContainsKey(skillID))
        {
            return false;
        }
 
        if (StatusMgr.Instance.IsExist(_hero.ServerInstID, skillID))
        {
            return false;
        }
 
        var _skill = _hero.SkillMgr.Get(skillID);
 
        // 判断是否是被封禁的技能
        if (!StatusMgr.Instance.CanAttack(_hero.ServerInstID, _skill.skillInfo.config.SkillOfSeries))
        {
            return false;
        }
 
        if (!_skill.IsValid())
        {
            return false;
        }
 
        return true;
    }
 
    protected bool CanCast(int skillID, bool userClick = false)
    {
        if (!CanCastActiveUse(skillID))
        {
            return false;
        }
 
        if (skillID == xpSkillID)
        {
            GA_Hero _hero = PlayerDatas.Instance.hero;
 
            if ((!skillModel.AutoUseXp()
             || GeneralDefine.NoXpDungeons.Contains(PlayerDatas.Instance.baseData.MapID)
             || (_hero.SelectTarget != null && _hero.SelectTarget is GActorPlayerBase)) && !userClick)
            {
                return false;
            }
        }
 
        return true;
    }
 
    protected GActorFight DecideAttackTarget(Vector3 searchCenter, float range, int lockNpcID = -1)
    {
        GA_Hero _hero = PlayerDatas.Instance.hero;
        GActorFight _target = _hero.SelectTarget as GActorFight;
 
        if (_target == null || !_target.CanAtked() || _target.ActorInfo.serverDie)
        {
            _target = GAMgr.Instance.FindAtkTarget(searchCenter, range, 360, lockNpcID);
        }
 
        if (_target != null && lockNpcID != -1)
        {
            var _npcFight = _target as GActorNpcFight;
            if(_npcFight != null)
            {
                if(_npcFight.NpcConfig.NPCID != lockNpcID)
                {
                    _target = GAMgr.Instance.FindAtkTarget(searchCenter, range, 360, lockNpcID);
                }
            }
        }
 
        return _target;
    }
 
    private PackModel m_PlayerBackModel;
    private PackModel PlayerBackModel
    {
        get
        {
            return m_PlayerBackModel ?? (m_PlayerBackModel = ModelCenter.Instance.GetModel<PackModel>());
        }
    }
 
    protected bool WaitForPickup()
    {
        GA_Hero _hero = PlayerDatas.Instance.hero;
        DropItemManager.DropObject _obj = null;
        if (DropItemManager.HandupTryGetHeroItem(out _obj))
        {
            bool _needPickupSelf = true;
 
            // 有掉落物
            // 是否是强制守护不能拾取的
            if (_obj.ownerType != 7)
            {
                if (DungeonOpenTimeConfig.Has(PlayerDatas.Instance.baseData.MapID)) // 是副本
                {
                    var _dungeonOpenTime = DungeonOpenTimeConfig.Get(PlayerDatas.Instance.baseData.MapID);
                    if (_dungeonOpenTime.GuardPick == 1)// 守护可以拾取
                    {
                        var _singleModel = PlayerBackModel.GetSinglePack(PackType.Equip);
                        if (_singleModel != null)
                        {
                            // 如果有守护
                            var _itemModel = _singleModel.GetItemByIndex((int)RoleEquipType.SpiritAnimal);
                            if (_itemModel != null // 有守护
                             && GeneralDefine.GuardianPickUpID.Contains(_itemModel.itemId))// 守护有拾取功能
                            {
                                _needPickupSelf = false;
                            }
                        }
                    }
                }
                else
                {
                    var _singleModel = PlayerBackModel.GetSinglePack(PackType.Equip);
                    if (_singleModel != null)
                    {
                        // 如果有守护
                        var _itemModel = _singleModel.GetItemByIndex((int)RoleEquipType.SpiritAnimal);
                        if (_itemModel != null // 有守护
                         && GeneralDefine.GuardianPickUpID.Contains(_itemModel.itemId))// 守护有拾取功能
                        {
                            _needPickupSelf = false;
                        }
                    }
                }
            }
 
            if (_needPickupSelf)
            {
                _hero.StopRush();
                Vector3 _targetPosition = _obj.dropItem.transform.position;
                float _chkDistSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, _targetPosition);
                if (_chkDistSqrt > 0.5f)
                {
                    _hero.MoveToPosition(_targetPosition);
                }
                return true;
            }
        }
        return false;
    }
 
    public static bool IsSkillNeedMove(int tag, E_SkillType skillType)
    {
        E_SkillCastTarget _targetType = (E_SkillCastTarget)(tag / 10);
        E_SkillCastType _castType = (E_SkillCastType)(tag % 10);
 
        if ((_targetType == E_SkillCastTarget.None
          || _targetType == E_SkillCastTarget.Self
          || _targetType == E_SkillCastTarget.SelfAndFriend
          || _castType == E_SkillCastType.None)
         && (skillType != E_SkillType.Attack))
        {
            return false;
        }
        else
        {
            return true;
        }
    }
}