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); } }
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"); }
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); }
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); }
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); } }