Search in sources :

Example 1 with FilterArtifactPermanent

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

the class MechanizedProductionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (sourceObject != null && sourceObject.getAttachedTo() != null) {
        Permanent enchantedArtifact = game.getPermanentOrLKIBattlefield(sourceObject.getAttachedTo());
        if (enchantedArtifact != null) {
            EmptyToken token = new EmptyToken();
            CardUtil.copyTo(token).from(enchantedArtifact, game);
            token.putOntoBattlefield(1, game, source, source.getControllerId());
        }
        Map<String, Integer> countNames = new HashMap<>();
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterArtifactPermanent(), source.getControllerId(), game)) {
            int counter = countNames.getOrDefault(permanent.getName(), 0);
            countNames.put(permanent.getName(), counter + 1);
        }
        for (Entry<String, Integer> entry : countNames.entrySet()) {
            if (entry.getValue() > 7) {
                Player controller = game.getPlayer(source.getControllerId());
                if (controller != null) {
                    game.informPlayers(controller.getLogName() + " controls eight or more artifacts with the same name as one another (" + entry.getKey() + ").");
                    controller.won(game);
                    return true;
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) Player(mage.players.Player) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) TargetPermanent(mage.target.TargetPermanent) HashMap(java.util.HashMap) EmptyToken(mage.game.permanent.token.EmptyToken)

Example 2 with FilterArtifactPermanent

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

the class MuzzioVisionaryArchitectEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int highCMC = 0;
    List<Permanent> controlledArtifacts = game.getBattlefield().getAllActivePermanents(new FilterArtifactPermanent(), controller.getId(), game);
    for (Permanent permanent : controlledArtifacts) {
        if (permanent.getSpellAbility() != null) {
            int cmc = permanent.getSpellAbility().getManaCosts().manaValue();
            if (cmc > highCMC) {
                highCMC = cmc;
            }
        }
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, highCMC));
    controller.lookAtCards(source, null, cards, game);
    if (!cards.isEmpty()) {
        TargetCard target = new TargetCard(Zone.LIBRARY, new FilterArtifactCard("artifact card to put onto the battlefield"));
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.choose(Outcome.Benefit, cards, target, game)) {
            Card card = cards.get(target.getFirstTarget(), game);
            if (card != null) {
                controller.revealCards(source, new CardsImpl(card), game);
                cards.remove(card);
                controller.moveCards(card, Zone.BATTLEFIELD, source, game);
            }
        }
    }
    controller.putCardsOnBottomOfLibrary(cards, game, source, true);
    return true;
}
Also used : Player(mage.players.Player) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) TargetCard(mage.target.TargetCard) FilterArtifactCard(mage.filter.common.FilterArtifactCard) TargetCard(mage.target.TargetCard) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

Example 3 with FilterArtifactPermanent

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

the class RustmouthOgreTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
    if (damageEvent.isCombatDamage() && event.getSourceId().equals(this.getSourceId())) {
        FilterArtifactPermanent filter = new FilterArtifactPermanent("artifact that player controls");
        filter.add(new ControllerIdPredicate(event.getPlayerId()));
        filter.setMessage("artifact controlled by " + game.getPlayer(event.getTargetId()).getLogName());
        this.getTargets().clear();
        this.addTarget(new TargetPermanent(filter));
        return true;
    }
    return false;
}
Also used : FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent) TargetPermanent(mage.target.TargetPermanent)

Example 4 with FilterArtifactPermanent

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

the class TragicArroganceffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<Permanent> choosenPermanent = new HashSet<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                FilterArtifactPermanent filterArtifactPermanent = new FilterArtifactPermanent("an artifact of " + player.getName());
                filterArtifactPermanent.add(new ControllerIdPredicate(playerId));
                Target target1 = new TargetArtifactPermanent(1, 1, filterArtifactPermanent, true);
                FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent("a creature of " + player.getName());
                filterCreaturePermanent.add(new ControllerIdPredicate(playerId));
                Target target2 = new TargetPermanent(1, 1, filterCreaturePermanent, true);
                FilterEnchantmentPermanent filterEnchantmentPermanent = new FilterEnchantmentPermanent("an enchantment of " + player.getName());
                filterEnchantmentPermanent.add(new ControllerIdPredicate(playerId));
                Target target3 = new TargetPermanent(1, 1, filterEnchantmentPermanent, true);
                FilterPlaneswalkerPermanent filterPlaneswalkerPermanent = new FilterPlaneswalkerPermanent("a planeswalker of " + player.getName());
                filterPlaneswalkerPermanent.add(new ControllerIdPredicate(playerId));
                Target target4 = new TargetPermanent(1, 1, filterPlaneswalkerPermanent, true);
                if (target1.canChoose(source.getSourceId(), controller.getId(), game)) {
                    controller.chooseTarget(Outcome.Benefit, target1, source, game);
                    Permanent artifact = game.getPermanent(target1.getFirstTarget());
                    if (artifact != null) {
                        choosenPermanent.add(artifact);
                    }
                    target1.clearChosen();
                }
                if (target2.canChoose(source.getSourceId(), controller.getId(), game)) {
                    controller.chooseTarget(Outcome.Benefit, target2, source, game);
                    Permanent creature = game.getPermanent(target2.getFirstTarget());
                    if (creature != null) {
                        choosenPermanent.add(creature);
                    }
                    target2.clearChosen();
                }
                if (target3.canChoose(source.getSourceId(), controller.getId(), game)) {
                    controller.chooseTarget(Outcome.Benefit, target3, source, game);
                    Permanent enchantment = game.getPermanent(target3.getFirstTarget());
                    if (enchantment != null) {
                        choosenPermanent.add(enchantment);
                    }
                    target3.clearChosen();
                }
                if (target4.canChoose(source.getSourceId(), controller.getId(), game)) {
                    controller.chooseTarget(Outcome.Benefit, target4, source, game);
                    Permanent planeswalker = game.getPermanent(target4.getFirstTarget());
                    if (planeswalker != null) {
                        choosenPermanent.add(planeswalker);
                    }
                    target4.clearChosen();
                }
            }
        }
        // Then each player sacrifices all other nonland permanents they control
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENTS_NON_LAND, playerId, game)) {
                    if (!choosenPermanent.contains(permanent)) {
                        permanent.sacrifice(source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) FilterPlaneswalkerPermanent(mage.filter.common.FilterPlaneswalkerPermanent) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) TargetPermanent(mage.target.TargetPermanent) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) FilterPlaneswalkerPermanent(mage.filter.common.FilterPlaneswalkerPermanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 5 with FilterArtifactPermanent

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

the class WarReportEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        int lifeToGain = game.getBattlefield().count(StaticFilters.FILTER_PERMANENT_CREATURE, source.getSourceId(), source.getControllerId(), game);
        lifeToGain += game.getBattlefield().count(new FilterArtifactPermanent(), source.getSourceId(), source.getControllerId(), game);
        player.gainLife(lifeToGain, game, source);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent)

Aggregations

FilterArtifactPermanent (mage.filter.common.FilterArtifactPermanent)18 Permanent (mage.game.permanent.Permanent)12 Player (mage.players.Player)10 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)6 TargetPermanent (mage.target.TargetPermanent)4 UUID (java.util.UUID)3 HashMap (java.util.HashMap)2 Card (mage.cards.Card)2 FilterPermanent (mage.filter.FilterPermanent)2 FilterArtifactCard (mage.filter.common.FilterArtifactCard)2 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)2 Target (mage.target.Target)2 TargetArtifactPermanent (mage.target.common.TargetArtifactPermanent)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 DamageEverythingEffect (mage.abilities.effects.common.DamageEverythingEffect)1 DrawCardAllEffect (mage.abilities.effects.common.DrawCardAllEffect)1 ReturnToHandFromBattlefieldAllEffect (mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect)1 SacrificeControllerEffect (mage.abilities.effects.common.SacrificeControllerEffect)1