Beispiel #1
0
        public void PassRate(string login, Guid id)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(login) || id == Guid.Empty)
                {
                    return;
                }

                using (GamePortalEntities dbContext = new GamePortalEntities())
                {
                    User gpUser = dbContext.Users.FirstOrDefault(p => p.Login == login);
                    if (gpUser == null)
                    {
                        return;
                    }

                    UserGame userGame = gpUser.UserGames.FirstOrDefault(p => p.Id == id);
                    if (userGame == null)
                    {
                        return;
                    }

                    userGame.IsIgnoreMind = false;
                    gpUser.Version        = Guid.NewGuid();
                    dbContext.SaveChanges();
                }
            }
            catch
            {
                return;
            }
        }
Beispiel #2
0
        public void StopUserGame(string login, Guid gameId, int mindPosition = 0, bool isIgnoreHonor = false)
        {
            TaskFactory.StartNew(() =>
            {
                try
                {
                    using (GamePortalEntities gamePortal = new GamePortalEntities())
                    {
                        User gpUser = gamePortal.Users.SingleOrDefault(p => p.Login == login);
                        if (gpUser == null)
                        {
                            return;
                        }

                        UserGame userGame = gpUser.UserGames.SingleOrDefault(p => p.GameId == gameId);

                        if (userGame != null)
                        {
                            //Завершил игру
                            if (mindPosition != 0)
                            {
                                userGame.IsIgnoreHonor = false;
                                userGame.HonorPosition = 5;
                                userGame.MindPosition  = mindPosition;

                                AddUserNotifiFunc?.Invoke(gpUser.ToWCFUser(gamePortal), string.Format("dynamic_gameEnd*{0}*{1}", userGame.HomeType, userGame.MindPosition));
                            }
                            else
                            {
                                //наказание ослабевает по мере увеличения их количества в партии
                                userGame.HonorPosition = 6 - gamePortal.UserGames.Count(p => p.GameId == gameId && !p.EndTime.HasValue);
                                userGame.IsIgnoreHonor = isIgnoreHonor;

                                if (AddUserNotifiFunc != null)
                                {
                                    WCFUserGame wcfUserGame = userGame.ToWCFUserGame();
                                    if (wcfUserGame.IsIgnoreHonor)
                                    {
                                        AddUserNotifiFunc(gpUser.ToWCFUser(gamePortal), $"dynamic_leftGame1*{"unknown home"}");//userGame.HomeType
                                    }
                                    else
                                    {
                                        AddUserNotifiFunc(gpUser.ToWCFUser(gamePortal), $"dynamic_leftGame2*{"unknown home"}*0");//userGame.HomeType
                                    }
                                }
                            }

                            userGame.EndTime = DateTimeOffset.UtcNow;
                            gpUser.Version   = Guid.NewGuid();

                            gamePortal.SaveChanges();
                        }
                    }
                }
                catch
                {
                }
            });
        }
Beispiel #3
0
        public void StartUserGame(string login, string homeType, Guid gameId, int gameType, bool isIgnoreDurationHours = false, bool IsIgnoreMind = false)
        {
#if !DEBUG //не учитывать рейтинг в отладочном режиме
            StopUserGame(login, gameId);

            TaskFactory.StartNew(() =>
            {
                try
                {
                    using (GamePortalEntities gamePortal = new GamePortalEntities())
                    {
                        User gpUser = gamePortal.Users.SingleOrDefault(p => p.Login == login);
                        if (gpUser == null)
                        {
                            return;
                        }

                        UserGame userGame = gpUser.UserGames.SingleOrDefault(p => p.GameId == gameId);
                        if (userGame == null)
                        {
                            userGame = new UserGame()
                            {
                                Id                    = Guid.NewGuid(),
                                GameId                = gameId,
                                GameType              = gameType,//+1 - игра с рандомом
                                Login                 = login,
                                HomeType              = homeType,
                                StartTime             = DateTimeOffset.UtcNow,
                                User                  = gpUser,
                                IsIgnoreMind          = IsIgnoreMind,
                                IsIgnoreDurationHours = isIgnoreDurationHours
                            };
                            gpUser.UserGames.Add(userGame);
                            gpUser.Version = Guid.NewGuid();
                            gamePortal.SaveChanges();
                        }
                    }
                }
                catch
                {
                }
            });
#endif
        }