"Cunningly Hidden"

This commit is contained in:
marcins78@gmail.com
2012-01-03 11:07:32 +00:00
parent 53736545ba
commit 4529a2b51c
2 changed files with 116 additions and 21 deletions

View File

@@ -0,0 +1,111 @@
package com.gempukku.lotro.cards.effects.discount;
import com.gempukku.lotro.cards.effects.DiscountEffect;
import com.gempukku.lotro.common.Filterable;
import com.gempukku.lotro.common.Zone;
import com.gempukku.lotro.filters.Filters;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.GameUtils;
import com.gempukku.lotro.logic.decisions.ArbitraryCardsSelectionDecision;
import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException;
import com.gempukku.lotro.logic.decisions.YesNoDecision;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class RemoveCardsFromDiscardDiscountEffect implements DiscountEffect {
private PhysicalCard _source;
private String _playerId;
private int _count;
private Filterable _cardFilter;
private boolean _paid;
private boolean _required;
public RemoveCardsFromDiscardDiscountEffect(PhysicalCard source, String playerId, int count, Filterable cardFilter) {
_source = source;
_playerId = playerId;
_count = count;
_cardFilter = cardFilter;
}
@Override
public int getDiscountPaidFor() {
return _paid ? 1000 : 0;
}
@Override
public void setMinimalRequiredDiscount(int minimalDiscount) {
_required = (minimalDiscount > 0);
}
@Override
public String getText(LotroGame game) {
return null;
}
@Override
public Type getType() {
return null;
}
@Override
public boolean isPlayableInFull(LotroGame game) {
return Filters.filter(game.getGameState().getDiscard(_playerId), game.getGameState(), game.getModifiersQuerying(), _cardFilter).size() >= _count;
}
@Override
public void playEffect(final LotroGame game) {
if (isPlayableInFull(game)) {
if (!_required) {
game.getUserFeedback().sendAwaitingDecision(_playerId,
new YesNoDecision("Do you want to remove cards from discard instead of paying twilight cost?") {
@Override
protected void yes() {
proceedDiscount(game);
}
});
} else {
proceedDiscount(game);
}
}
}
private void proceedDiscount(final LotroGame game) {
final Collection<PhysicalCard> removableCards = Filters.filter(game.getGameState().getDiscard(_playerId), game.getGameState(), game.getModifiersQuerying(), _cardFilter);
game.getUserFeedback().sendAwaitingDecision(_playerId,
new ArbitraryCardsSelectionDecision(1, "Choose cards to remove", removableCards, _count, _count) {
@Override
public void decisionMade(String result) throws DecisionResultInvalidException {
removeCards(game, getSelectedCardsByResponse(result));
_paid = true;
}
});
}
private void removeCards(LotroGame game, List<PhysicalCard> cardsToRemove) {
Set<PhysicalCard> removedCards = new HashSet<PhysicalCard>();
for (PhysicalCard physicalCard : cardsToRemove)
if (physicalCard.getZone() == Zone.DISCARD)
removedCards.add(physicalCard);
game.getGameState().removeCardsFromZone(_playerId, removedCards);
for (PhysicalCard removedCard : removedCards)
game.getGameState().addCardToZone(game, removedCard, Zone.REMOVED);
game.getGameState().sendMessage(_playerId + " removed " + GameUtils.getAppendedNames(removedCards) + " from discard using " + GameUtils.getCardLink(_source));
}
@Override
public boolean wasSuccessful() {
return !_required || _paid;
}
@Override
public boolean wasCarriedOut() {
return _paid;
}
}

View File

@@ -3,9 +3,8 @@ package com.gempukku.lotro.cards.set13.gollum;
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.RemovePlayedEventFromGameEffect;
import com.gempukku.lotro.cards.effects.choose.ChooseAndAddUntilEOPStrengthBonusEffect;
import com.gempukku.lotro.cards.effects.choose.ChooseAndRemoveCardsFromDiscardEffect;
import com.gempukku.lotro.cards.effects.discount.RemoveCardsFromDiscardDiscountEffect;
import com.gempukku.lotro.common.CardType;
import com.gempukku.lotro.common.Culture;
import com.gempukku.lotro.common.Phase;
@@ -13,10 +12,6 @@ import com.gempukku.lotro.common.Side;
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.Action;
import java.util.Collections;
import java.util.List;
/**
* Set: Bloodlines
@@ -34,6 +29,8 @@ public class Card13_045 extends AbstractEvent {
@Override
public boolean checkPlayRequirements(String playerId, LotroGame game, PhysicalCard self, int withTwilightRemoved, int twilightModifier, boolean ignoreRoamingPenalty, boolean ignoreCheckingDeadPile) {
if (PlayConditions.canRemoveFromDiscardToPlay(self, game, playerId, 4, Culture.GOLLUM))
twilightModifier -= 1000;
return super.checkPlayRequirements(playerId, game, self, withTwilightRemoved, twilightModifier, ignoreRoamingPenalty, ignoreCheckingDeadPile)
&& PlayConditions.canSpot(game, Filters.gollum);
}
@@ -41,23 +38,10 @@ public class Card13_045 extends AbstractEvent {
@Override
public PlayEventAction getPlayCardAction(String playerId, LotroGame game, PhysicalCard self, int twilightModifier, boolean ignoreRoamingPenalty) {
PlayEventAction action = new PlayEventAction(self);
action.setDiscountEffect(
new RemoveCardsFromDiscardDiscountEffect(self, playerId, 4, Culture.GOLLUM));
action.appendEffect(
new ChooseAndAddUntilEOPStrengthBonusEffect(action, self, playerId, 2, CardType.MINION));
return action;
}
@Override
public List<? extends Action> getPhaseActionsFromDiscard(String playerId, LotroGame game, PhysicalCard self) {
if (PlayConditions.isPhase(game, Phase.SKIRMISH)
&& PlayConditions.canPlayFromDiscard(playerId, game, self)
&& PlayConditions.canRemoveFromDiscardToPlay(self, game, playerId, 4, Culture.GOLLUM)) {
final PlayEventAction action = getPlayCardAction(playerId, game, self, 0, false);
action.appendCost(
new ChooseAndRemoveCardsFromDiscardEffect(action, self, playerId, 4, 4, Culture.GOLLUM));
action.appendEffect(
new RemovePlayedEventFromGameEffect(action));
return Collections.singletonList(action);
}
return null;
}
}