Refactoring Filters.accepts to mirror the signature of Filters.acceptsAny
This commit is contained in:
@@ -63,7 +63,8 @@ public class ActivatedFromStackedEffectProcessor implements EffectProcessor {
|
||||
actionSource.addPlayRequirement(
|
||||
(actionContext) -> {
|
||||
PhysicalCard stackedOnCard = actionContext.getSource().getStackedOn();
|
||||
return stackedOnCard != null && Filters.accepts(actionContext.getGame(), stackedOnFilterableSource.getFilterable(actionContext), stackedOnCard);
|
||||
return stackedOnCard != null && Filters.accepts(actionContext.getGame(), stackedOnCard,
|
||||
stackedOnFilterableSource.getFilterable(actionContext));
|
||||
}
|
||||
);
|
||||
EffectUtils.processRequirementsCostsAndEffects(value, environment, actionSource);
|
||||
|
||||
@@ -20,7 +20,7 @@ public class ExtraPossessionClassEffectProcessor implements EffectProcessor {
|
||||
(game, self, attachedTo) -> {
|
||||
DefaultActionContext actionContext = new DefaultActionContext(self.getOwner(), game, self, null, null);
|
||||
final Filterable attachedFilterable = attachedFilterableSource.getFilterable(actionContext);
|
||||
return Filters.accepts(game, attachedFilterable, attachedTo);
|
||||
return Filters.accepts(game, attachedTo, attachedFilterable);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,8 @@ public class ModifyOwnCost implements EffectProcessor {
|
||||
return 0;
|
||||
|
||||
if (target != null) {
|
||||
if (!Filters.accepts(actionContext.getGame(), onFilterableSource.getFilterable(actionContext), target))
|
||||
if (!Filters.accepts(actionContext.getGame(), target,
|
||||
onFilterableSource.getFilterable(actionContext)))
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -550,7 +550,7 @@ public class ValueResolver {
|
||||
int count = 0;
|
||||
for (PhysicalCard physicalCard : game.getGameState().getDeck(deckPlayer)) {
|
||||
count++;
|
||||
if (Filters.accepts(game, filterable, physicalCard))
|
||||
if (Filters.accepts(game, physicalCard, filterable))
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ModifyPlayOnCost implements ModifierSourceProducer {
|
||||
RequirementCondition.createCondition(conditions, actionContext), ModifierEffect.TWILIGHT_COST_MODIFIER) {
|
||||
@Override
|
||||
public int getTwilightCostModifier(LotroGame game, PhysicalCard physicalCard, PhysicalCard target, boolean ignoreRoamingPenalty) {
|
||||
if (target != null && Filters.accepts(game, onFilterable, target))
|
||||
if (target != null && Filters.accepts(game, target, onFilterable))
|
||||
return evaluator.evaluateExpression(game, null);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Location implements RequirementProducer {
|
||||
final Filterable filterable = filterableSource.getFilterable(actionContext);
|
||||
final LotroGame game = actionContext.getGame();
|
||||
final PhysicalCard currentSite = game.getGameState().getCurrentSite();
|
||||
return Filters.accepts(game, filterable, currentSite);
|
||||
return Filters.accepts(game, currentSite, filterable);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,8 @@ public class Discarded implements TriggerCheckerProducer {
|
||||
return false;
|
||||
|
||||
if (result && bySource != null) {
|
||||
if (source == null || !Filters.accepts(actionContext.getGame(), bySource.getFilterable(actionContext), source))
|
||||
if (source == null || !Filters.accepts(actionContext.getGame(), source,
|
||||
bySource.getFilterable(actionContext)))
|
||||
result = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class RevealedCardFromHand implements TriggerCheckerProducer {
|
||||
return false;
|
||||
final Filterable filterable = filterableSource.getFilterable(actionContext);
|
||||
final PhysicalCard revealedCard = revealCardFromHandResult.getRevealedCard();
|
||||
return Filters.accepts(actionContext.getGame(), filterable, revealedCard);
|
||||
return Filters.accepts(actionContext.getGame(), revealedCard, filterable);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class RevealsCardFromTopOfDrawDeck implements TriggerCheckerProducer {
|
||||
RevealCardFromTopOfDeckResult revealCardFromTopOfDeckResult = (RevealCardFromTopOfDeckResult) actionContext.getEffectResult();
|
||||
final Filterable filterable = filterableSource.getFilterable(actionContext);
|
||||
final PhysicalCard revealedCard = revealCardFromTopOfDeckResult.getRevealedCard();
|
||||
return Filters.accepts(actionContext.getGame(), filterable, revealedCard);
|
||||
return Filters.accepts(actionContext.getGame(), revealedCard, filterable);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SiteControlled implements TriggerCheckerProducer {
|
||||
if(playerId != null && !takeResult.getPlayerId().equals(playerId))
|
||||
return false;
|
||||
|
||||
return Filters.accepts(actionContext.getGame(), siteFilter, takeResult.getSite());
|
||||
return Filters.accepts(actionContext.getGame(), takeResult.getSite(), siteFilter);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SiteLiberated implements TriggerCheckerProducer {
|
||||
if(playerId != null && !takeResult.getPlayerId().equals(playerId))
|
||||
return false;
|
||||
|
||||
return Filters.accepts(actionContext.getGame(), siteFilter, takeResult.getSite());
|
||||
return Filters.accepts(actionContext.getGame(), takeResult.getSite(), siteFilter);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -38,7 +38,8 @@ public class TakesWound implements TriggerCheckerProducer {
|
||||
final boolean result = TriggerConditions.forEachWounded(actionContext.getGame(), actionContext.getEffectResult(), filterable);
|
||||
if(result && !source.equals("any")) {
|
||||
var sources = ((WoundResult) actionContext.getEffectResult()).getSources();
|
||||
if (sources.stream().noneMatch(woundSource -> Filters.accepts(actionContext.getGame(), sourceFilterable, woundSource))) {
|
||||
if (sources.stream().noneMatch(woundSource -> Filters.accepts(actionContext.getGame(), woundSource,
|
||||
sourceFilterable))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class WinsSkirmish implements TriggerCheckerProducer {
|
||||
private boolean checkResult(EffectResult effectResult, LotroGame game, Filterable winnerFilter, Filterable againstFilter) {
|
||||
if (effectResult.getType() == EffectResult.Type.CHARACTER_WON_SKIRMISH) {
|
||||
CharacterWonSkirmishResult wonResult = (CharacterWonSkirmishResult) effectResult;
|
||||
return Filters.accepts(game, winnerFilter, wonResult.getWinner())
|
||||
return Filters.accepts(game, wonResult.getWinner(), winnerFilter)
|
||||
&& Filters.acceptsAny(game, wonResult.getInvolving(), againstFilter);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -699,8 +699,9 @@ public class Filters {
|
||||
};
|
||||
}
|
||||
|
||||
public static boolean accepts(LotroGame game, Filterable filterable, PhysicalCard physicalCard) {
|
||||
return changeToFilter(filterable).accepts(game, physicalCard);
|
||||
public static boolean accepts(LotroGame game, PhysicalCard card, Filterable... filterable) {
|
||||
Filter filter = and(filterable);
|
||||
return filter.accepts(game, card);
|
||||
}
|
||||
|
||||
public static boolean acceptsAny(LotroGame game, Iterable<? extends PhysicalCard> cards, Filterable... filterable) {
|
||||
|
||||
@@ -15,6 +15,6 @@ public class MayNotBePlayedOnModifier extends AbstractModifier {
|
||||
|
||||
@Override
|
||||
public boolean canHavePlayedOn(LotroGame game, PhysicalCard playedCard, PhysicalCard target) {
|
||||
return !Filters.accepts(game, _unplayableCardFilter, playedCard);
|
||||
return !Filters.accepts(game, playedCard, _unplayableCardFilter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class TriggerConditions {
|
||||
public static boolean losesSkirmishInvolving(LotroGame game, EffectResult effectResult, Filterable loserFilter, Filterable involvingFilter) {
|
||||
if (effectResult.getType() == EffectResult.Type.CHARACTER_LOST_SKIRMISH) {
|
||||
CharacterLostSkirmishResult wonResult = (CharacterLostSkirmishResult) effectResult;
|
||||
return Filters.accepts(game, loserFilter, wonResult.getLoser())
|
||||
return Filters.accepts(game, wonResult.getLoser(), loserFilter)
|
||||
&& Filters.acceptsAny(game, wonResult.getInvolving(), involvingFilter);
|
||||
}
|
||||
return false;
|
||||
@@ -70,7 +70,7 @@ public class TriggerConditions {
|
||||
var tokenResult = (AddCultureTokenResult) effectResult;
|
||||
if (playerId != null && !playerId.equals(tokenResult.getPerformingPlayer()))
|
||||
return false;
|
||||
return Filters.accepts(game, from, tokenResult.getSource())
|
||||
return Filters.accepts(game, tokenResult.getSource(), from)
|
||||
&& Filters.and(targetFilters).accepts(game, tokenResult.getTarget());
|
||||
}
|
||||
return false;
|
||||
@@ -81,7 +81,7 @@ public class TriggerConditions {
|
||||
var tokenResult = (RemoveCultureTokenResult) effectResult;
|
||||
if (playerId != null && !playerId.equals(tokenResult.getPerformingPlayer()))
|
||||
return false;
|
||||
return Filters.accepts(game, from, tokenResult.getSource())
|
||||
return Filters.accepts(game, tokenResult.getSource(), from)
|
||||
&& Filters.and(targetFilters).accepts(game, tokenResult.getTarget());
|
||||
}
|
||||
return false;
|
||||
@@ -162,7 +162,7 @@ public class TriggerConditions {
|
||||
if (effectResult.getType() == EffectResult.Type.FOR_EACH_DISCARDED_FROM_HAND) {
|
||||
DiscardCardFromHandResult discardResult = (DiscardCardFromHandResult) effectResult;
|
||||
if (discardResult.getSource() != null
|
||||
&& Filters.accepts(game, discardedBy, discardResult.getSource()))
|
||||
&& Filters.accepts(game, discardResult.getSource(), discardedBy))
|
||||
return Filters.and(discarded).accepts(game, discardResult.getDiscardedCard());
|
||||
}
|
||||
return false;
|
||||
@@ -174,11 +174,11 @@ public class TriggerConditions {
|
||||
var wounded = woundResult.getWoundedCard();
|
||||
|
||||
return Filters.acceptsAny(game, woundResult.getSources(), woundedBy) &&
|
||||
Filters.and(filters).accepts(game, woundResult.getWoundedCard()) &&
|
||||
Filters.accepts(game, woundResult.getWoundedCard(), filters) &&
|
||||
(
|
||||
(Filters.or(CardType.ALLY, CardType.COMPANION).accepts(game, wounded) &&
|
||||
wounded.getZone() == Zone.DEAD) ||
|
||||
(Filters.accepts(game, CardType.MINION, wounded) &&
|
||||
(Filters.accepts(game, wounded, CardType.MINION) &&
|
||||
wounded.getZone() != Zone.SHADOW_CHARACTERS)
|
||||
);
|
||||
}
|
||||
@@ -211,7 +211,7 @@ public class TriggerConditions {
|
||||
if (effectResult.getType() == EffectResult.Type.FOR_EACH_EXERTED) {
|
||||
ExertResult exertResult = (ExertResult) effectResult;
|
||||
if (exertResult.getAction().getActionSource() != null
|
||||
&& Filters.accepts(game, exertedBy, exertResult.getAction().getActionSource()))
|
||||
&& Filters.accepts(game, exertResult.getAction().getActionSource(), exertedBy))
|
||||
return Filters.and(exerted).accepts(game, exertResult.getExertedCard());
|
||||
}
|
||||
return false;
|
||||
@@ -313,7 +313,7 @@ public class TriggerConditions {
|
||||
if (killedBy != Filters.any && (killers == null || killers.isEmpty() || killers.stream().allMatch(Objects::isNull)))
|
||||
return false;
|
||||
|
||||
return Filters.acceptsAny(game, killResult.getKillers(), killedBy) &&
|
||||
return Filters.acceptsAny(game, killers, killedBy) &&
|
||||
Filters.and(killed).accepts(game, killResult.getKilledCard());
|
||||
}
|
||||
return false;
|
||||
@@ -361,7 +361,7 @@ public class TriggerConditions {
|
||||
public static boolean isGettingDiscardedBy(Effect effect, LotroGame game, Filterable sourceFilter, Filterable... filters) {
|
||||
if (effect.getType() == Effect.Type.BEFORE_DISCARD_FROM_PLAY) {
|
||||
PreventableCardEffect preventableEffect = (PreventableCardEffect) effect;
|
||||
if (effect.getSource() != null && Filters.accepts(game, sourceFilter, effect.getSource()))
|
||||
if (effect.getSource() != null && Filters.accepts(game, effect.getSource(), sourceFilter))
|
||||
return Filters.acceptsAny(game, preventableEffect.getAffectedCardsMinusPrevented(game), filters);
|
||||
}
|
||||
return false;
|
||||
@@ -370,7 +370,7 @@ public class TriggerConditions {
|
||||
public static boolean isGettingDiscardedByOpponent(Effect effect, LotroGame game, String playerId, Filterable sourceFilter, Filterable... filters) {
|
||||
if (effect.getType() == Effect.Type.BEFORE_DISCARD_FROM_PLAY) {
|
||||
PreventableCardEffect preventableEffect = (PreventableCardEffect) effect;
|
||||
if (effect.getSource() != null && Filters.accepts(game, sourceFilter, effect.getSource())
|
||||
if (effect.getSource() != null && Filters.accepts(game, effect.getSource(), sourceFilter)
|
||||
&& !effect.getPerformingPlayer().equals(playerId))
|
||||
return Filters.acceptsAny(game, preventableEffect.getAffectedCardsMinusPrevented(game), filters);
|
||||
}
|
||||
@@ -398,11 +398,11 @@ public class TriggerConditions {
|
||||
final var zone = playResult.getPlayedFrom();
|
||||
|
||||
if (targetFilter != null && targetFilter != Filters.any &&
|
||||
(attachedTo == null || !Filters.accepts(game, targetFilter, attachedTo)))
|
||||
(attachedTo == null || !Filters.accepts(game, attachedTo, targetFilter)))
|
||||
return false;
|
||||
|
||||
if(fromFilter != null && fromFilter != Filters.any && cardPlayedFrom != null
|
||||
&& !Filters.accepts(game, fromFilter, cardPlayedFrom))
|
||||
&& !Filters.accepts(game, cardPlayedFrom, fromFilter))
|
||||
return false;
|
||||
|
||||
if(fromZone != null && zone != fromZone)
|
||||
@@ -444,9 +444,9 @@ public class TriggerConditions {
|
||||
public static boolean transferredCard(LotroGame game, EffectResult effectResult, Filterable transferredCard, Filterable transferredFrom, Filterable transferredTo) {
|
||||
if (effectResult.getType() == EffectResult.Type.CARD_TRANSFERRED) {
|
||||
CardTransferredResult transferResult = (CardTransferredResult) effectResult;
|
||||
return (Filters.accepts(game, transferredCard, transferResult.getTransferredCard())
|
||||
&& (transferredFrom == null || (transferResult.getTransferredFrom() != null && Filters.accepts(game, transferredFrom, transferResult.getTransferredFrom())))
|
||||
&& (transferredTo == null || (transferResult.getTransferredTo() != null && Filters.accepts(game, transferredTo, transferResult.getTransferredTo()))));
|
||||
return (Filters.accepts(game, transferResult.getTransferredCard(), transferredCard)
|
||||
&& (transferredFrom == null || (transferResult.getTransferredFrom() != null && Filters.accepts(game, transferResult.getTransferredFrom(), transferredFrom)))
|
||||
&& (transferredTo == null || (transferResult.getTransferredTo() != null && Filters.accepts(game, transferResult.getTransferredTo(), transferredTo))));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user