Пример #1
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);
            }
        }