Search in sources :

Example 11 with ZoneChangeEvent

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

the class HauntEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    switch(event.getType()) {
        case ENTERS_THE_BATTLEFIELD:
            return game.getState().getZone(getSourceId()) == Zone.BATTLEFIELD && event.getTargetId().equals(getSourceId());
        case ZONE_CHANGE:
            if (usedFromExile || game.getState().getZone(getSourceId()) != Zone.EXILED) {
                return false;
            }
            ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
            if (!zEvent.isDiesEvent()) {
                return false;
            }
            Card card = game.getCard(getSourceId());
            if (card == null || game.getCard(event.getTargetId()) == null) {
                return false;
            }
            String key = new StringBuilder("Haunting_").append(getSourceId().toString()).append(card.getZoneChangeCounter(game) + (game.getPermanentOrLKIBattlefield(event.getTargetId())).getZoneChangeCounter(game)).toString();
            Object object = game.getState().getValue(key);
            if (!(object instanceof FixedTarget)) {
                return false;
            }
            FixedTarget target = (FixedTarget) object;
            if (target.getTarget() != null && target.getTarget().equals(event.getTargetId())) {
                usedFromExile = true;
                return true;
            }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) MageObject(mage.MageObject) Card(mage.cards.Card)

Example 12 with ZoneChangeEvent

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

the class ColfenorTheLastYewTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!super.checkTrigger(event, game)) {
        return false;
    }
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    Permanent permanent = zEvent.getTarget();
    if (permanent == null) {
        return false;
    }
    FilterCard filterCard = new FilterCreatureCard("creature card with toughness less than " + permanent.getToughness().getValue());
    filterCard.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, permanent.getToughness().getValue()));
    filterCard.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(permanent, game))));
    this.getTargets().clear();
    this.addTarget(new TargetCardInYourGraveyard(0, 1, filterCard));
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) MageObjectReference(mage.MageObjectReference)

Example 13 with ZoneChangeEvent

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

the class DarigaazReincarnatedReturnEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent permanent = ((ZoneChangeEvent) event).getTarget();
    Player controller = game.getPlayer(source.getControllerId());
    if (permanent == null || controller == null) {
        return false;
    }
    return CardUtil.moveCardWithCounter(game, source, controller, permanent, Zone.EXILED, CounterType.EGG.createInstance(3));
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent)

Example 14 with ZoneChangeEvent

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

the class ErebossTitanTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (zEvent.getFromZone() == Zone.GRAVEYARD) {
        Card card = game.getCard(zEvent.getTargetId());
        Player controller = game.getPlayer(getControllerId());
        return card != null && card.isCreature(game) && controller != null && controller.hasOpponent(card.getOwnerId(), game);
    }
    return false;
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Player(mage.players.Player) Card(mage.cards.Card)

Example 15 with ZoneChangeEvent

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

the class GisaGloriousResurrectorReturnEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (zEvent.getTarget() instanceof PermanentToken) {
        return player.moveCards(zEvent.getTarget(), Zone.EXILED, source, game);
    }
    game.getState().setValue("GisaGloriousResurrectorExile" + source.getSourceId().toString() + game.getState().getZoneChangeCounter(source.getSourceId()), source);
    return player.moveCardsToExile(zEvent.getTarget(), source, game, false, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Player(mage.players.Player) PermanentToken(mage.game.permanent.PermanentToken)

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