Refactoring actions... again.

This commit is contained in:
marcins78@gmail.com
2011-11-02 10:56:52 +00:00
parent 6b4459372a
commit 55a51bcb3a
18 changed files with 91 additions and 110 deletions

View File

@@ -114,14 +114,4 @@ public class PlayEventAction extends AbstractCostToEffectAction {
return null; return null;
} }
@Override
public boolean wasSuccessful() {
return _cardPlayed && _playCardEffect.wasSuccessful() && !_playCardEffect.getPlayEventResult().isEventCancelled();
}
@Override
public boolean wasCarriedOut() {
return _cardPlayed && _playCardEffect.wasCarriedOut() && !_playCardEffect.getPlayEventResult().isEventCancelled();
}
} }

View File

@@ -104,12 +104,10 @@ public class PlayPermanentAction extends AbstractCostToEffectAction {
return null; return null;
} }
@Override
public boolean wasSuccessful() { public boolean wasSuccessful() {
return _cardPlayed && _playCardEffect.wasSuccessful(); return _cardPlayed && _playCardEffect.wasSuccessful();
} }
@Override
public boolean wasCarriedOut() { public boolean wasCarriedOut() {
return _cardPlayed && _playCardEffect.wasCarriedOut(); return _cardPlayed && _playCardEffect.wasCarriedOut();
} }

View File

