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 { } }); }
internal WCFUserGame ToWCFUserGame() { WCFUserGame result = new WCFUserGame { Id = this.Id, GameId = this.GameId, GameType = this.GameType, HomeType = this.HomeType, StartTime = this.StartTime, EndTime = this.EndTime, MindPosition = this.MindPosition, IsIgnoreMind = this.IsIgnoreMind, HonorPosition = this.HonorPosition, IsIgnoreHonor = this.IsIgnoreHonor, IsIgnoreDurationHours = this.IsIgnoreDurationHours }; return(result); }