public List<Action> DoSomething(Game game)
        {
            var actions = new List<Action>();
            _game = game;
            _player = _game.Players.First(p => p.Guid == PlayerGuid);
            _IAmEvil = _game.IsCharacterEvil(_player.Character, false);

            var availableActions = _game.AvailableActions(_player);
            if (availableActions.Count == 0)
                return null;

            if (availableActions.Any(a=>a.ActionType==ResistanceOnline.Core.Action.Type.VoteApprove))
            {
                actions.Add(new Action(PlayerGuid, TeamVote() ? Action.Type.VoteApprove : Action.Type.VoteReject));
            }

            if (availableActions.Any(a => a.ActionType == ResistanceOnline.Core.Action.Type.AssignExcalibur))
            {
                actions.Add( new Action(PlayerGuid, Action.Type.AssignExcalibur, AssignExcalibur().Name));
            }

            if (availableActions.Any(a => a.ActionType == ResistanceOnline.Core.Action.Type.UseExcalibur))
            {
                var target = UseExcalibur();
                var name = target==null? string.Empty : target.Name;
                actions.Add( new Action(PlayerGuid, Action.Type.UseExcalibur, name));
            }

            if (availableActions.Any(a => a.ActionType == ResistanceOnline.Core.Action.Type.FailQuest) || availableActions.Any(a => a.ActionType == ResistanceOnline.Core.Action.Type.SucceedQuest))
            {
                actions.Add( new Action(PlayerGuid, Quest() ? Action.Type.SucceedQuest : Action.Type.FailQuest));
            }

            if (availableActions.Any(a => a.ActionType == ResistanceOnline.Core.Action.Type.AddToTeam))
            {
                actions.Add( new Action(PlayerGuid, Action.Type.AddToTeam, ChooseTeamPlayer().Name));
            }

            if (availableActions.Any(a => a.ActionType == ResistanceOnline.Core.Action.Type.GuessMerlin))
            {
                actions.Add( new Action(PlayerGuid, Action.Type.GuessMerlin, GuessMerlin().Name));
            }

            if (availableActions.Any(a => a.ActionType == ResistanceOnline.Core.Action.Type.UseTheLadyOfTheLake))
            {
                actions.Add( new Action(PlayerGuid, Action.Type.UseTheLadyOfTheLake, LadyOfTheLakeTarget().Name));
            }

            if (availableActions.Any(a => a.ActionType == ResistanceOnline.Core.Action.Type.Message) && _thingsIWantToSay.Count > 0)
            {
                actions.AddRange(_thingsIWantToSay.Select(s => new Action(PlayerGuid, Action.Type.Message, s)).ToList());
            }

            return actions;
        }
