Fixes for Boosters in the Shop. Fixes issue 644 and issue 621

This commit is contained in:
wagic.the.homebrew
2011-05-05 05:51:50 +00:00
parent 9902b1c74b
commit 4c572a1ffa
2 changed files with 20 additions and 6 deletions
+10 -2
View File
@@ -321,13 +321,17 @@ void GameStateShop::purchaseBooster(int controlId)
ddw->Sort(WSrcCards::SORT_COLLECTOR); ddw->Sort(WSrcCards::SORT_COLLECTOR);
else else
ddw->Sort(WSrcCards::SORT_RARITY); ddw->Sort(WSrcCards::SORT_RARITY);
for (int x = 0; x < ddw->Size(); x++) for (int x = 0; x < ddw->Size(); x++)
{ {
MTGCard * c = ddw->getCard(x); MTGCard * c = ddw->getCard(x);
for (int copies = 0; copies < ddw->count(c); ++copies)
{
MTGCardInstance * ci = NEW MTGCardInstance(c, NULL); MTGCardInstance * ci = NEW MTGCardInstance(c, NULL);
boosterDisplay->AddCard(ci); boosterDisplay->AddCard(ci);
subBooster.push_back(ci); subBooster.push_back(ci);
} }
}
SAFE_DELETE(ddw); SAFE_DELETE(ddw);
myCollection->loadMatches(booster); myCollection->loadMatches(booster);
@@ -963,7 +967,7 @@ bool ShopBooster::unitTest()
DeckDataWrapper* ddw = NEW DeckDataWrapper(d); DeckDataWrapper* ddw = NEW DeckDataWrapper(d);
bool res = true; bool res = true;
int u = 0, r = 0; int u = 0, r = 0, s = 0;
int card = 0; int card = 0;
for(int i=0;i<ddw->Size(true);i++) for(int i=0;i<ddw->Size(true);i++)
{ {
@@ -973,12 +977,16 @@ bool ShopBooster::unitTest()
r+=ddw->count(c); r+=ddw->count(c);
else if(c->getRarity() == Constants::RARITY_U) else if(c->getRarity() == Constants::RARITY_U)
u+=ddw->count(c); u+=ddw->count(c);
else if(c->getRarity() == Constants::RARITY_S)
s+=ddw->count(c);
card++; card++;
} }
int count = ddw->getCount(); int count = ddw->getCount();
SAFE_DELETE(ddw); SAFE_DELETE(ddw);
SAFE_DELETE(d); 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, "<span class=\"error\">==Unexpected rarity count==</span><br />"); sprintf(result, "<span class=\"error\">==Unexpected rarity count==</span><br />");
TestSuite::Log(result); TestSuite::Log(result);
+7 -1
View File
@@ -46,9 +46,11 @@ int MTGPackSlot::add(WSrcCards * ocean, MTGDeck *to, int carryover)
myPool = MTGPack::getPool(pool); myPool = MTGPack::getPool(pool);
if (!myPool) if (!myPool)
myPool = ocean; myPool = ocean;
for (int i = 0; i < amt; i++) 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)) while (pos < entries.size() && entries[pos]->addCard(myPool, to))
pos++; pos++;
if (pos == entries.size()) if (pos == entries.size())
@@ -378,6 +380,10 @@ MTGPack * MTGPacks::getDefault()
defaultBooster.slotss.push_back(ps); defaultBooster.slotss.push_back(ps);
defaultBooster.bValid = true; defaultBooster.bValid = true;
defaultBooster.unlockStatus = 1; defaultBooster.unlockStatus = 1;
for (size_t i = 0; i < defaultBooster.slotss.size(); ++ i)
{
defaultBooster.slotss[i]->addEntry(NEW MTGPackEntryRandom("rarity:special;"));
}
} }
} }
return &defaultBooster; return &defaultBooster;