Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private void RecalculateNemeses(Player player, ApplicationUser currentUser)
        {
            var playerIdsToRecalculate = (from thePlayer in _dataContext.GetQueryable <Player>()
                                          where thePlayer.Active &&
                                          thePlayer.Nemesis.NemesisPlayerId == player.Id
                                          select thePlayer.Id).ToList();

            foreach (var playerId in playerIdsToRecalculate)
            {
                _nemesisRecalculator.RecalculateNemesis(playerId, currentUser, _dataContext);
            }
        }
Exemplo n.º 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}});
        }
Exemplo n.º 4
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();

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

            foreach (int playerId in playerIds)
            {
                nemesisRecalculator.RecalculateNemesis(playerId, currentUser);
            }
        }
        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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 private void RecalculateNemesis(IEnumerable <int> playerIdsThatNeedNewNemesis, ApplicationUser currentUser)
 {
     playerIdsThatNeedNewNemesis.Each((x => _nemesisRecalculator.RecalculateNemesis(x, currentUser)));
 }