Пример #1
0
        private void MainPageResponses(int responseID)
        {
            var        response   = GetResponseByID("MainPage", responseID);
            NWItem     collection = GetPC().GetLocalObject("ACTIVE_COLLECTION");
            List <int> sideboard  = (List <int>)GetResponseByID("MainPage", responseID).CustomData;

            if (response.Text == "Swap card from sideboard to deck")
            {
                GetPC().SetLocalInt("PAZAAK_ACTION", 1);
                ChangePage("SelectCardPage");
            }
            else if (response.Text == "Remove card from collection")
            {
                GetPC().SetLocalInt("PAZAAK_ACTION", 2);
                ChangePage("SelectCardPage");
            }

            // Build the responses for the select card page.
            ClearPageResponses("SelectCardPage");

            foreach (int card in sideboard)
            {
                AddResponseToPage("SelectCardPage", PazaakService.Display(PazaakService.GetCardInCollection(card, collection)), true, card);
            }
        }
Пример #2
0
        private void BuildTurnOptions(NWPlayer pc)
        {
            // Draw a card.
            int score = pc == game.player1 ? game.player1Score : game.player2Score;

            int card = game.DrawCard();

            score += card;
            game.lastCardPlayed = card;
            pc.FloatingText("You drew a " + card + " putting your score at " + score);
            if (pc == game.player1)
            {
                game.player1Score = score;
            }
            else
            {
                game.player2Score = score;
            }

            // Since we're having a turn, we can't be the one standing...
            bool bStand = game.player1Standing || game.player2Standing;

            string header = "Your score is at " + score + ". " + (bStand ? "The other player is standing. " : "") +
                            "What do you want to do?";

            SpeakString(pc.Name + " draws a " + card + " from the deck.  Their score is now " + score);

            if (pc.GetLocalInt("PAZAAK_REMINDED") == 0)
            {
                pc.SendMessage("(Pazaak Rules Reminder: highest score under 21 wins, ending your turn at 21+ loses you the round.  You may play up to one card from your hand each turn. A standing player does not get to play again, but ending your turn means you will have to draw at least one more card.)");
                pc.SetLocalInt("PAZAAK_REMINDED", 1);
            }

            SetPageHeader("MainPage", header);
            ClearPageResponses("MainPage");

            List <int> sideDeck = pc == game.player1 ? game.player1SideDeck : game.player2SideDeck;

            // Build options from the side deck.
            foreach (int sideCard in sideDeck)
            {
                if ((sideCard > 100 && sideCard < 107) || sideCard == 203)
                {
                    // Card can be played either of two ways.
                    AddResponseToPage("MainPage", "Play card from side deck: " + PazaakService.Display(sideCard) + " as positive", true, sideCard);
                    AddResponseToPage("MainPage", "Play card from side deck: " + PazaakService.Display(sideCard) + " as negative", true, sideCard);
                }
                else
                {
                    AddResponseToPage("MainPage", "Play card from side deck: " + PazaakService.Display(sideCard), true, sideCard);
                }
            }

            AddResponseToPage("MainPage", "End Turn", score < 21);
            AddResponseToPage("MainPage", "Stand");
        }
Пример #3
0
        private void SelectDeckSlotPageResponses(int responseID)
        {
            int    card       = GetPC().GetLocalInt("PAZAAK_CARD_SELECTED");
            int    slot       = Convert.ToInt32(GetResponseByID("SelectDeckSlotPage", responseID).CustomData.ToString());
            NWItem collection = GetPC().GetLocalObject("ACTIVE_COLLECTION");

            PazaakService.AddCardToDeck(card, collection, slot);

            // Rebuild the main page as the collection has changed.
            LoadMainPage();
            ChangePage("MainPage");
        }
