mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 21:42:07 -08:00
* Deals damage divided as you choose - fixed that some cards can't choose planeswalkers (example: Arc Lightning, see #7276);
Refactor: simplified FilterCreaturePlayerOrPlaneswalker to use single permanent filter;
This commit is contained in:
parent
347a3b1e1a
commit
255c292104
18 changed files with 162 additions and 222 deletions
|
|
@ -1,72 +1,48 @@
|
|||
package mage.filter.common;
|
||||
|
||||
import mage.MageItem;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.MageObject;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SubType;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.filter.predicate.Predicates;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* If you add predicate to permanentFilter then it will be applied to planeswalker too
|
||||
*
|
||||
* @author JRHerlehy Created on 4/8/18.
|
||||
*/
|
||||
public class FilterCreaturePlayerOrPlaneswalker extends FilterPermanentOrPlayer {
|
||||
|
||||
protected FilterCreaturePermanent creatureFilter;
|
||||
protected FilterPlaneswalkerPermanent planeswalkerFilter;
|
||||
|
||||
public FilterCreaturePlayerOrPlaneswalker() {
|
||||
this("any target");
|
||||
}
|
||||
|
||||
public FilterCreaturePlayerOrPlaneswalker(String name) {
|
||||
this(name, (SubType) null);
|
||||
}
|
||||
|
||||
public FilterCreaturePlayerOrPlaneswalker(String name, SubType... andCreatureTypes) {
|
||||
super(name);
|
||||
creatureFilter = new FilterCreaturePermanent();
|
||||
planeswalkerFilter = new FilterPlaneswalkerPermanent();
|
||||
List<Predicate<MageObject>> allCreaturePredicates = Arrays.stream(andCreatureTypes)
|
||||
.filter(Objects::nonNull)
|
||||
.map(SubType::getPredicate)
|
||||
.collect(Collectors.toList());
|
||||
allCreaturePredicates.add(0, CardType.CREATURE.getPredicate());
|
||||
Predicate<MageObject> planeswalkerPredicate = CardType.PLANESWALKER.getPredicate();
|
||||
|
||||
this.permanentFilter.add(Predicates.or(
|
||||
Predicates.and(allCreaturePredicates),
|
||||
planeswalkerPredicate
|
||||
));
|
||||
}
|
||||
|
||||
public FilterCreaturePlayerOrPlaneswalker(final FilterCreaturePlayerOrPlaneswalker filter) {
|
||||
super(filter);
|
||||
this.creatureFilter = filter.creatureFilter.copy();
|
||||
this.planeswalkerFilter = filter.planeswalkerFilter.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(MageItem o, Game game) {
|
||||
if (super.match(o, game)) {
|
||||
if (o instanceof Player) {
|
||||
return playerFilter.match((Player) o, game);
|
||||
} else if (o instanceof Permanent) {
|
||||
return creatureFilter.match((Permanent) o, game)
|
||||
|| planeswalkerFilter.match((Permanent) o, game);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(MageItem o, UUID sourceId, UUID playerId, Game game) {
|
||||
if (super.match(o, game)) { // process predicates
|
||||
if (o instanceof Player) {
|
||||
return playerFilter.match((Player) o, sourceId, playerId, game);
|
||||
} else if (o instanceof Permanent) {
|
||||
return creatureFilter.match((Permanent) o, sourceId, playerId, game)
|
||||
|| planeswalkerFilter.match((Permanent) o, sourceId, playerId, game);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public FilterCreaturePermanent getCreatureFilter() {
|
||||
return this.creatureFilter;
|
||||
}
|
||||
|
||||
public FilterPlaneswalkerPermanent getPlaneswalkerFilter() {
|
||||
return this.planeswalkerFilter;
|
||||
}
|
||||
|
||||
public void setCreatureFilter(FilterCreaturePermanent creatureFilter) {
|
||||
this.creatureFilter = creatureFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ public class TargetAnyTarget extends TargetImpl {
|
|||
}
|
||||
}
|
||||
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), 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) {
|
||||
|
|
@ -125,15 +125,6 @@ public class TargetAnyTarget extends TargetImpl {
|
|||
}
|
||||
}
|
||||
|
||||
for (Permanent planeswalker : game.getBattlefield().getActivePermanents(filter.getPlaneswalkerFilter(), sourceControllerId, game)) {
|
||||
if (planeswalker.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(planeswalker, sourceId, sourceControllerId, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +151,7 @@ public class TargetAnyTarget extends TargetImpl {
|
|||
}
|
||||
}
|
||||
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) {
|
||||
if (filter.match(permanent, null, sourceControllerId, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets) {
|
||||
|
|
@ -169,15 +160,6 @@ public class TargetAnyTarget extends TargetImpl {
|
|||
}
|
||||
}
|
||||
|
||||
for (Permanent planeswalker : game.getBattlefield().getActivePermanents(filter.getPlaneswalkerFilter(), sourceControllerId, game)) {
|
||||
if (filter.match(planeswalker, null, sourceControllerId, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -190,25 +172,18 @@ public class TargetAnyTarget extends TargetImpl {
|
|||
Player player = game.getPlayer(playerId);
|
||||
if (player != null
|
||||
&& player.canBeTargetedBy(targetSource, sourceControllerId, game)
|
||||
&& filter.getPlayerFilter().match(player, sourceId, sourceControllerId, game)) {
|
||||
&& filter.match(player, sourceId, sourceControllerId, game)) {
|
||||
possibleTargets.add(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)
|
||||
&& filter.getCreatureFilter().match(permanent, sourceId, sourceControllerId, game)) {
|
||||
&& filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
}
|
||||
|
||||
for (Permanent planeswalker : game.getBattlefield().getActivePermanents(filter.getPlaneswalkerFilter(), sourceControllerId, game)) {
|
||||
if (planeswalker.canBeTargetedBy(targetSource, sourceControllerId, game)
|
||||
&& filter.getPlaneswalkerFilter().match(planeswalker, sourceId, sourceControllerId, game)) {
|
||||
possibleTargets.add(planeswalker.getId());
|
||||
}
|
||||
}
|
||||
|
||||
return possibleTargets;
|
||||
}
|
||||
|
||||
|
|
@ -218,23 +193,17 @@ public class TargetAnyTarget extends TargetImpl {
|
|||
|
||||
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(filter.getCreatureFilter(), sourceControllerId, game)) {
|
||||
if (filter.getCreatureFilter().match(permanent, null, sourceControllerId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) {
|
||||
if (filter.getPermanentFilter().match(permanent, null, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
}
|
||||
|
||||
for (Permanent planeswalker : game.getBattlefield().getActivePermanents(filter.getPlaneswalkerFilter(), sourceControllerId, game)) {
|
||||
if (filter.getPlaneswalkerFilter().match(planeswalker, null, sourceControllerId, game)) {
|
||||
possibleTargets.add(planeswalker.getId());
|
||||
}
|
||||
}
|
||||
|
||||
return possibleTargets;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,23 +2,17 @@ package mage.target.common;
|
|||
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.common.FilterCreaturePlayerOrPlaneswalker;
|
||||
import mage.filter.common.FilterPermanentOrPlayer;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TargetAnyTargetAmount extends TargetPermanentOrPlayerAmount {
|
||||
|
||||
private static final FilterPermanentOrPlayer defaultFilter
|
||||
private static final FilterCreaturePlayerOrPlaneswalker defaultFilter
|
||||
= new FilterCreaturePlayerOrPlaneswalker("targets");
|
||||
|
||||
static {
|
||||
defaultFilter.getPermanentFilter().add(CardType.CREATURE.getPredicate());
|
||||
}
|
||||
|
||||
public TargetAnyTargetAmount(int amount) {
|
||||
this(amount, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package mage.target.common;
|
||||
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.common.FilterCreatureOrPlaneswalkerPermanent;
|
||||
|
||||
|
|
@ -16,18 +15,10 @@ public class TargetCreatureOrPlaneswalkerAmount extends TargetPermanentAmount {
|
|||
super(amount, defaultFilter);
|
||||
}
|
||||
|
||||
public TargetCreatureOrPlaneswalkerAmount(DynamicValue amount) {
|
||||
super(amount, defaultFilter);
|
||||
}
|
||||
|
||||
public TargetCreatureOrPlaneswalkerAmount(int amount, FilterPermanent filter) {
|
||||
super(amount, filter);
|
||||
}
|
||||
|
||||
public TargetCreatureOrPlaneswalkerAmount(DynamicValue amount, FilterPermanent filter) {
|
||||
super(amount, filter);
|
||||
}
|
||||
|
||||
private TargetCreatureOrPlaneswalkerAmount(final TargetCreatureOrPlaneswalkerAmount target) {
|
||||
super(target);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue