Пример #1
0
int Player::gainOrLoseLife(int value)
{
    if (!value)
        return 0; //Don't do anything if there's no actual life change
    if (value>0 && (opponent()->game->battlefield->hasAbility(Constants::NOLIFEGAINOPPONENT)||game->battlefield->hasAbility(Constants::NOLIFEGAIN)))//nolifegain
        return 0;

    thatmuch = abs(value); //the value that much is a variable to be used with triggered abilities.
    //ie:when ever you gain life, draw that many cards. when used in a trigger draw:thatmuch, will return the value
    //that the triggered event stored in the card for "that much".
    if (!inPlay()->hasAbility(Constants::CANTCHANGELIFE))
        life+=value;
    if (value<0)
        lifeLostThisTurn += abs(value);
    else if (value > 0)
    {
        lifeGainedThisTurn += abs(value);
    }

    //Send life event to listeners
    WEvent * lifed = NEW WEventLife(this,value);
    observer->receiveEvent(lifed);

    return value;
}
Пример #2
0
int Damage::resolve()
{
    if (damage < 0)
        damage = 0; //Negative damages cannot happen
    state = RESOLVED_OK;
    WEvent * e = NEW WEventDamage(this);
    //Replacement Effects
    e = observer->replacementEffects->replace(e);
    if (!e)
        return 0;
    WEventDamage * ev = dynamic_cast<WEventDamage*> (e);
    if (!ev)
    {
        observer->receiveEvent(e);
        return 0;
    }
    damage = ev->damage->damage;
    target = ev->damage->target;
    if (!damage)
    {
        delete (e);
        return 0;
    }

    //asorbing effects for cards controller-----------

    //reserved for culmulitive absorb ability coding

    //prevent next damage-----------------------------
    if (target->preventable > 0)
    {
        int preventing = MIN(target->preventable, damage);
        damage -= preventing;
        target->preventable -= preventing;
    }
    else
    {
        target->preventable = 0;
    }

    //-------------------------------------------------
    //Ajani Steadfast ---
    if(target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE && ((MTGCardInstance*)target)->hasType("planeswalker") && ((MTGCardInstance*)target)->controller()->forcefield)
        damage = 1;
    if (target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE)
    {
        MTGCardInstance * _target = (MTGCardInstance *) target;
        if ((_target)->protectedAgainst(source))
            damage = 0;
        //rulings = 10/4/2004    The damage prevention ability works even if it has no counters, as long as some effect keeps its toughness above zero.
        //these creature are essentially immune to damage. however 0/-1 effects applied through lords or counters can kill them.
        if ((_target)->has(Constants::PROTECTIONFROMCOLOREDSPELLS))
        {//damage is prevented as long as the damage source is a spell on the stack...
            if((source->currentZone == source->controller()->opponent()->game->stack||source->currentZone == source->controller()->game->stack) && (source->hasColor(1)||source->hasColor(2)||source->hasColor(3)||source->hasColor(4)||source->hasColor(5)))
                damage = 0;
        }
        if ((_target)->has(Constants::PHANTOM))
        {
            damage = 0;
            (_target)->counters->removeCounter(1, 1);
        }
        if ((_target)->has(Constants::ABSORB))
        {
            damage -=  (_target)->basicAbilities[(int)Constants::ABSORB];
            if(damage < 0)
                damage = 0;
        }
        if ((_target)->has(Constants::WILTING))
        {
            for (int j = damage; j > 0; j--)
            {
                (_target)->counters->addCounter(-1, -1);
            }
            damage = 0;
        }
        if ((_target)->has(Constants::VIGOR))
        {
            for (int j = damage; j > 0; j--)
            {
                (_target)->counters->addCounter(1, 1);
            }
            damage = 0;
        }
        if ((_target)->has(Constants::HYDRA))
        {
            for (int j = damage; j > 0; j--)
            {
                (_target)->counters->removeCounter(1, 1);
            }
            damage = 0;
        }
        if (!damage)
        {
            state = RESOLVED_NOK;
            delete (e);
            return 0;
        }
        _target->doDamageTest = 1;
    }
    if (target->type_as_damageable == Damageable::DAMAGEABLE_PLAYER)
    {//Ajani Steadfast
        if(((Player*)target)->forcefield)
            damage = 1;
        if(source->has(Constants::LIBRARYEATER) && typeOfDamage == 1)
        {
            for (int j = damage; j > 0; j--)
            {
                if(((Player*)target)->game->library->nb_cards)
                    ((Player*)target)->game->putInZone(((Player*)target)->game->library->cards[((Player*)target)->game->library->nb_cards - 1], ((Player*)target)->game->library, ((Player*)target)->game->graveyard);
            }
            damage = 0;
        }
        if(source->alias == 89092 && typeOfDamage == 1)//Szadek Lord of Secrets
        {
            for (int j = damage; j > 0; j--)
            {
                if(((Player*)target)->game->library->nb_cards)
                    ((Player*)target)->game->putInZone(((Player*)target)->game->library->cards[((Player*)target)->game->library->nb_cards - 1], ((Player*)target)->game->library, ((Player*)target)->game->graveyard);

                source->counters->addCounter(1, 1);
            }
            damage = 0;
        }
        if (!damage)
        {
            state = RESOLVED_NOK;
            delete (e);
            return 0;
        }
    }
    int a = damage;

    if (target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE && (source->has(Constants::WITHER) || source->has(
                    Constants::INFECT)))
    {
        // Damage for WITHER or poison on creatures. This should probably go in replacement effects
        MTGCardInstance * _target = (MTGCardInstance *) target;
        for (int i = 0; i < damage; i++)
        {
            _target->counters->addCounter(-1, -1);
        }
        if(_target->toughness <= 0 && _target->has(Constants::INDESTRUCTIBLE))
            _target->controller()->game->putInGraveyard(_target);
    }
    else if (target->type_as_damageable == Damageable::DAMAGEABLE_PLAYER && (source->has(Constants::INFECT)||source->has(Constants::POISONDAMAGER)))
    {
        // Poison on player
        Player * _target = (Player *) target;
        if(!_target->inPlay()->hasAbility(Constants::POISONSHROUD))
            _target->poisonCount += damage;//this will be changed to poison counters.
        _target->damageCount += damage;
        if ( typeOfDamage == 1 && target == source->controller()->opponent() )//add vector prowledtypes.
        {
            vector<string> values = MTGAllCards::getCreatureValuesById();
            for (size_t i = 0; i < values.size(); ++i)
            {
                if ( source->hasSubtype( values[i] ) && find(source->controller()->prowledTypes.begin(), source->controller()->prowledTypes.end(), values[i])==source->controller()->prowledTypes.end() )
                    source->controller()->prowledTypes.push_back(values[i]);
            }
        }
    }
    else if (target->type_as_damageable == Damageable::DAMAGEABLE_PLAYER && (source->has(Constants::POISONTOXIC) ||
                    source->has(Constants::POISONTWOTOXIC) || source->has(Constants::POISONTHREETOXIC)))
    {
        //Damage + 1, 2, or 3 poison counters on player
        Player * _target = (Player *) target;
        if(!_target->inPlay()->hasAbility(Constants::CANTCHANGELIFE))
            a = target->dealDamage(damage);
        target->damageCount += damage;
        if ( typeOfDamage == 1 && target == source->controller()->opponent() )//add vector prowledtypes.
        {
            vector<string> values = MTGAllCards::getCreatureValuesById();
            for (size_t i = 0; i < values.size(); ++i)
            {
                if ( source->hasSubtype( values[i] ) && find(source->controller()->prowledTypes.begin(), source->controller()->prowledTypes.end(), values[i])==source->controller()->prowledTypes.end() )
                    source->controller()->prowledTypes.push_back(values[i]);
            }
        }
        if(!_target->inPlay()->hasAbility(Constants::POISONSHROUD))
        {
            if (source->has(Constants::POISONTOXIC))
            {
                _target->poisonCount += 1;
            }
            else if (source->has(Constants::POISONTWOTOXIC))
            {
                _target->poisonCount += 2;
            }
            else
            {
                _target->poisonCount += 3;
            }
        }

    }
    else
    {
        // "Normal" case,
        //return the left over amount after effects have been applied to them.
        if (target->type_as_damageable == Damageable::DAMAGEABLE_PLAYER && ((Player *)target)->inPlay()->hasAbility(Constants::CANTCHANGELIFE))
            ;//do nothing
        else
            a = target->dealDamage(damage);
        target->damageCount += damage;//the amount must be the actual damage so i changed this from 1 to damage, this fixes pdcount and odcount
        if (target->type_as_damageable == Damageable::DAMAGEABLE_MTGCARDINSTANCE){
            ((MTGCardInstance*)target)->wasDealtDamage = true;
            ((MTGCardInstance*)source)->damageToCreature = true;
        }
        if (target->type_as_damageable == Damageable::DAMAGEABLE_PLAYER)
        {
            if(target == source->controller())
            {
                ((MTGCardInstance*)source)->damageToController = true;
            }
            else
            {
                ((MTGCardInstance*)source)->damageToOpponent = true;
            }
            target->lifeLostThisTurn += damage;
            if ( typeOfDamage == 1 && target == source->controller()->opponent() )//add vector prowledtypes.
            {
                vector<string> values = MTGAllCards::getCreatureValuesById();//getting a weird crash here. rarely.
                for (size_t i = 0; i < values.size(); ++i)
                {
                    if ( source->hasSubtype( values[i] ) && find(source->controller()->prowledTypes.begin(), source->controller()->prowledTypes.end(), values[i])==source->controller()->prowledTypes.end() )
                        source->controller()->prowledTypes.push_back(values[i]);
                }
            }
            WEvent * lifed = NEW WEventLife((Player*)target,-damage);
            observer->receiveEvent(lifed);
        }
    }

    //Send (Damage/Replaced effect) event to listeners
    observer->receiveEvent(e);
    return a;
}