Sealed Deck Mode / Random Card Fix

All code submission.
Post Reply
enderak
Posts: 52
Joined: Mon Jul 26, 2010 9:03 am

Sealed Deck Mode / Random Card Fix

Post by enderak » Thu Sep 16, 2010 9:23 pm

This is a patch that adds a Sealed Deck mode. This was done mostly for my amusement, but I think random modes have a huge gameplay potential.

Sealed Deck mode is added as a menu item when the random deck mode is unlocked. It's basically just another random deck mode with all 5 colors and a rarity distribution that matches 4th edition starter decks. Eventually I think it would be nice to combine all of the random modes into one mode where the player can select different options like the number of colors, sets to use, etc from a filter-like interface.

More importantly, this mode uncovered a problem where workaround tokens and the like where being added to decks. This problem has been fixed, and I believe this also fixes a similar problem with these tokens being sold in the shop, because they both use the same random card function.

Code: Select all

Index: projects/mtg/bin/Res/rules/sealed.txt
===================================================================
--- projects/mtg/bin/Res/rules/sealed.txt    (revision 0)
+++ projects/mtg/bin/Res/rules/sealed.txt    (revision 0)
@@ -0,0 +1,3 @@
+include mtg.txt
+[INIT]
+mode=sealed
Index: projects/mtg/include/GameApp.h
===================================================================
--- projects/mtg/include/GameApp.h    (revision 2281)
+++ projects/mtg/include/GameApp.h    (working copy)
@@ -41,7 +41,8 @@
   GAME_TYPE_MOMIR,
   GAME_TYPE_RANDOM1,
   GAME_TYPE_RANDOM2,
-  GAME_TYPE_STORY
+  GAME_TYPE_STORY,
+  GAME_TYPE_SEALED
 };
 
 class MTGAllCards;
Index: projects/mtg/include/Rules.h
===================================================================
--- projects/mtg/include/Rules.h    (revision 2281)
+++ projects/mtg/include/Rules.h    (working copy)
@@ -52,6 +52,7 @@
 protected:
   Player * loadPlayerMomir(int isAI);
   Player * loadPlayerRandom(int isAI, int mode);
+  Player * loadPlayerSealed(int isAI);
   Player * initPlayer(int playerId);
   MTGDeck * buildDeck( int playerId);
   int strToGameMode(string s);
Index: projects/mtg/src/GameStateDuel.cpp
===================================================================
--- projects/mtg/src/GameStateDuel.cpp    (revision 2281)
+++ projects/mtg/src/GameStateDuel.cpp    (working copy)
@@ -245,9 +245,12 @@
       } else if (mParent->gameType == GAME_TYPE_RANDOM1){
         rules = NEW Rules ("random1.txt");
         mGamePhase = DUEL_STATE_PLAY;
-      }else if (mParent->gameType == GAME_TYPE_RANDOM2) {
+      } else if (mParent->gameType == GAME_TYPE_RANDOM2) {
         rules = NEW Rules ("random2.txt");
         mGamePhase = DUEL_STATE_PLAY;
+      } else if (mParent->gameType == GAME_TYPE_SEALED) {
+        rules = NEW Rules ("sealed.txt");
+        mGamePhase = DUEL_STATE_PLAY;
       }
 #ifdef TESTSUITE
       else if (mParent->players[1] ==  PLAYER_TYPE_TESTSUITE){
@@ -325,7 +328,7 @@
               musictrack = "ai_baka_music.mp3";
              else if(mParent->gameType == GAME_TYPE_MOMIR)
               musictrack = "ai_baka_music_momir.mp3";
-             else if(mParent->gameType == GAME_TYPE_RANDOM1 || mParent->gameType == GAME_TYPE_RANDOM2)
+             else if(mParent->gameType == GAME_TYPE_RANDOM1 || mParent->gameType == GAME_TYPE_RANDOM2 || mParent->gameType == GAME_TYPE_SEALED)
               musictrack = "ai_baka_music_random.mp3";
 
           if(!MusicExist(musictrack))
Index: projects/mtg/src/GameStateMenu.cpp
===================================================================
--- projects/mtg/src/GameStateMenu.cpp    (revision 2281)
+++ projects/mtg/src/GameStateMenu.cpp    (working copy)
@@ -58,6 +58,7 @@
   SUBMENUITEM_RANDOM1,
   SUBMENUITEM_RANDOM2,
   SUBMENUITEM_STORY,
+  SUBMENUITEM_SEALED
 };
 
 
@@ -473,6 +474,7 @@
               if (options[Options::RANDOMDECK_MODE_UNLOCKED].number){
                   subMenuController->Add(SUBMENUITEM_RANDOM1, "Random 1 Color");
                   subMenuController->Add(SUBMENUITEM_RANDOM2, "Random 2 Colors");
+              subMenuController->Add(SUBMENUITEM_SEALED, "Sealed Deck");
               }
             subMenuController->Add(SUBMENUITEM_STORY,"Story");
               subMenuController->Add(SUBMENUITEM_CANCEL, "Cancel");
@@ -728,6 +730,13 @@
     currentState = MENU_STATE_MAJOR_DUEL | MENU_STATE_MINOR_SUBMENU_CLOSING;
     break;
 
+  case SUBMENUITEM_SEALED:
+    this->hasChosenGameType = 1;
+    mParent->gameType = GAME_TYPE_SEALED;
+    subMenuController->Close();
+    currentState = MENU_STATE_MAJOR_DUEL | MENU_STATE_MINOR_SUBMENU_CLOSING;
+    break;
+  
   case SUBMENUITEM_STORY:
     this->hasChosenGameType = 1;
     mParent->gameType = GAME_TYPE_STORY;
