Beispiel #1
0
        public string IssueGameCommand(DiceBot diceBot, BotMain botMain, string character, string channel, GameSession session, string[] terms)
        {
            string returnString = "";

            if (terms.Contains("showallnumbers"))
            {
                if (session.State == GameState.GameInProgress)
                {
                    string messageString = "Showing all information for this round of The King's Game:\n" + GetPlayerNumbers(session);
                    botMain.SendPrivateMessage(messageString, character);
                    returnString = Utils.GetCharacterUserTags(character) + " has been sent the information for this round's secret numbers.";
                }
                else
                {
                    returnString = "The King's Game is not already in progress, there are no numbers to show.";
                }
            }
            else if (terms.Contains("endround"))
            {
                returnString = "King's Game round has ended manually.";
                ResetGameRound(session);
            }
            else if (terms.Contains("awardpoints"))
            {
                if (session.State == GameState.GameInProgress)
                {
                    if (PlayerIsKing(session, character))
                    {
                        if (session.KingsGamePlayers == null || session.KingsGamePlayers.Count < GetMinPlayers())
                        {
                            returnString = "Error: King's Game players list not set correctly.";
                        }
                        else
                        {
                            List <int> playerAwardsTemp = Utils.GetAllNumbersFromInputs(terms);
                            List <int> playerAwards     = new List <int>();

                            //decrease all the numbers by 1 to match array indexes, rather than the card position for a player
                            if (playerAwardsTemp.Count > 0)
                            {
                                foreach (int i in playerAwardsTemp)
                                {
                                    if (i > 0 && i < session.KingsGamePlayers.Count)
                                    {
                                        playerAwards.Add(i);
                                    }
                                }
                            }

                            string playerAwardsList = "";
                            if (playerAwards.Count > 0)
                            {
                                foreach (int i in playerAwards)
                                {
                                    playerAwardsList += GetPlayerNameAndNumber(session, i);
                                    KingsGamePlayer player = session.KingsGamePlayers.FirstOrDefault(a => a.Role == i);
                                    if (player != null)
                                    {
                                        string chipsAward = diceBot.AddChips(player.Name, channel, 100, false);
                                        playerAwardsList += "\n" + chipsAward;
                                    }
                                    playerAwardsList += "\n";
                                }
                            }
                            else
                            {
                                playerAwardsList = "no one";
                            }


                            string messageString = "King " + Utils.GetCharacterUserTags(character) + " is awarding Points to :\n" + playerAwardsList;

                            returnString = messageString + "\n This round has finished.";

                            ResetGameRound(session);
                        }
                    }
                    else
                    {
                        returnString = "Only the king can award points for the round.";
                    }
                }
                else
                {
                    returnString = "The King's Game is not already in progress, points cannot be awarded.";
                }
            }
            else
            {
                returnString = "A command for " + GetGameName() + " was not found.";
            }

            return(returnString);
        }
Beispiel #2
0
        public string RunGame(System.Random r, List <String> playerNames, DiceBot diceBot, BotMain botMain, GameSession session)
        {
            botMain.SendMessageInChannel("[color=yellow]Selecting a new king and assigning numbers...[/color]", session.ChannelId);

            int index = r.Next(playerNames.Count);

            string selectedKing = playerNames[index];

            while (session.KingsGamePlayers != null && session.KingsGamePlayers.Count > 1 &&
                   session.KingsGamePlayers.FirstOrDefault(a => a.Role == 0) != null &&
                   session.KingsGamePlayers.FirstOrDefault(a => a.Role == 0).Name == selectedKing)
            {
                index = r.Next(playerNames.Count);

                selectedKing = playerNames[index];
            }

            int    kingTextNumber = r.Next(7);
            string kingIntroText  = "";

            switch (kingTextNumber)
            {
            case 0:
                kingIntroText = "All hail king ";
                break;

            case 1:
                kingIntroText = "The new king is ";
                break;

            case 2:
                kingIntroText = "Your king is ";
                break;

            case 3:
                kingIntroText = "Behold king ";
                break;

            case 4:
                kingIntroText = "A new king has been chosen, ";
                break;

            case 5:
                kingIntroText = "This round's king is ";
                break;

            case 6:
                kingIntroText = "The king is ";
                break;

            default:
                kingIntroText = "The new king is ";
                break;
            }


            int[] assignedNumbers = new int[playerNames.Count - 1];

            int createdNumbers = 0;

            List <int> includedInts = new List <int>();

            //assign a number to every remaining player
            for (int i = 0; i < assignedNumbers.Length; i++)
            {
                int assignedNumber = r.Next(assignedNumbers.Length - createdNumbers) + 1;

                int counter = 0;
                for (int q = 0; q < assignedNumber; q++)
                {
                    counter += 1;
                    while (includedInts.Contains(counter))
                    {
                        counter += 1;
                    }
                }

                includedInts.Add(counter);
                assignedNumbers[i] = counter;
                createdNumbers++;
            }

            int createdNumberIndex = 0;
            int playerNumber       = 0;

            session.KingsGamePlayers = new List <KingsGamePlayer>();

            foreach (string player in playerNames)
            {
                if (playerNumber != index)
                {
                    int    playerAssignedNumber = assignedNumbers[createdNumberIndex];
                    string messageToPlayer      = "Your number is " + playerAssignedNumber + " for this round.";
                    createdNumberIndex++;
                    session.KingsGamePlayers.Add(new KingsGamePlayer()
                    {
                        Name = player,
                        Role = playerAssignedNumber
                    });

                    botMain.SendPrivateMessage(messageToPlayer, player);
                }
                else
                {
                    session.KingsGamePlayers.Add(new KingsGamePlayer()
                    {
                        Name = player,
                        Role = 0
                    });
                }
                playerNumber++;
            }

            botMain.SendPrivateMessage("You are the king this round!\nGive your command to the other players using the numbers 1 - " + assignedNumbers.Length + " and then award points based on if they completed the tasks.", selectedKing);

            string outputString = "" + kingIntroText + Utils.GetCharacterUserTags(selectedKing) +
                                  "\nEveryone has been assigned their numbers and the king may make decrees using the numbers 1 - " + assignedNumbers.Length + "." +
                                  "\n..." +
                                  "\nNext Step: After the tasks are finished, the king must assign points with !gc awardpoints [player number(s)], or the round can be cancelled with !gc endround" +
                                  "\nNote: If there is any confusion about who has what number you can use !gc showallnumbers[/sub]";

            session.State = DiceFunctions.GameState.GameInProgress;

            return(outputString);
        }
Beispiel #3
0
 public void ResetGameRound(GameSession session)
 {
     session.State = GameState.Unstarted;
 }