Search in sources :

Example 1 with TargetLandPermanent

use of mage.target.common.TargetLandPermanent in project mage by magefree.

the class SunderingTitanDestroyLandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    Set<UUID> lands = new HashSet<>();
    if (controller != null && sourcePermanent != null) {
        for (SubType landName : SubType.getBasicLands()) {
            FilterLandPermanent filter = new FilterLandPermanent(landName + " to destroy");
            filter.add(landName.getPredicate());
            Target target = new TargetLandPermanent(1, 1, filter, true);
            if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
                controller.chooseTarget(outcome, target, source, game);
                lands.add(target.getFirstTarget());
            }
        }
        if (!lands.isEmpty()) {
            int destroyedLands = 0;
            for (UUID landId : lands) {
                Permanent land = game.getPermanent(landId);
                if (land != null) {
                    if (land.destroy(source, game, false)) {
                        destroyedLands++;
                    }
                }
            }
            game.informPlayers(sourcePermanent.getLogName() + ": " + destroyedLands + (destroyedLands > 1 ? " lands were" : "land was") + " destroyed");
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) SubType(mage.constants.SubType) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 2 with TargetLandPermanent

use of mage.target.common.TargetLandPermanent in project mage by magefree.

the class CyclopeanTombCounterWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObjectReference mor = new MageObjectReference(source.getSourceId(), source.getSourceObjectZoneChangeCounter(), game);
    CyclopeanTombCounterWatcher watcher = game.getState().getWatcher(CyclopeanTombCounterWatcher.class);
    if (controller != null && watcher != null) {
        Set<MageObjectReference> landRef = watcher.landMiredByCyclopeanTombInstance(mor, game);
        if (landRef == null || landRef.isEmpty()) {
            // no lands got mire counter from that instance
            return true;
        }
        FilterLandPermanent filter = new FilterLandPermanent("a land with a mire counter added from the Cyclopean Tomb instance (" + landRef.size() + " left)");
        Set<PermanentIdPredicate> idPref = new HashSet<>();
        for (MageObjectReference ref : landRef) {
            Permanent land = ref.getPermanent(game);
            if (land != null) {
                idPref.add(new PermanentIdPredicate(land.getId()));
            }
        }
        filter.add(Predicates.or(idPref));
        TargetLandPermanent target = new TargetLandPermanent(1, 1, filter, true);
        /*Player must choose a land each upkeep. Using the message are above the player hand where frequent interactions
             * take place is the most logical way to prompt for this scenario. A new constructor added to provide a not optional
             * option for any cards like this where the player must choose a target in such the way this card requires.
             */
        if (controller.chooseTarget(Outcome.Neutral, target, source, game)) {
            Permanent chosenLand = game.getPermanent(target.getFirstTarget());
            if (chosenLand != null) {
                Effect effect = new RemoveAllCountersTargetEffect(CounterType.MIRE);
                effect.setTargetPointer(new FixedTarget(chosenLand, game));
                effect.apply(game, source);
                landRef.remove(new MageObjectReference(chosenLand, game));
            }
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) RemoveAllCountersTargetEffect(mage.abilities.effects.common.counter.RemoveAllCountersTargetEffect) BecomesBasicLandTargetEffect(mage.abilities.effects.common.continuous.BecomesBasicLandTargetEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetLandPermanent(mage.target.common.TargetLandPermanent) RemoveAllCountersTargetEffect(mage.abilities.effects.common.counter.RemoveAllCountersTargetEffect) MageObjectReference(mage.MageObjectReference)

Example 3 with TargetLandPermanent

use of mage.target.common.TargetLandPermanent in project mage by magefree.

the class RisingWatersUntapEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(game.getActivePlayerId());
    FilterLandPermanent filter = new FilterLandPermanent("land you control");
    filter.add(new ControllerIdPredicate(game.getActivePlayerId()));
    Target target = new TargetLandPermanent(filter);
    if (player != null && player.chooseTarget(Outcome.Untap, target, source, game)) {
        for (UUID landId : target.getTargets()) {
            Permanent land = game.getPermanent(landId);
            if (land != null) {
                land.untap(game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetLandPermanent(mage.target.common.TargetLandPermanent) UUID(java.util.UUID)

Example 4 with TargetLandPermanent

use of mage.target.common.TargetLandPermanent in project mage by magefree.

the class SteamVinesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent steamVines = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (steamVines != null) {
        Permanent enchantedLand = game.getPermanentOrLKIBattlefield(steamVines.getAttachedTo());
        Player controller = game.getPlayer(source.getControllerId());
        if (enchantedLand != null && controller != null) {
            Player landsController = game.getPlayer(enchantedLand.getControllerId());
            if (game.getState().getZone(enchantedLand.getId()) == Zone.BATTLEFIELD) {
                // if 2 or more Steam Vines were on a land
                enchantedLand.destroy(source, game, false);
                if (landsController != null) {
                    landsController.damage(1, source.getSourceId(), source, game);
                }
            }
            if (!game.getBattlefield().getAllActivePermanents(CardType.LAND, game).isEmpty()) {
                // lands are available on the battlefield
                Target target = new TargetLandPermanent();
                // not a target, it is chosen
                target.setNotTarget(true);
                Card steamVinesCard = game.getCard(source.getSourceId());
                if (steamVinesCard != null && landsController != null) {
                    if (landsController.choose(Outcome.DestroyPermanent, target, source.getId(), game)) {
                        if (target.getFirstTarget() != null) {
                            Permanent landChosen = game.getPermanent(target.getFirstTarget());
                            if (landChosen != null) {
                                for (Target targetTest : steamVinesCard.getSpellAbility().getTargets()) {
                                    Filter filterTest = targetTest.getFilter();
                                    if (filterTest.match(landChosen, game)) {
                                        if (game.getBattlefield().containsPermanent(landChosen.getId())) {
                                            // verify that it is still on the battlefield
                                            game.informPlayers(landsController.getLogName() + " attaches " + steamVines.getLogName() + " to " + landChosen.getLogName());
                                            Effect effect = new AttachEffect(Outcome.Neutral);
                                            effect.setTargetPointer(new FixedTarget(landChosen, game));
                                            return effect.apply(game, source);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) Filter(mage.filter.Filter) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) AttachEffect(mage.abilities.effects.common.AttachEffect) TargetLandPermanent(mage.target.common.TargetLandPermanent) Card(mage.cards.Card) AttachEffect(mage.abilities.effects.common.AttachEffect)

Example 5 with TargetLandPermanent

use of mage.target.common.TargetLandPermanent in project mage by magefree.

the class ThespiansStageCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    Permanent copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (sourcePermanent != null && copyFromPermanent != null) {
        Permanent newPermanent = game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, new EmptyCopyApplier());
        Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ThespiansStageCopyEffect(), new GenericManaCost(2));
        ability.addCost(new TapSourceCost());
        ability.addTarget(new TargetLandPermanent());
        newPermanent.addAbility(ability, source.getSourceId(), game);
        return true;
    }
    return false;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) ColorlessManaAbility(mage.abilities.mana.ColorlessManaAbility) Ability(mage.abilities.Ability) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TargetLandPermanent(mage.target.common.TargetLandPermanent) TapSourceCost(mage.abilities.costs.common.TapSourceCost)

Aggregations

TargetLandPermanent (mage.target.common.TargetLandPermanent)15 Player (mage.players.Player)13 Permanent (mage.game.permanent.Permanent)12 FilterLandPermanent (mage.filter.common.FilterLandPermanent)11 Target (mage.target.Target)10 UUID (java.util.UUID)9 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)6 OneShotEffect (mage.abilities.effects.OneShotEffect)3 Card (mage.cards.Card)3 TargetPermanent (mage.target.TargetPermanent)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Ability (mage.abilities.Ability)2 Effect (mage.abilities.effects.Effect)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 MageObjectReference (mage.MageObjectReference)1 EntersBattlefieldTriggeredAbility (mage.abilities.common.EntersBattlefieldTriggeredAbility)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 PermanentsOnTheBattlefieldCondition (mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition)1