Beispiel #1
0
        //TODO need to have validation logic here (or on PlayedGame similar to what is on NewlyCompletedGame)
        public PlayedGame CreatePlayedGame(NewlyCompletedGame newlyCompletedGame, TransactionSource transactionSource, ApplicationUser currentUser)
        {
            GameDefinition gameDefinition = dataContext.FindById <GameDefinition>(newlyCompletedGame.GameDefinitionId);

            securedEntityValidatorForGameDefinition.ValidateAccess(gameDefinition, currentUser, typeof(GameDefinition), newlyCompletedGame.GameDefinitionId);

            this.ValidateAccessToPlayers(newlyCompletedGame, currentUser);

            List <PlayerGameResult> playerGameResults = TransformNewlyCompletedGamePlayerRanksToPlayerGameResults(newlyCompletedGame);

            PlayedGame playedGame = TransformNewlyCompletedGameIntoPlayedGame(
                newlyCompletedGame,
                currentUser.CurrentGamingGroupId,
                currentUser.Id,
                playerGameResults);

            dataContext.Save(playedGame, currentUser);

            playedGameTracker.TrackPlayedGame(currentUser, transactionSource);

            foreach (PlayerGameResult result in playerGameResults)
            {
                nemesisRecalculator.RecalculateNemesis(result.PlayerId, currentUser);
            }
            championRecalculator.RecalculateChampion(playedGame.GameDefinitionId, currentUser);

            return(playedGame);
        }
Beispiel #2
0
        private void RecalculateChampions(Player player, ApplicationUser applicationUser)
        {
            var championedGameDefinitionIds = _dataContext.GetQueryable <GameDefinition>()
                                              .Where(x => x.Champion.PlayerId == player.Id).Select(x => x.Id).ToList();

            championedGameDefinitionIds.ForEach(gameDefinitionId =>
                                                _championRecalculator.RecalculateChampion(gameDefinitionId, applicationUser, _dataContext));
        }
Beispiel #3
0
        internal virtual void DoPostSaveStuff(TransactionSource transactionSource,
            ApplicationUser currentUser, int playedGameId, int gameDefinitionId, List<PlayerGameResult> playerGameResults)
        {
            _playedGameTracker.TrackPlayedGame(currentUser, transactionSource);

            foreach (var result in playerGameResults)
            {
                _nemesisRecalculator.RecalculateNemesis(result.PlayerId, currentUser);
            }
            _championRecalculator.RecalculateChampion(gameDefinitionId, currentUser, false);

            SendEvents(new IBusinessLogicEvent[] {new PlayedGameCreatedEvent() {TriggerEntityId = playedGameId}});
        }
        public bool Handle(PlayedGameCreatedEvent @event)
        {
            //--process analytics
            try
            {
                _playedGameEventTracker.TrackPlayedGame(@event.CurrentUser, @event.TransactionSource);
            }
            catch (Exception ex)
            {
                _rollbar.SendException(ex);
                ex.ToExceptionless();
            }

            bool noExceptions;

            //--this is a weak solution to duplicate key exceptions getting logged when multiple games are recorded in quick succession. A better solution
            //  would be to only lock at the level required instead of locking globally
            lock (ChampionLock)
            {
                //--process champions
                //TODO this should only lock for each distinct GameDefinitionId
                _championRecalculator.RecalculateChampion(@event.GameDefinitionId, @event.CurrentUser, DataContext);
            }

            lock (NemesisLock)
            {
                //--process nemeses
                //TODO this should only lock for each distinct playerId
                foreach (var playerId in @event.ParticipatingPlayerIds)
                {
                    _nemesisRecalculator.RecalculateNemesis(playerId, @event.CurrentUser, DataContext);
                }
            }

            lock (GamingGroupChampionLock)
            {
                _gamingGroupChampionRecalculator.RecalculateGamingGroupChampion(@event.TriggerEntityId);
            }

            lock (AchievementsLock)
            {
                //--process achievements
                //TODO this should probably only lock at the GamingGroupdId level
                noExceptions = _achievementProcessor.ProcessAchievements(@event.TriggerEntityId);
            }

            return(noExceptions);
        }
Beispiel #5
0
        public void DeletePlayedGame(int playedGameId, ApplicationUser currentUser)
        {
            List <int> playerIds = (from playerResult in dataContext.GetQueryable <PlayerGameResult>()
                                    where playerResult.PlayedGameId == playedGameId
                                    select playerResult.PlayerId).ToList();
            var gameDefId = dataContext.GetQueryable <PlayerGameResult>()
                            .Where(p => p.PlayedGameId == playedGameId)
                            .Select(p => p.PlayedGame.GameDefinitionId)
                            .FirstOrDefault();

            dataContext.DeleteById <PlayedGame>(playedGameId, currentUser);
            dataContext.CommitAllChanges();

            foreach (int playerId in playerIds)
            {
                nemesisRecalculator.RecalculateNemesis(playerId, currentUser, dataContext);
            }

            championRecalculator.RecalculateChampion(gameDefId, currentUser, dataContext);
        }
Beispiel #6
0
 private void RecalculateChampions(IEnumerable <int> gameDefinitionIds, ApplicationUser currentUser)
 {
     gameDefinitionIds.Each(x => _championRecalculator.RecalculateChampion(x, currentUser));
 }