예제 #1
0
파일: Counters.cpp 프로젝트: Esplin/wagic
int Counters::addCounter(const char * _name, int _power, int _toughness)
{
    /*420.5n If a permanent has both a +1/+1 counter and a -1/-1 counter on it, N +1/+1 and N -1/-1 counters are removed from it, where N is the smaller of the number of +1/+1 and -1/-1 counters on it.*/
    GameObserver *g = target->getObserver();
    WEvent * e = NEW WEventCounters(this,_name,_power,_toughness);
    dynamic_cast<WEventCounters*>(e)->targetCard = this->target;
    if (e == g->replacementEffects->replace(e))
    {
        for (int i = 0; i < mCount; i++)
        {
            if (counters[i]->sameAs(_name, _power, _toughness))
            {
                counters[i]->added();
                counters[i]->nb++;
                WEvent * j = NEW WEventCounters(this,_name,_power,_toughness,true,false);
                dynamic_cast<WEventCounters*>(j)->targetCard = this->target;
                g->receiveEvent(j);
                delete(e);
                return mCount;
            }
        }
        Counter * counter = NEW Counter(target, _name, _power, _toughness);
        counters.push_back(counter);
        counter->added();
        WEvent * w = NEW WEventCounters(this,_name,_power,_toughness,true,false);
        dynamic_cast<WEventCounters*>(w)->targetCard = this->target;
        g->receiveEvent(w);
        mCount++;
        this->target->doDamageTest = 1;
        this->target->afterDamage();
    }
    delete(e);
    return mCount;
}