Search in sources :

Example 6 with DamagedEvent

use of mage.game.events.DamagedEvent in project mage by magefree.

the class DealsDamageToACreatureAllTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent permanent = game.getPermanent(event.getTargetId());
    if (permanent == null || !permanent.isCreature(game)) {
        return false;
    }
    if (combatDamageOnly && !((DamagedEvent) event).isCombatDamage()) {
        return false;
    }
    permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
    if (!filterPermanent.match(permanent, getSourceId(), getControllerId(), game)) {
        return false;
    }
    for (Effect effect : this.getEffects()) {
        effect.setValue("damage", event.getAmount());
        effect.setValue("sourceId", event.getSourceId());
        switch(setTargetPointer) {
            case PLAYER:
                effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));
                break;
            case PERMANENT:
                effect.setTargetPointer(new FixedTarget(permanent, game));
                break;
            case PERMANENT_TARGET:
                Permanent permanent_target = game.getPermanentOrLKIBattlefield(event.getTargetId());
                if (permanent_target != null) {
                    effect.setTargetPointer(new FixedTarget(permanent_target, game));
                }
                break;
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) DamagedEvent(mage.game.events.DamagedEvent) Effect(mage.abilities.effects.Effect)

Example 7 with DamagedEvent

use of mage.game.events.DamagedEvent in project mage by magefree.

the class HordewingSkaabTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedPlayerBatchEvent dEvent = (DamagedPlayerBatchEvent) event;
    Set<UUID> opponents = new HashSet<>();
    for (DamagedEvent damagedEvent : dEvent.getEvents()) {
        if (!damagedEvent.isCombatDamage()) {
            continue;
        }
        Permanent permanent = game.getPermanent(damagedEvent.getSourceId());
        if (permanent == null || !permanent.isControlledBy(getControllerId()) || !permanent.hasSubtype(SubType.ZOMBIE, game) || !game.getOpponents(getControllerId()).contains(damagedEvent.getTargetId())) {
            continue;
        }
        opponents.add(damagedEvent.getTargetId());
    }
    if (opponents.size() < 1) {
        return false;
    }
    this.getEffects().clear();
    this.addEffect(new DrawDiscardControllerEffect(opponents.size(), opponents.size()));
    return true;
}
Also used : DamagedPlayerBatchEvent(mage.game.events.DamagedPlayerBatchEvent) DamagedEvent(mage.game.events.DamagedEvent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) DrawDiscardControllerEffect(mage.abilities.effects.common.DrawDiscardControllerEffect) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 8 with DamagedEvent

use of mage.game.events.DamagedEvent in project mage by magefree.

the class ToralfsHammerEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedEvent dEvent = (DamagedEvent) event;
    if (dEvent.getExcess() < 1 || dEvent.isCombatDamage() || !game.getOpponents(getControllerId()).contains(game.getControllerId(event.getTargetId()))) {
        return false;
    }
    this.getEffects().clear();
    this.getTargets().clear();
    this.addEffect(new DamageTargetEffect(dEvent.getExcess()));
    FilterCreaturePlayerOrPlaneswalker filter = new FilterCreaturePlayerOrPlaneswalker();
    filter.getPermanentFilter().add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(event.getTargetId(), game))));
    this.addTarget(new TargetAnyTarget(filter));
    return true;
}
Also used : DamagedEvent(mage.game.events.DamagedEvent) FilterCreaturePlayerOrPlaneswalker(mage.filter.common.FilterCreaturePlayerOrPlaneswalker) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) MageObjectReference(mage.MageObjectReference) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Example 9 with DamagedEvent

use of mage.game.events.DamagedEvent in project mage by magefree.

the class BlindZealotTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Player opponent = game.getPlayer(event.getPlayerId());
    if (opponent == null || !event.getSourceId().equals(this.sourceId) || !((DamagedEvent) event).isCombatDamage()) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
    filter.add(new ControllerIdPredicate(opponent.getId()));
    this.getTargets().clear();
    this.addTarget(new TargetCreaturePermanent(filter));
    return true;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) DamagedEvent(mage.game.events.DamagedEvent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate)

Example 10 with DamagedEvent

use of mage.game.events.DamagedEvent in project mage by magefree.

the class CurseOfHospitalityEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedEvent dEvent = (DamagedEvent) event;
    Permanent permanent = getSourcePermanentIfItStillExists(game);
    if (!dEvent.isCombatDamage() || permanent == null || !dEvent.getPlayerId().equals(permanent.getAttachedTo())) {
        return false;
    }
    this.getEffects().setTargetPointer(new FixedTarget(game.getControllerId(dEvent.getSourceId())));
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) DamagedEvent(mage.game.events.DamagedEvent) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent)

Aggregations

DamagedEvent (mage.game.events.DamagedEvent)30 Permanent (mage.game.permanent.Permanent)16 FilterPermanent (mage.filter.FilterPermanent)6 Player (mage.players.Player)6 UUID (java.util.UUID)5 GainLifeEffect (mage.abilities.effects.common.GainLifeEffect)5 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)5 FixedTarget (mage.target.targetpointer.FixedTarget)5 HashSet (java.util.HashSet)3 MageObjectReference (mage.MageObjectReference)3 Effect (mage.abilities.effects.Effect)3 DrawCardSourceControllerEffect (mage.abilities.effects.common.DrawCardSourceControllerEffect)3 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)3 DamagedPlayerBatchEvent (mage.game.events.DamagedPlayerBatchEvent)3 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)2 FilterCard (mage.filter.FilterCard)2 DamagedPermanentBatchEvent (mage.game.events.DamagedPermanentBatchEvent)2 TargetPermanent (mage.target.TargetPermanent)2 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)2 java.util (java.util)1