* Proliferate - fixed that it highlights all permanents instead with counters only;

This commit is contained in:
Oleg Agafonov 2019-05-02 17:25:46 +04:00
parent a5ef712924
commit 3ff871c6de
7 changed files with 37 additions and 133 deletions

View file

@ -27,7 +27,8 @@ public final class GuildpactInformant extends CardImpl {
// Flying // Flying
this.addAbility(FlyingAbility.getInstance()); 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( this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(
new ProliferateEffect(), false new ProliferateEffect(), false
).setOrPlaneswalker(true)); ).setOrPlaneswalker(true));

View file

@ -1,4 +1,3 @@
package mage.abilities.common; package mage.abilities.common;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
@ -45,6 +44,7 @@ public class DealsCombatDamageToAPlayerTriggeredAbility extends TriggeredAbility
this.text = ability.text; this.text = ability.text;
this.setTargetPointer = ability.setTargetPointer; this.setTargetPointer = ability.setTargetPointer;
this.onlyOpponents = ability.onlyOpponents; this.onlyOpponents = ability.onlyOpponents;
this.orPlaneswalker = ability.orPlaneswalker;
} }
public DealsCombatDamageToAPlayerTriggeredAbility setOrPlaneswalker(boolean orPlaneswalker) { public DealsCombatDamageToAPlayerTriggeredAbility setOrPlaneswalker(boolean orPlaneswalker) {

View file

@ -4,11 +4,12 @@ import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.counters.Counter; import mage.counters.Counter;
import mage.filter.common.FilterPermanentOrPlayerWithCounter;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.Target; import mage.target.Target;
import mage.target.common.TargetPermanentOrPlayerWithCounter; import mage.target.common.TargetPermanentOrPlayer;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
@ -47,7 +48,7 @@ public class ProliferateEffect extends OneShotEffect {
if (controller == null) { if (controller == null) {
return false; return false;
} }
Target target = new TargetPermanentOrPlayerWithCounter(0, Integer.MAX_VALUE, true); Target target = new TargetPermanentOrPlayer(0, Integer.MAX_VALUE, new FilterPermanentOrPlayerWithCounter(), true);
Map<String, Serializable> options = new HashMap<>(); Map<String, Serializable> options = new HashMap<>();
options.put("UI.right.btn.text", "Done"); options.put("UI.right.btn.text", "Done");
controller.choose(Outcome.Benefit, target, source.getSourceId(), game, options); controller.choose(Outcome.Benefit, target, source.getSourceId(), game, options);

View file

@ -1,13 +1,11 @@
package mage.filter.common; package mage.filter.common;
import mage.MageItem;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import java.util.UUID; import java.util.UUID;
import mage.MageItem;
/** /**
* @author nantuko * @author nantuko
@ -28,24 +26,24 @@ public class FilterPermanentOrPlayerWithCounter extends FilterPermanentOrPlayer
@Override @Override
public boolean match(MageItem o, Game game) { public boolean match(MageItem o, Game game) {
if (o instanceof Player) { if (super.match(o, game)) {
if (((Player)o).getCounters().isEmpty()) { if (o instanceof Player) {
return false; return !((Player) o).getCounters().isEmpty();
} } else if (o instanceof Permanent) {
} else if (o instanceof Permanent) { return !((Permanent) o).getCounters(game).isEmpty();
if (((Permanent)o).getCounters(game).isEmpty()) {
return false;
} }
} }
return super.match(o, game); return false;
} }
@Override @Override
public boolean match(MageItem o, UUID sourceId, UUID playerId, Game game) { public boolean match(MageItem o, UUID sourceId, UUID playerId, Game game) {
if (o instanceof Player) { if (super.match(o, sourceId, playerId, game)) {
return playerFilter.match((Player) o, sourceId, playerId, game); if (o instanceof Player) {
} else if (o instanceof Permanent) { return !((Player) o).getCounters().isEmpty();
return permanentFilter.match((Permanent) o, sourceId, playerId, game); } else if (o instanceof Permanent) {
return !((Permanent) o).getCounters(game).isEmpty();
}
} }
return false; return false;
} }

View file

@ -8,23 +8,22 @@ package mage.target.common;
import mage.filter.common.FilterOpponentOrPlaneswalker; import mage.filter.common.FilterOpponentOrPlaneswalker;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public class TargetOpponentOrPlaneswalker extends TargetPermanentOrPlayer { public class TargetOpponentOrPlaneswalker extends TargetPermanentOrPlayer {
public TargetOpponentOrPlaneswalker() { public TargetOpponentOrPlaneswalker() {
this(1, 1, new FilterOpponentOrPlaneswalker("opponent or planeswalker"), false); this(1);
}
public TargetOpponentOrPlaneswalker(int numTargets) {
this(numTargets, numTargets, new FilterOpponentOrPlaneswalker(), false);
} }
public TargetOpponentOrPlaneswalker(FilterOpponentOrPlaneswalker filter) { public TargetOpponentOrPlaneswalker(FilterOpponentOrPlaneswalker filter) {
this(1, 1, filter, false); 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) { public TargetOpponentOrPlaneswalker(int minNumTargets, int maxNumTargets, FilterOpponentOrPlaneswalker filter, boolean notTarget) {
super(minNumTargets, maxNumTargets, filter, notTarget); super(minNumTargets, maxNumTargets, filter, notTarget);
} }

View file

@ -1,28 +1,26 @@
package mage.target.common; package mage.target.common;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.Filter; import mage.filter.Filter;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.StaticFilters;
import mage.filter.common.FilterPermanentOrPlayer; import mage.filter.common.FilterPermanentOrPlayer;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetImpl; import mage.target.TargetImpl;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/** /**
*
* @author nantuko * @author nantuko
*/ */
public class TargetPermanentOrPlayer extends TargetImpl { public class TargetPermanentOrPlayer extends TargetImpl {
protected FilterPermanentOrPlayer filter; protected FilterPermanentOrPlayer filter;
protected FilterPermanent filterPermanent;
public TargetPermanentOrPlayer() { public TargetPermanentOrPlayer() {
this(1, 1); this(1, 1);
@ -46,14 +44,12 @@ public class TargetPermanentOrPlayer extends TargetImpl {
this.zone = Zone.ALL; this.zone = Zone.ALL;
this.filter = filter; this.filter = filter;
this.targetName = filter.getMessage(); this.targetName = filter.getMessage();
this.filterPermanent = this.filter.getPermanentFilter();
this.notTarget = notTarget; this.notTarget = notTarget;
} }
public TargetPermanentOrPlayer(final TargetPermanentOrPlayer target) { public TargetPermanentOrPlayer(final TargetPermanentOrPlayer target) {
super(target); super(target);
this.filter = target.filter.copy(); this.filter = target.filter.copy();
this.filterPermanent = target.filterPermanent.copy();
} }
@Override @Override
@ -61,10 +57,6 @@ public class TargetPermanentOrPlayer extends TargetImpl {
return filter; return filter;
} }
public void setFilter(FilterPermanentOrPlayer filter) {
this.filter = filter;
}
@Override @Override
public boolean canTarget(UUID id, Game game) { public boolean canTarget(UUID id, Game game) {
Permanent permanent = game.getPermanent(id); 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 * {@link mage.players.Player} that can be chosen. Should only be used for
* Ability targets since this checks for protection, shroud etc. * 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 sourceControllerId - controller of the target event source
* @param game * @param game
* @return - true if enough valid {@link mage.game.permanent.Permanent} or * @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); MageObject targetSource = game.getObject(sourceId);
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) { for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
Player player = game.getPlayer(playerId); 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++; count++;
if (count >= this.minNumberOfTargets) { if (count >= this.minNumberOfTargets) {
return true; 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)) { if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
count++; count++;
if (count >= this.minNumberOfTargets) { 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)) { if (filter.match(permanent, null, sourceControllerId, game) && filter.match(permanent, game)) {
count++; count++;
if (count >= this.minNumberOfTargets) { if (count >= this.minNumberOfTargets) {
@ -187,11 +179,11 @@ public class TargetPermanentOrPlayer extends TargetImpl {
MageObject targetSource = game.getObject(sourceId); MageObject targetSource = game.getObject(sourceId);
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) { for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
Player player = game.getPlayer(playerId); 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); 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)) { if ((notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) && filter.match(permanent, sourceId, sourceControllerId, game)) {
possibleTargets.add(permanent.getId()); possibleTargets.add(permanent.getId());
} }
@ -204,11 +196,11 @@ public class TargetPermanentOrPlayer extends TargetImpl {
Set<UUID> possibleTargets = new HashSet<>(); Set<UUID> possibleTargets = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) { for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
if (player != null && filter.getPlayerFilter().match(player, game)) { if (player != null && filter.match(player, game)) {
possibleTargets.add(playerId); 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)) { if (filter.match(permanent, null, sourceControllerId, game)) {
possibleTargets.add(permanent.getId()); possibleTargets.add(permanent.getId());
} }
@ -237,6 +229,6 @@ public class TargetPermanentOrPlayer extends TargetImpl {
} }
public FilterPermanent getFilterPermanent() { public FilterPermanent getFilterPermanent() {
return filterPermanent.copy(); return filter.getPermanentFilter().copy();
} }
} }

View file

@ -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);
}
}