Search in sources :

Example 31 with EntersTheBattlefieldEvent

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

the class VigorMortisReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
    if (creature != null) {
        creature.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game, event.getAppliedEffects());
        discard();
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent)

Example 32 with EntersTheBattlefieldEvent

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

the class DevourEffect 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) {
        return false;
    }
    Target target = new TargetControlledPermanent(1, Integer.MAX_VALUE, devourFactor.getFilter(), true);
    target.setRequired(false);
    if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
        return false;
    }
    if (!controller.chooseUse(Outcome.Detriment, "Devour " + devourFactor.getCardType().toString().toLowerCase() + "s?", source, game)) {
        return false;
    }
    controller.chooseTarget(Outcome.Detriment, target, source, game);
    if (target.getTargets().isEmpty()) {
        return false;
    }
    List<Permanent> creaturesDevoured = new ArrayList<>();
    int devouredCreatures = 0;
    for (UUID targetId : target.getTargets()) {
        Permanent targetCreature = game.getPermanent(targetId);
        if (targetCreature != null && targetCreature.sacrifice(source, game)) {
            creaturesDevoured.add(targetCreature);
            devouredCreatures++;
        }
    }
    if (!game.isSimulation()) {
        game.informPlayers(creature.getLogName() + " devours " + devouredCreatures + " " + devourFactor.getCardType().toString().toLowerCase() + "s");
    }
    // need for multistep effects
    game.getState().processAction(game);
    int amountCounters;
    if (devourFactor == DevourFactor.DevourX) {
        amountCounters = devouredCreatures * devouredCreatures;
    } else {
        amountCounters = devouredCreatures * devourFactor.getFactor();
    }
    creature.addCounters(CounterType.P1P1.createInstance(amountCounters), source.getControllerId(), source, game);
    game.getState().setValue(creature.getId().toString() + "devoured", creaturesDevoured);
    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) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 33 with EntersTheBattlefieldEvent

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

the class InfiniteReflectionEntersBattlefieldEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    MageObject toCopyToObject = ((EntersTheBattlefieldEvent) event).getTarget();
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (sourcePermanent != null && toCopyToObject != null && sourcePermanent.getAttachedTo() != null) {
        Permanent toCopyFromPermanent = game.getPermanent(sourcePermanent.getAttachedTo());
        if (toCopyFromPermanent != null) {
            game.copyPermanent(toCopyFromPermanent, toCopyToObject.getId(), source, new EmptyCopyApplier());
        }
    }
    return false;
}
Also used : EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier) MageObject(mage.MageObject)

Example 34 with EntersTheBattlefieldEvent

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

the class UphillBattleTapEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent target = ((EntersTheBattlefieldEvent) event).getTarget();
    CreatureWasCastWatcher creatureSpellWatcher = game.getState().getWatcher(CreatureWasCastWatcher.class);
    PlayCreatureLandWatcher landWatcher = game.getState().getWatcher(PlayCreatureLandWatcher.class);
    if (target != null && ((creatureSpellWatcher != null && creatureSpellWatcher.wasCreatureCastThisTurn(target.getId())) || (landWatcher != null && landWatcher.wasLandPlayed(target.getId())))) {
        target.setTapped(true);
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) CreatureWasCastWatcher(mage.watchers.common.CreatureWasCastWatcher)

Example 35 with EntersTheBattlefieldEvent

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

the class NecromanticSummoningReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
    if (creature != null) {
        creature.addCounters(CounterType.P1P1.createInstance(2), source.getControllerId(), source, game, event.getAppliedEffects());
        discard();
    }
    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