Beispiel #1
0
bool ShopBooster::unitTest()
{
    //this tests the default random pack creation.
    MTGDeck * d = NEW MTGDeck(MTGCollection());
    char result[1024];

    randomStandard();
    MTGPack * mP = MTGPacks::getDefault();
    if(!altSet && mainSet->mPack) mP = mainSet->mPack;
    char buf[512];
    if(!altSet) sprintf(buf,"set:%s;",mainSet->id.c_str());
    else sprintf(buf,"set:%s;|set:%s;",mainSet->id.c_str(),altSet->id.c_str());
    mP->pool = buf;
    mP->assemblePack(d); //Use the primary packfile. assemblePack deletes pool.
    DeckDataWrapper* ddw = NEW DeckDataWrapper(d);
    bool res = true;

    int u = 0, r = 0, s = 0;
    int card = 0;
    for(int i=0;i<ddw->Size(true);i++)
    {
        MTGCard * c = ddw->getCard(i);
        if(!c) break;
        if(c->getRarity() == Constants::RARITY_R || c->getRarity() == Constants::RARITY_M)
        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);
    //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 />");
        TestSuite::Log(result);
        res = false;
    }
    if(count < 14)
    {
        sprintf(result, "<span class=\"error\">==Unexpected card count==</span><br />");
        TestSuite::Log(result);
        res = false;
    }
    sprintf(result, "<span class=\"success\">==Test Succesful !==</span><br />");
    TestSuite::Log(result);
    SAFE_DELETE(ddw);
    SAFE_DELETE(d);
    return res;
}
Beispiel #2
0
void GameStateShop::purchaseBooster(int controlId)
{
    if (playerdata->credits - mPrices[controlId] < 0)
        return;
    playerdata->credits -= mPrices[controlId];
    mInventory[controlId]--;
    SAFE_DELETE(booster);
    deleteDisplay();
    booster = NEW MTGDeck(MTGCollection());
    boosterDisplay = NEW BoosterDisplay(12, NULL, SCREEN_WIDTH - 200, SCREEN_HEIGHT / 2, this, NULL, 5);
    mBooster[controlId].addToDeck(booster, srcCards);

    string sort = mBooster[controlId].getSort();
    DeckDataWrapper * ddw = NEW DeckDataWrapper(booster);
    if (sort == "alpha")
        ddw->Sort(WSrcCards::SORT_ALPHA);
    else if (sort == "collector")
        ddw->Sort(WSrcCards::SORT_COLLECTOR);
    else
        ddw->Sort(WSrcCards::SORT_RARITY);

    for (int x = 0; x < ddw->Size(); x++)
    {
        MTGCard * c = ddw->getCard(x);
        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);

    myCollection->loadMatches(booster);
    mTouched = true;
    save(true);
    menu->Close();
}
Beispiel #3
0
bool GameStateAwards::enterStats(int option)
{
    if (option != Options::AWARD_COLLECTOR)
        return false;
    DeckDataWrapper* ddw = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), MTGCollection()));
    if (!ddw)
        return false;

    SAFE_DELETE(detailview);
    detailview = NEW WGuiList("Details");

    detailview->Add(NEW WGuiHeader("Collection Stats"));
    detailview->Entering(JGE_BTN_NONE);

    //Discover favorite set
    if (setlist.size() > 0)
    {
        int * counts = (int*) calloc(setlist.size(), sizeof(int));
        int setid = -1;
        int dupes = 0;
        MTGCard * many = NULL;
        MTGCard * costly = NULL;
        MTGCard * strong = NULL;
        MTGCard * tough = NULL;

        for (int t = 0; t < ddw->Size(); t++)
        {
            MTGCard * c = ddw->getCard(t);
            if (!c)
                continue;
            int count = ddw->count(c);
            if (!c->data->isLand() && (many == NULL || count > dupes))
            {
                many = c;
                dupes = count;
            }
            counts[c->setId] += count;
            if (costly == NULL || c->data->getManaCost()->getConvertedCost() > costly->data->getManaCost()->getConvertedCost())
                costly = c;

            if (c->data->isCreature() && (strong == NULL || c->data->getPower() > strong->data->getPower()))
                strong = c;

            if (c->data->isCreature() && (tough == NULL || c->data->getToughness() > tough->data->getToughness()))
                tough = c;
        }
        for (int i = 0; i < setlist.size(); i++)
        {
            if (setid < 0 || counts[i] > counts[setid])
                setid = i;
        }
        free(counts);

        char buf[1024];
        sprintf(buf, _("Total Value: %ic").c_str(), ddw->totalPrice());
        detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));//ddw->colors

        sprintf(buf, _("Total Cards (including duplicates): %i").c_str(), ddw->getCount(WSrcDeck::UNFILTERED_COPIES));
        detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));//ddw->colors

        sprintf(buf, _("Unique Cards: %i").c_str(), ddw->getCount(WSrcDeck::UNFILTERED_UNIQUE));
        detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));

        if (many)
        {
            sprintf(buf, _("Most Duplicates: %i (%s)").c_str(), dupes, many->data->getName().c_str());
            detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));
        }
        if (setid >= 0)
        {
            sprintf(buf, _("Favorite Set: %s").c_str(), setlist[setid].c_str());
            detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));
        }
        if (costly)
        {
            sprintf(buf, _("Highest Mana Cost: %i (%s)").c_str(), costly->data->getManaCost()->getConvertedCost(),
                            costly->data->getName().c_str());
            detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));
        }
        if (strong)
        {
            sprintf(buf, _("Most Powerful: %i (%s)").c_str(), strong->data->getPower(), strong->data->getName().c_str());
            detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));
        }
        if (tough)
        {
            sprintf(buf, _("Toughest: %i (%s)").c_str(), tough->data->getToughness(), strong->data->getName().c_str());
            detailview->Add(NEW WGuiItem(buf, WGuiItem::NO_TRANSLATE));
        }
    }

    SAFE_DELETE(ddw->parent);
    SAFE_DELETE(ddw);
    return true;
}