Search in sources :

Example 26 with DamagedEvent

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

the class PiousWarriorGainLifeEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent permanent = game.getPermanent(event.getTargetId());
    if (permanent == null || !permanent.isCreature(game) || !event.getTargetId().equals(this.sourceId) || !((DamagedEvent) event).isCombatDamage()) {
        return false;
    }
    this.getEffects().setValue("damageAmount", event.getAmount());
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) DamagedEvent(mage.game.events.DamagedEvent)

Example 27 with DamagedEvent

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

the class BlazingSunsteelEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent equipment = game.getPermanent(this.getSourceId());
    if (equipment == null) {
        return false;
    }
    UUID attachedCreature = equipment.getAttachedTo();
    if (attachedCreature == null) {
        return false;
    }
    int damage = 0;
    DamagedPermanentBatchEvent dEvent = (DamagedPermanentBatchEvent) event;
    for (DamagedEvent damagedEvent : dEvent.getEvents()) {
        UUID targetID = damagedEvent.getTargetId();
        if (targetID == null) {
            continue;
        }
        if (targetID == attachedCreature) {
            damage += damagedEvent.getAmount();
        }
    }
    if (damage > 0) {
        this.getEffects().setValue("equipped", attachedCreature);
        this.getEffects().setValue("damage", damage);
        return true;
    }
    return false;
}
Also used : DamagedPermanentBatchEvent(mage.game.events.DamagedPermanentBatchEvent) Permanent(mage.game.permanent.Permanent) DamagedEvent(mage.game.events.DamagedEvent) UUID(java.util.UUID)

Example 28 with DamagedEvent

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

the class ArashinWarBeastTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.DAMAGED_PERMANENT && event.getSourceId().equals(this.sourceId) && ((DamagedEvent) event).isCombatDamage() && !usedForCombatDamageStep) {
        Permanent creature = game.getPermanentOrLKIBattlefield(event.getTargetId());
        if (creature == null || !filter.match(creature, getSourceId(), getControllerId(), game)) {
            return false;
        }
        // trigger only once per combat damage step
        usedForCombatDamageStep = true;
        return true;
    }
    if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST) {
        usedForCombatDamageStep = false;
    }
    return false;
}
Also used : DamagedEvent(mage.game.events.DamagedEvent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent)

Example 29 with DamagedEvent

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

the class BreechesBrazenPlundererEffect method checkTrigger.

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

Example 30 with DamagedEvent

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

the class AegarTheFreezingFlameWatcher method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedEvent dEvent = (DamagedEvent) event;
    if (dEvent.getExcess() < 1 || !game.getOpponents(getControllerId()).contains(game.getControllerId(event.getTargetId()))) {
        return false;
    }
    AegarTheFreezingFlameWatcher watcher = game.getState().getWatcher(AegarTheFreezingFlameWatcher.class);
    return watcher != null && watcher.checkDamage(getControllerId(), event.getTargetId(), game);
}
Also used : DamagedEvent(mage.game.events.DamagedEvent)

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