@@ -8,14 +8,15 @@ import com.gempukku.lotro.logic.actions.SubAction;
import com.gempukku.lotro.logic.decisions.CardsSelectionDecision; import com.gempukku.lotro.logic.decisions.CardsSelectionDecision;
import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException; import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException;
import com.gempukku.lotro.logic.effects.DiscardCardsFromHandEffect; import com.gempukku.lotro.logic.effects.DiscardCardsFromHandEffect;
import com.gempukku.lotro.logic.timing.AbstractEffect; import com.gempukku.lotro.logic.timing.AbstractSubActionEffect;
import com.gempukku.lotro.logic.timing.Action; import com.gempukku.lotro.logic.timing.Action;
import com.gempukku.lotro.logic.timing.Effect; import com.gempukku.lotro.logic.timing.Effect;
import com.gempukku.lotro.logic.timing.EffectResult;
import java.util.Collection; import java.util.Collection;
import java.util.Set; import java.util.Set;
public class ChooseAndDiscardCardsFromHandEffect extends AbstractEffect { public class ChooseAndDiscardCardsFromHandEffect extends AbstractSubActionEffect {
private Action _action; private Action _action;
private String _playerId; private String _playerId;
private boolean _forced; private boolean _forced;
@@ -60,9 +61,9 @@ public class ChooseAndDiscardCardsFromHandEffect extends AbstractEffect {
} }
@Override @Override
protected FullEffectResult playEffectReturningResult(final LotroGame game) { public Collection<? extends EffectResult> playEffect(final LotroGame game) {
if (_forced && !game.getModifiersQuerying().canDiscardCardsFromHand(game.getGameState(), _playerId, _action.getActionSource())) if (_forced && !game.getModifiersQuerying().canDiscardCardsFromHand(game.getGameState(), _playerId, _action.getActionSource()))
return new FullEffectResult(null, false, false); return null;
Collection<PhysicalCard> hand = Filters.filter(game.getGameState().getHand(_playerId), game.getGameState(), game.getModifiersQuerying(), _filter); Collection<PhysicalCard> hand = Filters.filter(game.getGameState().getHand(_playerId), game.getGameState(), game.getModifiersQuerying(), _filter);
@@ -71,7 +72,7 @@ public class ChooseAndDiscardCardsFromHandEffect extends AbstractEffect {
if (hand.size() <= _minimum) { if (hand.size() <= _minimum) {
SubAction subAction = new SubAction(_action); SubAction subAction = new SubAction(_action);
subAction.appendEffect(new DiscardCardsFromHandEffect(_action.getActionSource(), _playerId, hand, _forced)); subAction.appendEffect(new DiscardCardsFromHandEffect(_action.getActionSource(), _playerId, hand, _forced));
game.getActionsEnvironment().addActionToStack(subAction); processSubAction(game, subAction);
cardsBeingDiscarded(hand, success); cardsBeingDiscarded(hand, success);
} else { } else {
game.getUserFeedback().sendAwaitingDecision(_playerId, game.getUserFeedback().sendAwaitingDecision(_playerId,
@@ -81,13 +82,13 @@ public class ChooseAndDiscardCardsFromHandEffect extends AbstractEffect {
Set<PhysicalCard> cards = getSelectedCardsByResponse(result); Set<PhysicalCard> cards = getSelectedCardsByResponse(result);
SubAction subAction = new SubAction(_action); SubAction subAction = new SubAction(_action);
subAction.appendEffect(new DiscardCardsFromHandEffect(_action.getActionSource(), _playerId, cards, _forced)); subAction.appendEffect(new DiscardCardsFromHandEffect(_action.getActionSource(), _playerId, cards, _forced));
game.getActionsEnvironment().addActionToStack(subAction); processSubAction(game, subAction);
cardsBeingDiscarded(cards, success); cardsBeingDiscarded(cards, success);
} }
}); });
} }
return new FullEffectResult(null, success, success); return null;
} }
protected void cardsBeingDiscarded(Collection<PhysicalCard> cardsBeingDiscarded, boolean success) { protected void cardsBeingDiscarded(Collection<PhysicalCard> cardsBeingDiscarded, boolean success) {

View File

@@ -13,6 +13,7 @@ import java.util.Collection;
public class ChooseAndDiscardCardsFromPlayEffect extends ChooseActiveCardsEffect { public class ChooseAndDiscardCardsFromPlayEffect extends ChooseActiveCardsEffect {
private Action _action; private Action _action;
private SubAction _resultSubAction;
public ChooseAndDiscardCardsFromPlayEffect(Action action, String playerId, int minimum, int maximum, Filterable... filters) { public ChooseAndDiscardCardsFromPlayEffect(Action action, String playerId, int minimum, int maximum, Filterable... filters) {
super(action.getActionSource(), playerId, "Choose cards to discard", minimum, maximum, filters); super(action.getActionSource(), playerId, "Choose cards to discard", minimum, maximum, filters);
@@ -27,12 +28,22 @@ public class ChooseAndDiscardCardsFromPlayEffect extends ChooseActiveCardsEffect
@Override @Override
protected void cardsSelected(LotroGame game, Collection<PhysicalCard> cards) { protected void cardsSelected(LotroGame game, Collection<PhysicalCard> cards) {
cardsToBeDiscardedCallback(cards); cardsToBeDiscardedCallback(cards);
SubAction subAction = new SubAction(_action); _resultSubAction = new SubAction(_action);
subAction.appendEffect(new DiscardCardsFromPlayEffect(_action.getActionSource(), Filters.in(cards))); _resultSubAction.appendEffect(new DiscardCardsFromPlayEffect(_action.getActionSource(), Filters.in(cards)));
game.getActionsEnvironment().addActionToStack(subAction); game.getActionsEnvironment().addActionToStack(_resultSubAction);
} }
protected void cardsToBeDiscardedCallback(Collection<PhysicalCard> cards) { protected void cardsToBeDiscardedCallback(Collection<PhysicalCard> cards) {
} }
@Override
public boolean wasSuccessful() {
return _resultSubAction != null && _resultSubAction.wasSuccessful();
}
@Override
public boolean wasCarriedOut() {
return _resultSubAction != null && _resultSubAction.wasCarriedOut();
}
} }

View File

@@ -8,15 +8,17 @@ import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.actions.SubAction; import com.gempukku.lotro.logic.actions.SubAction;
import com.gempukku.lotro.logic.decisions.CardsSelectionDecision; import com.gempukku.lotro.logic.decisions.CardsSelectionDecision;
import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException; import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException;
import com.gempukku.lotro.logic.timing.AbstractEffect; import com.gempukku.lotro.logic.timing.AbstractSubActionEffect;
import com.gempukku.lotro.logic.timing.Action; import com.gempukku.lotro.logic.timing.Action;
import com.gempukku.lotro.logic.timing.Effect; import com.gempukku.lotro.logic.timing.Effect;
import com.gempukku.lotro.logic.timing.EffectResult;
import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
public class ChooseAndDiscardStackedCardsEffect extends AbstractEffect { public class ChooseAndDiscardStackedCardsEffect extends AbstractSubActionEffect {
private Action _action; private Action _action;
private String _playerId; private String _playerId;
private int _minimum; private int _minimum;
@@ -49,18 +51,16 @@ public class ChooseAndDiscardStackedCardsEffect extends AbstractEffect {
} }
@Override @Override
protected FullEffectResult playEffectReturningResult(final LotroGame game) { public Collection<? extends EffectResult> playEffect(final LotroGame game) {
List<PhysicalCard> discardableCards = new LinkedList<PhysicalCard>(); List<PhysicalCard> discardableCards = new LinkedList<PhysicalCard>();
for (PhysicalCard stackedOnCard : Filters.filterActive(game.getGameState(), game.getModifiersQuerying(), _stackedOnFilter)) for (PhysicalCard stackedOnCard : Filters.filterActive(game.getGameState(), game.getModifiersQuerying(), _stackedOnFilter))
discardableCards.addAll(Filters.filter(game.getGameState().getStackedCards(stackedOnCard), game.getGameState(), game.getModifiersQuerying(), _stackedCardFilter)); discardableCards.addAll(Filters.filter(game.getGameState().getStackedCards(stackedOnCard), game.getGameState(), game.getModifiersQuerying(), _stackedCardFilter));
final boolean success = discardableCards.size() >= _minimum;
if (discardableCards.size() <= _minimum) { if (discardableCards.size() <= _minimum) {
SubAction subAction = new SubAction(_action); SubAction subAction = new SubAction(_action);
subAction.appendEffect(new DiscardStackedCardsEffect(_action.getActionSource(), discardableCards)); subAction.appendEffect(new DiscardStackedCardsEffect(_action.getActionSource(), discardableCards));
game.getActionsEnvironment().addActionToStack(subAction); processSubAction(game, subAction);
} else { } else {
game.getUserFeedback().sendAwaitingDecision(_playerId, game.getUserFeedback().sendAwaitingDecision(_playerId,
new CardsSelectionDecision(1, "Choose cards to discard", discardableCards, _minimum, _maximum) { new CardsSelectionDecision(1, "Choose cards to discard", discardableCards, _minimum, _maximum) {
@@ -69,11 +69,10 @@ public class ChooseAndDiscardStackedCardsEffect extends AbstractEffect {
Set<PhysicalCard> selectedCards = getSelectedCardsByResponse(result); Set<PhysicalCard> selectedCards = getSelectedCardsByResponse(result);
SubAction subAction = new SubAction(_action); SubAction subAction = new SubAction(_action);
subAction.appendEffect(new DiscardStackedCardsEffect(_action.getActionSource(), selectedCards)); subAction.appendEffect(new DiscardStackedCardsEffect(_action.getActionSource(), selectedCards));
game.getActionsEnvironment().addActionToStack(subAction); processSubAction(game, subAction);
} }
}); });
} }
return null;
return new FullEffectResult(null, success, success);
} }
} }

View File

@@ -17,6 +17,7 @@ import java.util.Collection;
public class ChooseAndExertCharactersEffect extends ChooseActiveCardsEffect { public class ChooseAndExertCharactersEffect extends ChooseActiveCardsEffect {
private Action _action; private Action _action;
private int _count; private int _count;
private SubAction _resultSubAction;
public ChooseAndExertCharactersEffect(Action action, String playerId, int minimum, int maximum, Filterable... filters) { public ChooseAndExertCharactersEffect(Action action, String playerId, int minimum, int maximum, Filterable... filters) {
this(action, playerId, minimum, maximum, 1, filters); this(action, playerId, minimum, maximum, 1, filters);
@@ -41,11 +42,11 @@ public class ChooseAndExertCharactersEffect extends ChooseActiveCardsEffect {
@Override @Override
protected final void cardsSelected(LotroGame game, Collection<PhysicalCard> characters) { protected final void cardsSelected(LotroGame game, Collection<PhysicalCard> characters) {
SubAction subAction = new SubAction(_action); _resultSubAction = new SubAction(_action);
for (int i = 0; i < _count; i++) { for (int i = 0; i < _count; i++) {
subAction.appendEffect(new ExertCharactersEffect(_action.getActionSource(), Filters.in(characters))); _resultSubAction.appendEffect(new ExertCharactersEffect(_action.getActionSource(), Filters.in(characters)));
} }
game.getActionsEnvironment().addActionToStack(subAction); game.getActionsEnvironment().addActionToStack(_resultSubAction);
for (PhysicalCard character : characters) for (PhysicalCard character : characters)
forEachCardExertedCallback(character); forEachCardExertedCallback(character);
@@ -54,4 +55,14 @@ public class ChooseAndExertCharactersEffect extends ChooseActiveCardsEffect {
protected void forEachCardExertedCallback(PhysicalCard character) { protected void forEachCardExertedCallback(PhysicalCard character) {
} }
@Override
public boolean wasSuccessful() {
return _resultSubAction != null && _resultSubAction.wasSuccessful();
}
@Override
public boolean wasCarriedOut() {
return _resultSubAction != null && _resultSubAction.wasCarriedOut();
}
} }

View File

@@ -1,5 +1,6 @@
package com.gempukku.lotro.cards.effects.choose; package com.gempukku.lotro.cards.effects.choose;
import com.gempukku.lotro.cards.actions.PlayPermanentAction;
import com.gempukku.lotro.common.Filterable; import com.gempukku.lotro.common.Filterable;
import com.gempukku.lotro.filters.Filter; import com.gempukku.lotro.filters.Filter;
import com.gempukku.lotro.filters.Filters; import com.gempukku.lotro.filters.Filters;
@@ -73,11 +74,19 @@ public class ChooseAndPlayCardFromDeadPileEffect implements Effect {
@Override @Override
public boolean wasSuccessful() { public boolean wasSuccessful() {
return _playCardAction != null && _playCardAction.wasSuccessful(); if (_playCardAction == null)
return false;
if (_playCardAction instanceof PlayPermanentAction)
return ((PlayPermanentAction) _playCardAction).wasSuccessful();
return true;
} }
@Override @Override
public boolean wasCarriedOut() { public boolean wasCarriedOut() {
return _playCardAction != null && _playCardAction.wasCarriedOut(); if (_playCardAction == null)
return false;
if (_playCardAction instanceof PlayPermanentAction)
return ((PlayPermanentAction) _playCardAction).wasCarriedOut();
return true;
} }
} }

View File

@@ -1,5 +1,6 @@
package com.gempukku.lotro.cards.effects.choose; package com.gempukku.lotro.cards.effects.choose;
import com.gempukku.lotro.cards.actions.PlayPermanentAction;
import com.gempukku.lotro.common.Filterable; import com.gempukku.lotro.common.Filterable;
import com.gempukku.lotro.filters.Filters; import com.gempukku.lotro.filters.Filters;
import com.gempukku.lotro.game.PhysicalCard; import com.gempukku.lotro.game.PhysicalCard;
@@ -65,11 +66,19 @@ public class ChooseAndPlayCardFromDeckEffect implements Effect {
@Override @Override
public boolean wasSuccessful() { public boolean wasSuccessful() {
return _playCardAction != null && _playCardAction.wasSuccessful(); if (_playCardAction == null)
return false;
if (_playCardAction instanceof PlayPermanentAction)
return ((PlayPermanentAction) _playCardAction).wasSuccessful();
return true;
} }
@Override @Override
public boolean wasCarriedOut() { public boolean wasCarriedOut() {
return _playCardAction != null && _playCardAction.wasCarriedOut(); if (_playCardAction == null)
return false;
if (_playCardAction instanceof PlayPermanentAction)
return ((PlayPermanentAction) _playCardAction).wasCarriedOut();
return true;
} }
} }

View File

@@ -1,5 +1,6 @@
package com.gempukku.lotro.cards.effects.choose; package com.gempukku.lotro.cards.effects.choose;
import com.gempukku.lotro.cards.actions.PlayPermanentAction;
import com.gempukku.lotro.common.Filterable; import com.gempukku.lotro.common.Filterable;
import com.gempukku.lotro.filters.Filter; import com.gempukku.lotro.filters.Filter;
import com.gempukku.lotro.filters.Filters; import com.gempukku.lotro.filters.Filters;
@@ -73,11 +74,19 @@ public class ChooseAndPlayCardFromDiscardEffect implements Effect {
@Override @Override
public boolean wasSuccessful() { public boolean wasSuccessful() {
return _playCardAction != null && _playCardAction.wasSuccessful(); if (_playCardAction == null)
return false;
if (_playCardAction instanceof PlayPermanentAction)
return ((PlayPermanentAction) _playCardAction).wasSuccessful();
return true;
} }
@Override @Override
public boolean wasCarriedOut() { public boolean wasCarriedOut() {
return _playCardAction != null && _playCardAction.wasCarriedOut(); if (_playCardAction == null)
return false;
if (_playCardAction instanceof PlayPermanentAction)
return ((PlayPermanentAction) _playCardAction).wasCarriedOut();
return true;
} }
} }

View File

@@ -1,5 +1,6 @@
package com.gempukku.lotro.cards.effects.choose; package com.gempukku.lotro.cards.effects.choose;
import com.gempukku.lotro.cards.actions.PlayPermanentAction;
import com.gempukku.lotro.common.Filterable; import com.gempukku.lotro.common.Filterable;
import com.gempukku.lotro.filters.Filter; import com.gempukku.lotro.filters.Filter;
import com.gempukku.lotro.filters.Filters; import com.gempukku.lotro.filters.Filters;
@@ -74,11 +75,19 @@ public class ChooseAndPlayCardFromHandEffect implements Effect {
@Override @Override
public boolean wasSuccessful() { public boolean wasSuccessful() {
return _playCardAction != null && _playCardAction.wasSuccessful(); if (_playCardAction == null)
return false;
if (_playCardAction instanceof PlayPermanentAction)
return ((PlayPermanentAction) _playCardAction).wasSuccessful();
return true;
} }
@Override @Override
public boolean wasCarriedOut() { public boolean wasCarriedOut() {
return _playCardAction != null && _playCardAction.wasCarriedOut(); if (_playCardAction == null)
return false;
if (_playCardAction instanceof PlayPermanentAction)
return ((PlayPermanentAction) _playCardAction).wasCarriedOut();
return true;
} }
} }

View File

@@ -11,7 +11,6 @@ public abstract class AbstractCostToEffectAction implements CostToEffectAction {
private LinkedList<Effect> _processedCosts = new LinkedList<Effect>(); private LinkedList<Effect> _processedCosts = new LinkedList<Effect>();
private LinkedList<Effect> _effects = new LinkedList<Effect>(); private LinkedList<Effect> _effects = new LinkedList<Effect>();
private LinkedList<Effect> _processedEffects = new LinkedList<Effect>();
private Phase _actionTimeword; private Phase _actionTimeword;
private String _performingPlayer; private String _performingPlayer;
@@ -72,24 +71,6 @@ public abstract class AbstractCostToEffectAction implements CostToEffectAction {
} }
protected final Effect getNextEffect() { protected final Effect getNextEffect() {
final Effect effect = _effects.poll(); return _effects.poll();
if (effect != null)
_processedEffects.add(effect);
return effect;
}
@Override
public boolean wasSuccessful() {
for (Effect processedCost : _processedCosts) {
if (!processedCost.wasSuccessful())
return false;
}
return true;
}
@Override
public boolean wasCarriedOut() {
return wasSuccessful();
} }
} }

View File

@@ -64,7 +64,6 @@ public class SubAction implements Action {
return effect; return effect;
} }
@Override
public boolean wasSuccessful() { public boolean wasSuccessful() {
if (!_effects.isEmpty()) if (!_effects.isEmpty())
return false; return false;
@@ -76,7 +75,6 @@ public class SubAction implements Action {
return true; return true;
} }
@Override
public boolean wasCarriedOut() { public boolean wasCarriedOut() {
if (!_effects.isEmpty()) if (!_effects.isEmpty())
return false; return false;

View File

@@ -24,14 +24,14 @@ public abstract class AbstractEffect implements Effect {
} }
@Override @Override
public final boolean wasCarriedOut() { public boolean wasCarriedOut() {
if (_carriedOut == null) if (_carriedOut == null)
throw new IllegalStateException("Effect has to be played first"); throw new IllegalStateException("Effect has to be played first");
return _carriedOut; return _carriedOut;
} }
@Override @Override
public final boolean wasSuccessful() { public boolean wasSuccessful() {
if (_successful == null) if (_successful == null)
throw new IllegalStateException("Effect has to be played first"); throw new IllegalStateException("Effect has to be played first");
return _successful; return _successful;

View File

@@ -20,8 +20,4 @@ public interface Action {
public String getText(LotroGame game); public String getText(LotroGame game);
public Effect nextEffect(LotroGame game); public Effect nextEffect(LotroGame game);
public boolean wasSuccessful();
public boolean wasCarriedOut();
} }

View File

@@ -99,14 +99,4 @@ public class PlayerReconcilesAction implements Action {
return _effectQueue.poll(); return _effectQueue.poll();
} }
@Override
public boolean wasCarriedOut() {
return true;
}
@Override
public boolean wasSuccessful() {
return true;
}
} }

View File

@@ -116,14 +116,4 @@ public class ResolveSkirmishAction implements Action {
else else
return Collections.emptyList(); return Collections.emptyList();
} }
@Override
public boolean wasCarriedOut() {
return true;
}
@Override
public boolean wasSuccessful() {
return true;
}
} }

View File

@@ -54,14 +54,4 @@ public class SimpleEffectAction implements Action {
_effect = null; _effect = null;
return result; return result;
} }
@Override
public boolean wasCarriedOut() {
return true;
}
@Override
public boolean wasSuccessful() {
return true;
}
} }

View File

@@ -38,14 +38,4 @@ public abstract class SystemAction implements Action {
public String getText(LotroGame game) { public String getText(LotroGame game) {
throw new UnsupportedOperationException("System action has no text"); throw new UnsupportedOperationException("System action has no text");
} }
@Override
public boolean wasCarriedOut() {
return true;
}
@Override
public boolean wasSuccessful() {
return true;
}
} }