Ejemplo n.º 2
0
        public GameModel(int gameId, Game game, Guid playerGuid)
        {
            _game = game;
            GameId = gameId;
            GameName = game.GameName;
            GameOwner = game.Players.First().Name;
            IsOwner = game.Players.First().Guid == playerGuid;
            PlayerCountSummary = ("player".ToQuantity(game.Players.Count));
            PlayersSummary = Useful.CommaQuibbling(game.Players.Select(p => p.Name).ToList());
            GameState = game.GameState.Humanize(LetterCasing.Sentence).ToString();
            GameSize = game.Players.Count;
            Rules = game.Rules.Select(r => r.Humanize()).ToList();
            RoundTables = game.RoundTables.Select(t=>String.Format("Quest {0} has {1} and requires {2}", (game.RoundTables.IndexOf(t) + 1).ToWords(), "player".ToQuantity(t.TeamSize, ShowQuantityAs.Words), "fail".ToQuantity(t.RequiredFails, ShowQuantityAs.Words))).ToList();
            LoyaltyCardsDeltInAdvance = new List<string>();
            if (game.Rules.Contains(Rule.LoyaltyCardsAreDeltInAdvance))
            {
                for (int i = 0; i < 4; i++)
                {
                    LoyaltyCardsDeltInAdvance.Add(string.Format("After quest {0}, Lancelot's {1} switch alegiance", (i + 1).ToWords(), game.LoyaltyDeck[i] == LoyaltyCard.SwitchAlegiance ? "will" : "will not"));
                }
            }

            var characters = new List<string>();
            foreach (var character in game.CharacterCards.Distinct()) {
                var count = game.CharacterCards.Count(c=>c==character);
                if (count > 1)
                {
                    switch (character)
                    {
                        case Character.LoyalServantOfArthur:
                            characters.Add(String.Format("{0} Loyal Servants of Arthur", count));
                            break;
                        case Character.MinionOfMordred:
                            characters.Add(String.Format("{0} Minions of Mordred", count));
                            break;
                        default:
                            characters.Add(character.Humanize().ToQuantity(count));
                            break;
                    }

                } else {
                    characters.Add(character.Humanize());
                }
            }
            Characters = Useful.CommaQuibbling(characters);

            var player = game.Players.FirstOrDefault(p => p.Guid == playerGuid);
            IsSpectator = player == null;
            PlayerName = player == null ? "Spectator" : player.Name;

            if (game.AssassinsGuessAtMerlin != null)
            {
                AssassinsGuessAtMerlinPlayerName = game.AssassinsGuessAtMerlin.Name;
                AssassinsGuessAtMerlinCharacter = game.AssassinsGuessAtMerlin.Character.ToString();
                Assassin = game.Players.First(p => p.Character == Character.Assassin).Name;
            }

            State = game.GameState.ToString();

            var availableActions = game.AvailableActions(player);

            var guessMerlin = availableActions.FirstOrDefault(a => a.ActionType == Core.Action.Type.GuessMerlin);
            if (guessMerlin != null)
            {
                GuessMerlinPlayersSelectList = new SelectList(guessMerlin.ActionItems);
            }

            var ladyOfTheLake = availableActions.FirstOrDefault(a => a.ActionType == Core.Action.Type.UseTheLadyOfTheLake);
            if (ladyOfTheLake != null)
            {
                LadyOfTheLakePlayerSelectList = new SelectList(ladyOfTheLake.ActionItems);
            }

            var useExcalibur = availableActions.FirstOrDefault(a => a.ActionType == Core.Action.Type.UseExcalibur);
            if (useExcalibur != null)
            {
                UseExcaliburSelectList = new SelectList(useExcalibur.ActionItems);
            }

            var assignExcalibur = availableActions.FirstOrDefault(a => a.ActionType == Core.Action.Type.AssignExcalibur);
            if (assignExcalibur != null)
            {
                AssignExcaliburSelectList = new SelectList(assignExcalibur.ActionItems);
            }

            var addToTeam = availableActions.FirstOrDefault(a => a.ActionType == Core.Action.Type.AddToTeam);
            if (addToTeam != null)
            {
                AddToTeamPlayersSelectList = new SelectList(addToTeam.ActionItems);
            }
            var removeFromTeam = availableActions.FirstOrDefault(a => a.ActionType == Core.Action.Type.RemoveFromTeam);
            if (removeFromTeam != null)
            {
                RemoveFromTeamSelectList = new SelectList(removeFromTeam.ActionItems);
            }

            var addRule = availableActions.FirstOrDefault(a => a.ActionType == Core.Action.Type.AddRule);
            if (addRule != null)
            {
                AddRulesSelectList = new SelectList(addRule.ActionItems);
            }

            var removeRule = availableActions.FirstOrDefault(a => a.ActionType == Core.Action.Type.RemoveRule);
            if (removeRule != null)
            {
                RemoveRuleSelectList = new SelectList(removeRule.ActionItems);
            }

            var addCharacterCard = availableActions.FirstOrDefault(a => a.ActionType == Core.Action.Type.AddCharacterCard);
            if (addCharacterCard != null)
            {
                AddCharacterCardsSelectList = new SelectList(addCharacterCard.ActionItems);
            }

            var removeCharacterCard = availableActions.FirstOrDefault(a => a.ActionType == Core.Action.Type.RemoveCharacterCard);
            if (removeCharacterCard != null)
            {
                RemoveCharacterCardSelectList = new SelectList(removeCharacterCard.ActionItems);
            }

            Actions = game.AvailableActions(player).Select(i => i.ActionType.ToString()).ToList();

            PlayerInfo = new List<PlayerInfoModel>();
            var waiting = new List<WaitingActionsModel>();
            foreach (var p in game.Players)
            {
                var playerInfo = new PlayerInfoModel
                {
                    Name = p.Name,
                    Knowledge = game.PlayerKnowledge(player, p).ToString()
                };

                //always know own character, or all characters if game is over
                if (p == player || GameOver)
                {
                    playerInfo.CharacterCard = p.Character;
                    playerInfo.Knowledge = p.Character.ToString();
                }

                PlayerInfo.Add(playerInfo);

                waiting.AddRange(game.AvailableActions(p).Select(a => new WaitingActionsModel { Action = a.ActionType, Name = p.Name }));
            }

            //build waiting message
            var waitings = waiting.Where(a=>a.Action != Core.Action.Type.Message).Select(w => w.Name).Distinct().ToList();
            if (waitings.Any())
            {
                WaitingMessage = String.Format("Waiting for {0}", Useful.CommaQuibbling(waitings));
            }

            Rounds = new List<RoundModel>();
            for(int i=0; i<game.Quests.Count; i++)
            {
                Rounds.Add(new RoundModel(game.Quests[i], i + 1, game, player, game.Players.Count));
            }

            if (GameOver)
            {
                GameOverMessage = String.Format("{0}, {1} win.", game.GameState.Humanize(LetterCasing.Sentence), Useful.CommaQuibbling(game.Winners.Select(p=>p.Name)));
            }
        }
