Search in sources :

Example 26 with EntersTheBattlefieldEvent

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

the class MysticReflectionGainAbilityEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    MysticReflectionWatcher watcher = game.getState().getWatcher(MysticReflectionWatcher.class);
    if (watcher != null) {
        if (watcher.getEnteredThisTurn() > this.enteredThisTurn) {
            discard();
            return false;
        }
    }
    Permanent permanentEnteringTheBattlefield = ((EntersTheBattlefieldEvent) event).getTarget();
    Permanent targetedPermanent = (Permanent) game.getState().getValue("MysticReflection" + identifier);
    return permanentEnteringTheBattlefield != null && targetedPermanent != null && permanentEnteringTheBattlefield.isCreature(game);
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent)

Example 27 with EntersTheBattlefieldEvent

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

the class FblthpTheLostTargetedTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!super.checkTrigger(event, game)) {
        return false;
    }
    EntersTheBattlefieldEvent entersEvent = (EntersTheBattlefieldEvent) event;
    if (entersEvent.getFromZone() == Zone.LIBRARY) {
        this.getEffects().clear();
        this.addEffect(new DrawCardSourceControllerEffect(2));
        return true;
    }
    FblthpTheLostWatcher watcher = game.getState().getWatcher(FblthpTheLostWatcher.class);
    int zcc = entersEvent.getTarget().getZoneChangeCounter(game) - 1;
    MageObjectReference mor = new MageObjectReference(entersEvent.getTargetId(), zcc, game);
    if (watcher != null && watcher.spellWasCastFromLibrary(mor)) {
        this.getEffects().clear();
        this.addEffect(new DrawCardSourceControllerEffect(2));
        return true;
    }
    this.getEffects().clear();
    this.addEffect(new DrawCardSourceControllerEffect(1));
    return true;
}
Also used : EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) MageObjectReference(mage.MageObjectReference)

Example 28 with EntersTheBattlefieldEvent

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

the class GuardianProjectEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent permanent = ((EntersTheBattlefieldEvent) event).getTarget();
    if (!filter.match(permanent, sourceId, controllerId, game)) {
        return false;
    }
    if (checkCondition(permanent, controllerId, game)) {
        this.getEffects().clear();
        this.addEffect(new GuardianProjectEffect(new MageObjectReference(permanent, game)));
        return true;
    }
    return false;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) MageObjectReference(mage.MageObjectReference)

Example 29 with EntersTheBattlefieldEvent

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

the class MasterBiomancerEntersBattlefieldEffect 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 power = sourceCreature.getPower().getValue();
        if (power > 0) {
            creature.addCounters(CounterType.P1P1.createInstance(power), source.getControllerId(), source, game);
        }
        ContinuousEffect effect = new AddCardSubTypeTargetEffect(SubType.MUTANT, Duration.Custom);
        effect.setTargetPointer(new FixedTarget(creature.getId(), creature.getZoneChangeCounter(game) + 1));
        game.addEffect(effect, source);
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) AddCardSubTypeTargetEffect(mage.abilities.effects.common.continuous.AddCardSubTypeTargetEffect)

Example 30 with EntersTheBattlefieldEvent

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

the class ShimatsuTheBloodcloakedEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
    Player controller = game.getPlayer(source.getControllerId());
    if (creature != null && controller != null) {
        Target target = new TargetControlledPermanent(0, Integer.MAX_VALUE, new FilterControlledPermanent(), true);
        if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
            return false;
        }
        controller.chooseTarget(Outcome.Detriment, target, source, game);
        if (!target.getTargets().isEmpty()) {
            int sacrificedCreatures = target.getTargets().size();
            game.informPlayers(controller.getLogName() + " sacrifices " + sacrificedCreatures + " creatures for " + creature.getLogName());
            for (UUID targetId : target.getTargets()) {
                Permanent targetCreature = game.getPermanent(targetId);
                if (targetCreature == null || !targetCreature.sacrifice(source, game)) {
                    return false;
                }
            }
            creature.addCounters(CounterType.P1P1.createInstance(sacrificedCreatures), source.getControllerId(), source, game);
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) UUID(java.util.UUID)

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