From 0b703b1be0ccdd84bef17ec479481d3d705f6a95 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 4 Apr 2019 22:15:33 -0400 Subject: [PATCH] Implemented Role Reversal --- Mage.Sets/src/mage/cards/r/RoleReversal.java | 94 +++++++++++++++++++ .../src/mage/cards/s/ShiftingLoyalties.java | 22 ++--- Mage.Sets/src/mage/sets/WarOfTheSpark.java | 1 + Mage/src/main/java/mage/MageObject.java | 7 +- 4 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/r/RoleReversal.java diff --git a/Mage.Sets/src/mage/cards/r/RoleReversal.java b/Mage.Sets/src/mage/cards/r/RoleReversal.java new file mode 100644 index 0000000000..f568a24904 --- /dev/null +++ b/Mage.Sets/src/mage/cards/r/RoleReversal.java @@ -0,0 +1,94 @@ +package mage.cards.r; + +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.effects.common.continuous.ExchangeControlTargetEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.target.TargetPermanent; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class RoleReversal extends CardImpl { + + public RoleReversal(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{U}{U}{R}"); + + // Exchange control of two target permanents that share a permanent type. + this.getSpellAbility().addEffect(new ExchangeControlTargetEffect( + Duration.EndOfGame, "Exchange control of two target permanents that share a permanent type." + )); + this.getSpellAbility().addTarget(new TargetPermanentsThatShareCardType()); + } + + private RoleReversal(final RoleReversal card) { + super(card); + } + + @Override + public RoleReversal copy() { + return new RoleReversal(this); + } +} + +class TargetPermanentsThatShareCardType extends TargetPermanent { + + TargetPermanentsThatShareCardType() { + super(2, 2, StaticFilters.FILTER_PERMANENT, false); + targetName = "permanents that share a permanent type"; + } + + private TargetPermanentsThatShareCardType(final TargetPermanentsThatShareCardType target) { + super(target); + } + + @Override + public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { + if (super.canTarget(controllerId, id, source, game)) { + if (!getTargets().isEmpty()) { + Permanent targetOne = game.getPermanent(getTargets().get(0)); + Permanent targetTwo = game.getPermanent(id); + if (targetOne == null || targetTwo == null) { + return false; + } + return targetOne.shareTypes(targetTwo); + } + return true; + } + return false; + } + + @Override + public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { + Set cardTypes = new HashSet<>(); + MageObject targetSource = game.getObject(sourceId); + if (targetSource != null) { + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { + if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { + for (CardType cardType : permanent.getCardType()) { + if (cardTypes.contains(cardType)) { + return true; + } + } + cardTypes.addAll(permanent.getCardType()); + } + } + } + return false; + } + + @Override + public TargetPermanentsThatShareCardType copy() { + return new TargetPermanentsThatShareCardType(this); + } +} diff --git a/Mage.Sets/src/mage/cards/s/ShiftingLoyalties.java b/Mage.Sets/src/mage/cards/s/ShiftingLoyalties.java index 7cd05fd423..5c502625ee 100644 --- a/Mage.Sets/src/mage/cards/s/ShiftingLoyalties.java +++ b/Mage.Sets/src/mage/cards/s/ShiftingLoyalties.java @@ -1,9 +1,6 @@ package mage.cards.s; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.abilities.effects.common.continuous.ExchangeControlTargetEffect; @@ -11,19 +8,22 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; -import mage.filter.FilterPermanent; +import mage.filter.StaticFilters; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.TargetPermanent; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + /** - * * @author LevelX2 */ public final class ShiftingLoyalties extends CardImpl { public ShiftingLoyalties(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{5}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{5}{U}"); // Exchange control of two target permanents that share a card type. (Artifact, creature, enchantment, land, and planeswalker are card types.) this.getSpellAbility().addEffect(new ExchangeControlTargetEffect(Duration.EndOfGame, "Exchange control of two target permanents that share a card type. (Artifact, creature, enchantment, land, and planeswalker are card types.)")); @@ -31,7 +31,7 @@ public final class ShiftingLoyalties extends CardImpl { } - public ShiftingLoyalties(final ShiftingLoyalties card) { + private ShiftingLoyalties(final ShiftingLoyalties card) { super(card); } @@ -43,12 +43,12 @@ public final class ShiftingLoyalties extends CardImpl { class TargetPermanentsThatShareCardType extends TargetPermanent { - public TargetPermanentsThatShareCardType() { - super(2, 2, new FilterPermanent(), false); + TargetPermanentsThatShareCardType() { + super(2, 2, StaticFilters.FILTER_PERMANENT, false); targetName = "permanents that share a card type"; } - public TargetPermanentsThatShareCardType(final TargetPermanentsThatShareCardType target) { + private TargetPermanentsThatShareCardType(final TargetPermanentsThatShareCardType target) { super(target); } @@ -72,7 +72,7 @@ class TargetPermanentsThatShareCardType extends TargetPermanent { public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { Set cardTypes = new HashSet<>(); MageObject targetSource = game.getObject(sourceId); - if(targetSource != null) { + if (targetSource != null) { for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { for (CardType cardType : permanent.getCardType()) { diff --git a/Mage.Sets/src/mage/sets/WarOfTheSpark.java b/Mage.Sets/src/mage/sets/WarOfTheSpark.java index a6f8571747..10423081df 100644 --- a/Mage.Sets/src/mage/sets/WarOfTheSpark.java +++ b/Mage.Sets/src/mage/sets/WarOfTheSpark.java @@ -93,6 +93,7 @@ public final class WarOfTheSpark extends ExpansionSet { cards.add(new SetCardInfo("Ravnica at War", 28, Rarity.RARE, mage.cards.r.RavnicaAtWar.class)); cards.add(new SetCardInfo("Relentless Advance", 64, Rarity.COMMON, mage.cards.r.RelentlessAdvance.class)); cards.add(new SetCardInfo("Rising Populace", 29, Rarity.COMMON, mage.cards.r.RisingPopulace.class)); + cards.add(new SetCardInfo("Role Reversal", 214, Rarity.RARE, mage.cards.r.RoleReversal.class)); cards.add(new SetCardInfo("Samut's Sprint", 142, Rarity.COMMON, mage.cards.s.SamutsSprint.class)); cards.add(new SetCardInfo("Samut, Tyrant Smasher", 235, Rarity.UNCOMMON, mage.cards.s.SamutTyrantSmasher.class)); cards.add(new SetCardInfo("Sorin's Thirst", 104, Rarity.COMMON, mage.cards.s.SorinsThirst.class)); diff --git a/Mage/src/main/java/mage/MageObject.java b/Mage/src/main/java/mage/MageObject.java index cb1812c44f..7497a44573 100644 --- a/Mage/src/main/java/mage/MageObject.java +++ b/Mage/src/main/java/mage/MageObject.java @@ -153,13 +153,18 @@ public interface MageObject extends MageItem, Serializable { * @return */ default boolean shareTypes(Card otherCard) { + return this.shareTypes(otherCard, false); + } + + default boolean shareTypes(Card otherCard, boolean permanentOnly) { if (otherCard == null) { throw new IllegalArgumentException("Params can't be null"); } for (CardType type : getCardType()) { - if (otherCard.getCardType().contains(type)) { + if (otherCard.getCardType().contains(type) + && (!permanentOnly || type.isPermanentType())) { return true; } }