Пример #4
0
        private void LoadMainPage()
        {
            NWItem collection = GetPC().GetLocalObject("ACTIVE_COLLECTION");
            Dictionary <int, int> collectedCards = new Dictionary <int, int>();
            Dictionary <int, int> deckCards      = new Dictionary <int, int>();

            string mainHeader = "Cards in your deck:";

            ClearPageResponses("MainPage");
            ClearPageResponses("SelectDeckSlotPage");

            // allow up to 100 cards in a collection.  That should be plenty, right?
            for (int ii = 1; ii <= 100; ii++)
            {
                int card = PazaakService.GetCardInCollection(ii, collection);

                if (card != 0)
                {
                    collectedCards.Add(ii, card);
                }
            }

            for (int jj = 1; jj <= 10; jj++)
            {
                int deckCard = PazaakService.GetCardInDeck(jj, collection);
                deckCards.Add(jj, collectedCards[deckCard]);
                mainHeader += " " + PazaakService.Display(collectedCards[deckCard]) + " ";
                AddResponseToPage("SelectDeckSlotPage", "Slot " + jj + " (" + PazaakService.Display(collectedCards[deckCard]) + ")", true, jj);
                collectedCards.Remove(deckCard);
            }

            mainHeader += "\n\nCards in your sideboard:";

            List <int> sideboard = collectedCards.Keys.ToList();

            foreach (int card in sideboard)
            {
                mainHeader += " " + PazaakService.Display(collectedCards[card]) + " ";
            }

            if (sideboard.Count == 0)
            {
                mainHeader += "\n\nFind more cards and add them to your collection for to be able to customise your deck.";
            }

            SetPageHeader("MainPage", mainHeader);

            // If we have a sideboard, allow the user to swap cards or remove cards.  Pass the sideboard
            AddResponseToPage("MainPage", "Swap card from sideboard to deck", sideboard.Count > 0, sideboard);
            AddResponseToPage("MainPage", "Remove card from collection", sideboard.Count > 0, sideboard);
        }
Пример #5
0
        private bool CheckEndRound(NWObject table, float delay = 0.0f)
        {
            // SpeakString("DEBUG: Checking end round.  Player 1 standing? " + game.player1Standing + " Player 2 standing? " + game.player2Standing + " Scores: " + game.player1Score + "/" + game.player2Score);
            // If the game is already over, skip the rest.
            if (table.GetLocalInt("IN_GAME") == 0)
            {
                return(true);
            }

            if (game.player1Score > 20 || game.player2Score > 20 || (game.player1Standing && game.player2Standing))
            {
                game.EndRound();

                if (game.player1Sets == 3)
                {
                    DelayCommand(0.5f + delay, () =>
                    {
                        SpeakString(GetName(game.player1) + " wins, 3 sets to " + game.player2Sets + "!");
                    });
                    PazaakService.EndGame(table, game);
                    table.DeleteLocalInt("IN_GAME");
                }
                else if (game.player2Sets == 3)
                {
                    DelayCommand(1.5f + delay, () =>
                    {
                        SpeakString(GetName(game.player2) + " wins, 3 sets to " + game.player1Sets + "!");
                    });
                    PazaakService.EndGame(table, game);
                    table.DeleteLocalInt("IN_GAME");
                }
                else
                {
                    DelayCommand(1.5f + delay, () =>
                    {
                        SpeakString("New set beginning.  " + GetName(game.player1) + " has won " + game.player1Sets + " sets, " +
                                    GetName(game.player2) + " has won " + game.player2Sets + " sets. " + GetName(game.nextTurn) + " to play.");
                    });
                }

                return(true);
            }

            return(false);
        }
Пример #6
0
        private void SelectCardPageResponses(int responseID)
        {
            int card = Convert.ToInt32(GetResponseByID("SelectCardPage", responseID).CustomData.ToString());

            if (GetPC().GetLocalInt("PAZAAK_ACTION") == 1)
            {
                ChangePage("SelectDeckSlotPage");
                GetPC().SetLocalInt("PAZAAK_CARD_SELECTED", card);
            }
            else
            {
                NWItem collection = GetPC().GetLocalObject("ACTIVE_COLLECTION");
                PazaakService.RemoveCardFromCollection(card, collection);

                // Rebuild the main page as the collection has changed.
                LoadMainPage();
                ChangePage("MainPage");
            }
        }
