Search in sources :

Example 1 with FilterControlledArtifactPermanent

use of mage.filter.common.FilterControlledArtifactPermanent in project mage by magefree.

the class TransmuteArtifactEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    // Sacrifice an artifact.
    int manaValue = 0;
    boolean sacrifice = false;
    TargetControlledPermanent targetArtifact = new TargetControlledPermanent(new FilterControlledArtifactPermanent());
    if (controller.chooseTarget(Outcome.Sacrifice, targetArtifact, source, game)) {
        Permanent permanent = game.getPermanent(targetArtifact.getFirstTarget());
        if (permanent != null) {
            manaValue = permanent.getManaValue();
            sacrifice = permanent.sacrifice(source, game);
        }
    } else {
        return true;
    }
    // If you do, search your library for an artifact card.
    if (sacrifice && controller.searchLibrary(target, source, game)) {
        if (!target.getTargets().isEmpty()) {
            for (UUID cardId : target.getTargets()) {
                Card card = controller.getLibrary().getCard(cardId, game);
                if (card != null) {
                    // If that card's converted mana cost is less than or equal to the sacrificed artifact's converted mana cost, put it onto the battlefield.
                    if (card.getManaValue() <= manaValue) {
                        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                    } else {
                        // If it's greater, you may pay {X}, where X is the difference. If you do, put it onto the battlefield.
                        Cost cost = ManaUtil.createManaCost(card.getManaValue() - manaValue, true);
                        boolean payed = false;
                        if (controller.chooseUse(Outcome.Benefit, "Do you want to pay " + cost.getText() + " to put it onto the battlefield?", source, game) && cost.pay(source, game, source, source.getControllerId(), false)) {
                            payed = true;
                        }
                        if (payed) {
                            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                        } else {
                            // If you don't, put it into its owner's graveyard. Then shuffle your library
                            controller.moveCards(card, Zone.GRAVEYARD, source, game);
                        }
                    }
                }
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    controller.shuffleLibrary(source, game);
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) Card(mage.cards.Card) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

Example 2 with FilterControlledArtifactPermanent

use of mage.filter.common.FilterControlledArtifactPermanent in project mage by magefree.

the class CataclysmEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Card> chosen = new ArrayList<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        Target target1 = new TargetControlledPermanent(1, 1, new FilterControlledArtifactPermanent(), true);
        Target target2 = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
        Target target3 = new TargetControlledPermanent(1, 1, new FilterControlledEnchantmentPermanent(), true);
        Target target4 = new TargetControlledPermanent(1, 1, new FilterControlledLandPermanent(), true);
        if (target1.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target1.isChosen() && target1.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target1, source, game);
            }
            Permanent artifact = game.getPermanent(target1.getFirstTarget());
            if (artifact != null) {
                chosen.add(artifact);
            }
            target1.clearChosen();
        }
        if (target2.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target2.isChosen() && target2.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target2, source, game);
            }
            Permanent creature = game.getPermanent(target2.getFirstTarget());
            if (creature != null) {
                chosen.add(creature);
            }
            target2.clearChosen();
        }
        if (target3.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target3.isChosen() && target3.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target3, source, game);
            }
            Permanent enchantment = game.getPermanent(target3.getFirstTarget());
            if (enchantment != null) {
                chosen.add(enchantment);
            }
            target3.clearChosen();
        }
        if (target4.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target4.isChosen() && target4.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target4, source, game);
            }
            Permanent land = game.getPermanent(target4.getFirstTarget());
            if (land != null) {
                chosen.add(land);
            }
            target4.clearChosen();
        }
    }
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
        if (!chosen.contains(permanent)) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) FilterControlledEnchantmentPermanent(mage.filter.common.FilterControlledEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID) FilterControlledEnchantmentPermanent(mage.filter.common.FilterControlledEnchantmentPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) Card(mage.cards.Card)

Example 3 with FilterControlledArtifactPermanent

use of mage.filter.common.FilterControlledArtifactPermanent in project mage by magefree.

the class ScrapWelderCost method getFixedCostsFromAnnouncedValue.

@Override
public Cost getFixedCostsFromAnnouncedValue(int xValue) {
    FilterControlledArtifactPermanent filter = new FilterControlledArtifactPermanent("an artifact with mana value " + xValue);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, xValue));
    return new SacrificeTargetCost(filter);
}
Also used : ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent)

Example 4 with FilterControlledArtifactPermanent

use of mage.filter.common.FilterControlledArtifactPermanent in project mage by magefree.

the class AncientRunesDamageTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player != null) {
        int damage = game.getBattlefield().getAllActivePermanents(new FilterControlledArtifactPermanent("artifacts"), targetPointer.getFirst(game, source), game).size();
        player.damage(damage, source.getSourceId(), source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent)

Example 5 with FilterControlledArtifactPermanent

use of mage.filter.common.FilterControlledArtifactPermanent in project mage by magefree.

the class DismantleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller != null) {
        if (permanent != null) {
            int counterCount = 0;
            counterCount = permanent.getCounters(game).values().stream().map((counter) -> counter.getCount()).reduce(counterCount, Integer::sum);
            permanent.destroy(source, game, false);
            if (counterCount > 0) {
                Target target = new TargetControlledPermanent(1, 1, new FilterControlledArtifactPermanent("an artifact you control"), true);
                if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
                    controller.chooseTarget(Outcome.Benefit, target, source, game);
                    Permanent artifact = game.getPermanent(target.getFirstTarget());
                    Counter counter;
                    if (controller.chooseUse(Outcome.BoostCreature, "Choose which kind of counters to add", null, "+1/+1 counters", "Charge counters", source, game)) {
                        counter = CounterType.P1P1.createInstance(counterCount);
                    } else {
                        counter = CounterType.CHARGE.createInstance(counterCount);
                    }
                    if (artifact != null) {
                        artifact.addCounters(counter, source.getControllerId(), source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) Counter(mage.counters.Counter) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent)

Aggregations

FilterControlledArtifactPermanent (mage.filter.common.FilterControlledArtifactPermanent)6 Player (mage.players.Player)5 Permanent (mage.game.permanent.Permanent)4 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)4 Card (mage.cards.Card)3 Target (mage.target.Target)3 UUID (java.util.UUID)2 FilterArtifactCard (mage.filter.common.FilterArtifactCard)2 ArrayList (java.util.ArrayList)1 Cost (mage.abilities.costs.Cost)1 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)1 Counter (mage.counters.Counter)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 FilterControlledEnchantmentPermanent (mage.filter.common.FilterControlledEnchantmentPermanent)1 FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)1 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)1 TargetArtifactPermanent (mage.target.common.TargetArtifactPermanent)1