Пример #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);
        }
    }
Пример #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!
    }
Пример #3
0
    public MovementPackage(Destination destination, IntersectionAnalysis previousIntersectionAnalysis, Transform mover, float distanceScalar)
    {
        MovementCount++;
        DistanceScalar = distanceScalar;
        _mover         = mover;

        Destination = destination;

        IntersectionAnalysis = ShouldUsePreviousIntersections(previousIntersectionAnalysis)
            ? previousIntersectionAnalysis
            : new IntersectionAnalysis(destination);

        _parallelAnalysis = new ParallelAnalysis(Destination, distanceScalar);

        IntersectionAnalysis.DrawIntersectionVectors();

        Evaluate(distanceScalar);
        LocationBeforeCollisionAdjustment = Destination.TargetLocation;
        Destination.TargetLocation        = BoundaryHelper.HandleBoundaryCollision(Destination.TargetLocation, destination.MoveDirection);
        BoundaryPathFinder = new BoundaryPathFinder(_mover, Destination);
    }
Пример #4
0
 private bool ShouldUsePreviousIntersections(IntersectionAnalysis previousIntersectionAnalysis)
 {
     return(previousIntersectionAnalysis != null && previousIntersectionAnalysis.HasIntersections());
 }
Пример #5
0
 private bool NothingFound()
 {
     return(IntersectionAnalysis.HasIntersections() == false && _parallelAnalysis.ParallelUnit == null);
 }
Пример #6
0
 private bool ParallelAndIntersectionsFound()
 {
     return(IntersectionAnalysis.HasIntersections() && _parallelAnalysis.ParallelUnit != null);
 }
Пример #7
0
 private bool OnlyParallelUnitFound()
 {
     return(IntersectionAnalysis.HasIntersections() == false && _parallelAnalysis.ParallelUnit != null);
 }