コード例 #1
0
        public async Task <GeofenceDataSingleResult> UpsertBoundary(string projectUid, [FromBody] BoundaryRequest request)
        {
            Log.LogInformation(
                $"{ToString()}.{nameof(UpsertBoundary)}: CustomerUID={CustomerUid} BoundaryRequest: {JsonConvert.SerializeObject(request)}");

            var requestFull = BoundaryRequestFull.Create(
                CustomerUid,
                IsApplication,
                await GetProject(projectUid),
                GetUserId,
                request);

            requestFull.Validate(ServiceExceptionHandler);
            requestFull.Request.BoundaryPolygonWKT = GeofenceValidation.MakeGoodWkt(requestFull.Request.BoundaryPolygonWKT);

            var getResult = await BoundaryHelper.GetProjectBoundaries(
                Log, ServiceExceptionHandler,
                projectUid, _projectRepository, _geofenceRepository).ConfigureAwait(false);

            if (getResult.GeofenceData.Any(g => request.Name.Equals(g.GeofenceName, StringComparison.OrdinalIgnoreCase)))
            {
                ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 62);
            }

            var executor = RequestExecutorContainer.Build <UpsertBoundaryExecutor>(ConfigStore, Logger,
                                                                                   ServiceExceptionHandler, _geofenceRepository, _projectRepository, ProjectProxy);
            var result = await executor.ProcessAsync(requestFull) as GeofenceDataSingleResult;

            Log.LogInformation(
                $"{ToString()}.UpsertBoundary Completed: resultCode: {result?.Code} result: {JsonConvert.SerializeObject(result)}");
            return(result);
        }
コード例 #2
0
    public MovementPlan GetStartingPlan(Vector2 currentMoveDirection, IUnit unit)
    {
        var moveDirection = unit != null
            ? ((Vector2)unit.Transform.position - unit.AngleDefinition.GetPointClosestTo(_player.transform.position)).normalized
            : currentMoveDirection;
        var targetLocation = unit?.AngleDefinition.GetPointClosestTo(_player.transform.position) ?? StartingTargetLocation(_player.transform.position, moveDirection);

        targetLocation =
            BoundaryHelper.HandleBoundaryCollision(targetLocation, moveDirection);

        // Obstacle start position = mover.position
        // Target end position = targetLocation (only adjust if there is no unit)

        _currentIntersections = _intersectionDetector.GetIntersectionsFromUnit(unit);

        var startingPlanValues = new MovementPlanValues(targetLocation, moveDirection, unit, _currentIntersections);
        var startingPlanStates = new MovementPlanStates(false, unit == null, false);

        var movementPlan = new MovementPlan(startingPlanValues, startingPlanStates);

        movementPlan.SetFirst();

        OnFirstMove?.Invoke(1);

        return(EditMovementPlanForObstacles(movementPlan, _player.transform.position));
    }
コード例 #3
0
    private Vector2?FindBestTargetPosition()
    {
        var fearDirection  = (_unitEnemy.Transform.position - _player.transform.position).normalized;
        var targetPosition = _unitEnemy.Transform.position + fearDirection * 2f;

        targetPosition =
            BoundaryHelper.AdjustDirectionToFindValidPosition(_unitEnemy.Transform.position, 2f, targetPosition);
        return(targetPosition);
    }
コード例 #4
0
    private Vector2?FindAttackDestination()
    {
        OnAttackStart?.Invoke();
        _spriteRenderer.color = Color.yellow;

        var directionToPlayer    = (_player.transform.position - transform.position).normalized;
        var projectedDestination = _player.transform.position + directionToPlayer * 10f;

        _attackDestination = BoundaryHelper.PointBeforeCollisionWithBoundaryWithBuffer(transform.position, projectedDestination, 2f);

        return(_attackDestination);
    }
コード例 #5
0
    public MovementPackage(Transform mover, Destination destination, float distanceScalar)
    {
        _mover = mover;
        MovementCount++;
        DistanceScalar             = distanceScalar;
        Destination                = destination;
        Destination.TargetLocation = BoundaryHelper.HandleBoundaryCollision(Destination.TargetLocation, destination.MoveDirection);
        if (BoundaryHelper.WillBeMovingThroughBoundary(_mover.transform.position, Destination.TargetLocation))
        {
            Destination = null;
        }

        if (Vector2.Distance(destination.TargetLocation, mover.transform.position) > 0.1f)
        {
            OnFirstMove?.Invoke();
        }
    }
