Search in sources :

Example 26 with TargetControlledCreaturePermanent

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

the class HumiliateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getSourceId(), source.getControllerId(), game) < 1) {
        return false;
    }
    TargetPermanent target = new TargetControlledCreaturePermanent();
    target.setNotTarget(true);
    target.withChooseHint("+1/+1 counter");
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    return permanent != null && permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 27 with TargetControlledCreaturePermanent

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

the class LinessaZephyrMageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player targetPlayer = game.getPlayer(source.getFirstTarget());
        if (targetPlayer != null) {
            // Target player returns a creature they control to its owner's hand,
            Target target = new TargetControlledCreaturePermanent();
            target.setNotTarget(true);
            if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(target.getFirstTarget());
                if (permanent != null) {
                    targetPlayer.moveCards(permanent, Zone.HAND, source, game);
                }
            }
            // then repeats this process for an artifact,
            FilterControlledPermanent filter = new FilterControlledPermanent("artifact you control");
            filter.add(CardType.ARTIFACT.getPredicate());
            target = new TargetControlledPermanent(filter);
            target.setNotTarget(true);
            if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(target.getFirstTarget());
                if (permanent != null) {
                    targetPlayer.moveCards(permanent, Zone.HAND, source, game);
                }
            }
            // an enchantment,
            filter = new FilterControlledPermanent("enchantment you control");
            filter.add(CardType.ENCHANTMENT.getPredicate());
            target = new TargetControlledPermanent(filter);
            target.setNotTarget(true);
            if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(target.getFirstTarget());
                if (permanent != null) {
                    targetPlayer.moveCards(permanent, Zone.HAND, source, game);
                }
            }
            // and a land.
            filter = new FilterControlledPermanent("land you control");
            filter.add(CardType.LAND.getPredicate());
            target = new TargetControlledPermanent(filter);
            target.setNotTarget(true);
            if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(target.getFirstTarget());
                if (permanent != null) {
                    targetPlayer.moveCards(permanent, Zone.HAND, source, game);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) TargetPlayer(mage.target.TargetPlayer) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 28 with TargetControlledCreaturePermanent

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

the class SakashimasWillCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetPermanent target = new TargetControlledCreaturePermanent();
    target.setNotTarget(true);
    if (!target.canChoose(source.getSourceId(), player.getId(), game)) {
        return false;
    }
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent chosenCreature = game.getPermanent(target.getFirstTarget());
    if (chosenCreature == null) {
        return false;
    }
    for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_CREATURE, player.getId(), source.getSourceId(), game)) {
        if (permanent == null || permanent.getId().equals(chosenCreature.getId())) {
            continue;
        }
        game.copyPermanent(Duration.EndOfTurn, chosenCreature, permanent.getId(), source, new EmptyCopyApplier());
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier) TargetPermanent(mage.target.TargetPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 29 with TargetControlledCreaturePermanent

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

the class ConvokeEffect method addSpecialAction.

@Override
public void addSpecialAction(Ability source, Game game, ManaCost unpaid) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && game.getBattlefield().containsControlled(filterUntapped, source, game, 1)) {
        if (source.getAbilityType() == AbilityType.SPELL) {
            SpecialAction specialAction = new ConvokeSpecialAction(unpaid, this);
            specialAction.setControllerId(source.getControllerId());
            specialAction.setSourceId(source.getSourceId());
            // create filter for possible creatures to tap
            FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
            filter.add(TappedPredicate.UNTAPPED);
            if (unpaid.getMana().getGeneric() == 0) {
                List<ColorPredicate> colorPredicates = new ArrayList<>();
                if (unpaid.getMana().getBlack() > 0) {
                    colorPredicates.add(new ColorPredicate(ObjectColor.BLACK));
                }
                if (unpaid.getMana().getBlue() > 0) {
                    colorPredicates.add(new ColorPredicate(ObjectColor.BLUE));
                }
                if (unpaid.getMana().getRed() > 0) {
                    colorPredicates.add(new ColorPredicate(ObjectColor.RED));
                }
                if (unpaid.getMana().getGreen() > 0) {
                    colorPredicates.add(new ColorPredicate(ObjectColor.GREEN));
                }
                if (unpaid.getMana().getWhite() > 0) {
                    colorPredicates.add(new ColorPredicate(ObjectColor.WHITE));
                }
                filter.add(Predicates.or(colorPredicates));
            }
            Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
            target.setTargetName("tap creature card as convoke's pay");
            specialAction.addTarget(target);
            if (specialAction.canActivate(source.getControllerId(), game).canActivate()) {
                game.getState().getSpecialActions().add(specialAction);
            }
        }
    }
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) SpecialAction(mage.abilities.SpecialAction) Target(mage.target.Target) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ArrayList(java.util.ArrayList) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 30 with TargetControlledCreaturePermanent

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

the class ArmoredSkyhunterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 6));
    TargetCardInLibrary targetCard = new TargetCardInLibrary(0, 1, filter);
    player.choose(outcome, cards, targetCard, game);
    Card card = game.getCard(targetCard.getFirstTarget());
    if (card == null) {
        return player.putCardsOnBottomOfLibrary(cards, game, source, false);
    }
    player.moveCards(card, Zone.BATTLEFIELD, source, game);
    cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.LIBRARY);
    Permanent equipment = game.getPermanent(card.getId());
    if (equipment == null || !equipment.hasSubtype(SubType.EQUIPMENT, game)) {
        return player.putCardsOnBottomOfLibrary(cards, game, source, false);
    }
    TargetPermanent targetPermanent = new TargetControlledCreaturePermanent(0, 1);
    targetCard.setNotTarget(true);
    player.choose(outcome, targetPermanent, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(targetPermanent.getFirstTarget());
    if (permanent != null) {
        permanent.addAttachment(equipment.getId(), source, game);
    }
    return player.putCardsOnBottomOfLibrary(cards, game, source, false);
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard)

Aggregations

TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)78 Player (mage.players.Player)73 Permanent (mage.game.permanent.Permanent)64 Target (mage.target.Target)41 UUID (java.util.UUID)29 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)27 TargetPermanent (mage.target.TargetPermanent)18 ArrayList (java.util.ArrayList)14 Cost (mage.abilities.costs.Cost)10 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)9 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)8 FixedTarget (mage.target.targetpointer.FixedTarget)8 Ability (mage.abilities.Ability)6 FilterPermanent (mage.filter.FilterPermanent)6 MageObject (mage.MageObject)5 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)5 OneShotEffect (mage.abilities.effects.OneShotEffect)4 Card (mage.cards.Card)4 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)3 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3