using UnityEngine;
|
|
using System.Collections.Generic;
|
|
public class HeroAI_D4_Qlzf : HeroAI_Auto
|
{
|
/// <summary>
|
/// 配置路点集合
|
/// </summary>
|
private List<Vector3> m_PointList = new List<Vector3>();
|
|
/// <summary>
|
/// 搜寻路点索引
|
/// </summary>
|
private int m_Index;
|
|
|
public sealed override bool Condition()
|
{
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
if (_hero == null)
|
{
|
return false;
|
}
|
|
if (_hero.aiHandler.currentType == E_HeroAIType.D4_QLZF)
|
{
|
return true;
|
}
|
|
return base.Condition();
|
}
|
|
protected override void OnEnter()
|
{
|
m_PointList.Clear();
|
m_Index = 0;
|
FuncConfigConfig func = FuncConfigConfig.Get("AI198Point");
|
LitJson.JsonData _data = LitJson.JsonMapper.ToObject(func.Numerical1);
|
|
string _chkKey = (PlayerDatas.Instance.baseData.MapID * 100 + PlayerDatas.Instance.baseData.dungeonLineId).ToString();
|
#if UNITY_EDITOR
|
Debug.Log("客户端AI检测配置ID: " + _chkKey);
|
#endif
|
foreach (var _key in _data.Keys)
|
{
|
if (_key.Equals(_chkKey))
|
{
|
for (int j = 0; j < _data[_key].Count; ++j)
|
{
|
Vector3 _pos = new Vector3((int)_data[_key][j][0] * .5f,
|
0,
|
(int)_data[_key][j][1] * .5f);
|
m_PointList.Add(_pos);
|
}
|
}
|
}
|
|
m_HandupRange = 10;
|
}
|
|
protected override bool OnUpdate()
|
{
|
GA_Hero _hero = PlayerDatas.Instance.hero;
|
|
if (_hero == null)
|
{
|
return false;
|
}
|
|
// 实时判断英雄当前的目标
|
GActorFight _actor = _hero.SelectTarget as GActorFight;
|
|
// 没有可选择目标
|
if (_actor == null
|
|| !_actor.CanAtked())
|
{
|
// 自动帮其选择一个
|
_actor = SelectTarget();
|
|
// 选不到
|
if (_actor == null)
|
{
|
if (m_Index > m_PointList.Count - 1)
|
{
|
m_Index = 0;
|
}
|
|
// 开始判断路点距离
|
float _chkDistSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, m_PointList[m_Index]);
|
|
// 未到达路点则寻路至路点
|
if (_chkDistSqrt > .25f)
|
{
|
_hero.MoveToPosition(m_PointList[m_Index]);
|
}
|
// 到达路点就去往下一个路点
|
else
|
{
|
m_Index += 1;
|
if (m_Index > m_PointList.Count - 1)
|
{
|
m_Index = 1;
|
}
|
}
|
|
return true;
|
}
|
else
|
{
|
_hero.SelectTarget = _actor;
|
_hero.LockTarget = _actor;
|
}
|
}
|
|
return false;
|
}
|
|
protected sealed override void OnExit()
|
{
|
m_PointList.Clear();
|
}
|
|
public sealed override bool IsOver()
|
{
|
if (base.IsOver())
|
{
|
return true;
|
}
|
|
return PlayerDatas.Instance.hero.aiHandler.currentType
|
!= E_HeroAIType.D4_QLZF;
|
}
|
|
protected sealed override GActorFight SelectTarget()
|
{
|
return DecideAttackTarget(PlayerDatas.Instance.hero.Pos,
|
m_HandupRange);
|
}
|
}
|