コード例 #6
0
    public bool FoundPath(Vector2 checkFromPosition, Vector2 checkToPosition, Vector2 moveDirection)
    {
        var obstacle = ObstacleHelper.GetObstacle(checkFromPosition, checkToPosition);

        if (BoundaryHelper.ContainedInObstacleCollider(checkToPosition) || BoundaryHelper.TargetLocationEndsInsideObstacle(checkToPosition))
        {
            checkToPosition = BoundaryHelper.FindPositionThroughObstacle(checkToPosition, checkFromPosition);
        }

        checkToPosition += moveDirection * 5f;

        if (obstacle == null)
        {
            return(false);
        }

        TargetLocationOnceFinishedWithObstaclePath = checkToPosition;
        PointBeforeStartingObstaclePath            = checkFromPosition;

        var adjustedPointToCheckClosestToStart = checkFromPosition;

        var closestPointToStart = obstacle.FindClosestPointOnSegmentFromProjectedPoint(adjustedPointToCheckClosestToStart);

        while (closestPointToStart == null)
        {
            adjustedPointToCheckClosestToStart += moveDirection * StepTowardsObstacleSide;

            closestPointToStart = obstacle.FindClosestPointOnSegmentFromProjectedPoint(adjustedPointToCheckClosestToStart);
        }

        var adjustedPointToCheckClosestToEnd = checkToPosition;

        var closestPointToEnd = obstacle.FindClosestPointOnSegmentFromProjectedPoint(adjustedPointToCheckClosestToEnd);

        while (closestPointToEnd == null)
        {
            adjustedPointToCheckClosestToEnd -= moveDirection * StepTowardsObstacleSide;

            closestPointToEnd = obstacle.FindClosestPointOnSegmentFromProjectedPoint(adjustedPointToCheckClosestToEnd);
        }

        _currentObstaclePath = obstacle.BestPath(closestPointToStart, closestPointToEnd, checkToPosition);

        return(_currentObstaclePath != null && _currentObstaclePath.Count > 0);
    }
コード例 #7
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);
    }
コード例 #8
0
    public MovementPlan FinishPlanOrMoveToNextIntersect(MovementPlan previousPlan)
    {
        MovementPlan movementPlan;

        if (previousPlan.ValidIntersections())
        {
            _currentIntersections = previousPlan.CurrentIntersections;
            var targetUnit     = _currentIntersections.Dequeue();
            var targetLocation = targetUnit.AngleDefinition.IntersectionPoint;

            // Obstacle start position = previousPlan.TargetLocation
            // Target end position = targetLocation (never adjusted)

            var nextIntersectionMovementValues = new MovementPlanValues(targetLocation, previousPlan.MoveDirection, targetUnit, _currentIntersections);
            var nextIntersectionMovementStates = new MovementPlanStates(true, false, false);

            movementPlan = new MovementPlan(nextIntersectionMovementValues, nextIntersectionMovementStates);

            return(EditMovementPlanForObstacles(movementPlan, previousPlan.TargetLocation));
        }

        var finishedTargetPosition = FinishedTargetLocation(previousPlan.TargetLocation, previousPlan.MoveDirection);

        finishedTargetPosition =
            BoundaryHelper.HandleBoundaryCollision(finishedTargetPosition, previousPlan.MoveDirection);

        // Obstacle start position = previousPlan.TargetLocation
        // Target end position = Adjusted(finishedTargetPosition);

        var finishedMovementValues = new MovementPlanValues(finishedTargetPosition, previousPlan.MoveDirection, null, null);
        var finishedMovementStates = new MovementPlanStates(false, true, false);

        movementPlan = new MovementPlan(finishedMovementValues, finishedMovementStates);

        return(EditMovementPlanForObstacles(movementPlan, previousPlan.TargetLocation));
    }
