Fixing issues with single card being returned
This commit is contained in:
@@ -59,6 +59,8 @@ public class DefaultActionContext implements ActionContext {
|
||||
@Override
|
||||
public PhysicalCard getCardFromMemory(String memory) {
|
||||
final Collection<PhysicalCard> physicalCards = cardMemory.get(memory);
|
||||
if (physicalCards.size() == 0)
|
||||
return null;
|
||||
if (physicalCards.size() != 1)
|
||||
throw new RuntimeException("Unable to retrieve one card from memory: " + memory);
|
||||
return physicalCards.iterator().next();
|
||||
|
||||
@@ -31,7 +31,7 @@ public class PreventCardEffectAppender implements EffectAppenderProducer {
|
||||
new DelayedAppender() {
|
||||
@Override
|
||||
protected Effect createEffect(boolean cost, CostToEffectAction action, ActionContext actionContext) {
|
||||
return new PreventCardEffect((PreventableCardEffect) actionContext.getEffect(), actionContext.getCardFromMemory(memory));
|
||||
return new PreventCardEffect((PreventableCardEffect) actionContext.getEffect(), Filters.in(actionContext.getCardsFromMemory(memory)));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.gempukku.lotro.cards.build.field.effect.appender.resolver.CardResolve
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import com.gempukku.lotro.logic.actions.CostToEffectAction;
|
||||
import com.gempukku.lotro.logic.effects.ReplaceInSkirmishEffect;
|
||||
import com.gempukku.lotro.logic.timing.DoNothingEffect;
|
||||
import com.gempukku.lotro.logic.timing.Effect;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -32,7 +33,10 @@ public class ReplaceInSkirmish implements EffectAppenderProducer {
|
||||
@Override
|
||||
protected Effect createEffect(boolean cost, CostToEffectAction action, ActionContext actionContext) {
|
||||
final PhysicalCard card = actionContext.getCardFromMemory("_temp");
|
||||
return new ReplaceInSkirmishEffect(card, filterableSource.getFilterable(actionContext));
|
||||
if (card != null)
|
||||
return new ReplaceInSkirmishEffect(card, filterableSource.getFilterable(actionContext));
|
||||
else
|
||||
return new DoNothingEffect();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -39,14 +39,17 @@ public class StackCardsFromDiscard implements EffectAppenderProducer {
|
||||
@Override
|
||||
protected List<? extends Effect> createEffects(boolean cost, CostToEffectAction action, ActionContext actionContext) {
|
||||
final PhysicalCard card = actionContext.getCardFromMemory("_temp1");
|
||||
final Collection<? extends PhysicalCard> cardsInDiscard = actionContext.getCardsFromMemory("_temp2");
|
||||
if (card != null) {
|
||||
final Collection<? extends PhysicalCard> cardsInDiscard = actionContext.getCardsFromMemory("_temp2");
|
||||
|
||||
List<Effect> result = new LinkedList<>();
|
||||
for (PhysicalCard physicalCard : cardsInDiscard) {
|
||||
result.add(new StackCardFromDiscardEffect(physicalCard, card));
|
||||
List<Effect> result = new LinkedList<>();
|
||||
for (PhysicalCard physicalCard : cardsInDiscard) {
|
||||
result.add(new StackCardFromDiscardEffect(physicalCard, card));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -39,14 +39,17 @@ public class StackCardsFromHand implements EffectAppenderProducer {
|
||||
@Override
|
||||
protected List<? extends Effect> createEffects(boolean cost, CostToEffectAction action, ActionContext actionContext) {
|
||||
final PhysicalCard card = actionContext.getCardFromMemory("_temp1");
|
||||
final Collection<? extends PhysicalCard> cardsInHand = actionContext.getCardsFromMemory("_temp2");
|
||||
if (card != null) {
|
||||
final Collection<? extends PhysicalCard> cardsInHand = actionContext.getCardsFromMemory("_temp2");
|
||||
|
||||
List<Effect> result = new LinkedList<>();
|
||||
for (PhysicalCard physicalCard : cardsInHand) {
|
||||
result.add(new StackCardFromHandEffect(physicalCard, card));
|
||||
List<Effect> result = new LinkedList<>();
|
||||
for (PhysicalCard physicalCard : cardsInHand) {
|
||||
result.add(new StackCardFromHandEffect(physicalCard, card));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -43,14 +43,17 @@ public class StackCardsFromPlay implements EffectAppenderProducer {
|
||||
@Override
|
||||
protected List<? extends Effect> createEffects(boolean cost, CostToEffectAction action, ActionContext actionContext) {
|
||||
final PhysicalCard card = actionContext.getCardFromMemory("_temp1");
|
||||
final Collection<? extends PhysicalCard> cardsInHand = actionContext.getCardsFromMemory("_temp2");
|
||||
if (card != null) {
|
||||
final Collection<? extends PhysicalCard> cardsInHand = actionContext.getCardsFromMemory("_temp2");
|
||||
|
||||
List<Effect> result = new LinkedList<>();
|
||||
for (PhysicalCard physicalCard : cardsInHand) {
|
||||
result.add(new StackCardFromPlayEffect(physicalCard, card));
|
||||
List<Effect> result = new LinkedList<>();
|
||||
for (PhysicalCard physicalCard : cardsInHand) {
|
||||
result.add(new StackCardFromPlayEffect(physicalCard, card));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.gempukku.lotro.cards.build.field.effect.appender.resolver.CardResolve
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import com.gempukku.lotro.logic.actions.CostToEffectAction;
|
||||
import com.gempukku.lotro.logic.effects.StackPlayedEventOnACardEffect;
|
||||
import com.gempukku.lotro.logic.timing.DoNothingEffect;
|
||||
import com.gempukku.lotro.logic.timing.Effect;
|
||||
import com.gempukku.lotro.logic.timing.results.PlayEventResult;
|
||||
import org.json.simple.JSONObject;
|
||||
@@ -30,9 +31,11 @@ public class StackPlayedEvent implements EffectAppenderProducer {
|
||||
@Override
|
||||
protected Effect createEffect(boolean cost, CostToEffectAction action, ActionContext actionContext) {
|
||||
final PhysicalCard card = actionContext.getCardFromMemory("_temp1");
|
||||
|
||||
final PlayEventResult playEventResult = (PlayEventResult) actionContext.getEffectResult();
|
||||
return new StackPlayedEventOnACardEffect(playEventResult.getPlayEventAction(), card);
|
||||
if (card != null) {
|
||||
final PlayEventResult playEventResult = (PlayEventResult) actionContext.getEffectResult();
|
||||
return new StackPlayedEventOnACardEffect(playEventResult.getPlayEventAction(), card);
|
||||
} else
|
||||
return new DoNothingEffect();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.gempukku.lotro.cards.build.field.effect.appender.resolver.PlayerResol
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import com.gempukku.lotro.logic.actions.CostToEffectAction;
|
||||
import com.gempukku.lotro.logic.effects.StackTopCardsFromDeckEffect;
|
||||
import com.gempukku.lotro.logic.timing.DoNothingEffect;
|
||||
import com.gempukku.lotro.logic.timing.Effect;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -36,9 +37,12 @@ public class StackTopCardsOfDrawDeck implements EffectAppenderProducer {
|
||||
@Override
|
||||
protected Effect createEffect(boolean cost, CostToEffectAction action, ActionContext actionContext) {
|
||||
final PhysicalCard card = actionContext.getCardFromMemory(cardMemory);
|
||||
final String deckId = playerSource.getPlayer(actionContext);
|
||||
if (card != null) {
|
||||
final String deckId = playerSource.getPlayer(actionContext);
|
||||
|
||||
return new StackTopCardsFromDeckEffect(actionContext.getSource(), deckId, count, card);
|
||||
return new StackTopCardsFromDeckEffect(actionContext.getSource(), deckId, count, card);
|
||||
} else
|
||||
return new DoNothingEffect();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.gempukku.lotro.cards.build.field.effect.appender.resolver;
|
||||
import com.gempukku.lotro.cards.build.CardGenerationEnvironment;
|
||||
import com.gempukku.lotro.cards.build.InvalidCardDefinitionException;
|
||||
import com.gempukku.lotro.cards.build.PlayerSource;
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import com.gempukku.lotro.logic.GameUtils;
|
||||
|
||||
public class PlayerResolver {
|
||||
@@ -17,7 +18,14 @@ public class PlayerResolver {
|
||||
return ((actionContext) -> actionContext.getGame().getGameState().getCurrentPlayerId());
|
||||
else if (type.startsWith("ownerFromMemory(") && type.endsWith(")")) {
|
||||
String memory = type.substring(type.indexOf("(") + 1, type.lastIndexOf(")"));
|
||||
return (actionContext) -> actionContext.getCardFromMemory(memory).getOwner();
|
||||
return (actionContext) -> {
|
||||
final PhysicalCard cardFromMemory = actionContext.getCardFromMemory(memory);
|
||||
if (cardFromMemory != null)
|
||||
return cardFromMemory.getOwner();
|
||||
else
|
||||
// Sensible default
|
||||
return actionContext.getPerformingPlayer();
|
||||
};
|
||||
}
|
||||
throw new InvalidCardDefinitionException("Unable to resolve player resolver of type: " + type);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import com.gempukku.lotro.logic.GameUtils;
|
||||
import com.gempukku.lotro.logic.modifiers.evaluator.*;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class ValueResolver {
|
||||
public static ValueSource resolveEvaluator(Object value, int defaultValue, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
if (value == null)
|
||||
@@ -95,7 +97,11 @@ public class ValueResolver {
|
||||
final Keyword keyword = FieldUtils.getEnum(Keyword.class, object.get("keyword"), "keyword");
|
||||
return (actionContext) -> {
|
||||
final LotroGame game = actionContext.getGame();
|
||||
int count = game.getModifiersQuerying().getKeywordCount(game, actionContext.getCardFromMemory(memory), keyword);
|
||||
int count = 0;
|
||||
final Collection<? extends PhysicalCard> cardsFromMemory = actionContext.getCardsFromMemory(memory);
|
||||
for (PhysicalCard cardFromMemory : cardsFromMemory) {
|
||||
count += game.getModifiersQuerying().getKeywordCount(game, cardFromMemory, keyword);
|
||||
}
|
||||
return new ConstantEvaluator(count);
|
||||
};
|
||||
} else if (type.equalsIgnoreCase("limit")) {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.gempukku.lotro.logic.timing;
|
||||
|
||||
import com.gempukku.lotro.game.state.LotroGame;
|
||||
|
||||
public class DoNothingEffect extends UnrespondableEffect {
|
||||
@Override
|
||||
protected void doPlayEffect(LotroGame game) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user