Simplifying choice effect

This commit is contained in:
marcins78@gmail.com
2011-08-29 13:29:18 +00:00
parent 7fadb1dd12
commit fe8b29a442
2 changed files with 32 additions and 38 deletions

View File

@@ -8,25 +8,24 @@ import com.gempukku.lotro.logic.timing.UnrespondableEffect;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
public class ChoiceCostEffect extends UnrespondableEffect { public class ChoiceEffect extends UnrespondableEffect {
private CostToEffectAction _action; private CostToEffectAction _action;
private String _choicePlayerId; private String _choicePlayerId;
private Map<EffectPreCondition, Effect> _preConditions; private List<Effect> _possibleEffects;
private boolean _addedAsCost; private boolean _addedAsCost;
public ChoiceCostEffect(CostToEffectAction action, String choicePlayerId, Map<EffectPreCondition, Effect> preConditions, boolean addedAsCost) { public ChoiceEffect(CostToEffectAction action, String choicePlayerId, List<Effect> possibleEffects, boolean addedAsCost) {
_action = action; _action = action;
_choicePlayerId = choicePlayerId; _choicePlayerId = choicePlayerId;
_preConditions = preConditions; _possibleEffects = possibleEffects;
_addedAsCost = addedAsCost; _addedAsCost = addedAsCost;
} }
@Override @Override
public boolean canPlayEffect(LotroGame game) { public boolean canPlayEffect(LotroGame game) {
for (EffectPreCondition effectPreCondition : _preConditions.keySet()) { for (Effect effect : _possibleEffects) {
boolean result = effectPreCondition.getResult(game); boolean result = effect.canPlayEffect(game);
if (result) if (result)
return true; return true;
} }
@@ -37,9 +36,9 @@ public class ChoiceCostEffect extends UnrespondableEffect {
@Override @Override
public void playEffect(LotroGame game) { public void playEffect(LotroGame game) {
final List<Effect> possibleEffects = new LinkedList<Effect>(); final List<Effect> possibleEffects = new LinkedList<Effect>();
for (Map.Entry<EffectPreCondition, Effect> entry : _preConditions.entrySet()) { for (Effect effect : _possibleEffects) {
if (entry.getKey().getResult(game)) if (effect.canPlayEffect(game))
possibleEffects.add(entry.getValue()); possibleEffects.add(effect);
} }
if (possibleEffects.size() > 1) { if (possibleEffects.size() > 1) {

View File

@@ -2,7 +2,10 @@ package com.gempukku.lotro.cards.set1.elven;
import com.gempukku.lotro.cards.AbstractAttachableFPPossession; import com.gempukku.lotro.cards.AbstractAttachableFPPossession;
import com.gempukku.lotro.cards.PlayConditions; import com.gempukku.lotro.cards.PlayConditions;
import com.gempukku.lotro.cards.effects.*; import com.gempukku.lotro.cards.effects.AddUntilEndOfPhaseModifierEffect;
import com.gempukku.lotro.cards.effects.ChoiceEffect;
import com.gempukku.lotro.cards.effects.ChooseAndDiscardCardFromHandEffect;
import com.gempukku.lotro.cards.effects.ExertCharacterEffect;
import com.gempukku.lotro.cards.modifiers.StrengthModifier; import com.gempukku.lotro.cards.modifiers.StrengthModifier;
import com.gempukku.lotro.common.Culture; import com.gempukku.lotro.common.Culture;
import com.gempukku.lotro.common.Keyword; import com.gempukku.lotro.common.Keyword;
@@ -18,10 +21,8 @@ import com.gempukku.lotro.logic.timing.Action;
import com.gempukku.lotro.logic.timing.Effect; import com.gempukku.lotro.logic.timing.Effect;
import com.gempukku.lotro.logic.timing.UnrespondableEffect; import com.gempukku.lotro.logic.timing.UnrespondableEffect;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Set: The Fellowship of the Ring * Set: The Fellowship of the Ring
@@ -57,24 +58,19 @@ public class Card1_047 extends AbstractAttachableFPPossession {
|| game.getGameState().getHand(playerId).size() >= 2)) { || game.getGameState().getHand(playerId).size() >= 2)) {
final CostToEffectAction action = new CostToEffectAction(self, "Exert Arwen or discard 2 cards from hand to make her Strength +1"); final CostToEffectAction action = new CostToEffectAction(self, "Exert Arwen or discard 2 cards from hand to make her Strength +1");
Map<EffectPreCondition, Effect> possibleCosts = new HashMap<EffectPreCondition, Effect>(); List<Effect> possibleCosts = new LinkedList<Effect>();
possibleCosts.put( possibleCosts.add(
new EffectPreCondition() { new ExertCharacterEffect(self.getAttachedTo()));
@Override possibleCosts.add(
public boolean getResult(LotroGame game) { new UnrespondableEffect() {
return PlayConditions.canExert(game.getGameState(), game.getModifiersQuerying(), self.getAttachedTo());
}
}, new ExertCharacterEffect(self.getAttachedTo()));
possibleCosts.put(
new EffectPreCondition() {
@Override
public boolean getResult(LotroGame game) {
return (game.getGameState().getHand(playerId).size() >= 2);
}
}, new UnrespondableEffect() {
@Override @Override
public String getText() { public String getText() {
return "Discard 2 cards from hand"; return "Discard 2 cards";
}
@Override
public boolean canPlayEffect(LotroGame game) {
return game.getGameState().getHand(playerId).size() >= 2;
} }
@Override @Override
@@ -82,11 +78,10 @@ public class Card1_047 extends AbstractAttachableFPPossession {
action.addCost(new ChooseAndDiscardCardFromHandEffect(action, playerId, true)); action.addCost(new ChooseAndDiscardCardFromHandEffect(action, playerId, true));
action.addCost(new ChooseAndDiscardCardFromHandEffect(action, playerId, true)); action.addCost(new ChooseAndDiscardCardFromHandEffect(action, playerId, true));
} }
} });
);
action.addCost( action.addCost(
new ChoiceCostEffect(action, playerId, possibleCosts, true)); new ChoiceEffect(action, playerId, possibleCosts, true));
action.addEffect( action.addEffect(
new AddUntilEndOfPhaseModifierEffect( new AddUntilEndOfPhaseModifierEffect(
new StrengthModifier(self, "Strength +1", Filters.sameCard(self.getAttachedTo()), 1), new StrengthModifier(self, "Strength +1", Filters.sameCard(self.getAttachedTo()), 1),