Search in sources :

Example 56 with ZoneChangeEvent

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

the class NimDeathmantleEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    Permanent permanent = zEvent.getTarget();
    if (permanent != null && permanent.isOwnedBy(this.controllerId) && zEvent.isDiesEvent() && !(permanent instanceof PermanentToken) && permanent.isCreature(game)) {
        getEffects().get(0).setTargetPointer(new FixedTarget(permanent.getId(), permanent.getZoneChangeCounter(game) + 1));
        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)

Example 57 with ZoneChangeEvent

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

the class RayamiFirstOfTheFallenReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent permanent = ((ZoneChangeEvent) event).getTarget();
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || permanent == null) {
        return false;
    }
    controller.moveCards(permanent, Zone.EXILED, source, game);
    Card card = game.getCard(permanent.getId());
    card.addCounters(CounterType.BLOOD.createInstance(), source.getControllerId(), source, game);
    return true;
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) Card(mage.cards.Card)

Example 58 with ZoneChangeEvent

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

the class VoltaicVisionaryWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.ZONE_CHANGE || ((ZoneChangeEvent) event).getToZone() != Zone.EXILED) {
        return;
    }
    Card card = game.getCard(event.getTargetId());
    UUID exileId = game.getExile().getExileZones().stream().filter(exileZone -> exileZone.contains(card)).map(ExileZone::getId).findFirst().orElse(null);
    if (exileId == null) {
        return;
    }
    map.computeIfAbsent(exileId, x -> new HashSet<>()).add(new MageObjectReference(card, game));
}
Also used : java.util(java.util) Zone(mage.constants.Zone) MageObjectReference(mage.MageObjectReference) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) SubType(mage.constants.SubType) TransformSourceEffect(mage.abilities.effects.common.TransformSourceEffect) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) Watcher(mage.watchers.Watcher) TapSourceCost(mage.abilities.costs.common.TapSourceCost) ExileZone(mage.game.ExileZone) GameEvent(mage.game.events.GameEvent) ExileTopXMayPlayUntilEndOfTurnEffect(mage.abilities.effects.common.ExileTopXMayPlayUntilEndOfTurnEffect) TransformAbility(mage.abilities.keyword.TransformAbility) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) CardImpl(mage.cards.CardImpl) ActivateAsSorceryActivatedAbility(mage.abilities.common.ActivateAsSorceryActivatedAbility) CardType(mage.constants.CardType) WatcherScope(mage.constants.WatcherScope) Card(mage.cards.Card) DamageControllerEffect(mage.abilities.effects.common.DamageControllerEffect) Ability(mage.abilities.Ability) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) ExileZone(mage.game.ExileZone) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Example 59 with ZoneChangeEvent

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

the class DiesAttachedTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!((ZoneChangeEvent) event).isDiesEvent()) {
        return false;
    }
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    boolean triggered = false;
    if (zEvent.getTarget() != null && zEvent.getTarget().getAttachments() != null && zEvent.getTarget().getAttachments().contains(this.getSourceId())) {
        triggered = true;
    } else {
        // If the attachment and attachedTo went to graveyard at the same time, the trigger applies.
        // If the attachment is removed beforehand, the trigger fails.
        // IE: A player cast Planar Clensing.  The attachment is Disenchanted in reponse
        // and successfully removed from the attachedTo.  The trigger fails.
        Permanent attachment = getSourcePermanentOrLKI(game);
        Card attachmentCard = game.getCard(getSourceId());
        if (attachment != null && zEvent.getTargetId() != null && attachment.getAttachedTo() != null && zEvent.getTargetId().equals(attachment.getAttachedTo())) {
            Permanent attachedTo = game.getPermanentOrLKIBattlefield(attachment.getAttachedTo());
            if (attachedTo != null && // Demonic Vigor
            game.getState().getZone(attachedTo.getId()) == (Zone.GRAVEYARD) && attachmentCard != null && attachment.getAttachedToZoneChangeCounter() == attachedTo.getZoneChangeCounter(game) && attachment.getZoneChangeCounter(game) == attachmentCard.getZoneChangeCounter(game)) {
                triggered = true;
            }
        }
    }
    if (!triggered) {
        return false;
    }
    if (zEvent.getTarget() == null) {
        return true;
    }
    getEffects().setValue("attachedTo", zEvent.getTarget());
    // zone change info from battlefield
    getEffects().setValue("zcc", zEvent.getTarget().getZoneChangeCounter(game) + 1);
    if (setTargetPointer == SetTargetPointer.ATTACHED_TO_CONTROLLER) {
        Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
        if (attachment != null && attachment.getAttachedTo() != null) {
            Permanent attachedTo = (Permanent) game.getLastKnownInformation(attachment.getAttachedTo(), Zone.BATTLEFIELD, attachment.getAttachedToZoneChangeCounter());
            if (attachedTo != null) {
                getEffects().setTargetPointer(new FixedTarget(attachedTo.getControllerId()));
            }
        }
    }
    // set targetpointer to the creature that died
    if (setTargetPointer == SetTargetPointer.CARD || setTargetPointer == SetTargetPointer.PERMANENT) {
        Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
        if (attachment != null && attachment.getAttachedTo() != null) {
            Permanent attachedTo = (Permanent) game.getLastKnownInformation(attachment.getAttachedTo(), Zone.BATTLEFIELD, attachment.getAttachedToZoneChangeCounter());
            if (attachedTo != null) {
                getEffects().setTargetPointer(new FixedTarget(attachedTo.getId()));
            }
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent) Card(mage.cards.Card)

Example 60 with ZoneChangeEvent

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

the class GodEternalEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (zEvent.getTargetId().equals(this.getSourceId())) {
        this.getEffects().clear();
        this.addEffect(new GodEternalEffect(new MageObjectReference(zEvent.getTarget(), game)));
        return true;
    }
    return false;
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) MageObjectReference(mage.MageObjectReference)

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