Ejemplo n.º 3
0
        public GameModel(Game game, Guid? playerGuid)
        {
            GameId = game.GameId;
            PlayerGuid = playerGuid;
            GameSize = game.GameSize;

            RoundTables = game.RoundTables;

            var player = game.Players.FirstOrDefault(p => p.Guid == playerGuid);
            IsSpectator = player == null;

            PlayerName = player == null ? "Spectator" : player.Name;

            if (game.ImpersonationEnabled)
            {
                ImpersonationList = game.Players.ToList();
            }

            AssassinsGuessAtMerlin = game.AssassinsGuessAtMerlin;
            GameState = game.DetermineState();
            CharactersInGame = game.AvailableCharacters.ToList();
            AllCharactersSelectList =
                Enum.GetValues(typeof(Character))
                    .Cast<Character>()
                    .Where(c => c != Character.UnAllocated)
                    .Select(c => new SelectListItem { Text = c.Humanize(LetterCasing.Sentence), Value = c.ToString() })
                    .ToList();

            //can guess anyone but self
            GuessMerlinPlayersSelectList = new SelectList(game.Players.Where(p=>p!=player).Select(p => p.Name));

            //can put anyone on a team who isn't already on it
            AddToTeamPlayersSelectList = new SelectList(game.Players.Where(p=> !game.CurrentRound.CurrentTeam.TeamMembers.Select(t=>t.Name).ToList().Contains(p.Name)).Select(p => p.Name));

            Actions = game.AvailableActions(player);

            PlayerInfo = new List<PlayerInfoModel>();
            Waiting = new List<WaitingActionsModel>();
            foreach (var p in game.Players)
            {
                var playerInfo = new PlayerInfoModel
                {
                    Name = p.Name,
                    CouldBeMerlin = Game.DetectMerlin(player, p),
                    IsEvil = Game.DetectEvil(player, p)
                };

                //always know own character, or all characters if game is over
                if ((p==player || GameState == Game.State.EvilTriumphs || GameState == Game.State.GoodPrevails || GameState == Game.State.MerlinDies) && p.Character != Character.UnAllocated) {
                    playerInfo.CharacterCard = p.Character;
                }

                PlayerInfo.Add(playerInfo);

                Waiting.AddRange(game.AvailableActions(p).Select(a => new WaitingActionsModel { Action = a, Name = p.Name }));
            }

            //game history
            Rounds = new List<RoundModel>();
            foreach (var round in game.Rounds)
            {
                Rounds.Add(new RoundModel(round));
            }
        }
Ejemplo n.º 4
0
        void SendMessagesAsAppropriate(Game game, int gameId)
        {
            foreach(var player in game.Players.Where(player => player.PlayerType == Player.Type.Human))
            {
                var actions = game.AvailableActions(player).Select(a=>a.ActionType).Where(a => a != Action.Type.Message);
                if(actions.Any() && !_userConnections.ContainsValue(player.Guid))
                {
                    var user = _simpleDb.GetUser(player.Guid);

                    SendMessage(
                        user.Id,
                        ("Your attention is required on " + game.GameName).Humanize(LetterCasing.Sentence),
                        ("Things have happened and you need to " + Useful.CommaQuibbling(actions.Select(a => a.Humanize()), "or") + ".").Humanize(LetterCasing.Sentence),
                        gameId.ToString()
                    );
                }
            }
        }