diff --git a/Mage.Sets/src/mage/cards/c/ChaosDefiler.java b/Mage.Sets/src/mage/cards/c/ChaosDefiler.java new file mode 100644 index 00000000000..b7103fbc3bd --- /dev/null +++ b/Mage.Sets/src/mage/cards/c/ChaosDefiler.java @@ -0,0 +1,107 @@ +package mage.cards.c; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.EntersBattlefieldOrDiesSourceTriggeredAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.keyword.TrampleAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.filter.FilterPermanent; +import mage.filter.StaticFilters; +import mage.filter.common.FilterNonlandPermanent; +import mage.filter.predicate.permanent.ControllerIdPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetPermanent; +import mage.util.RandomUtil; + +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class ChaosDefiler extends CardImpl { + + public ChaosDefiler(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{3}{B}{R}"); + + this.subtype.add(SubType.DEMON); + this.subtype.add(SubType.CONSTRUCT); + this.power = new MageInt(5); + this.toughness = new MageInt(4); + + // Trample + this.addAbility(TrampleAbility.getInstance()); + + // Battle Cannon -- When Chaos Defiler enters the battlefield or dies, for each opponent, choose a nonland permanent that players controls. Destroy one of them chosen at random. + this.addAbility(new EntersBattlefieldOrDiesSourceTriggeredAbility( + new ChaosDefilerEffect(), false + ).withFlavorWord("Battle Cannon")); + } + + private ChaosDefiler(final ChaosDefiler card) { + super(card); + } + + @Override + public ChaosDefiler copy() { + return new ChaosDefiler(this); + } +} + +class ChaosDefilerEffect extends OneShotEffect { + + ChaosDefilerEffect() { + super(Outcome.Benefit); + staticText = "for each opponent, choose a nonland permanent " + + "that players controls. Destroy one of them chosen at random"; + } + + private ChaosDefilerEffect(final ChaosDefilerEffect effect) { + super(effect); + } + + @Override + public ChaosDefilerEffect copy() { + return new ChaosDefilerEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + Set permanents = new HashSet<>(); + for (UUID opponentId : game.getOpponents(source.getControllerId())) { + if (!game.getBattlefield().contains( + StaticFilters.FILTER_CONTROLLED_PERMANENT_NON_LAND, + opponentId, source, game, 1 + )) { + continue; + } + Player opponent = game.getPlayer(opponentId); + if (opponent == null) { + continue; + } + FilterPermanent filter = new FilterNonlandPermanent( + "nonland permanent controlled by " + opponent.getName() + ); + filter.add(new ControllerIdPredicate(opponentId)); + TargetPermanent target = new TargetPermanent(filter); + player.choose(outcome, target, source, game); + permanents.add(game.getPermanent(target.getFirstTarget())); + } + permanents.removeIf(Objects::isNull); + Permanent permanent = RandomUtil.randomFromCollection(permanents); + return permanent != null && permanent.destroy(source, game); + } +} diff --git a/Mage.Sets/src/mage/sets/Warhammer40000.java b/Mage.Sets/src/mage/sets/Warhammer40000.java index 45220a0a0c9..cb0af805393 100644 --- a/Mage.Sets/src/mage/sets/Warhammer40000.java +++ b/Mage.Sets/src/mage/sets/Warhammer40000.java @@ -39,6 +39,7 @@ public final class Warhammer40000 extends ExpansionSet { cards.add(new SetCardInfo("Bred for the Hunt", 222, Rarity.UNCOMMON, mage.cards.b.BredForTheHunt.class)); cards.add(new SetCardInfo("Broodlord", 89, Rarity.RARE, mage.cards.b.Broodlord.class)); cards.add(new SetCardInfo("Cave of Temptation", 267, Rarity.COMMON, mage.cards.c.CaveOfTemptation.class)); + cards.add(new SetCardInfo("Chaos Defiler", 110, Rarity.RARE, mage.cards.c.ChaosDefiler.class)); cards.add(new SetCardInfo("Chaos Warp", 205, Rarity.RARE, mage.cards.c.ChaosWarp.class)); cards.add(new SetCardInfo("Choked Estuary", 268, Rarity.RARE, mage.cards.c.ChokedEstuary.class)); cards.add(new SetCardInfo("Chromatic Lantern", 232, Rarity.RARE, mage.cards.c.ChromaticLantern.class));