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