Example #1
0
void GameStateShop::Start()
{
    menu = NULL;
    bListCards = false;
    mTouched = false;
    mStage = STAGE_FADE_IN;
    mElapsed = 0;
    needLoad = true;
    booster = NULL;
    srcCards = NEW WSrcUnlockedCards(0);
    srcCards->setElapsed(15);
    srcCards->addFilter(NEW WCFilterNOT(NEW WCFilterRarity("T")));
    srcCards->addFilter(NEW WCFilterNOT(NEW WCFilterSet(MTGSets::INTERNAL_SET)));

    bigSync = 0;
    shopMenu = NEW WGuiMenu(JGE_BTN_DOWN, JGE_BTN_UP, true, &bigSync);
    MTGAllCards * ac = MTGCollection();
    playerdata = NEW PlayerData(ac);
    myCollection = NEW DeckDataWrapper(playerdata->collection);
    pricelist = NEW PriceList("settings/prices.dat", ac);
    for (int i = 0; i < SHOP_SLOTS; i++)
    {
        WGuiCardDistort * dist;
        if (i < BOOSTER_SLOTS)
            dist = NEW WGuiCardDistort(NULL, true);
        else
        {
            dist = NEW WGuiCardDistort(srcCards, true);
            dist->mOffset.setOffset(i - BOOSTER_SLOTS);
        }
        dist->xy = WDistort(_x1[i], _y1[i], _x2[i], _y2[i], _x3[i], _y3[i], _x4[i], _y4[i]);
        shopMenu->Add(NEW WGuiButton(dist, -102, i, this));
    }
    shopMenu->Entering(JGE_BTN_NONE);

    if (!bigDisplay)
    {
        bigDisplay = NEW WGuiCardImage(srcCards);
        bigDisplay->mOffset.Hook(&bigSync);
        bigDisplay->mOffset.setOffset(-BOOSTER_SLOTS);
        bigDisplay->setX(385);
        bigDisplay->setY(135);
    }

    for (int i = 0; i < 8; ++i)
    {
        std::ostringstream stream;
        stream << "iconspsp" << i;
        pspIcons[i] = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float) i * 32, 0, 32, 32, stream.str(), RETRIEVE_MANAGE);
        pspIcons[i]->SetHotSpot(16, 16);
    }

    JRenderer::GetInstance()->EnableVSync(true);

    taskList = NULL;
    packlist = NEW MTGPacks();
    packlist->loadAll();
    load();
}
Example #2
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;
}
Example #3
0
void StatsWrapper::updateStats(string filename, MTGAllCards *collection)
{
    if (FileExists(filename))
    {
        MTGDeck * mtgd = NEW MTGDeck(filename.c_str(), collection);
        DeckDataWrapper *deckDataWrapper = NEW DeckDataWrapper(mtgd);
        updateStats(deckDataWrapper);
        SAFE_DELETE( mtgd );
        SAFE_DELETE( deckDataWrapper );
    }

}
Example #4
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();
}
Example #5
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;
}