Search in sources :

Example 6 with EntersTheBattlefieldEvent

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

the class ArchelosLagoonMysticEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    Permanent sourceObject = game.getPermanent(source.getSourceId());
    if (sourceObject == null) {
        return false;
    }
    Permanent targetObject = ((EntersTheBattlefieldEvent) event).getTarget();
    if (targetObject == null) {
        return false;
    }
    return !sourceObject.getId().equals(targetObject.getId()) && sourceObject.isTapped() == this.tapped;
}
Also used : Permanent(mage.game.permanent.Permanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent)

Example 7 with EntersTheBattlefieldEvent

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

the class ArchfiendsVesselEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (super.checkTrigger(event, game)) {
        if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
            EntersTheBattlefieldEvent entersTheBattlefieldEvent = (EntersTheBattlefieldEvent) event;
            if (entersTheBattlefieldEvent.getTargetId().equals(getSourceId()) && entersTheBattlefieldEvent.getFromZone() == Zone.GRAVEYARD) {
                return true;
            } else {
                SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
                List<Spell> spellsCastFromGraveyard = watcher.getSpellsCastFromGraveyardThisTurn(getControllerId());
                if (spellsCastFromGraveyard != null) {
                    return spellsCastFromGraveyard.stream().anyMatch(spell -> spell.getMainCard().getId().equals((entersTheBattlefieldEvent.getTarget().getMainCard().getId())));
                }
            }
        }
    }
    return false;
}
Also used : EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) Spell(mage.game.stack.Spell)

Example 8 with EntersTheBattlefieldEvent

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

the class DracoplasmEffect 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, filter, true);
        if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
            return false;
        }
        controller.chooseTarget(Outcome.Detriment, target, source, game);
        if (!target.getTargets().isEmpty()) {
            int power = 0;
            int toughness = 0;
            for (UUID targetId : target.getTargets()) {
                Permanent targetCreature = game.getPermanent(targetId);
                if (targetCreature != null && targetCreature.sacrifice(source, game)) {
                    power = CardUtil.overflowInc(power, targetCreature.getPower().getValue());
                    toughness = CardUtil.overflowInc(toughness, targetCreature.getToughness().getValue());
                }
            }
            ContinuousEffect effect = new SetPowerToughnessSourceEffect(power, toughness, Duration.Custom, SubLayer.SetPT_7b);
            game.addEffect(effect, source);
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) SetPowerToughnessSourceEffect(mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID)

Example 9 with EntersTheBattlefieldEvent

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

the class RhythmOfTheWildEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
    Player player = game.getPlayer(source.getControllerId());
    if (creature == null || player == null) {
        return false;
    }
    if (player.chooseUse(outcome, "Have " + creature.getLogName() + " enter the battlefield with a +1/+1 counter on it or with haste?", null, "+1/+1 counter", "Haste", source, game)) {
        game.informPlayers(player.getLogName() + " choose to put a +1/+1 counter on " + creature.getName());
        creature.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game, event.getAppliedEffects());
    } else {
        ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), 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) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 10 with EntersTheBattlefieldEvent

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

the class AmplifyEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent sourceCreature = ((EntersTheBattlefieldEvent) event).getTarget();
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || sourceCreature == null) {
        return false;
    }
    FilterCreatureCard filter = new FilterCreatureCard("creatures cards to reveal");
    filter.add(new AmplifyPredicate(sourceCreature));
    // You can’t reveal this card or any other cards that are entering the battlefield at the same time as this card.
    filter.add(Predicates.not(new CardIdPredicate(source.getSourceId())));
    for (Permanent enteringPermanent : game.getPermanentsEntering().values()) {
        filter.add(Predicates.not(new CardIdPredicate(enteringPermanent.getId())));
    }
    if (controller.getHand().count(filter, source.getSourceId(), source.getControllerId(), game) <= 0) {
        return false;
    }
    if (!controller.chooseUse(outcome, "Reveal cards to Amplify?", source, game)) {
        return false;
    }
    TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
    if (controller.chooseTarget(outcome, target, source, game) && !target.getTargets().isEmpty()) {
        Cards cards = new CardsImpl();
        cards.addAll(target.getTargets());
        int amountCounters = cards.size() * amplifyFactor.getFactor();
        sourceCreature.addCounters(CounterType.P1P1.createInstance(amountCounters), source.getControllerId(), source, game);
        controller.revealCards(sourceCreature.getIdName(), cards, game);
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Permanent(mage.game.permanent.Permanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) TargetCardInHand(mage.target.common.TargetCardInHand) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

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