diff --git a/Mage.Sets/src/mage/cards/a/AuraGraft.java b/Mage.Sets/src/mage/cards/a/AuraGraft.java index 82397b57a6e..2a46cf70829 100644 --- a/Mage.Sets/src/mage/cards/a/AuraGraft.java +++ b/Mage.Sets/src/mage/cards/a/AuraGraft.java @@ -12,17 +12,16 @@ import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.SubType; -import mage.filter.Filter; import mage.filter.FilterPermanent; import mage.filter.predicate.ObjectSourcePlayer; import mage.filter.predicate.ObjectSourcePlayerPredicate; import mage.filter.predicate.mageobject.AnotherPredicate; +import mage.filter.predicate.permanent.PermanentCanBeAttachedToPredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.Target; import mage.target.TargetPermanent; -import mage.util.TargetAddress; /** * @author duncant @@ -66,27 +65,6 @@ class AttachedToPermanentPredicate implements ObjectSourcePlayerPredicate { - - protected Permanent aura; - - public PermanentCanBeAttachedToPredicate(Permanent aura) { - super(); - this.aura = aura; - } - - @Override - public boolean apply(ObjectSourcePlayer input, Game game) { - Permanent potentialAttachment = input.getObject(); - for (TargetAddress addr : TargetAddress.walk(aura)) { - Target target = addr.getTarget(aura); - Filter filter = target.getFilter(); - return filter.match(potentialAttachment, game); - } - return false; - } -} - class MoveTargetAuraEffect extends OneShotEffect { public MoveTargetAuraEffect() { diff --git a/Mage.Sets/src/mage/cards/i/InfectiousRage.java b/Mage.Sets/src/mage/cards/i/InfectiousRage.java new file mode 100644 index 00000000000..c6f7c08db78 --- /dev/null +++ b/Mage.Sets/src/mage/cards/i/InfectiousRage.java @@ -0,0 +1,112 @@ +package mage.cards.i; + +import mage.abilities.Ability; +import mage.abilities.common.DiesAttachedTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.continuous.BoostEnchantedEffect; +import mage.abilities.keyword.EnchantAbility; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterPermanent; +import mage.filter.predicate.permanent.PermanentCanBeAttachedToPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetPermanent; +import mage.target.common.TargetCreaturePermanent; +import mage.util.RandomUtil; + +import java.util.List; +import java.util.UUID; + +/** + * @author xenohedron + */ + +public final class InfectiousRage extends CardImpl { + + public InfectiousRage(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{R}"); + this.subtype.add(SubType.AURA); + + // Enchant creature + TargetPermanent auraTarget = new TargetCreaturePermanent(); + this.getSpellAbility().addTarget(auraTarget); + this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); + Ability ability = new EnchantAbility(auraTarget); + this.addAbility(ability); + + // Enchanted creature gets +2/-1. + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(2, -1))); + + // When enchanted creature dies, choose a creature at random Infectious Rage can enchant. + // Return Infectious Rage to the battlefield attached to that creature. + this.addAbility(new DiesAttachedTriggeredAbility(new InfectiousRageReattachEffect(), "enchanted creature")); + + } + + private InfectiousRage(final InfectiousRage card) { + super(card); + } + + @Override + public InfectiousRage copy() { + return new InfectiousRage(this); + } +} + +class InfectiousRageReattachEffect extends OneShotEffect { + + public InfectiousRageReattachEffect() { + super(Outcome.PutCardInPlay); + this.staticText = "choose a creature at random {this} can enchant. Return {this} to the battlefield attached to that creature."; + } + + public InfectiousRageReattachEffect(final InfectiousRageReattachEffect effect) { + super(effect); + } + + @Override + public InfectiousRageReattachEffect copy() { + return new InfectiousRageReattachEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + + Player controller = game.getPlayer(source.getControllerId()); + Card auraCard = game.getCard(source.getSourceId()); + Permanent auraPermanent = source.getSourcePermanentOrLKI(game); + if (controller == null || auraCard == null || auraPermanent == null) { + return false; + } + if (source.getSourceObjectZoneChangeCounter() != auraCard.getZoneChangeCounter(game)) { + return false; + } + + FilterPermanent filter = new FilterPermanent(); + filter.add(CardType.CREATURE.getPredicate()); + filter.add(new PermanentCanBeAttachedToPredicate(auraPermanent)); // Doesn't yet exclude creatures with protection abilities + List permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game); + + if (!permanents.isEmpty()) { + Permanent creature = RandomUtil.randomFromCollection(permanents); + if (creature != null) { + game.getState().setValue("attachTo:" + auraCard.getId(), creature); + controller.moveCards(auraCard, Zone.BATTLEFIELD, source, game); + return creature.addAttachment(auraCard.getId(), source, game); + } + } + else { + game.informPlayers("No valid creatures for " + auraPermanent.getLogName() + "to enchant."); + } + + return false; + + } + +} diff --git a/Mage.Sets/src/mage/sets/Judgment.java b/Mage.Sets/src/mage/sets/Judgment.java index cb194b4fd64..9eb9265b58f 100644 --- a/Mage.Sets/src/mage/sets/Judgment.java +++ b/Mage.Sets/src/mage/sets/Judgment.java @@ -93,6 +93,7 @@ public final class Judgment extends ExpansionSet { cards.add(new SetCardInfo("Hapless Researcher", 42, Rarity.COMMON, mage.cards.h.HaplessResearcher.class)); cards.add(new SetCardInfo("Harvester Druid", 120, Rarity.COMMON, mage.cards.h.HarvesterDruid.class)); cards.add(new SetCardInfo("Hunting Grounds", 138, Rarity.RARE, mage.cards.h.HuntingGrounds.class)); + cards.add(new SetCardInfo("Infectious Rage", 92, Rarity.UNCOMMON, mage.cards.i.InfectiousRage.class)); cards.add(new SetCardInfo("Ironshell Beetle", 121, Rarity.COMMON, mage.cards.i.IronshellBeetle.class)); cards.add(new SetCardInfo("Jeska, Warrior Adept", 93, Rarity.RARE, mage.cards.j.JeskaWarriorAdept.class)); cards.add(new SetCardInfo("Keep Watch", 43, Rarity.COMMON, mage.cards.k.KeepWatch.class)); diff --git a/Mage/src/main/java/mage/filter/predicate/permanent/PermanentCanBeAttachedToPredicate.java b/Mage/src/main/java/mage/filter/predicate/permanent/PermanentCanBeAttachedToPredicate.java new file mode 100644 index 00000000000..d905903602d --- /dev/null +++ b/Mage/src/main/java/mage/filter/predicate/permanent/PermanentCanBeAttachedToPredicate.java @@ -0,0 +1,35 @@ +package mage.filter.predicate.permanent; + +import mage.filter.Filter; +import mage.filter.predicate.ObjectSourcePlayer; +import mage.filter.predicate.ObjectSourcePlayerPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.target.Target; +import mage.util.TargetAddress; + +/** + * @author duncant + */ + +public class PermanentCanBeAttachedToPredicate implements ObjectSourcePlayerPredicate { + + protected Permanent aura; + + public PermanentCanBeAttachedToPredicate(Permanent aura) { + super(); + this.aura = aura; + } + + @Override + public boolean apply(ObjectSourcePlayer input, Game game) { + // TODO: Is it possible to add functionality to exclude objects the aura can't enchant (e.g. protection from)? + Permanent potentialAttachment = input.getObject(); + for (TargetAddress addr : TargetAddress.walk(aura)) { + Target target = addr.getTarget(aura); + Filter filter = target.getFilter(); + return filter.match(potentialAttachment, game); + } + return false; + } +}