Пример #7
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            if (item.Tag == "PazaakCard" && target.Tag == "PazaakCollection")
            {
                user.ClearAllActions(); // In case they are in the manage collection dialog, avoid conflicts.
                PazaakService.AddCardToCollection(item, target);
                return;
            }

            if (item.Tag == "PazaakCollection" && target.Tag == "PazaakTable")
            {
                user.SetLocalObject("ACTIVE_COLLECTION", item);
                DialogService.StartConversation(user, target, "PazaakTable");
                return;
            }

            if (item.Tag == "PazaakCollection" && (!target.IsValid || target == user))
            {
                user.SetLocalObject("ACTIVE_COLLECTION", item);
                DialogService.StartConversation(user, user, "PazaakCollection");
                return;
            }
        }
Пример #8
0
        private void BuildSideDeck(NWObject player)
        {
            NWItem     collection  = player.GetLocalObject("ACTIVE_COLLECTION");
            List <int> deckToBuild = new List <int>(4);
            List <int> playerDeck  = new List <int>(10);

            int random;

            if (collection.IsValid)
            {
                // We have a player with a real deck.  Build the list and select 4 random cards from it.
                for (int ii = 1; ii <= 10; ii++)
                {
                    playerDeck.Add(PazaakService.GetCardInCollection(PazaakService.GetCardInDeck(ii, collection), collection));
                }
            }
            else
            {
                // This is an NPC.  Give them a deck with 6 random + cards, 3-4 random - cards and 0-1 random wild card.
                // See PazaakCard.cs for values.
                if (RandomService.D6(1) == 6)
                {
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));

                    playerDeck.Add(RandomService.D6(1) * -1);
                    playerDeck.Add(RandomService.D6(1) * -1);
                    playerDeck.Add(RandomService.D6(1) * -1);

                    playerDeck.Add(RandomService.D6(1) + 100);
                }
                else
                {
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));

                    playerDeck.Add(RandomService.D6(1) * -1);
                    playerDeck.Add(RandomService.D6(1) * -1);
                    playerDeck.Add(RandomService.D6(1) * -1);
                    playerDeck.Add(RandomService.D6(1) * -1);
                }
            }

            random = RandomService.Random(10);
            deckToBuild.Add(playerDeck[random]);
            playerDeck.Remove(random);

            random = RandomService.Random(9);
            deckToBuild.Add(playerDeck[random]);
            playerDeck.Remove(random);

            random = RandomService.Random(8);
            deckToBuild.Add(playerDeck[random]);
            playerDeck.Remove(random);

            random = RandomService.Random(7);
            deckToBuild.Add(playerDeck[random]);
            playerDeck.Remove(random);

            if (player1 == player)
            {
                player1SideDeck = deckToBuild;
            }
            else
            {
                player2SideDeck = deckToBuild;
            }
        }
Пример #9
0
        private int PlayNPCCard(float delay)
        {
            // We'll call this method to do one of three things.
            // - If our score is over 20, rescue it to sub 20.
            // - If playing a card would put us over a standing player's score, play it.
            // - If playing a card would put us to exactly 20, play it.
            // NPCs will never have the "special" cards (200+).
            if (game.player2Score > 20)
            {
                foreach (int card in game.player2SideDeck)
                {
                    int adjust = 0;
                    if (card > 0 && card < 7)
                    {
                        continue;
                    }
                    if (card > 100 && card < 107)
                    {
                        adjust = -1 * (card - 100);
                    }
                    if (card < 0)
                    {
                        adjust = card;
                    }

                    if (game.player2Score + adjust < 21)
                    {
                        game.player2Score += adjust;
                        int score = game.player2Score;
                        DelayCommand(1.0f + delay, () => { SpeakString(GetName(game.player2) + " plays " + PazaakService.Display(card) + " from hand.  Score is now " + score); });
                        game.player2SideDeck.Remove(card);
                        break;
                    }
                }
            }
            else
            {
                int targetScore = game.player1Standing ? game.player1Score : 19;

                foreach (int card in game.player2SideDeck)
                {
                    int adjust = 0;
                    if (card > 0 && card < 7)
                    {
                        adjust = card;
                    }
                    if (card > 100 && card < 107)
                    {
                        adjust = card - 100;
                    }
                    if (card < 0)
                    {
                        continue;
                    }

                    if (game.player2Score + adjust < 21 && game.player2Score + adjust > targetScore)
                    {
                        game.player2Score += adjust;
                        int score = game.player2Score;
                        DelayCommand(1.0f + delay, () => { SpeakString(GetName(game.player2) + " plays " + PazaakService.Display(card) + " from hand.  Score is now " + score); });
                        game.player2SideDeck.Remove(card);
                        break;
                    }
                }
            }

            return(game.player2Score);
        }
