Search in sources :

Example 16 with ZoneChangeEvent

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

the class LuminousBroodmothEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (zEvent.getTarget() == null || zEvent.getTarget().getId().equals(this.getSourceId())) {
        return false;
    }
    Permanent permanent = game.getPermanentOrLKIBattlefield(zEvent.getTarget().getId());
    if (permanent != null && zEvent.isDiesEvent() && permanent.isCreature(game) && !permanent.getAbilities().containsKey(FlyingAbility.getInstance().getId()) && permanent.isControlledBy(this.controllerId)) {
        this.getEffects().setTargetPointer(new FixedTarget(zEvent.getTargetId()));
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent)

Example 17 with ZoneChangeEvent

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

the class ShrivelingRotEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (zEvent.isDiesEvent()) {
        if (zEvent.getTarget().isCreature(game)) {
            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) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect)

Example 18 with ZoneChangeEvent

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

the class WookieeMysticWatcher 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())) {
            Permanent creature = game.getPermanent(event.getSourceId());
            creature.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
            creatures.remove(event.getSourceId());
        }
    }
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) Spell(mage.game.stack.Spell)

Example 19 with ZoneChangeEvent

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

the class LeavesBattlefieldAllTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (zEvent.getFromZone() == Zone.BATTLEFIELD) {
        UUID targetId = event.getTargetId();
        Permanent permanent = game.getPermanentOrLKIBattlefield(targetId);
        if (filter.match(permanent, getSourceId(), getControllerId(), game)) {
            if (setTargetPointer != SetTargetPointer.NONE) {
                for (Effect effect : this.getEffects()) {
                    switch(setTargetPointer) {
                        case PERMANENT:
                            effect.setTargetPointer(new FixedTarget(permanent, game));
                            break;
                        case PLAYER:
                            effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));
                            break;
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID)

Example 20 with ZoneChangeEvent

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

the class DiesSourceTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (!zEvent.isDiesEvent() || !event.getTargetId().equals(getSourceId())) {
        return false;
    }
    getEffects().setValue("permanentLeftBattlefield", zEvent.getTarget());
    return true;
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent)

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