Beispiel #1
0
    private void Evaluate(float distanceScalar)
    {
        if (MoveThroughDangerousEnemy())
        {
            for (var i = 0; i < _chargePenaltyForMovingThroughDangerousEnemy; i++)
            {
                OnCollisionWithEnemyWhileMovingThroughIntersection?.Invoke();
            }

            if (Destination.PreviousIntersectingUnit != null)
            {
                _parallelAnalysis.ParallelUnit = Destination.PreviousIntersectingUnit;
                SetDestinationForParallelUnit();
                Destination.PreviousIntersectingUnit = null;
                return;
            }
        }

        if (OnlyParallelUnitFound())
        {
            SetDestinationForParallelUnit();
            return;
        }

        if (OnlyIntersectionsFound())
        {
            SetDestinationForNextIntersection();
            return;
        }

        if (ParallelAndIntersectionsFound())
        {
            var intersectionLocation = IntersectionAnalysis.PeekIntersections().AngleDefinition.IntersectionPoint;
            var parallelUnitLocation = _parallelAnalysis.ParallelUnit.Transform.position;

            var parallelIsCloser = Vector2.Distance(parallelUnitLocation, _mover.transform.position) <
                                   Vector2.Distance(intersectionLocation, _mover.transform.position);

            if (parallelIsCloser)
            {
                SetDestinationForParallelUnit();
            }
            else
            {
                SetDestinationForNextIntersection();
            }

            return;
        }

        if (NothingFound())
        {
            Finished = true;
            Destination.TargetLocation += Destination.MoveDirection * (distanceScalar + distanceScalar * .5f);
        }
    }
Beispiel #2
0
    private void SetDestinationForNextIntersection()
    {
        if (IntersectionAnalysis.PeekIntersections().KillHandler.KillPoint.HasValue)
        {
            IntersectionAnalysis.GetNextUnit();

            if (!IntersectionAnalysis.HasIntersections())
            {
                return;
            }
        }
        Destination.DestinationType = DestinationType.Intersection;
        Destination.Unit            = null;

        Destination.TargetLocation = IntersectionAnalysis.GetNextUnit().AngleDefinition.IntersectionPoint;
        // Set move direction AFTER the redirect to determine which way we're actually going to move!
    }