From 4c572a1ffa01066dfdf018bbf4872980fa9ad7c6 Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew" Date: Thu, 5 May 2011 05:51:50 +0000 Subject: [PATCH] Fixes for Boosters in the Shop. Fixes issue 644 and issue 621 --- projects/mtg/src/GameStateShop.cpp | 18 +++++++++++++----- projects/mtg/src/MTGPack.cpp | 8 +++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/projects/mtg/src/GameStateShop.cpp b/projects/mtg/src/GameStateShop.cpp index de85a7ba8..7c11a4346 100644 --- a/projects/mtg/src/GameStateShop.cpp +++ b/projects/mtg/src/GameStateShop.cpp @@ -321,12 +321,16 @@ void GameStateShop::purchaseBooster(int controlId) ddw->Sort(WSrcCards::SORT_COLLECTOR); else ddw->Sort(WSrcCards::SORT_RARITY); + for (int x = 0; x < ddw->Size(); x++) { MTGCard * c = ddw->getCard(x); - MTGCardInstance * ci = NEW MTGCardInstance(c, NULL); - boosterDisplay->AddCard(ci); - subBooster.push_back(ci); + for (int copies = 0; copies < ddw->count(c); ++copies) + { + MTGCardInstance * ci = NEW MTGCardInstance(c, NULL); + boosterDisplay->AddCard(ci); + subBooster.push_back(ci); + } } SAFE_DELETE(ddw); @@ -963,7 +967,7 @@ bool ShopBooster::unitTest() DeckDataWrapper* ddw = NEW DeckDataWrapper(d); bool res = true; - int u = 0, r = 0; + int u = 0, r = 0, s = 0; int card = 0; for(int i=0;iSize(true);i++) { @@ -973,12 +977,16 @@ bool ShopBooster::unitTest() r+=ddw->count(c); else if(c->getRarity() == Constants::RARITY_U) u+=ddw->count(c); + else if(c->getRarity() == Constants::RARITY_S) + s+=ddw->count(c); card++; } int count = ddw->getCount(); SAFE_DELETE(ddw); SAFE_DELETE(d); - if(r != 1 || u != 3 ) + //Note: When there are special cards, the count IS going to be messed up, so do not perform the check for Rare and Uncommon in that case + //also see http://code.google.com/p/wagic/issues/detail?id=644 + if(!s && (r != 1 || u != 3) ) { sprintf(result, "==Unexpected rarity count==
"); TestSuite::Log(result); diff --git a/projects/mtg/src/MTGPack.cpp b/projects/mtg/src/MTGPack.cpp index 7b1a91a32..82ca37672 100644 --- a/projects/mtg/src/MTGPack.cpp +++ b/projects/mtg/src/MTGPack.cpp @@ -46,9 +46,11 @@ int MTGPackSlot::add(WSrcCards * ocean, MTGDeck *to, int carryover) myPool = MTGPack::getPool(pool); if (!myPool) myPool = ocean; + for (int i = 0; i < amt; i++) { - size_t pos = rand() % entries.size(); + std::random_shuffle(entries.begin(), entries.end()); + size_t pos = 0; while (pos < entries.size() && entries[pos]->addCard(myPool, to)) pos++; if (pos == entries.size()) @@ -378,6 +380,10 @@ MTGPack * MTGPacks::getDefault() defaultBooster.slotss.push_back(ps); defaultBooster.bValid = true; defaultBooster.unlockStatus = 1; + for (size_t i = 0; i < defaultBooster.slotss.size(); ++ i) + { + defaultBooster.slotss[i]->addEntry(NEW MTGPackEntryRandom("rarity:special;")); + } } } return &defaultBooster;