|
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;
|
}
|
}
|
}
|