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.List;
import java.util.Map;
public class ChoiceCostEffect extends UnrespondableEffect {
public class ChoiceEffect extends UnrespondableEffect {
private CostToEffectAction _action;
private String _choicePlayerId;
private Map<EffectPreCondition, Effect> _preConditions;
private List<Effect> _possibleEffects;
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;
_choicePlayerId = choicePlayerId;
_preConditions = preConditions;
_possibleEffects = possibleEffects;
_addedAsCost = addedAsCost;
}
@Override
public boolean canPlayEffect(LotroGame game) {
for (EffectPreCondition effectPreCondition : _preConditions.keySet()) {
boolean result = effectPreCondition.getResult(game);
for (Effect effect : _possibleEffects) {
boolean result = effect.canPlayEffect(game);
if (result)
return true;
}
@@ -37,9 +36,9 @@ public class ChoiceCostEffect extends UnrespondableEffect {
@Override
public void playEffect(LotroGame game) {
final List<Effect> possibleEffects = new LinkedList<Effect>();
for (Map.Entry<EffectPreCondition, Effect> entry : _preConditions.entrySet()) {
if (entry.getKey().getResult(game))
possibleEffects.add(entry.getValue());
for (Effect effect : _possibleEffects) {
if (effect.canPlayEffect(game))
possibleEffects.add(effect);
}
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.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.common.Culture;
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.UnrespondableEffect;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* Set: The Fellowship of the Ring
@@ -57,24 +58,19 @@ public class Card1_047 extends AbstractAttachableFPPossession {
|| 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");
Map<EffectPreCondition, Effect> possibleCosts = new HashMap<EffectPreCondition, Effect>();
possibleCosts.put(
new EffectPreCondition() {
@Override
public boolean getResult(LotroGame game) {
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() {
List<Effect> possibleCosts = new LinkedList<Effect>();
possibleCosts.add(
new ExertCharacterEffect(self.getAttachedTo()));
possibleCosts.add(
new UnrespondableEffect() {
@Override
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
@@ -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 ChoiceCostEffect(action, playerId, possibleCosts, true));
new ChoiceEffect(action, playerId, possibleCosts, true));
action.addEffect(
new AddUntilEndOfPhaseModifierEffect(
new StrengthModifier(self, "Strength +1", Filters.sameCard(self.getAttachedTo()), 1),