Exemplo n.º 1
0
MTGPlayerCards::MTGPlayerCards(Player* player, int * idList, int idListSize)
    : owner(player)
{
    init();
    int i;

    for (i = 0; i < idListSize; i++)
    {
        MTGCard * card = MTGCollection()->getCardById(idList[i]);
        if (card)
        {
            MTGCardInstance * newCard = NEW MTGCardInstance(card, this);
            library->addCard(newCard);
        }
    }
}
Exemplo n.º 2
0
void MTGPlayerCards::initDeck(MTGDeck * deck)
{
    resetLibrary();
    map<int, int>::iterator it;
    for (it = deck->cards.begin(); it != deck->cards.end(); it++)
    {
        MTGCard * card = deck->getCardById(it->first);
        if (card)
        {
            for (int i = 0; i < it->second; i++)
            {
                MTGCardInstance * newCard = NEW MTGCardInstance(card, this);
                library->addCard(newCard);
            }
        }
    }
}
Exemplo n.º 3
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();
}
Exemplo n.º 4
0
bool MTGGameZone::parseLine(const string& ss)
{
    bool result = false;
    string s = ss;

    for (int i = 0; i < nb_cards; i++)
    {
        SAFE_DELETE( cards[i] );
    }
    cards.clear();
    cardsMap.clear();
    nb_cards = 0;

    while(s.size())
    {
        size_t limiter = s.find(",");
        MTGCard * card = 0;
        string toFind;
        if (limiter != string::npos)
        {
            toFind = trim(s.substr(0, limiter));
            s = s.substr(limiter + 1);
        }
        else
        {
            toFind = trim(s);
            s = "";
        }

        card = MTGCollection()->getCardByName(toFind);
        int id = Rules::getMTGId(toFind);

        if (card)
        {
            /* For the moment we add the card directly in the final zone.
                This is not the normal way and this prevents to resolve spells.
                We'll need a fusion operation afterward to cast relevant spells */
            MTGCardInstance * newCard = NEW MTGCardInstance(card, owner->game);
            addCard(newCard);
            result = true;
        }
        else
        {
            if(toFind == "*")
                nb_cards++;
            else if ( id < 0 )
            {
                // For the moment, we create a dummy Token to please the testsuite
                Token* myToken = new Token(id);
                addCard(myToken);
                result = true;
            }
            else
            {
                DebugTrace("Card unfound " << toFind << " " << id);
            }
        }
    }

    return result;
}