Search in sources :

Example 41 with EntersTheBattlefieldEvent

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

the class BreathlessKnightTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event instanceof EntersTheBattlefieldEvent) {
        EntersTheBattlefieldEvent entersEvent = (EntersTheBattlefieldEvent) event;
        Permanent permanent = entersEvent.getTarget();
        if (permanent != null && permanent.isCreature(game) && permanent.isControlledBy(this.getControllerId())) {
            if (entersEvent.getFromZone() == Zone.GRAVEYARD) {
                return true;
            }
            CastFromGraveyardWatcher watcher = game.getState().getWatcher(CastFromGraveyardWatcher.class);
            int zcc = game.getState().getZoneChangeCounter(entersEvent.getSourceId());
            return watcher != null && watcher.spellWasCastFromGraveyard(entersEvent.getSourceId(), zcc - 1);
        }
    }
    return false;
}
Also used : EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) Permanent(mage.game.permanent.Permanent) CastFromGraveyardWatcher(mage.watchers.common.CastFromGraveyardWatcher)

Example 42 with EntersTheBattlefieldEvent

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

the class AncientGreenwardenEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (!(event instanceof NumberOfTriggersEvent)) {
        return false;
    }
    NumberOfTriggersEvent numberOfTriggersEvent = (NumberOfTriggersEvent) event;
    if (!source.isControlledBy(event.getPlayerId())) {
        return false;
    }
    GameEvent sourceEvent = numberOfTriggersEvent.getSourceEvent();
    if (sourceEvent == null || sourceEvent.getType() != GameEvent.EventType.ENTERS_THE_BATTLEFIELD || !(sourceEvent instanceof EntersTheBattlefieldEvent) || !((EntersTheBattlefieldEvent) sourceEvent).getTarget().isLand(game)) {
        return false;
    }
    return game.getPermanent(numberOfTriggersEvent.getSourceId()) != null;
}
Also used : NumberOfTriggersEvent(mage.game.events.NumberOfTriggersEvent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) GameEvent(mage.game.events.GameEvent)

Example 43 with EntersTheBattlefieldEvent

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

the class BloodsporeThrinaxEntersBattlefieldEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent sourceCreature = game.getPermanent(source.getSourceId());
    Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
    if (sourceCreature != null && creature != null) {
        int amount = sourceCreature.getCounters(game).getCount(CounterType.P1P1);
        if (amount > 0) {
            creature.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game);
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent)

Aggregations

EntersTheBattlefieldEvent (mage.game.events.EntersTheBattlefieldEvent)43 Permanent (mage.game.permanent.Permanent)36 Player (mage.players.Player)8 FixedTarget (mage.target.targetpointer.FixedTarget)6 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)5 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)5 ContinuousEffect (mage.abilities.effects.ContinuousEffect)4 FilterPermanent (mage.filter.FilterPermanent)4 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)4 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)4 UUID (java.util.UUID)3 Effect (mage.abilities.effects.Effect)3 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)3 Target (mage.target.Target)3 MageObject (mage.MageObject)2 MageObjectReference (mage.MageObjectReference)2 LoseLifeTargetEffect (mage.abilities.effects.common.LoseLifeTargetEffect)2 SetPowerToughnessSourceEffect (mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect)2 Card (mage.cards.Card)2 GameEvent (mage.game.events.GameEvent)2