Fixing how permanents are played.

This commit is contained in:
marcins78@gmail.com
2011-09-05 22:15:41 +00:00
parent 9ee8672097
commit 4f06198ff5
2 changed files with 110 additions and 11 deletions

View File

@@ -1,29 +1,127 @@
package com.gempukku.lotro.cards.actions;
import com.gempukku.lotro.cards.effects.*;
import com.gempukku.lotro.common.Keyword;
import com.gempukku.lotro.common.Zone;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.logic.actions.DefaultCostToEffectAction;
import com.gempukku.lotro.logic.actions.CostToEffectAction;
import com.gempukku.lotro.logic.effects.TriggeringEffect;
import com.gempukku.lotro.logic.timing.Effect;
import com.gempukku.lotro.logic.timing.results.PlayCardResult;
public class PlayPermanentAction extends DefaultCostToEffectAction {
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class PlayPermanentAction implements CostToEffectAction {
private PhysicalCard _source;
private Iterator<Effect> _preCostIterator;
private List<Effect> _costs = new ArrayList<Effect>();
private int _nextCostIndex;
private Effect _putCardIntoPlayEffect;
private boolean _cardPutIntoPlay;
private Effect _playCardEffect;
private boolean _cardPlayed;
private List<Effect> _effects = new ArrayList<Effect>();
private int _nextEffectIndex;
private Effect _discardCardEffect;
private boolean _cardDiscarded;
public PlayPermanentAction(PhysicalCard card, Zone zone) {
this(card, zone, 0);
}
public PlayPermanentAction(PhysicalCard card, Zone zone, int twilightModifier) {
super(card, null, "Play " + card.getBlueprint().getName());
_source = card;
addCost(new RemoveCardFromZoneEffect(card));
addCost(new PayTwilightCostEffect(card, twilightModifier));
addEffect(new PutCardIntoPlayEffect(card, zone));
List<Effect> preCostEffects = new LinkedList<Effect>();
preCostEffects.add(new RemoveCardFromZoneEffect(card));
preCostEffects.add(new PayTwilightCostEffect(card, twilightModifier));
if (card.getZone() == Zone.DECK)
addEffect(new ShuffleDeckEffect(card.getOwner()));
addEffect(new CardAffectingGameEffect(card));
addEffect(new TriggeringEffect(new PlayCardResult(card)));
preCostEffects.add(new ShuffleDeckEffect(card.getOwner()));
// addFinalEffect(new PutCardIntoDiscardEffect(card));
_preCostIterator = preCostEffects.iterator();
_putCardIntoPlayEffect = new PutCardIntoPlayEffect(card, zone);
_playCardEffect = new TriggeringEffect(new PlayCardResult(card));
_discardCardEffect = new PutCardIntoDiscardEffect(card);
}
public void addCost(Effect cost) {
_costs.add(cost);
}
public void addEffect(Effect effect) {
_effects.add(effect);
}
@Override
public PhysicalCard getActionSource() {
return _source;
}
@Override
public Keyword getType() {
return null;
}
@Override
public String getText() {
return "Play " + _source.getBlueprint().getName();
}
@Override
public Effect nextEffect() {
if (_preCostIterator.hasNext())
return _preCostIterator.next();
boolean anyCostCancelledOrFailed = false;
for (int i = 0; i < _nextCostIndex; i++) {
Effect cost = _costs.get(i);
if (cost.isCancelled() || cost.isFailed())
anyCostCancelledOrFailed = true;
}
if (!anyCostCancelledOrFailed) {
if (_nextCostIndex < _costs.size()) {
Effect cost = _costs.get(_nextCostIndex);
_nextCostIndex++;
return cost;
}
if (!_cardPutIntoPlay) {
_cardPutIntoPlay = true;
return _putCardIntoPlayEffect;
}
if (!_cardPlayed) {
_cardPlayed = true;
return _playCardEffect;
}
if (!_playCardEffect.isCancelled() && !_playCardEffect.isFailed()) {
if (_nextEffectIndex < _effects.size()) {
Effect effect = _effects.get(_nextEffectIndex);
_nextEffectIndex++;
return effect;
}
}
} else {
if (!_cardDiscarded) {
_cardDiscarded = true;
return _discardCardEffect;
}
}
return null;
}
}

View File

@@ -19,5 +19,6 @@ public class PutCardIntoPlayEffect extends UnrespondableEffect {
public void playEffect(LotroGame game) {
GameState gameState = game.getGameState();
gameState.addCardToZone(_physicalCard, _zone);
gameState.startAffecting(_physicalCard, game.getModifiersEnvironment());
}
}