"Above the Battlement"

This commit is contained in:
marcins78@gmail.com
2011-11-07 16:20:02 +00:00
parent 7d27c0bf78
commit ca70685d8c
4 changed files with 191 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ import com.gempukku.lotro.logic.timing.Effect;
import com.gempukku.lotro.logic.timing.EffectResult;
import com.gempukku.lotro.logic.timing.results.*;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -213,6 +214,16 @@ public class PlayConditions {
return Filters.filter(game.getGameState().getDeadPile(playerId), game.getGameState(), game.getModifiersQuerying(), Filters.and(filters, Filters.playable(game))).size() > 0;
}
public static boolean canPlayFromStacked(String playerId, LotroGame game, Filterable stackedOn, Filterable... filters) {
final Collection<PhysicalCard> matchingStackedOn = Filters.filterActive(game.getGameState(), game.getModifiersQuerying(), stackedOn);
for (PhysicalCard stackedOnCard : matchingStackedOn) {
if (Filters.filter(game.getGameState().getStackedCards(stackedOnCard), game.getGameState(), game.getModifiersQuerying(), Filters.and(filters, Filters.playable(game))).size() > 0)
return true;
}
return false;
}
public static boolean canPlayFromDiscard(String playerId, LotroGame game, Filterable... filters) {
if (game.getModifiersQuerying().hasFlagActive(game.getGameState(), ModifierFlag.CANT_PLAY_FROM_DISCARD_OR_DECK))
return false;

View File

@@ -0,0 +1,95 @@
package com.gempukku.lotro.cards.effects.choose;
import com.gempukku.lotro.cards.actions.PlayPermanentAction;
import com.gempukku.lotro.common.Filterable;
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.ArbitraryCardsSelectionDecision;
import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException;
import com.gempukku.lotro.logic.timing.Action;
import com.gempukku.lotro.logic.timing.Effect;
import com.gempukku.lotro.logic.timing.EffectResult;
import java.util.*;
public class ChooseAndPlayCardFromStackedEffect implements Effect {
private String _playerId;
private Filterable _stackedOn;
private Filter _filter;
private int _twilightModifier;
private Action _playCardAction;
public ChooseAndPlayCardFromStackedEffect(String playerId, Filterable stackedOn, Filterable... filter) {
this(playerId, stackedOn, 0, filter);
}
public ChooseAndPlayCardFromStackedEffect(String playerId, Filterable stackedOn, int twilightModifier, Filterable... filter) {
_playerId = playerId;
_stackedOn = stackedOn;
_filter = Filters.and(filter);
_twilightModifier = twilightModifier;
}
@Override
public String getText(LotroGame game) {
return "Play card from stacked";
}
@Override
public boolean isPlayableInFull(LotroGame game) {
return getPlayableFromStacked(game).size() > 0;
}
@Override
public Type getType() {
return null;
}
private Collection<PhysicalCard> getPlayableFromStacked(LotroGame game) {
Set<PhysicalCard> possibleCards = new HashSet<PhysicalCard>();
for (PhysicalCard stackedOnCard : Filters.filterActive(game.getGameState(), game.getModifiersQuerying(), _stackedOn))
possibleCards.addAll(Filters.filter(game.getGameState().getStackedCards(stackedOnCard), game.getGameState(), game.getModifiersQuerying(), _filter, Filters.playable(game, _twilightModifier)));
return possibleCards;
}
@Override
public Collection<? extends EffectResult> playEffect(final LotroGame game) {
Collection<PhysicalCard> playableFromStacked = getPlayableFromStacked(game);
if (playableFromStacked.size() > 0) {
game.getUserFeedback().sendAwaitingDecision(_playerId,
new ArbitraryCardsSelectionDecision(1, "Choose a card to play", new LinkedList<PhysicalCard>(playableFromStacked), 1, 1) {
@Override
public void decisionMade(String result) throws DecisionResultInvalidException {
List<PhysicalCard> selectedCards = getSelectedCardsByResponse(result);
if (selectedCards.size() > 0) {
PhysicalCard selectedCard = selectedCards.get(0);
_playCardAction = selectedCard.getBlueprint().getPlayCardAction(_playerId, game, selectedCard, _twilightModifier);
game.getActionsEnvironment().addActionToStack(_playCardAction);
}
}
});
}
return null;
}
@Override
public boolean wasSuccessful() {
if (_playCardAction == null)
return false;
if (_playCardAction instanceof PlayPermanentAction)
return ((PlayPermanentAction) _playCardAction).wasSuccessful();
return true;
}
@Override
public boolean wasCarriedOut() {
if (_playCardAction == null)
return false;
if (_playCardAction instanceof PlayPermanentAction)
return ((PlayPermanentAction) _playCardAction).wasCarriedOut();
return true;
}
}

View File

@@ -0,0 +1,84 @@
package com.gempukku.lotro.cards.set7.sauron;
import com.gempukku.lotro.cards.AbstractEvent;
import com.gempukku.lotro.cards.PlayConditions;
import com.gempukku.lotro.cards.actions.PlayEventAction;
import com.gempukku.lotro.cards.effects.ChoiceEffect;
import com.gempukku.lotro.cards.effects.RemoveBurdenEffect;
import com.gempukku.lotro.cards.effects.choose.ChooseAndPlayCardFromDiscardEffect;
import com.gempukku.lotro.cards.effects.choose.ChooseAndPlayCardFromStackedEffect;
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 com.gempukku.lotro.logic.timing.Effect;
import com.gempukku.lotro.logic.timing.UnrespondableEffect;
import java.util.LinkedList;
import java.util.List;
/**
* Set: The Return of the King
* Side: Shadow
* Culture: Sauron
* Twilight Cost: 0
* Type: Event • Shadow
* Game Text: Play a bieseger stacked on a site you control or remove a burden to play a [SAURON] Orc from your discard
* pile.
*/
public class Card7_262 extends AbstractEvent {
public Card7_262() {
super(Side.SHADOW, 0, Culture.SAURON, "Above the Battlement", Phase.SHADOW);
}
@Override
public boolean checkPlayRequirements(String playerId, LotroGame game, PhysicalCard self, int twilightModifier) {
return super.checkPlayRequirements(playerId, game, self, twilightModifier)
&& (
(PlayConditions.canRemoveBurdens(game, self, 1)
&& PlayConditions.canPlayFromDiscard(playerId, game, Culture.SAURON, Race.ORC)
)
|| PlayConditions.canPlayFromStacked(playerId, game, Filters.siteControlled(playerId), Keyword.BESIEGER));
}
@Override
public PlayEventAction getPlayCardAction(final String playerId, LotroGame game, final PhysicalCard self, int twilightModifier) {
final PlayEventAction action = new PlayEventAction(self);
List<Effect> possibleCosts = new LinkedList<Effect>();
if (PlayConditions.canPlayFromStacked(playerId, game, Filters.siteControlled(playerId), Keyword.BESIEGER))
possibleCosts.add(
new UnrespondableEffect() {
@Override
public String getText(LotroGame game) {
return "Play a besieger stacked on a site you control";
}
@Override
protected void doPlayEffect(LotroGame game) {
action.appendEffect(
new ChooseAndPlayCardFromStackedEffect(playerId, Filters.siteControlled(playerId), Keyword.BESIEGER));
}
});
if (PlayConditions.canRemoveBurdens(game, self, 1)
&& PlayConditions.canPlayFromDiscard(playerId, game, Culture.SAURON, Race.ORC))
possibleCosts.add(
new UnrespondableEffect() {
@Override
public String getText(LotroGame game) {
return "Remove a burden to play a SAURON Orc from your discard pile";
}
@Override
protected void doPlayEffect(LotroGame game) {
action.insertCost(
new RemoveBurdenEffect(self));
action.appendEffect(
new ChooseAndPlayCardFromDiscardEffect(playerId, game.getGameState().getDiscard(playerId), Culture.SAURON, Race.ORC));
}
});
action.appendCost(
new ChoiceEffect(action, playerId, possibleCosts));
return action;
}
}

View File

@@ -19,7 +19,7 @@ public enum Keyword implements Filterable {
DAMAGE("Damage", true, true), DEFENDER("Defender", true, true), AMBUSH("Ambush", true, true), FIERCE("Fierce", true), ARCHER("Archer", true),
UNHASTY("Unhasty", true), RANGER("Ranger", true), TRACKER("Tracker", true), VILLAGER("Villager", true), MACHINE("Machine", true), ENGINE("Engine", true),
SOUTHRON("Southron", true), EASTERLING("Easterling", true), VALIANT("Valiant", true), KNIGHT("Knight", true), FORTIFICATION("Fortification", true),
WARG_RIDER("Warg-rider", true);
WARG_RIDER("Warg-rider", true), BESIEGER("Besieger", true);
private String _humanReadable;
private boolean _infoDisplayable;