Search in sources :

Example 1 with TargetArtifactPermanent

use of mage.target.common.TargetArtifactPermanent 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)

Aggregations

HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 FilterArtifactPermanent (mage.filter.common.FilterArtifactPermanent)1 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)1 FilterEnchantmentPermanent (mage.filter.common.FilterEnchantmentPermanent)1 FilterPlaneswalkerPermanent (mage.filter.common.FilterPlaneswalkerPermanent)1 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)1 Permanent (mage.game.permanent.Permanent)1 Player (mage.players.Player)1 Target (mage.target.Target)1 TargetPermanent (mage.target.TargetPermanent)1 TargetArtifactPermanent (mage.target.common.TargetArtifactPermanent)1