Search in sources :

Example 1 with FilterControlledEnchantmentPermanent

use of mage.filter.common.FilterControlledEnchantmentPermanent 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)

Aggregations

ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Card (mage.cards.Card)1 FilterControlledArtifactPermanent (mage.filter.common.FilterControlledArtifactPermanent)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 FilterControlledEnchantmentPermanent (mage.filter.common.FilterControlledEnchantmentPermanent)1 FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)1 Permanent (mage.game.permanent.Permanent)1 Player (mage.players.Player)1 Target (mage.target.Target)1 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)1