예제 #1
0
 private void updatePath()
 {
     if (!PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
     {
         PathEntity path = this.theEntity.navigator.getPath();
         if (path != null && path.NodeCountRemaining() <= 2)
         {
             this.pathCounter = 0;
         }
     }
     if (--this.pathCounter <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
     {
         this.pathCounter = 6 + this.theEntity.rand.RandomRange(10);
         PathFinderThread.Instance.FindPath(this.theEntity, this.seekPos, this.theEntity.GetMoveSpeedAggro(), true, this);
     }
 }
예제 #2
0
    public override void Update()
    {
        // No entity, so no need to do anything.
        if (this.entityTarget == null || this.entityTargetPos == null)
        {
            DisplayLog(" Entity Target or EntityTarget Position is null");
            return;
        }

        // Let the entity keep looking at you, otherwise it may just sping around.
        this.theEntity.SetLookPosition(this.entityTargetPos);
        this.theEntity.RotateTo(this.entityTargetPos.x, this.entityTargetPos.y + 2, this.entityTargetPos.z, 30f, 30f);

        if (this.theEntity is EntityAliveSDX)
        {
            if (EntityUtilities.CanExecuteTask(this.theEntity.entityId, EntityUtilities.Orders.SetPatrolPoint))
            {
                // Make them a lot closer to you when they are following you.
                (this.theEntity as EntityAliveSDX).UpdatePatrolPoints(this.theEntity.world.FindSupportingBlockPos(this.entityTarget.position));
            }
        }
        Vector3 a = this.theEntity.position - this.entityTargetPos;

        if (a.sqrMagnitude < 2f)
        {
            DisplayLog("Entity is too close. Ending pathing.");
            this.pathCounter = 0;
            return;
        }

        this.theEntity.moveHelper.CalcIfUnreachablePos(this.entityTargetPos);

        // if the entity is not calculating a path, check how many nodes are left, and reset the path counter if its too low.
        if (!PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
        {
            PathEntity path = this.theEntity.navigator.getPath();
            if (path != null && path.NodeCountRemaining() <= 2)
            {
                this.pathCounter = 0;
            }
        }

        if (--this.pathCounter <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
        {
            DisplayLog(" Path Counter is 0: Finding new path to " + this.entityTargetPos);
            // If its still not calculating a path, find a new path to the leader
            this.pathCounter = 6 + this.theEntity.rand.RandomRange(10);
            PathFinderThread.Instance.FindPath(this.theEntity, this.entityTarget.position, this.theEntity.GetMoveSpeedAggro(), true, this);
        }

        if (this.theEntity.Climbing)
        {
            return;
        }

        // If there's no path, calculate one.
        if (this.theEntity.navigator.noPathAndNotPlanningOne())
        {
            DisplayLog("No Path and Not Planning One. Searching for new path to : " + this.entityTargetPos);
            PathFinderThread.Instance.FindPath(this.theEntity, this.entityTarget.position, this.theEntity.GetMoveSpeedAggro(), true, this);
        }
    }
예제 #3
0
    public override void Update()
    {
        Vector3 position           = Vector3.zero;
        float   targetXZDistanceSq = 0f;

        // No entity, so no need to do anything.
        if (this.entityTarget == null)
        {
            return;
        }

        // Let the entity keep looking at you, otherwise it may just sping around.
        this.theEntity.SetLookPosition(this.entityTarget.getHeadPosition());
        this.theEntity.RotateTo(this.entityTarget.position.x, this.entityTarget.position.y + 2, this.entityTarget.position.z, 30f, 30f);

        // Find the location of the entity, and figure out where it's at.
        position           = this.entityTarget.position;
        targetXZDistanceSq = base.GetTargetXZDistanceSq(6);

        if (entityAliveSDX)
        {
            if (entityAliveSDX.CanExecuteTask(EntityAliveSDX.Orders.SetPatrolPoint))
            {
                // Make them a lot closer to you when they are following you.
                this.distanceToEntity = 1f;
                entityAliveSDX.UpdatePatrolPoints(this.theEntity.world.FindSupportingBlockPos(this.entityTarget.position));
            }
        }
        Vector3 a = position - this.entityTargetPos;

        if (a.sqrMagnitude < 1f)
        {
            this.entityTargetVel = this.entityTargetVel * 0.7f + a * 0.3f;
        }

        this.entityTargetPos = position;
        this.theEntity.moveHelper.CalcIfUnreachablePos(position);
        // num is used to determine how close and comfortable the entity approaches you, so let's make sure they respect some personal space
        if (distanceToEntity < 1)
        {
            distanceToEntity = 3;
        }


        // if the entity is not calculating a path, check how many nodes are left, and reset the path counter if its too low.
        if (!PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
        {
            PathEntity path = this.theEntity.navigator.getPath();
            if (path != null && path.NodeCountRemaining() <= 2)
            {
                this.pathCounter = 0;
            }
        }

        if (--this.pathCounter <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
        {
            // If its still not calculating a path, find a new path to the leader
            this.pathCounter = 6 + this.theEntity.GetRandom().Next(10);
            PathFinderThread.Instance.FindPath(this.theEntity, this.entityTarget.position, this.theEntity.GetMoveSpeedAggro(), true, this);
        }

        if (this.theEntity.Climbing)
        {
            return;
        }

        // If there's no path, calculate one.
        if (this.theEntity.navigator.noPathAndNotPlanningOne())
        {
            PathFinderThread.Instance.FindPath(this.theEntity, this.entityTarget.position, this.theEntity.GetMoveSpeedAggro(), true, this);
        }
    }