diff --git a/Mage.Sets/src/mage/cards/m/ModifyMemory.java b/Mage.Sets/src/mage/cards/m/ModifyMemory.java new file mode 100644 index 0000000000..aaa41a8fb6 --- /dev/null +++ b/Mage.Sets/src/mage/cards/m/ModifyMemory.java @@ -0,0 +1,105 @@ +package mage.cards.m; + +import mage.abilities.Ability; +import mage.abilities.condition.Condition; +import mage.abilities.decorator.ConditionalOneShotEffect; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +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.common.FilterCreaturePermanent; +import mage.game.Controllable; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.target.Target; +import mage.target.common.TargetCreaturePermanent; +import mage.target.targetpointer.EachTargetPointer; + +import java.util.Collection; +import java.util.Objects; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class ModifyMemory extends CardImpl { + + public ModifyMemory(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{4}{U}"); + + // Exchange control of two target creatures controlled by different players. If you control neither creature, draw three cards. + this.getSpellAbility().addEffect(new ExchangeControlTargetEffect( + Duration.Custom, "exchange control of two target creatures controlled by different players" + ).setTargetPointer(new EachTargetPointer())); + this.getSpellAbility().addEffect(new ConditionalOneShotEffect( + new DrawCardSourceControllerEffect(3), ModifyMemoryCondition.instance, + "If you control neither creature, draw three cards" + )); + this.getSpellAbility().addTarget(new ModifyMemoryTarget()); + } + + private ModifyMemory(final ModifyMemory card) { + super(card); + } + + @Override + public ModifyMemory copy() { + return new ModifyMemory(this); + } +} + +enum ModifyMemoryCondition implements Condition { + instance; + + @Override + public boolean apply(Game game, Ability source) { + return source + .getTargets() + .stream() + .map(Target::getTargets) + .flatMap(Collection::stream) + .map(game::getPermanentOrLKIBattlefield) + .filter(Objects::nonNull) + .map(Controllable::getControllerId) + .noneMatch(source::isControlledBy); + } +} + +class ModifyMemoryTarget extends TargetCreaturePermanent { + + private static final FilterCreaturePermanent filter + = new FilterCreaturePermanent("creatures controlled by different players"); + + ModifyMemoryTarget() { + super(2, 2, filter, false); + } + + private ModifyMemoryTarget(final ModifyMemoryTarget target) { + super(target); + } + + @Override + public ModifyMemoryTarget copy() { + return new ModifyMemoryTarget(this); + } + + @Override + public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { + if (!super.canTarget(controllerId, id, source, game)) { + return false; + } + Permanent creature = game.getPermanent(id); + if (creature == null) { + return false; + } + return this.getTargets() + .stream() + .map(game::getPermanent) + .filter(Objects::nonNull) + .noneMatch(permanent -> !creature.getId().equals(permanent.getId()) + && creature.isControlledBy(permanent.getControllerId()) + ); + } +} diff --git a/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java b/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java index 422a5e5c0f..c4db76e77d 100644 --- a/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java +++ b/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java @@ -360,6 +360,7 @@ public final class CommanderLegendsBattleForBaldursGate extends ExpansionSet { cards.add(new SetCardInfo("Mirror Entity", 701, Rarity.RARE, mage.cards.m.MirrorEntity.class)); cards.add(new SetCardInfo("Mizzium Mortars", 803, Rarity.RARE, mage.cards.m.MizziumMortars.class)); cards.add(new SetCardInfo("Mocking Doppelganger", 667, Rarity.RARE, mage.cards.m.MockingDoppelganger.class)); + cards.add(new SetCardInfo("Modify Memory", 83, Rarity.UNCOMMON, mage.cards.m.ModifyMemory.class)); cards.add(new SetCardInfo("Mold Folk", 133, Rarity.COMMON, mage.cards.m.MoldFolk.class)); cards.add(new SetCardInfo("Monster Manual", 242, Rarity.RARE, mage.cards.m.MonsterManual.class)); cards.add(new SetCardInfo("Moonshae Pixie", 84, Rarity.UNCOMMON, mage.cards.m.MoonshaePixie.class));