From 3ff871c6de6fe87c0bb96aafa58ebcc4bc74f50c Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Thu, 2 May 2019 17:25:46 +0400 Subject: [PATCH] * Proliferate - fixed that it highlights all permanents instead with counters only; --- .../src/mage/cards/g/GuildpactInformant.java | 3 +- ...CombatDamageToAPlayerTriggeredAbility.java | 2 +- .../common/counter/ProliferateEffect.java | 5 +- .../FilterPermanentOrPlayerWithCounter.java | 28 +++--- .../common/TargetOpponentOrPlaneswalker.java | 11 ++- .../common/TargetPermanentOrPlayer.java | 34 +++----- .../TargetPermanentOrPlayerWithCounter.java | 87 ------------------- 7 files changed, 37 insertions(+), 133 deletions(-) delete mode 100644 Mage/src/main/java/mage/target/common/TargetPermanentOrPlayerWithCounter.java diff --git a/Mage.Sets/src/mage/cards/g/GuildpactInformant.java b/Mage.Sets/src/mage/cards/g/GuildpactInformant.java index 47d833255f3..564d26a6375 100644 --- a/Mage.Sets/src/mage/cards/g/GuildpactInformant.java +++ b/Mage.Sets/src/mage/cards/g/GuildpactInformant.java @@ -27,7 +27,8 @@ public final class GuildpactInformant extends CardImpl { // Flying this.addAbility(FlyingAbility.getInstance()); - // Whenever Guildpact Informant deals combat damage to a player or planeswalker, proliferate. (Choose any number of permanents and/or players, then give each another counter of each kind already there.) + // Whenever Guildpact Informant deals combat damage to a player or planeswalker, + // proliferate. (Choose any number of permanents and/or players, then give each another counter of each kind already there.) this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility( new ProliferateEffect(), false ).setOrPlaneswalker(true)); diff --git a/Mage/src/main/java/mage/abilities/common/DealsCombatDamageToAPlayerTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/DealsCombatDamageToAPlayerTriggeredAbility.java index acf69c2ba12..e05f4cf3bba 100644 --- a/Mage/src/main/java/mage/abilities/common/DealsCombatDamageToAPlayerTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/DealsCombatDamageToAPlayerTriggeredAbility.java @@ -1,4 +1,3 @@ - package mage.abilities.common; import mage.abilities.TriggeredAbilityImpl; @@ -45,6 +44,7 @@ public class DealsCombatDamageToAPlayerTriggeredAbility extends TriggeredAbility this.text = ability.text; this.setTargetPointer = ability.setTargetPointer; this.onlyOpponents = ability.onlyOpponents; + this.orPlaneswalker = ability.orPlaneswalker; } public DealsCombatDamageToAPlayerTriggeredAbility setOrPlaneswalker(boolean orPlaneswalker) { diff --git a/Mage/src/main/java/mage/abilities/effects/common/counter/ProliferateEffect.java b/Mage/src/main/java/mage/abilities/effects/common/counter/ProliferateEffect.java index 005e6c0712d..e82e3c94def 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/counter/ProliferateEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/counter/ProliferateEffect.java @@ -4,11 +4,12 @@ import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.constants.Outcome; import mage.counters.Counter; +import mage.filter.common.FilterPermanentOrPlayerWithCounter; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.Target; -import mage.target.common.TargetPermanentOrPlayerWithCounter; +import mage.target.common.TargetPermanentOrPlayer; import java.io.Serializable; import java.util.HashMap; @@ -47,7 +48,7 @@ public class ProliferateEffect extends OneShotEffect { if (controller == null) { return false; } - Target target = new TargetPermanentOrPlayerWithCounter(0, Integer.MAX_VALUE, true); + Target target = new TargetPermanentOrPlayer(0, Integer.MAX_VALUE, new FilterPermanentOrPlayerWithCounter(), true); Map options = new HashMap<>(); options.put("UI.right.btn.text", "Done"); controller.choose(Outcome.Benefit, target, source.getSourceId(), game, options); diff --git a/Mage/src/main/java/mage/filter/common/FilterPermanentOrPlayerWithCounter.java b/Mage/src/main/java/mage/filter/common/FilterPermanentOrPlayerWithCounter.java index 6f5dfa5dba4..16c0eb36233 100644 --- a/Mage/src/main/java/mage/filter/common/FilterPermanentOrPlayerWithCounter.java +++ b/Mage/src/main/java/mage/filter/common/FilterPermanentOrPlayerWithCounter.java @@ -1,13 +1,11 @@ - - package mage.filter.common; +import mage.MageItem; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; import java.util.UUID; -import mage.MageItem; /** * @author nantuko @@ -28,24 +26,24 @@ public class FilterPermanentOrPlayerWithCounter extends FilterPermanentOrPlayer @Override public boolean match(MageItem o, Game game) { - if (o instanceof Player) { - if (((Player)o).getCounters().isEmpty()) { - return false; - } - } else if (o instanceof Permanent) { - if (((Permanent)o).getCounters(game).isEmpty()) { - return false; + if (super.match(o, game)) { + if (o instanceof Player) { + return !((Player) o).getCounters().isEmpty(); + } else if (o instanceof Permanent) { + return !((Permanent) o).getCounters(game).isEmpty(); } } - return super.match(o, game); + return false; } @Override public boolean match(MageItem o, UUID sourceId, UUID playerId, Game game) { - if (o instanceof Player) { - return playerFilter.match((Player) o, sourceId, playerId, game); - } else if (o instanceof Permanent) { - return permanentFilter.match((Permanent) o, sourceId, playerId, game); + if (super.match(o, sourceId, playerId, game)) { + if (o instanceof Player) { + return !((Player) o).getCounters().isEmpty(); + } else if (o instanceof Permanent) { + return !((Permanent) o).getCounters(game).isEmpty(); + } } return false; } diff --git a/Mage/src/main/java/mage/target/common/TargetOpponentOrPlaneswalker.java b/Mage/src/main/java/mage/target/common/TargetOpponentOrPlaneswalker.java index ac89c3f5375..20f4fa974e2 100644 --- a/Mage/src/main/java/mage/target/common/TargetOpponentOrPlaneswalker.java +++ b/Mage/src/main/java/mage/target/common/TargetOpponentOrPlaneswalker.java @@ -8,23 +8,22 @@ package mage.target.common; import mage.filter.common.FilterOpponentOrPlaneswalker; /** - * * @author LevelX2 */ public class TargetOpponentOrPlaneswalker extends TargetPermanentOrPlayer { public TargetOpponentOrPlaneswalker() { - this(1, 1, new FilterOpponentOrPlaneswalker("opponent or planeswalker"), false); - } - - public TargetOpponentOrPlaneswalker(int numTargets) { - this(numTargets, numTargets, new FilterOpponentOrPlaneswalker(), false); + this(1); } public TargetOpponentOrPlaneswalker(FilterOpponentOrPlaneswalker filter) { this(1, 1, filter, false); } + public TargetOpponentOrPlaneswalker(int numTargets) { + this(numTargets, numTargets, new FilterOpponentOrPlaneswalker("opponent or planeswalker"), false); + } + public TargetOpponentOrPlaneswalker(int minNumTargets, int maxNumTargets, FilterOpponentOrPlaneswalker filter, boolean notTarget) { super(minNumTargets, maxNumTargets, filter, notTarget); } diff --git a/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayer.java b/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayer.java index 70dab46b02e..cee4973c4f8 100644 --- a/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayer.java +++ b/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayer.java @@ -1,28 +1,26 @@ package mage.target.common; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.constants.Zone; import mage.filter.Filter; import mage.filter.FilterPermanent; -import mage.filter.StaticFilters; import mage.filter.common.FilterPermanentOrPlayer; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.TargetImpl; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + /** - * * @author nantuko */ public class TargetPermanentOrPlayer extends TargetImpl { protected FilterPermanentOrPlayer filter; - protected FilterPermanent filterPermanent; public TargetPermanentOrPlayer() { this(1, 1); @@ -46,14 +44,12 @@ public class TargetPermanentOrPlayer extends TargetImpl { this.zone = Zone.ALL; this.filter = filter; this.targetName = filter.getMessage(); - this.filterPermanent = this.filter.getPermanentFilter(); this.notTarget = notTarget; } public TargetPermanentOrPlayer(final TargetPermanentOrPlayer target) { super(target); this.filter = target.filter.copy(); - this.filterPermanent = target.filterPermanent.copy(); } @Override @@ -61,10 +57,6 @@ public class TargetPermanentOrPlayer extends TargetImpl { return filter; } - public void setFilter(FilterPermanentOrPlayer filter) { - this.filter = filter; - } - @Override public boolean canTarget(UUID id, Game game) { Permanent permanent = game.getPermanent(id); @@ -118,7 +110,7 @@ public class TargetPermanentOrPlayer extends TargetImpl { * {@link mage.players.Player} that can be chosen. Should only be used for * Ability targets since this checks for protection, shroud etc. * - * @param sourceId - the target event source + * @param sourceId - the target event source * @param sourceControllerId - controller of the target event source * @param game * @return - true if enough valid {@link mage.game.permanent.Permanent} or @@ -130,14 +122,14 @@ public class TargetPermanentOrPlayer extends TargetImpl { MageObject targetSource = game.getObject(sourceId); for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) { Player player = game.getPlayer(playerId); - if (player != null && player.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.getPlayerFilter().match(player, sourceId, sourceControllerId, game)) { + if (player != null && player.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(player, sourceId, sourceControllerId, game)) { count++; if (count >= this.minNumberOfTargets) { return true; } } } - for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT, sourceControllerId, game)) { + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) { if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { count++; if (count >= this.minNumberOfTargets) { @@ -170,7 +162,7 @@ public class TargetPermanentOrPlayer extends TargetImpl { } } } - for (Permanent permanent : game.getBattlefield().getActivePermanents(filterPermanent, sourceControllerId, game)) { + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) { if (filter.match(permanent, null, sourceControllerId, game) && filter.match(permanent, game)) { count++; if (count >= this.minNumberOfTargets) { @@ -187,11 +179,11 @@ public class TargetPermanentOrPlayer extends TargetImpl { MageObject targetSource = game.getObject(sourceId); for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) { Player player = game.getPlayer(playerId); - if (player != null && (notTarget || player.canBeTargetedBy(targetSource, sourceControllerId, game)) && filter.getPlayerFilter().match(player, sourceId, sourceControllerId, game)) { + if (player != null && (notTarget || player.canBeTargetedBy(targetSource, sourceControllerId, game)) && filter.match(player, sourceId, sourceControllerId, game)) { possibleTargets.add(playerId); } } - for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterPermanent(), sourceControllerId, game)) { + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) { if ((notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) && filter.match(permanent, sourceId, sourceControllerId, game)) { possibleTargets.add(permanent.getId()); } @@ -204,11 +196,11 @@ public class TargetPermanentOrPlayer extends TargetImpl { Set possibleTargets = new HashSet<>(); for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) { Player player = game.getPlayer(playerId); - if (player != null && filter.getPlayerFilter().match(player, game)) { + if (player != null && filter.match(player, game)) { possibleTargets.add(playerId); } } - for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, sourceControllerId, game)) { + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) { if (filter.match(permanent, null, sourceControllerId, game)) { possibleTargets.add(permanent.getId()); } @@ -237,6 +229,6 @@ public class TargetPermanentOrPlayer extends TargetImpl { } public FilterPermanent getFilterPermanent() { - return filterPermanent.copy(); + return filter.getPermanentFilter().copy(); } } diff --git a/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayerWithCounter.java b/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayerWithCounter.java deleted file mode 100644 index d6a515991df..00000000000 --- a/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayerWithCounter.java +++ /dev/null @@ -1,87 +0,0 @@ - - -package mage.target.common; - -import mage.abilities.Ability; -import mage.filter.common.FilterPermanentOrPlayerWithCounter; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; -import java.util.UUID; -import mage.filter.FilterPermanent; -import mage.filter.predicate.permanent.CounterPredicate; - -/** - * - * @author nantuko - */ -public class TargetPermanentOrPlayerWithCounter extends TargetPermanentOrPlayer { - - protected final FilterPermanentOrPlayerWithCounter targetFilter; - - public TargetPermanentOrPlayerWithCounter() { - this(1, 1); - } - - public TargetPermanentOrPlayerWithCounter(int numTargets) { - this(numTargets, numTargets); - } - - public TargetPermanentOrPlayerWithCounter(int minNumTargets, int maxNumTargets) { - this(minNumTargets, maxNumTargets, false); - } - - public TargetPermanentOrPlayerWithCounter(int minNumTargets, int maxNumTargets, boolean notTarget) { - super(minNumTargets, maxNumTargets, notTarget); - this.targetFilter = new FilterPermanentOrPlayerWithCounter(); - this.filterPermanent = new FilterPermanent(); - this.filterPermanent.add(new CounterPredicate(null)); - this.targetName = targetFilter.getMessage(); - } - - public TargetPermanentOrPlayerWithCounter(final TargetPermanentOrPlayerWithCounter target) { - super(target); - this.targetFilter = target.targetFilter.copy(); - super.setFilter(this.targetFilter); - } - - @Override - public TargetPermanentOrPlayerWithCounter copy() { - return new TargetPermanentOrPlayerWithCounter(this); - } - - @Override - public boolean canTarget(UUID id, Game game) { - Permanent permanent = game.getPermanent(id); - if (permanent != null) { - if (permanent.getCounters(game).isEmpty()) { - return false; - } - } - Player player = game.getPlayer(id); - if (player != null) { - if (player.getCounters().isEmpty()) { - return false; - } - } - return super.canTarget(id, game); - } - - @Override - public boolean canTarget(UUID id, Ability source, Game game) { - Permanent permanent = game.getPermanent(id); - if (permanent != null) { - if (permanent.getCounters(game).isEmpty()) { - return false; - } - } - Player player = game.getPlayer(id); - if (player != null) { - if (player.getCounters().isEmpty()) { - return false; - } - } - return super.canTarget(id, source, game); - } - -}