Exemplo n.º 1
0
        private GameStateModel GetGameStateBySnapshot(GameAggregate gameSnapshot)
        {
            GameStateModel result = new GameStateModel
            {
                Id                     = gameSnapshot.Id,
                Status                 = gameSnapshot.Status,
                UserId                 = gameSnapshot.UserId,
                UserHeroId             = gameSnapshot.UserHeroId,
                OpponentId             = gameSnapshot.OpponentId,
                OpponentHeroId         = gameSnapshot.OpponentHeroId,
                SelfPlaying            = gameSnapshot.SelfPlaying,
                Speed                  = gameSnapshot.Speed,
                Difficulty             = gameSnapshot.Difficulty,
                UserCoins              = gameSnapshot.UserCoins,
                OpponentCoins          = gameSnapshot.OpponentCoins,
                Castles                = new List <CastleStateModel>(),
                UserProducedTroopTypes = gameSnapshot.UserProducedTroopTypes,
                UserSoldiers           = Mapper.Map <List <SoldierModel> >(gameSnapshot.UserSoldiers),
                OpponentSoldiers       = Mapper.Map <List <SoldierModel> >(gameSnapshot.OpponentSoldiers)
            };

            foreach (var castle in gameSnapshot.Castles)
            {
                CastleStateModel castleModel = Mapper.Map <CastleStateModel>(castle);
                result.Castles.Add(castleModel);
            }
            return(result);
        }
Exemplo n.º 2
0
#pragma warning disable 1998
        public async Task <GameStateModel> GetState(Guid id, int streamVersion)
#pragma warning restore 1998
        {
            GameStateModel result = new GameStateModel
            {
                Id       = id,
                HasError = false
            };
            ISnapshot     latestSnapshot = _store.Advanced.GetSnapshot(id, streamVersion);
            GameAggregate gameSnapshot   = latestSnapshot?.Payload as GameAggregate;

            if (gameSnapshot == null)
            {
                return(null);
            }
            result.Status         = gameSnapshot.Status;
            result.UserId         = gameSnapshot.UserId;
            result.UserHeroId     = gameSnapshot.UserHeroId;
            result.OpponentId     = gameSnapshot.OpponentId;
            result.OpponentHeroId = gameSnapshot.OpponentHeroId;
            result.StreamRevision = latestSnapshot.StreamRevision;
            result.SelfPlaying    = gameSnapshot.SelfPlaying;
            result.Castles        = new List <CastleStateModel>();
            foreach (var castle in gameSnapshot.Castles)
            {
                CastleStateModel castleModel = Mapper.Map <CastleStateModel>(castle);
                //var events = _domain.GetNotExecuteEvents<CreateSoldierEvent>(id);
                //var latestEvent = events.FirstOrDefault(e => e.CastleId == castle.Id);
                //if (latestEvent != null)
                //    castleModel.ProduceExecuteAt = latestEvent.ExecuteAt;
                result.Castles.Add(castleModel);
            }
            return(result);
        }
Exemplo n.º 3
0
 public static string GetCastleIconByBattleAtPercent(GameStateModel state, CastleStateModel castle, double percent)
 {
     try
     {
         if (castle.Army == Army.Blue)
         {
             return(BlueCastleRedSiege.Where(e => e.Key <= percent).OrderByDescending(e => e.Key).First().Value);
         }
         if (castle.Army == Army.Red)
         {
             return(RedCastleBlueSiege.Where(e => e.Key <= percent).OrderByDescending(e => e.Key).First().Value);
         }
         bool isBlue = castle.Siege.OwnerUserId == state?.UserId;
         if (isBlue)
         {
             return(NeutralBlueSiege.Where(e => e.Key <= percent).OrderByDescending(e => e.Key).First().Value);
         }
         return(NeutralRedSiege.Where(e => e.Key <= percent).OrderByDescending(e => e.Key).First().Value);
     }
     catch (Exception e)
     {
         return(GetCastleIcon(state, castle) + "_100");
     }
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public static string GetCastleIcon(GameStateModel state, CastleStateModel castle, bool includeSiege = true)
        {
            string icon = GetCastleIconByArmy(castle.Army);

            return(icon);
        }