예제 #1
0
 public virtual bool Perform()
 {
     return(_actor.TryUsePoints(PointCost, Strict));
 }
예제 #2
0
    private void UpdateLogic()
    {
        if (FireAction.PointCost <= Actor.CurrentActionPoints)
        {
            if (CheckVisibility() && !CheckLookingAt())
            {
                Agent.isStopped = true;

                var angleDiff = Vector3.SignedAngle(transform.forward, Target.transform.position - transform.position, Vector3.up);

                transform.Rotate(new Vector3(0, Mathf.Sign(angleDiff) * RotationSpeed * Time.smoothDeltaTime, 0));
                var angleDiff1 = Vector3.SignedAngle(transform.forward, Target.transform.position - transform.position, Vector3.up);
                if (Mathf.Sign(angleDiff) != Mathf.Sign(angleDiff1))
                {
                    transform.LookAt(Target.transform);
                    transform.rotation = Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y, 0);
                }
                else
                {
                    return;
                }


                if (!Actor.TryUsePoints(Quaternion.Angle(transform.rotation, _oldRotation) * 0.01f, false))
                {
                    Agent.isStopped  = true;
                    Agent.enabled    = false;
                    Obstacle.enabled = true;
                    return;
                }
            }

            if (CheckVisibility() && CheckLookingAt())
            {
                if (FireAction.OnCooldown)
                {
                    Agent.isStopped = true;
                }

                if (FireAction.Perform())
                {
                    return;
                }
            }
        }

        var dist = Vector3.Distance(transform.position, _oldPosition);

        Agent.isStopped      = false;
        Agent.updatePosition = true;
        if (!Actor.TryUsePoints(dist, false))
        {
            Agent.isStopped  = true;
            Agent.enabled    = false;
            Obstacle.enabled = true;
        }

        //Avoid stuck
        if (FireAction.PointCost > Actor.CurrentActionPoints)
        {
            if (Mathf.Approximately(_oldPoints, Actor.CurrentActionPoints))
            {
                Agent.isStopped  = true;
                Agent.enabled    = false;
                Obstacle.enabled = true;
                Actor.EndTurn();
            }
        }
    }