/// <summary> /// Insert a vote to kick a user <paramref name="vote"/> /// </summary> /// <param name="vote">The user's vote to kick</param> /// <returns></returns> public Entities.ActionResponses.VoteToKick Execute(Entities.GamePlayerKickVote vote) { Entities.ActionResponses.VoteToKick response = new Entities.ActionResponses.VoteToKick(); Entities.Filters.Game.Select filter = new Entities.Filters.Game.Select(); filter.DataToSelect = Entities.Enums.Game.Select.None; filter.GameID = vote.GameID; Entities.Game game = _selectGame.Execute(filter); if (game.IsCurrentPlayer(vote.VotedUserId)) { response = _insert.Execute(vote); response.ResponseCode = Entities.ActionResponses.Enums.VoteToKick.VoteSuccessful; response.Game = game; if (vote.Vote) { response.VotesToKick++; } else { response.VotesToStay++; } return(response); } else { response.ResponseCode = Entities.ActionResponses.Enums.VoteToKick.IneligiblePlayerToVote; return(response); } }
/// <summary> /// Play a list of cards from a user's hand /// </summary> /// <param name="cardIDs">The card IDs the user has selected </param> /// <param name="gameID">The game ID in which the user wants to play the card</param> /// <param name="userId">The user Id</param> /// <param name="autoPlayed">Were these cards auto played</param> /// <returns>PlayCard action result containing any errors and the round the card was played.</returns> public Entities.ActionResponses.PlayCard Execute(List <Int32> cardIDs, Int32 gameID, Int32 userId, Boolean autoPlayed = false) { Entities.ActionResponses.PlayCard response = _playCard.Execute(cardIDs, gameID, userId, autoPlayed); if (response.ResponseCode == Entities.ActionResponses.Enums.PlayCardResponseCode.Success) { Entities.Filters.Game.Select filter = new Entities.Filters.Game.Select(); filter.DataToSelect = Entities.Enums.Game.Select.GamePlayerCards; filter.GameID = gameID; Entities.Game game = _selectGame.Execute(filter); game.Rounds.Add(response.CurrentRound); if (response.CurrentRound.AllPlayersAnswered() && game.SecondsToPlay > 0) { var cachedJobId = MemoryCache.Default.Get(game.RoundTimerKey); BackgroundJob.Delete(cachedJobId as String); } _sendMessage.CardPlayed(game, true); _updateGame.Execute(game.GameID, DateTime.UtcNow, null); } return(response); }
public JsonResult Index(int id) { Entities.Models.Game.Listing.Detail model = new Entities.Models.Game.Listing.Detail(); Entities.Filters.Game.Select filter = new Entities.Filters.Game.Select(); filter.GameID = id; return(Json(new { Game = new Entities.Models.Game.Listing.Game(_selectGame.Execute(filter), Authentication.Security.CurrentUserId) }, JsonRequestBehavior.AllowGet)); }
public void RefreshGameView(Int32 gameID, Entities.Enums.ConnectionType connectionType) { Join(gameID, connectionType); AS.GameRound.Base.ISelect _selectGameRound = BusinessLogic.UnityConfig.Container.Resolve <AS.GameRound.Base.ISelect>(); AS.Game.Base.ISelect _selectGame = BusinessLogic.UnityConfig.Container.Resolve <AS.Game.Base.ISelect>(); AS.GamePlayerKickVote.Base.ISelect _selectVotes = BusinessLogic.UnityConfig.Container.Resolve <AS.GamePlayerKickVote.Base.ISelect>(); AS.ActiveConnection.Base.ISelect _selectConnection = BusinessLogic.UnityConfig.Container.Resolve <AS.ActiveConnection.Base.ISelect>(); Int32 currentUserId = Authentication.Security.CurrentUserId; Entities.ActiveConnection connection = _selectConnection.Execute(new Entities.Filters.ActiveConnection.Select(Context.ConnectionId, currentUserId)); Entities.Filters.GamePlayerKickVote.SelectForGame kickVoteFilter = new Entities.Filters.GamePlayerKickVote.SelectForGame(); kickVoteFilter.GameID = gameID; List <Entities.GamePlayerKickVote> votes = _selectVotes.Execute(kickVoteFilter); IEnumerable <IGrouping <Int32, Entities.GamePlayerKickVote> > grouped = votes.GroupBy(x => x.KickUserId); Entities.Models.Game.Board.VoteToKick kickModel = null; List <Entities.Models.Game.Board.VoteToKick> votesToKick = new List <Entities.Models.Game.Board.VoteToKick>(); foreach (IGrouping <Int32, Entities.GamePlayerKickVote> group in grouped) { if (group.FirstOrDefault(x => x.VotedUserId == currentUserId) == null) { kickModel = new Entities.Models.Game.Board.VoteToKick(group.First().KickUser, group.Count(x => x.Vote), group.Count(x => !x.Vote)); votesToKick.Add(kickModel); } } List <Entities.GameRound> completedRounds = _selectGameRound.Execute(new Entities.Filters.GameRound.SelectCompleted(gameID)); Entities.Game game = _selectGame.Execute(new Entities.Filters.Game.Select { GameID = gameID, DataToSelect = Entities.Enums.Game.Select.GamePlayerCards | Entities.Enums.Game.Select.Rounds }); Entities.Enums.GamePlayerType playerType = (connection != null && connection.ConnectionType == Entities.Enums.ConnectionType.GamePlayer) ? Entities.Enums.GamePlayerType.Player : Entities.Enums.GamePlayerType.Spectator; Entities.Models.Game.Board.GameBoard model = new Entities.Models.Game.Board.GameBoard(game, currentUserId, playerType, votesToKick, completedRounds); Clients.Client(Context.ConnectionId).UpdateGameView(model, model.LobbyViewModel); }
/// <summary> /// Complete the current round /// </summary> /// <param name="gameID">The ID of the game that contains the round</param> /// <param name="cardIDs">The IDs of the winning cards</param> /// <param name="userId">The user Id trying to complete the round</param> /// <returns></returns> public Entities.ActionResponses.RoundComplete Execute(Int32 gameID, List <Int32> cardIDs, Int32 userId) { Entities.ActionResponses.RoundComplete response = new Entities.ActionResponses.RoundComplete(); Entities.GameRound currentRound = _selectGameRound.Execute(gameID, true); //Validate that the user trying to complete the round is in fact the commander if (currentRound.IsCommander(userId)) { //Validate that select cards were actually played during the round List <Int32> invalidWinners = currentRound.ValidateWinnerSelection(cardIDs); if (invalidWinners.Count == 0) { Entities.User newCommander = currentRound.Winner(); //Update cards as winners Entities.Filters.GameRoundCard.UpdateWinner cardfilter = new Entities.Filters.GameRoundCard.UpdateWinner(); cardfilter.CardIDs = cardIDs; cardfilter.GameID = gameID; Boolean autoPlayed = _updateGameRoundCard.Execute(cardfilter); if (!autoPlayed) { //Update player points Entities.Filters.GamePlayer.UpdatePoints playerFilter = new Entities.Filters.GamePlayer.UpdatePoints(); playerFilter.GameID = gameID; playerFilter.UserId = newCommander.UserId; _updateGamePlayer.Execute(playerFilter); } //Start round Entities.Filters.Game.Select gameFilter = new Entities.Filters.Game.Select(); gameFilter.GameID = gameID; gameFilter.DataToSelect = Entities.Enums.Game.Select.GamePlayerCards; Entities.Game game = _selectGame.Execute(gameFilter); response.NewRoundCreated = _startGameRoud.Execute(game, game.NextCommander(newCommander)); response.CompletedRound = currentRound; response.Game = game; if (!response.NewRoundCreated) { response.Game.Rounds.Add(currentRound); } } } return(response); }
public JsonResult Games(List <int> gameIds) { Entities.Filters.Game.SelectAll filter = new Entities.Filters.Game.SelectAll(); filter.GameIds = gameIds ?? new List <int>(); List <Entities.Game> games = _selectGame.Execute(filter); return(new JsonResult { Data = new { Games = games.Select(x => new Entities.Models.Game.Listing.Game(x)), MaxOfficialDeckCount = filter.MaxOfficialCount }, JsonRequestBehavior = JsonRequestBehavior.AllowGet, MaxJsonLength = Int32.MaxValue }); }