Search in sources :

Example 1 with DamagedEvent

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

the class FiendlashEffect 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;
    }
    game.getState().setValue("Fiendlash" + equipment.getId(), attachedCreature);
    DamagedPermanentBatchEvent dEvent = (DamagedPermanentBatchEvent) event;
    for (DamagedEvent damagedEvent : dEvent.getEvents()) {
        UUID targetID = damagedEvent.getTargetId();
        if (targetID == null) {
            continue;
        }
        if (targetID == attachedCreature) {
            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 2 with DamagedEvent

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

the class GlyphOfLifeGainLifeEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getTargetId().equals(this.getFirstTarget())) {
        DamagedEvent damageEvent = (DamagedEvent) event;
        Permanent attackingCreature = game.getPermanentOrLKIBattlefield(damageEvent.getSourceId());
        if (attackingCreature != null && attackingCreature.isCreature(game) && attackingCreature.isAttacking()) {
            this.getEffects().get(0).setValue("damageAmount", event.getAmount());
            return true;
        }
    }
    return false;
}
Also used : DamagedEvent(mage.game.events.DamagedEvent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent)

Example 3 with DamagedEvent

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

the class ZarethSanTheTricksterTriggeredAbility 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;
    }
    FilterCard filter = new FilterPermanentCard("permanent card in " + opponent.getLogName() + "'s graveyard");
    filter.add(new OwnerIdPredicate(opponent.getId()));
    this.getTargets().clear();
    this.addTarget(new TargetCardInGraveyard(filter));
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) DamagedEvent(mage.game.events.DamagedEvent)

Example 4 with DamagedEvent

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

the class CombatDamageToCreatureWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.DAMAGED_PERMANENT || !((DamagedEvent) event).isCombatDamage()) {
        return;
    }
    Permanent permanent = game.getPermanent(event.getTargetId());
    if (permanent == null || !permanent.isCreature(game)) {
        return;
    }
    MageObjectReference damageSource = new MageObjectReference(event.getSourceId(), game);
    dealtCombatDamageToCreature.add(damageSource);
}
Also used : DamagedEvent(mage.game.events.DamagedEvent) Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference)

Example 5 with DamagedEvent

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

the class DealsCombatDamageToAPlayerTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getSourceId().equals(getSourceId()) || !((DamagedEvent) event).isCombatDamage()) {
        return false;
    }
    switch(event.getType()) {
        case DAMAGED_PLAYER:
            if (onlyOpponents && !game.getOpponents(getControllerId()).contains(event.getTargetId())) {
                return false;
            }
            break;
        case DAMAGED_PERMANENT:
            Permanent permanent = game.getPermanent(event.getTargetId());
            if (permanent == null || !permanent.isPlaneswalker(game) || !orPlaneswalker) {
                return false;
            }
    }
    if (setTargetPointer) {
        getAllEffects().setTargetPointer(new FixedTarget(event.getPlayerId()));
        getAllEffects().setValue("damage", event.getAmount());
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) DamagedEvent(mage.game.events.DamagedEvent) 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