You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 lines
2.5 KiB

using BehaviorDesigner.Runtime.Tasks;
using System.Collections.Generic;
using UnityEngine;
namespace CoreGame.Render
{
/// <summary>
/// TODO
/// </summary>
public class HitAndMove : Action
{
[SerializeField] private float range;
private CombatEntity m_OwnerEnt;
private Vector2 m_TargetPos;
private List<CombatEntity> m_TargetList;
private float m_StartTime;//��Щʱ�򵽲���Ŀ��㣬����һ���ڵ����ִ��ʱ��
public override void OnStart()
{
m_StartTime = Time.time;
m_OwnerEnt = Owner.GetEntity<CombatEntity>();
var ac = m_OwnerEnt.aI;
var maxSqrDis = float.MaxValue;
int targetEid = 0;
for (var index = 0; index < ac.targetList.Count; index++)
{
var targetId = ac.targetList[index];
var target1 = Contexts.Combat.GetEntity(targetId);
if (target1.IsValid() == false)
{
continue;
}
var sqrDis = (m_OwnerEnt.transformProxy.position - target1.transformProxy.position).sqrMagnitude;
if (sqrDis < maxSqrDis)
{
maxSqrDis = sqrDis;
targetEid = targetId;
}
}
var target = Contexts.Combat.GetEntity(targetEid);
Vector2 monsterPosition = m_OwnerEnt.transformProxy.position;
Vector2 playerPosition = target.transformProxy.position;
Vector2 monster2Player = (playerPosition - monsterPosition).normalized;
float randomaRadius = RandomSrv.Range(0f, Mathf.PI * 2);
Vector2 randomDir = new Vector2(Mathf.Cos(randomaRadius), Mathf.Sin(randomaRadius));
Vector2 fleeDir = (randomDir - monster2Player).normalized;
m_TargetPos = randomDir * range;
}
public override TaskStatus OnUpdate()
{
var speed = 1.5f;// m_OwnerEnt.property.MoveSpeed;
m_OwnerEnt.navAgentProxy.SetDestination(m_TargetPos, speed);
if ((m_OwnerEnt.transformProxy.position - m_TargetPos).sqrMagnitude < 0.1f)
{
return TaskStatus.Success;
}
if (m_StartTime + 1.5f < Time.time)
{
m_OwnerEnt.navAgentProxy.StopNav();
return TaskStatus.Failure;
}
return TaskStatus.Running;
}
}
}