Пример #10
0
        private void LoadMainPage()
        {
            NWObject table = _.OBJECT_SELF;
            NWPlayer pc    = GetPC();

            game = PazaakService.GetCurrentGame(table);

            if (game == null && table.GetLocalInt("IN_GAME") == 2)
            {
                // Belt and bracers clean up code.
                table.DeleteLocalInt("IN_GAME");
            }

            // Check whether we have a game, or whether we should create one.
            if (table.GetLocalInt("IN_GAME") == 2)
            {
                CheckEndRound(table);

                if (game.nextTurn == pc)
                {
                    // Our turn.
                    BuildTurnOptions(pc);
                }
                else if (game.player2.IsNPC)
                {
                    // NPC turn.  Handle some
                    DoNPCTurn(game);
                    CheckEndRound(table);
                    if (game.nextTurn == game.player2)
                    {
                        DoNPCTurn(game);
                    }
                    BuildTurnOptions(pc);
                }
                else
                {
                    // Other player turn.
                    SetPageHeader("MainPage", "It is not currently your turn.");
                    ClearPageResponses("MainPage");
                }
            }
            // Table is open for a second player.
            else if (table.GetLocalInt("IN_GAME") == 1)
            {
                NWObject collection = pc.GetLocalObject("ACTIVE_COLLECTION");

                if (GetName(table.GetLocalObject("PLAYER_1")) == pc.Name)
                {
                    SetPageHeader("MainPage", "You are waiting for an opponent here.  Or play against the host.");
                    ClearPageResponses("MainPage");
                    AddResponseToPage("MainPage", "Table host (NPC)");
                }
                // Check that the player has an active Pazaak deck.
                else if (collection.IsValid)
                {
                    SetPageHeader("MainPage", GetName(table.GetLocalObject("PLAYER_1")) + " is waiting for an opponent.  Join game?");
                    ClearPageResponses("MainPage");
                    AddResponseToPage("MainPage", "Join game");
                }
                else
                {
                    SetPageHeader("MainPage", "Use your Pazaak Collection on this table to join the game.");
                    ClearPageResponses("MainPage");
                }
            }
            // Create a game.  Offer the PC a choice of vs NPC or vs Player.
            else
            {
                NWObject collection = pc.GetLocalObject("ACTIVE_COLLECTION");
                // Check that the player has an active Pazaak deck.
                if (collection.IsValid)
                {
                    table.SetLocalInt("IN_GAME", 1);
                    table.SetLocalObject("PLAYER_1", pc);
                    table.DeleteLocalObject("PLAYER_2");

                    SetPageHeader("MainPage", "Game created.  Will this be against another player, or the table owner?");
                    ClearPageResponses("MainPage");
                    AddResponseToPage("MainPage", "A player");
                    AddResponseToPage("MainPage", "Table host (NPC)");
                }
                else
                {
                    SetPageHeader("MainPage", "Use your Pazaak Collection on this table to join the game.");
                    ClearPageResponses("MainPage");
                }
            }
        }
Пример #11
0
        private void MainPageResponses(int responseID)
        {
            var      response = GetResponseByID("MainPage", responseID);
            NWObject table    = _.OBJECT_SELF;
            NWPlayer pc       = GetPC();

            game = PazaakService.GetCurrentGame(table);

            if (response.Text == "A player")
            {
                // Leave table open for PC to join.
                EndConversation();
            }
            else if (response.Text == "Table host (NPC)")
            {
                NWCreature NPC = GetNearestCreature(CreatureType.IsAlive, 1, pc.Object, 1, (int)CreatureType.PlayerCharacter, 0);

                if (NPC.IsValid)
                {
                    AssignCommand(NPC, () => { ActionMoveToObject(table); });
                    game = PazaakService.StartGame(table, pc, NPC);
                    table.SetLocalInt("IN_GAME", 2);

                    if (game.nextTurn == game.player2)
                    {
                        DelayCommand(2.0f, () => { DoNPCTurn(game); });
                    }
                }
                else
                {
                    pc.SendMessage("Sorry, this table has no host.");
                }

                EndConversation();
            }
            else if (response.Text == "Join game")
            {
                NWObject p1 = table.GetLocalObject("PLAYER_1");
                PazaakService.StartGame(table, p1, pc);
                table.SetLocalInt("IN_GAME", 2);

                EndConversation();
            }
            else if (response.Text.StartsWith("Play card from side deck"))
            {
                // Get the card value and modify the score.  Then rebuild the options.
                int    card     = Convert.ToInt32(GetResponseByID("MainPage", responseID).CustomData.ToString());
                string cardText = "You play a " + PazaakService.Display(card);

                if (pc == game.player1)
                {
                    game.player1SideDeck.Remove(card);
                }
                else
                {
                    game.player2SideDeck.Remove(card);
                }

                if (card > 100 && card < 107)
                {
                    // Make it a 1-6 number.
                    card -= 100;

                    if (response.Text.EndsWith("negative"))
                    {
                        // Played as negative, so flip the sign.
                        card *= -1;
                    }
                }

                if (card > 200)
                {
                    switch (card)
                    {
                    case 201:     // Flip
                    {
                        card = (pc == game.player1 ? game.player1HandCardsPlayedThisSet : game.player2HandCardsPlayedThisSet) * -2;
                        break;
                    }

                    case 202:     // Double
                    {
                        card = game.lastCardPlayed;
                        break;
                    }

                    case 203:     // Tiebreaker
                    {
                        card = 1;
                        if (response.Text.EndsWith("negative"))
                        {
                            // Played as negative, so flip the sign.
                            card *= -1;
                        }
                        game.tiebreaker = pc;
                        break;
                    }
                    }
                }

                int score;
                if (pc == game.player1)
                {
                    game.player1Score += card;
                    game.player1HandCardsPlayedThisSet += card;
                    score = game.player1Score;
                }
                else
                {
                    game.player2Score += card;
                    game.player2HandCardsPlayedThisSet += card;
                    score = game.player2Score;
                }

                pc.FloatingText(cardText + ". Your score is now " + score);
                SpeakString(pc.Name + " plays a " + cardText + ", taking their score to " + score);

                // Since we're having a turn, we can't be the one standing...
                bool bStand = game.player1Standing || game.player2Standing;

                string header = "Your score is at " + score + ". " + (bStand ? "The other player is standing. " : "") +
                                "What do you want to do?";

                SetPageHeader("MainPage", header);
                ClearPageResponses("MainPage");
                AddResponseToPage("MainPage", "End Turn", score < 21);
                AddResponseToPage("MainPage", "Stand");
            }
            else if (response.Text == "End Turn" || response.Text == "Stand")
            {
                // Whatever happens, end the dialog.
                EndConversation();

                // Process end turn responses, then do NPC turn if it's an NPC game.
                if (response.Text == "Stand")
                {
                    if (pc == game.player1)
                    {
                        game.player1Standing = true;
                    }
                    else
                    {
                        game.player2Standing = true;
                    }
                }

                // Record that it is time for the next player to take their turn, unless they are standing.
                if (pc == game.player1 && !game.player2Standing)
                {
                    game.nextTurn = game.player2;
                }
                else if (pc == game.player2 && !game.player1Standing)
                {
                    game.nextTurn = game.player1;
                }

                // If both players are PCs, we shouldn't have to do anything more now.  But if we're playing with an NPC, now the NPC needs
                // to take their turn.
                float delay = 1.0f;

                if (!CheckEndRound(table) && game.player2.IsNPC && !game.player2Standing)
                {
                    game = DoNPCTurn(game);

                    while (game.player2.IsNPC && game.player1Standing && !game.player2Standing && !CheckEndRound(table, delay))
                    {
                        // PC is standing, so keep playing NPC turns until the round ends.
                        game   = DoNPCTurn(game, delay);
                        delay += 1.0f;
                    }
                }

                CheckEndRound(table, delay);
            }
        }