Index: projects/mtg/src/MTGDeck.cpp
===================================================================
--- projects/mtg/src/MTGDeck.cpp    (revision 2281)
+++ projects/mtg/src/MTGDeck.cpp    (working copy)
@@ -610,8 +610,8 @@
   for (int i = 0; i < collectionTotal; i++){
     MTGCard * card = database->_(i);
     int r = card->getRarity();
-    if (r != Constants::RARITY_T && (rarity == -1 || r==rarity) &&
-    (!_subtype || card->data->hasSubtype(subtype))
+    // make sure rarity and subtype matches, make sure we never add items setID = -1 as these are just workaround tokens
+    if (r != Constants::RARITY_T && (rarity == -1 || r==rarity) && card->setId != -1 && (!_subtype || card->data->hasSubtype(subtype))
     ){
       int ok = 0;
 
Index: projects/mtg/src/Rules.cpp
===================================================================
--- projects/mtg/src/Rules.cpp    (revision 2281)
+++ projects/mtg/src/Rules.cpp    (working copy)
@@ -215,7 +215,27 @@
     return NEW AIPlayerBaka(deck,deckFile, deckFileSmall, "");
 }
 
+Player * Rules::loadPlayerSealed(int isAI){
+  MTGDeck * tempDeck = NEW MTGDeck(GameApp::collection);
 
+  // Distribution based on 4th Edition starter decks: 22[L], 26[C], 9[U], 3[R]
+  tempDeck->addRandomCards(22,0,0,Constants::RARITY_L);
+  tempDeck->addRandomCards(26,0,0,Constants::RARITY_C);
+  tempDeck->addRandomCards(9,0,0,Constants::RARITY_U);
+  tempDeck->addRandomCards(3,0,0,Constants::RARITY_R);
+
+  string deckFile = "sealed";
+  string deckFileSmall = "sealed";
+
+  MTGPlayerCards * deck =  NEW MTGPlayerCards(tempDeck);
+  delete tempDeck;
+
+  if (!isAI) // Human Player
+    return NEW HumanPlayer(deck, deckFile, deckFileSmall);
+  else
+    return NEW AIPlayerBaka(deck, deckFile, deckFileSmall, "");
+}
+
 Player * Rules::initPlayer(int playerId){
   GameObserver * g = GameObserver::GetInstance();
   Player * p = g->players[playerId];
@@ -231,6 +251,8 @@
         return loadPlayerRandom(isAI,GAME_TYPE_RANDOM1);
       case GAME_TYPE_RANDOM2:
         return loadPlayerRandom(isAI,GAME_TYPE_RANDOM2);
+        case GAME_TYPE_SEALED:
+          return loadPlayerSealed(isAI);
     }
   }
   return p;
@@ -430,5 +452,6 @@
   if (s.compare("momir")==0) return GAME_TYPE_MOMIR;
   if (s.compare("random1")==0) return GAME_TYPE_RANDOM1;
   if (s.compare("random2")==0) return GAME_TYPE_RANDOM2;
+  if (s.compare("sealed")==0) return GAME_TYPE_SEALED;
   return GAME_TYPE_CLASSIC;
 }
Right now you have to manually erase/add sets if you want to restrict which cards are included in your decks. Doing this makes for some interesting combinations though, you just need to make sure at least one set has basic lands (UNH is good for this).

Also beware, the AI gets a random deck as well, and as we all know some cards just don't work well with the AI. This could be solved by using the grading system to prevent questionable cards from being added to the AI's deck. I don't think the grading system is used very much in practice though, so there would be some significant work needed to grade all the cards.

mnguyen
Posts: 229
Joined: Thu Apr 29, 2010 4:13 pm

Re: Sealed Deck Mode / Random Card Fix

Post by mnguyen » Fri Sep 17, 2010 12:25 am

I don't this fixes the token in the shop issue as I believe none of the affected code in your patch is called by the shop code.

Here's my patch to the tokens in the shop:

replace line 357 of WDataSrc.cpp ( r2281 ) with the following:

Code: Select all

  if(it->second && unlocked[it->second->setId] && (it->second->getId() > 0))
What's different is the last bit of the conditional. Since all tokens should have a negative id, this will prevent the addition of tokens to the shop collection.
It seems to work so far, I haven't seen any tokens since i put this in.
Cheers!

enderak
Posts: 52
Joined: Mon Jul 26, 2010 9:03 am

Re: Sealed Deck Mode / Random Card Fix

Post by enderak » Fri Sep 17, 2010 12:40 am

You are right. I thought I checked this fix when I originally did it, but I just checked again and I'm getting tokens.

Does keep them from being added to random decks still, so it wasn't a total bust! :)

wololo
Site Admin
Posts: 3727
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: Sealed Deck Mode / Random Card Fix

Post by wololo » Fri Sep 17, 2010 9:35 am

mnguyen : unfortunately some tokens now have positive ids, so I am not sure your fix is enough.
enderak 's fix is closer to what I imagined (check for setId != -1) . That plus a cleanup of incorrectly coded tokens

mnguyen
Posts: 229
Joined: Thu Apr 29, 2010 4:13 pm

Re: Sealed Deck Mode / Random Card Fix

Post by mnguyen » Sat Sep 18, 2010 2:21 am

i realized that after I posted my "fix", when I had that conversation with you and Zeth. It was worth a try though! :)

Post Reply