"Dwarven Foresight"

This commit is contained in:
marcins78@gmail.com
2011-10-06 16:19:53 +00:00
parent 058b616fc7
commit e1edc87af9
3 changed files with 130 additions and 2 deletions

View File

@@ -0,0 +1,76 @@
package com.gempukku.lotro.cards.effects;
import com.gempukku.lotro.filters.Filter;
import com.gempukku.lotro.filters.Filters;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.decisions.CardsSelectionDecision;
import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException;
import com.gempukku.lotro.logic.timing.AbstractEffect;
import com.gempukku.lotro.logic.timing.Action;
import com.gempukku.lotro.logic.timing.EffectResult;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public abstract class ChooseStackedCardsEffect extends AbstractEffect {
private Action _action;
private String _playerId;
private int _minimum;
private int _maximum;
private Filter _stackedOnFilter;
private Filter _stackedCardFilter;
public ChooseStackedCardsEffect(Action action, String playerId, int minimum, int maximum, Filter stackedOnFilter, Filter stackedCardFilter) {
_action = action;
_playerId = playerId;
_minimum = minimum;
_maximum = maximum;
_stackedOnFilter = stackedOnFilter;
_stackedCardFilter = stackedCardFilter;
}
@Override
public EffectResult.Type getType() {
return null;
}
@Override
public String getText(LotroGame game) {
return "Choose stacked card";
}
@Override
public boolean isPlayableInFull(LotroGame game) {
return Filters.countActive(game.getGameState(), game.getModifiersQuerying(), _stackedOnFilter, Filters.hasStacked(_stackedCardFilter)) > 0;
}
@Override
protected FullEffectResult playEffectReturningResult(final LotroGame game) {
List<PhysicalCard> stackedCards = new LinkedList<PhysicalCard>();
for (PhysicalCard stackedOnCard : Filters.filterActive(game.getGameState(), game.getModifiersQuerying(), _stackedOnFilter))
stackedCards.addAll(Filters.filter(game.getGameState().getStackedCards(stackedOnCard), game.getGameState(), game.getModifiersQuerying(), _stackedCardFilter));
final boolean success = stackedCards.size() >= _minimum;
if (stackedCards.size() <= _minimum) {
cardsChosen(stackedCards);
} else {
game.getUserFeedback().sendAwaitingDecision(_playerId,
new CardsSelectionDecision(1, "Choose card(s)", stackedCards, _minimum, _maximum) {
@Override
public void decisionMade(String result) throws DecisionResultInvalidException {
Set<PhysicalCard> stackedCards = getSelectedCardsByResponse(result);
cardsChosen(stackedCards);
}
});
}
return new FullEffectResult(null, success, success);
}
protected abstract void cardsChosen(Collection<PhysicalCard> stackedCards);
}

View File

@@ -33,8 +33,8 @@ public class PutCardFromStackedIntoHandEffect extends AbstractEffect {
@Override
protected FullEffectResult playEffectReturningResult(LotroGame game) {
if (game.getModifiersQuerying().canDrawCardAndIncrement(game.getGameState(), _card.getOwner())
&& _card.getZone() == Zone.STACKED) {
if (_card.getZone() == Zone.STACKED
&& game.getModifiersQuerying().canDrawCardAndIncrement(game.getGameState(), _card.getOwner())) {
GameState gameState = game.getGameState();
gameState.sendMessage(_card.getOwner() + " puts " + GameUtils.getCardLink(_card) + " from stacked on another card into his or her hand");
gameState.removeCardFromZone(_card);

View File

@@ -0,0 +1,52 @@
package com.gempukku.lotro.cards.set4.dwarven;
import com.gempukku.lotro.cards.AbstractEvent;
import com.gempukku.lotro.cards.actions.PlayEventAction;
import com.gempukku.lotro.cards.effects.ChooseStackedCardsEffect;
import com.gempukku.lotro.cards.effects.PutCardFromStackedIntoHandEffect;
import com.gempukku.lotro.common.*;
import com.gempukku.lotro.filters.Filters;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import java.util.Collection;
/**
* Set: The Two Towers
* Side: Free
* Culture: Dwarven
* Twilight Cost: 0
* Type: Event
* Game Text: Fellowship: Spot a Dwarf to take a Free Peoples card stacked on a [DWARVEN] condition into hand.
*/
public class Card4_045 extends AbstractEvent {
public Card4_045() {
super(Side.FREE_PEOPLE, Culture.DWARVEN, "Dwarven Foresight", Phase.FELLOWSHIP);
}
@Override
public boolean checkPlayRequirements(String playerId, LotroGame game, PhysicalCard self, int twilightModifier) {
return super.checkPlayRequirements(playerId, game, self, twilightModifier)
&& Filters.canSpot(game.getGameState(), game.getModifiersQuerying(), Filters.race(Race.DWARF));
}
@Override
public PlayEventAction getPlayCardAction(String playerId, LotroGame game, PhysicalCard self, int twilightModifier) {
final PlayEventAction action = new PlayEventAction(self);
action.appendEffect(
new ChooseStackedCardsEffect(action, playerId, 1, 1, Filters.and(Filters.culture(Culture.DWARVEN), Filters.type(CardType.CONDITION)), Filters.side(Side.FREE_PEOPLE)) {
@Override
protected void cardsChosen(Collection<PhysicalCard> stackedCards) {
for (PhysicalCard card : stackedCards)
action.insertEffect(
new PutCardFromStackedIntoHandEffect(card));
}
});
return action;
}
@Override
public int getTwilightCost() {
return 0;
}
}