refactor: fully replace PermanentInListPredicate

with PermanentReferenceInCollectionPredicate

related to #10639, #11471, the existence of this was misleading devs to use it incorrectly
This commit is contained in:
xenohedron 2024-01-31 19:39:27 -05:00
parent c528491544
commit 4dd97b41fc
7 changed files with 30 additions and 59 deletions

View file

@ -14,7 +14,7 @@ import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.filter.common.FilterAttackingCreature;
import mage.filter.common.FilterBlockingCreature;
import mage.filter.predicate.permanent.PermanentInListPredicate;
import mage.filter.predicate.permanent.PermanentReferenceInCollectionPredicate;
import mage.game.Game;
import mage.game.combat.CombatGroup;
import mage.game.events.BlockerDeclaredEvent;
@ -111,7 +111,7 @@ class BalduvianWarlordUnblockEffect extends OneShotEffect {
Player targetsController = game.getPlayer(permanent.getControllerId());
if (targetsController != null) {
FilterAttackingCreature filter = new FilterAttackingCreature("creature attacking " + targetsController.getLogName());
filter.add(new PermanentInListPredicate(list));
filter.add(new PermanentReferenceInCollectionPredicate(list, game));
TargetPermanent target = new TargetPermanent(filter);
target.withNotTarget(true);
if (target.canChoose(controller.getId(), source, game)) {

View file

@ -1,4 +1,3 @@
package mage.cards.c;
import java.util.ArrayList;
@ -19,9 +18,9 @@ import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.PhaseStep;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.permanent.PermanentInListPredicate;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.PermanentReferenceInCollectionPredicate;
import mage.game.Game;
import mage.game.combat.CombatGroup;
import mage.game.events.BlockerDeclaredEvent;
@ -119,7 +118,7 @@ class CamouflageEffect extends ContinuousRuleModifyingEffectImpl {
spentBlockers.add(possibleBlocker);
}
}
filter.add(Predicates.not(new PermanentInListPredicate(spentBlockers)));
filter.add(Predicates.not(new PermanentReferenceInCollectionPredicate(spentBlockers, game)));
}
if (defender.chooseUse(Outcome.Neutral, "Make a new blocker pile? If not, all remaining piles stay empty. (remaining piles: " + (attackerCount - masterList.size()) + ')', source, game)) {
Target target = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, filter, true);

View file

@ -1,4 +1,3 @@
package mage.cards.d;
import java.util.ArrayList;
@ -18,7 +17,7 @@ import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.filter.common.FilterLandPermanent;
import mage.filter.predicate.permanent.PermanentInListPredicate;
import mage.filter.predicate.permanent.PermanentReferenceInCollectionPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.ManaPoolItem;
@ -112,7 +111,7 @@ class DrainPowerEffect extends OneShotEffect {
Permanent permanent;
if (permList.size() > 1 || target != null) {
FilterLandPermanent filter2 = new FilterLandPermanent("land you control to tap for mana (remaining: " + permList.size() + ')');
filter2.add(new PermanentInListPredicate(permList));
filter2.add(new PermanentReferenceInCollectionPredicate(permList, game));
target = new TargetPermanent(1, 1, filter2, true);
while (!target.isChosen() && target.canChoose(targetPlayer.getId(), source, game) && targetPlayer.canRespond()) {
targetPlayer.chooseTarget(Outcome.Neutral, target, source, game);

View file

@ -14,7 +14,7 @@ import mage.constants.PhaseStep;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterAttackingCreature;
import mage.filter.predicate.permanent.DefendingPlayerControlsNoSourcePredicate;
import mage.filter.predicate.permanent.PermanentInListPredicate;
import mage.filter.predicate.permanent.PermanentReferenceInCollectionPredicate;
import mage.game.Game;
import mage.game.combat.CombatGroup;
import mage.game.events.BlockerDeclaredEvent;
@ -125,7 +125,7 @@ class FalseOrdersUnblockEffect extends OneShotEffect {
return false;
}
FilterAttackingCreature filter = new FilterAttackingCreature("creature attacking " + targetsController.getLogName());
filter.add(new PermanentInListPredicate(list));
filter.add(new PermanentReferenceInCollectionPredicate(list, game));
TargetPermanent target = new TargetPermanent(filter);
target.withNotTarget(true);
if (target.canChoose(controller.getId(), source, game)) {

View file

@ -12,7 +12,7 @@ import mage.constants.CardType;
import mage.constants.Outcome;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.PermanentInListPredicate;
import mage.filter.predicate.permanent.PermanentReferenceInCollectionPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -66,30 +66,26 @@ class FellBeastsShriekEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<Permanent> creaturesChosen = new ArrayList<>();
// For each opponent, get the creature to tap+goad
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (controller.hasOpponent(playerId, game)) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
target.withNotTarget(true);
if (opponent.choose(Outcome.Detriment, target, source, game)) {
creaturesChosen.add(game.getPermanent(target.getTargets().get(0)));
}
}
if (controller == null) {
return false;
}
List<Permanent> creaturesChosen = new ArrayList<>();
// For each opponent, get the creature to tap+goad
for (UUID playerId : game.getOpponents(controller.getId())) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
target.withNotTarget(true);
if (opponent.choose(Outcome.Detriment, target, source, game)) {
creaturesChosen.add(game.getPermanent(target.getTargets().get(0)));
}
}
FilterPermanent filter = new FilterCreaturePermanent();
filter.add(new PermanentInListPredicate(creaturesChosen));
new TapAllEffect(filter).apply(game, source);
ContinuousEffect goadEffect = new GoadAllEffect(filter);
game.addEffect(goadEffect, source);
return true;
}
return false;
FilterPermanent filter = new FilterCreaturePermanent();
filter.add(new PermanentReferenceInCollectionPredicate(creaturesChosen, game));
new TapAllEffect(filter).apply(game, source);
ContinuousEffect goadEffect = new GoadAllEffect(filter);
game.addEffect(goadEffect, source);
return true;
}
}

View file

@ -1,25 +0,0 @@
package mage.filter.predicate.permanent;
import java.util.List;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author L_J
*/
public class PermanentInListPredicate implements Predicate<Permanent> {
private final List<Permanent> permanents;
public PermanentInListPredicate(List<Permanent> permanents) {
this.permanents = permanents;
}
@Override
public boolean apply(Permanent input, Game game) {
return (permanents.contains(input));
}
}

View file

@ -21,7 +21,9 @@ public class PermanentReferenceInCollectionPredicate implements Predicate<Perman
this.references = references;
}
public PermanentReferenceInCollectionPredicate(Collection<Permanent> permanents, Game game) {
this.references = permanents.stream().map((p) -> new MageObjectReference(p, game))
this.references = permanents
.stream()
.map(p -> new MageObjectReference(p, game))
.collect(Collectors.toSet());
}