Search in sources :

Example 26 with ZoneChangeEvent

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

the class UnscytheEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (((ZoneChangeEvent) event).isDiesEvent()) {
        ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
        if (zEvent.getTarget().isCreature(game)) {
            // target token can't create Zombie
            Permanent equipment = game.getPermanent(getSourceId());
            // the currently equiped creature must have done damage to the dying creature
            if (equipment != null && equipment.getAttachedTo() != null) {
                boolean damageDealt = false;
                for (MageObjectReference mor : zEvent.getTarget().getDealtDamageByThisTurn()) {
                    if (mor.refersTo(equipment.getAttachedTo(), game)) {
                        damageDealt = true;
                        break;
                    }
                }
                if (damageDealt) {
                    Effect effect = this.getEffects().get(0);
                    effect.setTargetPointer(new FixedTarget(event.getTargetId()));
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) BoostEquippedEffect(mage.abilities.effects.common.continuous.BoostEquippedEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) GainAbilityAttachedEffect(mage.abilities.effects.common.continuous.GainAbilityAttachedEffect) MageObjectReference(mage.MageObjectReference)

Example 27 with ZoneChangeEvent

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

the class UnquenchableFuryTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    Permanent permanent = zEvent.getTarget();
    return permanent != null && zEvent.isDiesEvent() && permanent.getId().equals(this.getSourceId()) && permanent.isOwnedBy(permanent.getControllerId());
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent)

Example 28 with ZoneChangeEvent

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

the class VoidMawCost method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
            Permanent permanent = ((ZoneChangeEvent) event).getTarget();
            if (permanent != null) {
                UUID exileZoneId = CardUtil.getCardExileZoneId(game, source);
                if (controller.moveCardsToExile(permanent, source, game, false, exileZoneId, sourceObject.getIdName())) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) UUID(java.util.UUID)

Example 29 with ZoneChangeEvent

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

the class HallOfTheBanditLordWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.MANA_PAID) {
        MageObject target = game.getObject(event.getTargetId());
        if (event.getSourceId() != null && event.getSourceId().equals(this.getSourceId()) && target != null && target.isCreature(game) && event.getFlag()) {
            if (target instanceof Spell) {
                this.creatures.add(((Spell) target).getCard().getId());
            }
        }
    }
    if (event.getType() == GameEvent.EventType.COUNTERED) {
        if (creatures.contains(event.getTargetId())) {
            creatures.remove(event.getSourceId());
        }
    }
    if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
        if (creatures.contains(event.getSourceId())) {
            ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
            // spell was e.g. exiled and goes again to stack, so previous cast has not resolved.
            if (zEvent.getToZone() == Zone.STACK) {
                creatures.remove(event.getSourceId());
            }
        }
    }
    if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
        if (creatures.contains(event.getSourceId())) {
            ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
            effect.setTargetPointer(new FixedTarget(event.getSourceId(), game));
            game.addEffect(effect, source);
            creatures.remove(event.getSourceId());
        }
    }
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) MageObject(mage.MageObject) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Spell(mage.game.stack.Spell)

Example 30 with ZoneChangeEvent

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

the class MimicVatCreateTokenEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    // make sure card is on battlefield
    UUID sourceCardId = getSourceId();
    if (game.getPermanent(sourceCardId) == null) {
        // or it is being removed
        if (game.getLastKnownInformation(sourceCardId, Zone.BATTLEFIELD) == null) {
            return false;
        }
    }
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    Permanent permanent = zEvent.getTarget();
    if (permanent != null && zEvent.isDiesEvent() && !(permanent instanceof PermanentToken) && permanent.isCreature(game)) {
        getEffects().get(0).setTargetPointer(new FixedTarget(permanent.getId(), game));
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) UUID(java.util.UUID)

Aggregations

ZoneChangeEvent (mage.game.events.ZoneChangeEvent)94 Permanent (mage.game.permanent.Permanent)56 Player (mage.players.Player)27 FixedTarget (mage.target.targetpointer.FixedTarget)23 Card (mage.cards.Card)20 UUID (java.util.UUID)14 MageObject (mage.MageObject)11 MageObjectReference (mage.MageObjectReference)10 Effect (mage.abilities.effects.Effect)9 FilterCard (mage.filter.FilterCard)8 PermanentToken (mage.game.permanent.PermanentToken)8 FilterPermanent (mage.filter.FilterPermanent)7 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)7 Ability (mage.abilities.Ability)6 OneShotEffect (mage.abilities.effects.OneShotEffect)6 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)6 Spell (mage.game.stack.Spell)6 Zone (mage.constants.Zone)5 TargetPermanent (mage.target.TargetPermanent)5 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)5