mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
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:
parent
c528491544
commit
4dd97b41fc
7 changed files with 30 additions and 59 deletions
|
|
@ -14,7 +14,7 @@ import mage.cards.CardSetInfo;
|
||||||
import mage.constants.*;
|
import mage.constants.*;
|
||||||
import mage.filter.common.FilterAttackingCreature;
|
import mage.filter.common.FilterAttackingCreature;
|
||||||
import mage.filter.common.FilterBlockingCreature;
|
import mage.filter.common.FilterBlockingCreature;
|
||||||
import mage.filter.predicate.permanent.PermanentInListPredicate;
|
import mage.filter.predicate.permanent.PermanentReferenceInCollectionPredicate;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.combat.CombatGroup;
|
import mage.game.combat.CombatGroup;
|
||||||
import mage.game.events.BlockerDeclaredEvent;
|
import mage.game.events.BlockerDeclaredEvent;
|
||||||
|
|
@ -111,7 +111,7 @@ class BalduvianWarlordUnblockEffect extends OneShotEffect {
|
||||||
Player targetsController = game.getPlayer(permanent.getControllerId());
|
Player targetsController = game.getPlayer(permanent.getControllerId());
|
||||||
if (targetsController != null) {
|
if (targetsController != null) {
|
||||||
FilterAttackingCreature filter = new FilterAttackingCreature("creature attacking " + targetsController.getLogName());
|
FilterAttackingCreature filter = new FilterAttackingCreature("creature attacking " + targetsController.getLogName());
|
||||||
filter.add(new PermanentInListPredicate(list));
|
filter.add(new PermanentReferenceInCollectionPredicate(list, game));
|
||||||
TargetPermanent target = new TargetPermanent(filter);
|
TargetPermanent target = new TargetPermanent(filter);
|
||||||
target.withNotTarget(true);
|
target.withNotTarget(true);
|
||||||
if (target.canChoose(controller.getId(), source, game)) {
|
if (target.canChoose(controller.getId(), source, game)) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
package mage.cards.c;
|
package mage.cards.c;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -19,9 +18,9 @@ import mage.constants.Duration;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.constants.PhaseStep;
|
import mage.constants.PhaseStep;
|
||||||
import mage.filter.predicate.Predicates;
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.filter.predicate.permanent.PermanentInListPredicate;
|
|
||||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||||
import mage.filter.common.FilterCreaturePermanent;
|
import mage.filter.common.FilterCreaturePermanent;
|
||||||
|
import mage.filter.predicate.permanent.PermanentReferenceInCollectionPredicate;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.combat.CombatGroup;
|
import mage.game.combat.CombatGroup;
|
||||||
import mage.game.events.BlockerDeclaredEvent;
|
import mage.game.events.BlockerDeclaredEvent;
|
||||||
|
|
@ -119,7 +118,7 @@ class CamouflageEffect extends ContinuousRuleModifyingEffectImpl {
|
||||||
spentBlockers.add(possibleBlocker);
|
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)) {
|
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);
|
Target target = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, filter, true);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
package mage.cards.d;
|
package mage.cards.d;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -18,7 +17,7 @@ import mage.constants.CardType;
|
||||||
import mage.constants.Duration;
|
import mage.constants.Duration;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.filter.common.FilterLandPermanent;
|
import mage.filter.common.FilterLandPermanent;
|
||||||
import mage.filter.predicate.permanent.PermanentInListPredicate;
|
import mage.filter.predicate.permanent.PermanentReferenceInCollectionPredicate;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.players.ManaPoolItem;
|
import mage.players.ManaPoolItem;
|
||||||
|
|
@ -112,7 +111,7 @@ class DrainPowerEffect extends OneShotEffect {
|
||||||
Permanent permanent;
|
Permanent permanent;
|
||||||
if (permList.size() > 1 || target != null) {
|
if (permList.size() > 1 || target != null) {
|
||||||
FilterLandPermanent filter2 = new FilterLandPermanent("land you control to tap for mana (remaining: " + permList.size() + ')');
|
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);
|
target = new TargetPermanent(1, 1, filter2, true);
|
||||||
while (!target.isChosen() && target.canChoose(targetPlayer.getId(), source, game) && targetPlayer.canRespond()) {
|
while (!target.isChosen() && target.canChoose(targetPlayer.getId(), source, game) && targetPlayer.canRespond()) {
|
||||||
targetPlayer.chooseTarget(Outcome.Neutral, target, source, game);
|
targetPlayer.chooseTarget(Outcome.Neutral, target, source, game);
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import mage.constants.PhaseStep;
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
import mage.filter.common.FilterAttackingCreature;
|
import mage.filter.common.FilterAttackingCreature;
|
||||||
import mage.filter.predicate.permanent.DefendingPlayerControlsNoSourcePredicate;
|
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.Game;
|
||||||
import mage.game.combat.CombatGroup;
|
import mage.game.combat.CombatGroup;
|
||||||
import mage.game.events.BlockerDeclaredEvent;
|
import mage.game.events.BlockerDeclaredEvent;
|
||||||
|
|
@ -125,7 +125,7 @@ class FalseOrdersUnblockEffect extends OneShotEffect {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
FilterAttackingCreature filter = new FilterAttackingCreature("creature attacking " + targetsController.getLogName());
|
FilterAttackingCreature filter = new FilterAttackingCreature("creature attacking " + targetsController.getLogName());
|
||||||
filter.add(new PermanentInListPredicate(list));
|
filter.add(new PermanentReferenceInCollectionPredicate(list, game));
|
||||||
TargetPermanent target = new TargetPermanent(filter);
|
TargetPermanent target = new TargetPermanent(filter);
|
||||||
target.withNotTarget(true);
|
target.withNotTarget(true);
|
||||||
if (target.canChoose(controller.getId(), source, game)) {
|
if (target.canChoose(controller.getId(), source, game)) {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import mage.constants.CardType;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
import mage.filter.common.FilterCreaturePermanent;
|
import mage.filter.common.FilterCreaturePermanent;
|
||||||
import mage.filter.predicate.permanent.PermanentInListPredicate;
|
import mage.filter.predicate.permanent.PermanentReferenceInCollectionPredicate;
|
||||||
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;
|
||||||
|
|
@ -66,30 +66,26 @@ class FellBeastsShriekEffect extends OneShotEffect {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player controller = game.getPlayer(source.getControllerId());
|
Player controller = game.getPlayer(source.getControllerId());
|
||||||
if (controller != null) {
|
if (controller == null) {
|
||||||
List<Permanent> creaturesChosen = new ArrayList<>();
|
return false;
|
||||||
|
}
|
||||||
// For each opponent, get the creature to tap+goad
|
List<Permanent> creaturesChosen = new ArrayList<>();
|
||||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
// For each opponent, get the creature to tap+goad
|
||||||
if (controller.hasOpponent(playerId, game)) {
|
for (UUID playerId : game.getOpponents(controller.getId())) {
|
||||||
Player opponent = game.getPlayer(playerId);
|
Player opponent = game.getPlayer(playerId);
|
||||||
if (opponent != null) {
|
if (opponent != null) {
|
||||||
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
|
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
|
||||||
target.withNotTarget(true);
|
target.withNotTarget(true);
|
||||||
if (opponent.choose(Outcome.Detriment, target, source, game)) {
|
if (opponent.choose(Outcome.Detriment, target, source, game)) {
|
||||||
creaturesChosen.add(game.getPermanent(target.getTargets().get(0)));
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -21,7 +21,9 @@ public class PermanentReferenceInCollectionPredicate implements Predicate<Perman
|
||||||
this.references = references;
|
this.references = references;
|
||||||
}
|
}
|
||||||
public PermanentReferenceInCollectionPredicate(Collection<Permanent> permanents, Game game) {
|
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());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue