Search in sources :

Example 1 with FilterInPlay

use of mage.filter.FilterInPlay in project mage by magefree.

the class PreventAllDamageByAllObjectsEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (!super.applies(event, source, game) || !(event instanceof DamageEvent) || event.getAmount() <= 0) {
        return false;
    }
    DamageEvent damageEvent = (DamageEvent) event;
    if (!damageEvent.isCombatDamage() && onlyCombat) {
        return false;
    }
    if (filter == null) {
        return true;
    }
    MageObject damageSource = game.getObject(damageEvent.getSourceId());
    if (damageSource == null) {
        return false;
    }
    if (filter instanceof FilterInPlay) {
        return ((FilterInPlay) filter).match(damageSource, source.getSourceId(), source.getControllerId(), game);
    }
    return filter.match(damageSource, game);
}
Also used : FilterInPlay(mage.filter.FilterInPlay) MageObject(mage.MageObject) DamageEvent(mage.game.events.DamageEvent)

Aggregations

MageObject (mage.MageObject)1 FilterInPlay (mage.filter.FilterInPlay)1 DamageEvent (mage.game.events.DamageEvent)1