예제 #1
0
        public CreateSoldierEvent GetCreateSoldierEvent(Guid gameId, Army army, string troopType, string ownerUserId, bool immediately = false)
        {
            var    snap           = _domain.GetGameSnapshot(gameId);
            var    game           = snap?.Payload as GameAggregate;
            double productionTime = 0;

            if (!immediately)
            {
                productionTime = _gameSettings.ProductionTime;
                if (game != null)
                {
                    productionTime = productionTime * GameSpeedHelper.GetSpeedValue(game.Speed);
                }
            }
            var @event = new CreateSoldierEvent(army,
                                                troopType, DateTime.UtcNow,
                                                TimeSpan.FromMinutes(productionTime),
                                                ownerUserId);

            return(@event);
        }
예제 #2
0
        private async Task <RouteModel> GetBattalionRoute(GameStateModel game, CastleStateModel castle, CastleStateModel destinationCastle, List <string> soldierIds)
        {
            // get route
            RouteModel route        = null;
            var        detailCastle = await _gameService.DetailCastle(game.Id, new Guid(castle.Id), string.Empty, -1);

            var soldiers = detailCastle.Soldiers?.Where(e => soldierIds.Contains(e.Id)).ToList();

            if (soldiers == null)
            {
                return(null);
            }
            var gameSpeed = _gameSettings.GetMovementSpeedOfGame(
                GameSpeedHelper.GetSpeedValue(game.Speed));
            var battalionSpeed = soldiers.Min(e => e.CastleTroopType.MovementSpeed) * gameSpeed;
            var isNotFight     = soldiers.Any(e => !e.CastleTroopType.IsFlight);

            if (isNotFight)
            {
                var direction = await _directionProvider.GetDirection(castle.Position, destinationCastle.Position);

                if (direction.Status == DirectionsStatusCodes.OK && direction.Routes != null && direction.Routes.Any() &&
                    direction.Routes.ElementAt(0).Legs != null && direction.Routes.ElementAt(0).Legs.Any())
                {
                    var selectedRouteLeg = direction.Routes.ElementAt(0).Legs.ElementAt(0);
                    route = new RouteModel
                    {
                        Steps = selectedRouteLeg.Steps.Select(step => new RouteStepModel()
                        {
                            StartLocation =
                                new PositionModel
                            {
                                Lat = step.StartLocation.Latitude,
                                Lng = step.StartLocation.Longitude
                            },
                            EndLocation =
                                new PositionModel {
                                Lat = step.EndLocation.Latitude, Lng = step.EndLocation.Longitude
                            },
                            Distance = step.Distance.Value,
                            Duration =
                                TimeSpan.FromSeconds(step.Distance.Value /
                                                     battalionSpeed)
                        }).ToList(),
                        Distance = selectedRouteLeg.Distance.Value,
                        Duration =
                            TimeSpan.FromSeconds(selectedRouteLeg.Distance.Value /
                                                 battalionSpeed)
                    };
                }
            }
            else
            {
                var distance = Helpers.DistanceBetween(castle.Position.Lat, castle.Position.Lng,
                                                       destinationCastle.Position.Lat, destinationCastle.Position.Lng);
                var duration = TimeSpan.FromSeconds(distance / battalionSpeed);
                route = new RouteModel()
                {
                    Distance = distance,
                    Duration = duration,
                    Steps    = new List <RouteStepModel>()
                    {
                        new RouteStepModel()
                        {
                            StartLocation = castle.Position,
                            EndLocation   = destinationCastle.Position,
                            Distance      = distance,
                            Duration      = duration
                        }
                    }
                };
            }

            return(route);
        }
예제 #3
0
 public RouteModel FormatRoute(Leg selectedRouteLeg, GameSpeed gameSpeed)
 {
     return(new RouteModel
     {
         Steps = selectedRouteLeg.Steps.Select(step => new RouteStepModel()
         {
             StartLocation =
                 new PositionModel {
                 Lat = step.StartLocation.Latitude, Lng = step.StartLocation.Longitude
             },
             EndLocation = new PositionModel {
                 Lat = step.EndLocation.Latitude, Lng = step.EndLocation.Longitude
             },
             Distance = step.Distance.Value,
             Duration = TimeSpan.FromSeconds(step.Distance.Value / _gameSettings.GetMovementSpeedOfGame(GameSpeedHelper.GetSpeedValue(gameSpeed)))
         }).ToList(),
         Distance = selectedRouteLeg.Distance.Value,
         Duration = TimeSpan.FromSeconds(selectedRouteLeg.Distance.Value / _gameSettings.GetMovementSpeedOfGame(GameSpeedHelper.GetSpeedValue(gameSpeed)))
     });
 }
예제 #4
0
 public TimeSpan GetRevenueTimeBySpeed(GameSpeed speed)
 {
     return(TimeSpan.FromMinutes(_gameSettings.RevenueTime * GameSpeedHelper.GetSpeedValue(speed)));
 }
예제 #5
0
        public double CalculateCoin(GameAggregate game, CastleAggregate castle)
        {
            var revenueCoins = _gameSettings.RevenueCoins * GameSpeedHelper.GetSpeedValue(game.Speed);

            return(revenueCoins);
        }
예제 #6
0
        public DateTime GetBattleTime(GameSpeed speed)
        {
            var siegeTime = _gameSettings.SiegeTime * GameSpeedHelper.GetSpeedValue(speed);

            return(DateTime.UtcNow.AddMinutes(siegeTime));
        }