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); } }
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! }
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); }
private bool ShouldUsePreviousIntersections(IntersectionAnalysis previousIntersectionAnalysis) { return(previousIntersectionAnalysis != null && previousIntersectionAnalysis.HasIntersections()); }
private bool NothingFound() { return(IntersectionAnalysis.HasIntersections() == false && _parallelAnalysis.ParallelUnit == null); }
private bool ParallelAndIntersectionsFound() { return(IntersectionAnalysis.HasIntersections() && _parallelAnalysis.ParallelUnit != null); }
private bool OnlyParallelUnitFound() { return(IntersectionAnalysis.HasIntersections() == false && _parallelAnalysis.ParallelUnit != null); }