コード例 #9
0
        /// <summary>
        /// Processes the 'Get Custom Boundaries' Request for a project
        /// </summary>
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            var request = CastRequestObjectTo <BaseRequestFull>(item, 52);

            if (request == null)
            {
                return(null);
            }

            var boundaries  = new List <GeofenceData>();
            var projectRepo = (IProjectRepository)auxRepository;

            Task <GeofenceDataListResult> boundariesTask = null;

            //Task<List<GeofenceData>> favoritesTask = null;
            //Task<List<GeofenceData>> associatedTask = null;
            try
            {
                //a) Custom boundaries
                boundariesTask = BoundaryHelper.GetProjectBoundaries(
                    log, serviceExceptionHandler, request.ProjectUid, projectRepo, (IGeofenceRepository)Repository);
                //b) favorite geofences that overlap project

                // geofence and UnifiedProd services are not available to ccss
                //favoritesTask =
                //  GeofenceProxy.GetFavoriteGeofences(request.CustomerUid, request.UserUid, request.CustomHeaders);
                ////c) unified productivity associated geofences
                //associatedTask = UnifiedProductivityProxy.GetAssociatedGeofences(request.ProjectUid, request.CustomHeaders);

                await Task.WhenAll(boundariesTask /*, favoritesTask, associatedTask */);
            }
            catch (Exception e)
            {
                log.LogError(e, "Failed to retrieve all boundaries");
            }

            try
            {
                if (boundariesTask != null && !boundariesTask.IsFaulted && boundariesTask.Result != null)
                {
                    boundaries.AddRange(boundariesTask.Result.GeofenceData);
                }
                //if (associatedTask != null && !associatedTask.IsFaulted && associatedTask.Result != null)
                //  boundaries.AddRange(associatedTask.Result);
                //if (favoritesTask != null && !favoritesTask.IsFaulted && favoritesTask.Result != null)
                //{
                //  //Find out which favorite geofences overlap project boundary
                //  var overlappingGeofences =
                //    (await projectRepo.DoPolygonsOverlap(request.ProjectGeometryWKT,
                //      favoritesTask.Result.Select(g => g.GeometryWKT))).ToList();
                //  for (var i = 0; i < favoritesTask.Result.Count; i++)
                //  {
                //    if (overlappingGeofences[i])
                //      boundaries.Add(favoritesTask.Result[i]);
                //  }
                //}
            }
            catch (Exception ex)
            {
                log.LogError(ex, "Failed to aggregate all boundaries");
            }

            //Remove any duplicates
            boundaries = boundaries.Distinct(new DistinctGeofenceComparer()).ToList();

            return(new GeofenceDataListResult
            {
                GeofenceData = boundaries.ToImmutableList()
            });
        }
コード例 #10
0
    public Queue <IUnit> GetIntersectionsRelativeTo(IUnit firstUnit)
    {
        var possibleIntersections = new List <IUnit>();
        var firstStartCheckPoint  = firstUnit.Transform.position;

        foreach (var unit in _units)
        {
            if (unit == firstUnit ||
                unit == null ||
                !BoundaryHelper.OnScreen(unit.Transform.position) ||
                unit.Transform.gameObject.activeInHierarchy == false ||
                unit.KillHandler.KillPoint.HasValue ||
                unit.AngleDefinition.IntersectionPoint != Vector2.zero && BoundaryHelper.ContainedInObstacleCollider(unit.AngleDefinition.IntersectionPoint))
            {
                continue;
            }

            var firstRearCheckPoint = firstUnit.AngleDefinition.RearPointRelative;

            var rearPoint    = unit.AngleDefinition.RearPointRelative;
            var forwardPoint = unit.AngleDefinition.ForwardPointRelative;

            if (IntersectionMaths.IsIntersecting(firstStartCheckPoint, firstRearCheckPoint, rearPoint, forwardPoint))
            {
                var intersect = IntersectionMaths.FindIntersection(firstStartCheckPoint, firstRearCheckPoint,
                                                                   rearPoint, forwardPoint);

                if (intersect != null)
                {
                    var directionThroughKillPoint =
                        (unit.KillHandler.GetFauxKillPoint() - (Vector2)unit.Transform.position).normalized;
                    if (possibleIntersections.Any(t => Vector2.Distance(intersect.Value, t.AngleDefinition.IntersectionPoint) < 1f))
                    {
                        continue;
                    }
                    if (!NodeGrid.Instance.NodeFromWorldPosition(intersect.Value).IsWalkable ||
                        !BoundaryHelper.OnScreen(intersect.Value) ||
                        BoundaryHelper.ContainedInObstacleCollider(intersect.Value))
                    {
                        continue;
                    }

                    if (Vector2.Distance(unit.Transform.position, intersect.Value) < 2f ||
                        Vector2.Distance(unit.Transform.position, firstStartCheckPoint) < 1f ||
                        Vector2.Distance(firstUnit.Transform.position, intersect.Value) < 1f)
                    {
                        continue;
                    }

                    unit.AngleDefinition.SetIntersectionPoint(intersect.Value);
                    possibleIntersections.Add(unit);
                }
            }
        }

        if (possibleIntersections.Count <= 0)
        {
            return(null);
        }

        var orderedIntersections = possibleIntersections.OrderBy(t =>
                                                                 Vector2.Distance(firstStartCheckPoint, t.AngleDefinition.IntersectionPoint));

        var intersectOrder = new Queue <IUnit>();

        for (var i = 0; i < orderedIntersections.Count(); i++)
        {
            intersectOrder.Enqueue(orderedIntersections.ElementAt(i));
        }
        return(intersectOrder.Count > 0 ? intersectOrder : null);
    }