Change how effects work.

This commit is contained in:
marcins78@gmail.com
2011-09-20 19:58:39 +00:00
parent b55f04a865
commit 6a1622c84c
37 changed files with 298 additions and 187 deletions

View File

@@ -1,20 +1,40 @@
package com.gempukku.lotro.cards.effects;
import com.gempukku.lotro.cards.PlayConditions;
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.timing.AbstractEffect;
import com.gempukku.lotro.logic.timing.EffectResult;
import com.gempukku.lotro.logic.timing.results.ExertResult;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public class ExertCharacterEffect extends AbstractEffect {
private String _playerId;
private PhysicalCard _physicalCard;
private boolean _prevented;
private final Filter _filter;
private Set<PhysicalCard> _prevented = new HashSet<PhysicalCard>();
public ExertCharacterEffect(String playerId, PhysicalCard physicalCard) {
public ExertCharacterEffect(String playerId, PhysicalCard card) {
_playerId = playerId;
_physicalCard = physicalCard;
_filter = Filters.sameCard(card);
}
public ExertCharacterEffect(String playerId, Filter card) {
_playerId = playerId;
_filter = card;
}
public List<PhysicalCard> getCardsToBeExerted(LotroGame game) {
List<PhysicalCard> cardsToExert = new LinkedList<PhysicalCard>();
for (PhysicalCard physicalCard : Filters.filterActive(game.getGameState(), game.getModifiersQuerying(), _filter)) {
cardsToExert.add(physicalCard);
}
cardsToExert.removeAll(_prevented);
return cardsToExert;
}
@Override
@@ -22,31 +42,41 @@ public class ExertCharacterEffect extends AbstractEffect {
return EffectResult.Type.EXERT;
}
public PhysicalCard getExertedCard() {
return _physicalCard;
}
@Override
public String getText(LotroGame game) {
return "Exert " + _physicalCard.getBlueprint().getName();
List<PhysicalCard> cards = getCardsToBeExerted(game);
return "Exert - " + getAppendedNames(cards);
}
private String getAppendedNames(List<PhysicalCard> cards) {
StringBuilder sb = new StringBuilder();
for (PhysicalCard card : cards)
sb.append(card.getBlueprint().getName() + ", ");
if (sb.length() == 0)
return "none";
else
return sb.substring(0, sb.length() - 1);
}
@Override
public boolean canPlayEffect(LotroGame game) {
return PlayConditions.canExert(game.getGameState(), game.getModifiersQuerying(), _physicalCard);
return getCardsToBeExerted(game).size() > 0;
}
@Override
public EffectResult playEffect(LotroGame game) {
if (!_prevented) {
game.getGameState().sendMessage(_playerId + " exerts " + _physicalCard.getBlueprint().getName());
game.getGameState().addWound(_physicalCard);
return new ExertResult(_physicalCard);
public EffectResult[] playEffect(LotroGame game) {
List<PhysicalCard> woundedCards = getCardsToBeExerted(game);
for (PhysicalCard woundedCard : woundedCards) {
game.getGameState().sendMessage(_playerId + " exerts " + woundedCard.getBlueprint().getName());
game.getGameState().addWound(woundedCard);
}
return null;
return new EffectResult[]{new ExertResult(woundedCards)};
}
public void prevent() {
_prevented = true;
public void prevent(PhysicalCard card) {
_prevented.add(card);
}
}

View File

@@ -8,6 +8,8 @@ import com.gempukku.lotro.logic.timing.AbstractEffect;
import com.gempukku.lotro.logic.timing.EffectResult;
import com.gempukku.lotro.logic.timing.results.ExertResult;
import java.util.Collections;
public class ExhaustCharacterEffect extends AbstractEffect {
private String _playerId;
private CostToEffectAction _action;
@@ -43,7 +45,7 @@ public class ExhaustCharacterEffect extends AbstractEffect {
}
@Override
public EffectResult playEffect(LotroGame game) {
public EffectResult[] playEffect(LotroGame game) {
if (_sendMessage)
game.getGameState().sendMessage(_playerId + " exhausts " + _physicalCard.getBlueprint().getName());
game.getGameState().addWound(_physicalCard);
@@ -51,6 +53,6 @@ public class ExhaustCharacterEffect extends AbstractEffect {
_action.addCost(new ExhaustCharacterEffect(_playerId, _action, _cost, _physicalCard, false));
else
_action.addEffect(new ExhaustCharacterEffect(_playerId, _action, _cost, _physicalCard, false));
return new ExertResult(_physicalCard);
return new EffectResult[]{new ExertResult(Collections.singletonList(_physicalCard))};
}
}

View File

@@ -0,0 +1,21 @@
package com.gempukku.lotro.cards.effects;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.timing.UnrespondableEffect;
public class PreventExertEffect extends UnrespondableEffect {
private ExertCharacterEffect _effect;
private PhysicalCard _card;
public PreventExertEffect(ExertCharacterEffect effect, PhysicalCard card) {
_effect = effect;
_card = card;
}
@Override
protected void doPlayEffect(LotroGame game) {
_effect.prevent(_card);
}
}

View File

@@ -23,9 +23,9 @@ public class PutOnTheOneRingEffect extends AbstractEffect {
}
@Override
public EffectResult playEffect(LotroGame game) {
public EffectResult[] playEffect(LotroGame game) {
game.getGameState().sendMessage("Ring-bearer puts on The One Ring");
game.getGameState().setWearingRing(true);
return new PutOnTheOneRingResult();
return new EffectResult[]{new PutOnTheOneRingResult()};
}
}

View File

@@ -28,9 +28,9 @@ public class RemoveBurdenEffect extends AbstractEffect {
}
@Override
public EffectResult playEffect(LotroGame game) {
public EffectResult[] playEffect(LotroGame game) {
game.getGameState().sendMessage(_playerId + " removes a burden");
game.getGameState().removeBurdens(1);
return new RemoveBurdenResult();
return new EffectResult[]{new RemoveBurdenResult()};
}
}

View File

@@ -3,6 +3,7 @@ package com.gempukku.lotro.cards.set1.gandalf;
import com.gempukku.lotro.cards.AbstractResponseEvent;
import com.gempukku.lotro.cards.actions.PlayEventAction;
import com.gempukku.lotro.cards.effects.ExertCharacterEffect;
import com.gempukku.lotro.cards.effects.PreventExertEffect;
import com.gempukku.lotro.common.CardType;
import com.gempukku.lotro.common.Culture;
import com.gempukku.lotro.common.Keyword;
@@ -10,9 +11,9 @@ 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.effects.ChooseActiveCardEffect;
import com.gempukku.lotro.logic.timing.Effect;
import com.gempukku.lotro.logic.timing.EffectResult;
import com.gempukku.lotro.logic.timing.UnrespondableEffect;
import java.util.Collections;
import java.util.List;
@@ -37,16 +38,19 @@ public class Card1_085 extends AbstractResponseEvent {
}
@Override
public List<PlayEventAction> getOptionalBeforeActions(String playerId, LotroGame game, final Effect effect, PhysicalCard self) {
public List<PlayEventAction> getOptionalBeforeActions(final String playerId, LotroGame game, final Effect effect, PhysicalCard self) {
if (effect.getType() == EffectResult.Type.EXERT
&& Filters.canSpot(game.getGameState(), game.getModifiersQuerying(), Filters.name("Gandalf"))) {
if (((ExertCharacterEffect) effect).getExertedCard().getBlueprint().getCardType() == CardType.COMPANION) {
PlayEventAction action = new PlayEventAction(self);
final ExertCharacterEffect exertEffect = (ExertCharacterEffect) effect;
List<PhysicalCard> exertedCharacters = exertEffect.getCardsToBeExerted(game);
if (Filters.filter(exertedCharacters, game.getGameState(), game.getModifiersQuerying(), Filters.type(CardType.COMPANION)).size() > 0) {
final PlayEventAction action = new PlayEventAction(self);
action.addEffect(
new UnrespondableEffect() {
new ChooseActiveCardEffect(playerId, "Choose character", Filters.type(CardType.COMPANION), Filters.in(exertedCharacters)) {
@Override
public void doPlayEffect(LotroGame game) {
((ExertCharacterEffect) effect).prevent();
protected void cardSelected(PhysicalCard card) {
action.addEffect(
new PreventExertEffect(exertEffect, card));
}
});
return Collections.singletonList(action);

View File

@@ -50,8 +50,8 @@ public class Card1_093 extends AbstractEvent {
action.addCost(
new ExertCharacterEffect(playerId, arwen) {
@Override
public EffectResult playEffect(LotroGame game) {
EffectResult effectResult = super.playEffect(game);
public EffectResult[] playEffect(LotroGame game) {
EffectResult[] effectResult = super.playEffect(game);
action.addEffect(
new AddUntilEndOfPhaseModifierEffect(
new StrengthModifier(self, Filters.name("Aragorn"), 3), Phase.SKIRMISH));
@@ -63,8 +63,8 @@ public class Card1_093 extends AbstractEvent {
action.addCost(
new ExertCharacterEffect(playerId, aragorn) {
@Override
public EffectResult playEffect(LotroGame game) {
EffectResult effectResult = super.playEffect(game);
public EffectResult[] playEffect(LotroGame game) {
EffectResult[] effectResult = super.playEffect(game);
action.addEffect(
new AddUntilEndOfPhaseModifierEffect(
new StrengthModifier(self, Filters.name("Arwen"), 3), Phase.SKIRMISH));

View File

@@ -47,8 +47,8 @@ public class Card1_100 extends AbstractPermanent {
action.addCost(
new ExertCharacterEffect(playerId, arwen) {
@Override
public EffectResult playEffect(LotroGame game) {
EffectResult effectResult = super.playEffect(game);
public EffectResult[] playEffect(LotroGame game) {
EffectResult[] effectResult = super.playEffect(game);
if (aragorn != null)
action.addEffect(new HealCharacterEffect(playerId, aragorn));
return effectResult;
@@ -59,8 +59,8 @@ public class Card1_100 extends AbstractPermanent {
action.addCost(
new ExertCharacterEffect(playerId, aragorn) {
@Override
public EffectResult playEffect(LotroGame game) {
EffectResult effectResult = super.playEffect(game);
public EffectResult[] playEffect(LotroGame game) {
EffectResult[] effectResult = super.playEffect(game);
if (arwen != null)
action.addEffect(new HealCharacterEffect(playerId, arwen));
return effectResult;

View File

@@ -14,7 +14,7 @@ import com.gempukku.lotro.logic.modifiers.Modifier;
import com.gempukku.lotro.logic.timing.EffectResult;
import com.gempukku.lotro.logic.timing.results.KillResult;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
@@ -46,16 +46,20 @@ public class Card1_182 extends AbstractAttachable {
public List<RequiredTriggerAction> getRequiredAfterTriggers(LotroGame game, EffectResult effectResult, PhysicalCard self) {
if (effectResult.getType() == EffectResult.Type.KILL) {
KillResult killResult = (KillResult) effectResult;
PhysicalCard killedCard = killResult.getKilledCard();
Skirmish skirmish = game.getGameState().getSkirmish();
if (killedCard.getBlueprint().getCardType() == CardType.COMPANION && skirmish != null
&& skirmish.getFellowshipCharacter() == killedCard && skirmish.getShadowCharacters().contains(self.getAttachedTo())) {
int burdens = (killedCard.getBlueprint().getRace() == Race.HOBBIT) ? 2 : 1;
RequiredTriggerAction action = new RequiredTriggerAction(self, null, "Add " + burdens + " burden(s)");
for (int i = 0; i < burdens; i++)
action.addEffect(new AddBurdenEffect(self.getOwner()));
return Collections.singletonList(action);
List<PhysicalCard> killedCards = killResult.getKilledCards();
List<RequiredTriggerAction> actions = new LinkedList<RequiredTriggerAction>();
for (PhysicalCard killedCard : killedCards) {
Skirmish skirmish = game.getGameState().getSkirmish();
if (killedCard.getBlueprint().getCardType() == CardType.COMPANION
&& skirmish != null && skirmish.getShadowCharacters().contains(self.getAttachedTo())) {
int burdens = (killedCard.getBlueprint().getRace() == Race.HOBBIT) ? 2 : 1;
RequiredTriggerAction action = new RequiredTriggerAction(self, null, "Add " + burdens + " burden(s)");
for (int i = 0; i < burdens; i++)
action.addEffect(new AddBurdenEffect(self.getOwner()));
actions.add(action);
}
}
return actions;
}
return null;
}

View File

@@ -45,7 +45,7 @@ public class Card1_189 extends AbstractResponseEvent {
public List<PlayEventAction> getOptionalAfterActions(final String playerId, final LotroGame game, EffectResult effectResult, PhysicalCard self) {
if (((
effectResult.getType() == EffectResult.Type.EXERT
&& game.getModifiersQuerying().hasKeyword(game.getGameState(), ((ExertResult) effectResult).getExertedCard(), Keyword.RING_BEARER))
&& Filters.filter(((ExertResult) effectResult).getExertedCards(), game.getGameState(), game.getModifiersQuerying(), Filters.keyword(Keyword.RING_BEARER)).size() > 0)
|| (
effectResult.getType() == EffectResult.Type.WOUND
&& Filters.filter(((WoundResult) effectResult).getWoundedCards(), game.getGameState(), game.getModifiersQuerying(), Filters.keyword(Keyword.RING_BEARER)).size() > 0))

View File

@@ -40,7 +40,7 @@ public class Card1_265 extends AbstractResponseEvent {
&& PlayConditions.canPayForShadowCard(game, self, 0)) {
Skirmish skirmish = game.getGameState().getSkirmish();
if (effectResult.getType() == EffectResult.Type.KILL
&& ((KillResult) effectResult).getKilledCard().getBlueprint().getCardType() == CardType.COMPANION
&& Filters.filter(((KillResult) effectResult).getKilledCards(), game.getGameState(), game.getModifiersQuerying(), Filters.type(CardType.COMPANION)).size() > 0
&& skirmish != null
&& Filters.filter(skirmish.getShadowCharacters(), game.getGameState(), game.getModifiersQuerying(), Filters.culture(Culture.SAURON), Filters.race(Race.ORC)).size() > 0) {
PlayEventAction action = new PlayEventAction(self);

View File

@@ -39,7 +39,7 @@ public class Card1_273 extends AbstractResponseEvent {
&& PlayConditions.canPayForShadowCard(game, self, 0)) {
Skirmish skirmish = game.getGameState().getSkirmish();
if (effectResult.getType() == EffectResult.Type.KILL
&& ((KillResult) effectResult).getKilledCard().getBlueprint().getCardType() == CardType.COMPANION
&& Filters.filter(((KillResult) effectResult).getKilledCards(), game.getGameState(), game.getModifiersQuerying(), Filters.type(CardType.COMPANION)).size() > 0
&& skirmish != null
&& Filters.filter(skirmish.getShadowCharacters(), game.getGameState(), game.getModifiersQuerying(), Filters.culture(Culture.SAURON), Filters.race(Race.ORC)).size() > 0) {
PlayEventAction action = new PlayEventAction(self);

View File

@@ -53,9 +53,9 @@ public class Card1_310 extends AbstractCompanion {
}
@Override
public List<OptionalTriggerAction> getOptionalBeforeTriggers(String playerId, LotroGame lotroGame, Effect effect, PhysicalCard self) {
public List<OptionalTriggerAction> getOptionalBeforeTriggers(String playerId, LotroGame game, Effect effect, PhysicalCard self) {
if (effect.getType() == EffectResult.Type.KILL) {
if (((KillEffect) effect).getKilledCard().getBlueprint().getName().equals("Frodo")) {
if (Filters.filter(((KillEffect) effect).getCharactersToBeKilled(), game.getGameState(), game.getModifiersQuerying(), Filters.name("Frodo")).size() > 0) {
OptionalTriggerAction action = new OptionalTriggerAction(self, Keyword.RESPONSE, "Make Sam the Ring-Bearer");
action.addEffect(new MakeRingBearerEffect(self));
return Collections.singletonList(action);

View File

@@ -6,6 +6,7 @@ import com.gempukku.lotro.cards.effects.ExertCharacterEffect;
import com.gempukku.lotro.cards.effects.MakeRingBearerEffect;
import com.gempukku.lotro.cards.effects.RemoveBurdenEffect;
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.actions.DefaultCostToEffectAction;
@@ -48,9 +49,9 @@ public class Card1_311 extends AbstractCompanion {
}
@Override
public List<OptionalTriggerAction> getOptionalBeforeTriggers(String playerId, LotroGame lotroGame, Effect effect, PhysicalCard self) {
public List<OptionalTriggerAction> getOptionalBeforeTriggers(String playerId, LotroGame game, Effect effect, PhysicalCard self) {
if (effect.getType() == EffectResult.Type.KILL) {
if (((KillEffect) effect).getKilledCard().getBlueprint().getName().equals("Frodo")) {
if (Filters.filter(((KillEffect) effect).getCharactersToBeKilled(), game.getGameState(), game.getModifiersQuerying(), Filters.name("Frodo")).size() > 0) {
OptionalTriggerAction action = new OptionalTriggerAction(self, Keyword.RESPONSE, "Make Sam the Ring-Bearer");
action.addEffect(new MakeRingBearerEffect(self));
return Collections.singletonList(action);

View File

@@ -14,7 +14,7 @@ public abstract class AbstractActionProxy implements ActionProxy {
}
@Override
public List<? extends Action> getRequiredAfterTriggers(LotroGame lotroGame, EffectResult effectResult) {
public List<? extends Action> getRequiredAfterTriggers(LotroGame lotroGame, EffectResult effectResults) {
return null;
}
}

View File

@@ -10,5 +10,5 @@ import java.util.List;
public interface ActionProxy {
public List<? extends Action> getRequiredBeforeTriggers(LotroGame lotroGame, Effect effect);
public List<? extends Action> getRequiredAfterTriggers(LotroGame lotroGame, EffectResult effectResult);
public List<? extends Action> getRequiredAfterTriggers(LotroGame lotroGame, EffectResult effectResults);
}

View File

@@ -14,11 +14,11 @@ public interface ActionsEnvironment {
public List<Action> getOptionalBeforeActions(String playerId, Effect effect);
public List<Action> getRequiredAfterTriggers(EffectResult effectResult);
public List<Action> getRequiredAfterTriggers(EffectResult[] effectResults);
public List<Action> getOptionalAfterTriggers(String playerId, EffectResult effectResult);
public List<Action> getOptionalAfterTriggers(String playerId, EffectResult[] effectResults);
public List<Action> getOptionalAfterActions(String playerId, EffectResult effectResult);
public List<Action> getOptionalAfterActions(String playerId, EffectResult[] effectResults);
public void addUntilStartOfPhaseActionProxy(ActionProxy actionProxy, Phase phase);

View File

@@ -106,25 +106,27 @@ public class DefaultActionsEnvironment implements ActionsEnvironment {
}
@Override
public List<Action> getRequiredAfterTriggers(EffectResult effectResult) {
GatherRequiredAfterTriggers gatherActions = new GatherRequiredAfterTriggers(effectResult);
public List<Action> getRequiredAfterTriggers(EffectResult[] effectResults) {
GatherRequiredAfterTriggers gatherActions = new GatherRequiredAfterTriggers(effectResults);
_lotroGame.getGameState().iterateActiveCards(gatherActions);
List<Action> gatheredActions = gatherActions.getActions();
for (ActionProxy actionProxy : _actionProxies) {
List<? extends Action> actions = actionProxy.getRequiredAfterTriggers(_lotroGame, effectResult);
if (actions != null)
gatheredActions.addAll(actions);
for (EffectResult effectResult : effectResults) {
List<? extends Action> actions = actionProxy.getRequiredAfterTriggers(_lotroGame, effectResult);
if (actions != null)
gatheredActions.addAll(actions);
}
}
return gatheredActions;
}
@Override
public List<Action> getOptionalAfterTriggers(String playerId, EffectResult effectResult) {
GatherOptionalAfterTriggers gatherActions = new GatherOptionalAfterTriggers(playerId, effectResult);
public List<Action> getOptionalAfterTriggers(String playerId, EffectResult[] effectResults) {
GatherOptionalAfterTriggers gatherActions = new GatherOptionalAfterTriggers(playerId, effectResults);
_lotroGame.getGameState().iterateActiveCards(playerId, gatherActions);
@@ -132,8 +134,8 @@ public class DefaultActionsEnvironment implements ActionsEnvironment {
}
@Override
public List<Action> getOptionalAfterActions(String playerId, EffectResult effectResult) {
GatherOptionalAfterActions gatherAfterActions = new GatherOptionalAfterActions(playerId, effectResult);
public List<Action> getOptionalAfterActions(String playerId, EffectResult[] effectResults) {
GatherOptionalAfterActions gatherAfterActions = new GatherOptionalAfterActions(playerId, effectResults);
_lotroGame.getGameState().iterateActivableCards(playerId, gatherAfterActions);
@@ -146,18 +148,20 @@ public class DefaultActionsEnvironment implements ActionsEnvironment {
}
private class GatherRequiredAfterTriggers extends CompletePhysicalCardVisitor {
private EffectResult _effectResult;
private EffectResult[] _effectResults;
private List<Action> _actions = new LinkedList<Action>();
private GatherRequiredAfterTriggers(EffectResult effectResult) {
_effectResult = effectResult;
private GatherRequiredAfterTriggers(EffectResult[] effectResults) {
_effectResults = effectResults;
}
@Override
protected void doVisitPhysicalCard(PhysicalCard physicalCard) {
List<? extends Action> actions = physicalCard.getBlueprint().getRequiredAfterTriggers(_lotroGame, _effectResult, physicalCard);
if (actions != null)
_actions.addAll(actions);
for (EffectResult effectResult : _effectResults) {
List<? extends Action> actions = physicalCard.getBlueprint().getRequiredAfterTriggers(_lotroGame, effectResult, physicalCard);
if (actions != null)
_actions.addAll(actions);
}
}
public List<Action> getActions() {
@@ -209,19 +213,22 @@ public class DefaultActionsEnvironment implements ActionsEnvironment {
private class GatherOptionalAfterTriggers extends CompletePhysicalCardVisitor {
private String _playerId;
private EffectResult _effectResult;
private EffectResult[] _effectResults;
private List<Action> _actions = new LinkedList<Action>();
private GatherOptionalAfterTriggers(String playerId, EffectResult effectResult) {
private GatherOptionalAfterTriggers(String playerId, EffectResult[] effectResults) {
_playerId = playerId;
_effectResult = effectResult;
_effectResults = effectResults;
}
@Override
protected void doVisitPhysicalCard(PhysicalCard physicalCard) {
List<? extends Action> actions = physicalCard.getBlueprint().getOptionalAfterTriggers(_playerId, _lotroGame, _effectResult, physicalCard);
if (actions != null)
_actions.addAll(actions);
for (EffectResult effectResult : _effectResults) {
List<? extends Action> actions = physicalCard.getBlueprint().getOptionalAfterTriggers(_playerId, _lotroGame, effectResult, physicalCard);
if (actions != null)
_actions.addAll(actions);
}
}
public List<Action> getActions() {
@@ -253,19 +260,21 @@ public class DefaultActionsEnvironment implements ActionsEnvironment {
private class GatherOptionalAfterActions extends CompletePhysicalCardVisitor {
private String _playerId;
private EffectResult _effectResult;
private EffectResult[] _effectResults;
private List<Action> _actions = new LinkedList<Action>();
private GatherOptionalAfterActions(String playerId, EffectResult effectResult) {
private GatherOptionalAfterActions(String playerId, EffectResult[] effectResults) {
_playerId = playerId;
_effectResult = effectResult;
_effectResults = effectResults;
}
@Override
protected void doVisitPhysicalCard(PhysicalCard physicalCard) {
List<? extends Action> actions = physicalCard.getBlueprint().getOptionalAfterActions(_playerId, _lotroGame, _effectResult, physicalCard);
if (actions != null)
_actions.addAll(actions);
for (EffectResult effectResult : _effectResults) {
List<? extends Action> actions = physicalCard.getBlueprint().getOptionalAfterActions(_playerId, _lotroGame, effectResult, physicalCard);
if (actions != null)
_actions.addAll(actions);
}
}
public List<Action> getActions() {

View File

@@ -1,14 +0,0 @@
package com.gempukku.lotro.logic.actions;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.logic.effects.DiscardAttachedCardsEffect;
import com.gempukku.lotro.logic.effects.KillEffect;
public class KillAction extends DefaultCostToEffectAction {
public KillAction(PhysicalCard card) {
super(null, null, "Kill the character");
addEffect(new KillEffect(card));
addEffect(new DiscardAttachedCardsEffect(card));
}
}

View File

@@ -49,13 +49,13 @@ public class AssignmentEffect extends AbstractEffect {
}
@Override
public EffectResult playEffect(LotroGame game) {
public EffectResult[] playEffect(LotroGame game) {
game.getGameState().sendMessage(_playerId + " assigns minion(s) to skirmish");
for (Map.Entry<PhysicalCard, List<PhysicalCard>> physicalCardListEntry : _assignments.entrySet()) {
PhysicalCard fpChar = physicalCardListEntry.getKey();
List<PhysicalCard> minions = physicalCardListEntry.getValue();
game.getGameState().assignToSkirmishes(fpChar, minions);
}
return new AssignmentResult(_assignments);
return new EffectResult[]{new AssignmentResult(_assignments)};
}
}

View File

@@ -34,7 +34,7 @@ public class DiscardAttachedCardsEffect extends AbstractEffect {
}
@Override
public EffectResult playEffect(LotroGame game) {
public EffectResult[] playEffect(LotroGame game) {
List<PhysicalCard> discardedCards = new LinkedList<PhysicalCard>();
GameState gameState = game.getGameState();
List<PhysicalCard> attachedCards = gameState.getAttachedCards(_card);
@@ -45,6 +45,6 @@ public class DiscardAttachedCardsEffect extends AbstractEffect {
discardedCards.add(attachedCard);
}
return new DiscardCardsFromPlayResult(discardedCards);
return new EffectResult[]{new DiscardCardsFromPlayResult(discardedCards)};
}
}

View File

@@ -39,7 +39,7 @@ public class DiscardCardFromPlayEffect extends AbstractEffect {
}
@Override
public EffectResult playEffect(LotroGame game) {
public EffectResult[] playEffect(LotroGame game) {
_discardedCards = new LinkedList<PhysicalCard>();
if (_source == null || game.getModifiersQuerying().canBeDiscardedFromPlay(game.getGameState(), _card, _source)) {
@@ -67,6 +67,6 @@ public class DiscardCardFromPlayEffect extends AbstractEffect {
gameState.addCardToZone(stackedCard, Zone.DISCARD);
}
}
return new DiscardCardsFromPlayResult(_discardedCards);
return new EffectResult[]{new DiscardCardsFromPlayResult(_discardedCards)};
}
}

View File

@@ -59,7 +59,7 @@ public class DiscardCardsFromPlayEffect extends AbstractEffect {
}
@Override
public EffectResult playEffect(LotroGame game) {
public EffectResult[] playEffect(LotroGame game) {
List<PhysicalCard> cardsToDiscard = getCardsToBeDiscarded(game);
List<PhysicalCard> discardedCards = new LinkedList<PhysicalCard>();
for (PhysicalCard card : cardsToDiscard) {
@@ -88,6 +88,6 @@ public class DiscardCardsFromPlayEffect extends AbstractEffect {
if (_source != null && discardedCards.size() > 0)
game.getGameState().sendMessage(_source.getOwner() + " discards multiple cards from play using " + _source.getBlueprint().getName());
return new DiscardCardsFromPlayResult(discardedCards);
return new EffectResult[]{new DiscardCardsFromPlayResult(discardedCards)};
}
}

View File

@@ -71,7 +71,7 @@ public class HealCharacterEffect extends AbstractEffect {
}
@Override
public EffectResult playEffect(LotroGame game) {
public EffectResult[] playEffect(LotroGame game) {
List<PhysicalCard> cardsToHeal = getCardsToBeHealed(game);
for (PhysicalCard cardToHeal : cardsToHeal) {
@@ -79,6 +79,6 @@ public class HealCharacterEffect extends AbstractEffect {
game.getGameState().removeWound(cardToHeal);
}
return new HealResult(cardsToHeal);
return new EffectResult[]{new HealResult(cardsToHeal)};
}
}

View File

@@ -7,13 +7,17 @@ import com.gempukku.lotro.game.state.GameState;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.timing.AbstractEffect;
import com.gempukku.lotro.logic.timing.EffectResult;
import com.gempukku.lotro.logic.timing.results.DiscardCardsFromPlayResult;
import com.gempukku.lotro.logic.timing.results.KillResult;
public class KillEffect extends AbstractEffect {
private PhysicalCard _card;
import java.util.LinkedList;
import java.util.List;
public KillEffect(PhysicalCard card) {
_card = card;
public class KillEffect extends AbstractEffect {
private List<PhysicalCard> _cards;
public KillEffect(List<PhysicalCard> cards) {
_cards = cards;
}
@Override
@@ -21,32 +25,74 @@ public class KillEffect extends AbstractEffect {
return EffectResult.Type.KILL;
}
public PhysicalCard getKilledCard() {
return _card;
public List<PhysicalCard> getCharactersToBeKilled() {
return _cards;
}
@Override
public String getText(LotroGame game) {
return "Kill " + _card.getBlueprint().getName();
List<PhysicalCard> cards = getCharactersToBeKilled();
return "Kill - " + getAppendedNames(cards);
}
private String getAppendedNames(List<PhysicalCard> cards) {
StringBuilder sb = new StringBuilder();
for (PhysicalCard card : cards)
sb.append(card.getBlueprint().getName() + ", ");
if (sb.length() == 0)
return "none";
else
return sb.substring(0, sb.length() - 1);
}
@Override
public boolean canPlayEffect(LotroGame game) {
Zone zone = _card.getZone();
return zone == Zone.FREE_CHARACTERS || zone == Zone.FREE_SUPPORT || zone == Zone.SHADOW_CHARACTERS;
return true;
}
@Override
public EffectResult playEffect(LotroGame game) {
GameState gameState = game.getGameState();
gameState.sendMessage(_card.getBlueprint().getName() + " gets killed");
gameState.stopAffecting(_card);
gameState.removeCardFromZone(_card);
if (_card.getBlueprint().getSide() == Side.FREE_PEOPLE)
gameState.addCardToZone(_card, Zone.DEAD);
else
gameState.addCardToZone(_card, Zone.DISCARD);
public EffectResult[] playEffect(LotroGame game) {
List<PhysicalCard> discardedCards = new LinkedList<PhysicalCard>();
List<PhysicalCard> killedCards = new LinkedList<PhysicalCard>();
return new KillResult(_card);
for (PhysicalCard card : _cards) {
GameState gameState = game.getGameState();
gameState.sendMessage(card.getBlueprint().getName() + " gets killed");
gameState.stopAffecting(card);
gameState.removeCardFromZone(card);
if (card.getBlueprint().getSide() == Side.FREE_PEOPLE) {
killedCards.add(card);
gameState.addCardToZone(card, Zone.DEAD);
} else {
discardedCards.add(card);
gameState.addCardToZone(card, Zone.DISCARD);
}
List<PhysicalCard> attachedCards = gameState.getAttachedCards(card);
for (PhysicalCard attachedCard : attachedCards) {
discardedCards.add(attachedCard);
gameState.stopAffecting(attachedCard);
gameState.removeCardFromZone(attachedCard);
gameState.addCardToZone(attachedCard, Zone.DISCARD);
}
List<PhysicalCard> stackedCards = gameState.getStackedCards(card);
for (PhysicalCard stackedCard : stackedCards) {
gameState.removeCardFromZone(stackedCard);
gameState.addCardToZone(stackedCard, Zone.DISCARD);
}
}
if (killedCards.size() > 0 && discardedCards.size() > 0) {
return new EffectResult[]{new KillResult(killedCards), new DiscardCardsFromPlayResult(discardedCards)};
} else if (killedCards.size() > 0) {
return new EffectResult[]{new KillResult(killedCards)};
} else if (discardedCards.size() > 0) {
return new EffectResult[]{new DiscardCardsFromPlayResult(discardedCards)};
} else {
return null;
}
}
}

View File

@@ -33,8 +33,8 @@ public class OverwhelmedEffect extends AbstractEffect {
}
@Override
public EffectResult playEffect(LotroGame game) {
public EffectResult[] playEffect(LotroGame game) {
game.getGameState().sendMessage("Skirmish finishes with an overwhelm");
return new OverwhelmSkirmishResult(_winners, _losers);
return new EffectResult[]{new OverwhelmSkirmishResult(_winners, _losers)};
}
}

View File

@@ -43,7 +43,7 @@ public class PlayCardEffect extends AbstractEffect {
}
@Override
public EffectResult playEffect(LotroGame game) {
return new PlayCardResult(_cardPlayed, _attachedToCard);
public EffectResult[] playEffect(LotroGame game) {
return new EffectResult[]{new PlayCardResult(_cardPlayed, _attachedToCard)};
}
}

View File

@@ -33,8 +33,8 @@ public class SkirmishResolvedEffect extends AbstractEffect {
}
@Override
public EffectResult playEffect(LotroGame game) {
public EffectResult[] playEffect(LotroGame game) {
game.getGameState().sendMessage("Skirmish finishes with a normal win");
return new NormalSkirmishResult(_winners, _losers);
return new EffectResult[]{new NormalSkirmishResult(_winners, _losers)};
}
}

View File

@@ -29,7 +29,7 @@ public class TriggeringEffect extends AbstractEffect {
}
@Override
public EffectResult playEffect(LotroGame game) {
return _effectResult;
public EffectResult[] playEffect(LotroGame game) {
return new EffectResult[]{_effectResult};
}
}

View File

@@ -66,7 +66,7 @@ public class WoundCharacterEffect extends AbstractEffect {
}
@Override
public EffectResult playEffect(LotroGame game) {
public EffectResult[] playEffect(LotroGame game) {
List<PhysicalCard> woundedCards = getCardsToBeWounded(game);
for (PhysicalCard woundedCard : woundedCards) {
@@ -74,7 +74,7 @@ public class WoundCharacterEffect extends AbstractEffect {
game.getGameState().addWound(woundedCard);
}
return new WoundResult(woundedCards);
return new EffectResult[]{new WoundResult(woundedCards)};
}
public void prevent(PhysicalCard card) {

View File

@@ -17,5 +17,5 @@ public interface Effect {
public boolean canPlayEffect(LotroGame game);
public EffectResult playEffect(LotroGame game);
public EffectResult[] playEffect(LotroGame game);
}

View File

@@ -61,7 +61,7 @@ public class TurnProcedure {
private class PlayOutRecognizableEffect extends SystemAction {
private Effect _effect;
private EffectResult _effectResult;
private EffectResult[] _effectResults;
private boolean _checkedPlayability;
private boolean _checkedIsAboutToRequiredResponses;
private boolean _checkedIsAboutToOptionalResponses;
@@ -109,17 +109,17 @@ public class TurnProcedure {
}
if (!_effectPlayed) {
if (_effect.canPlayEffect(_game))
_effectResult = _effect.playEffect(_game);
_effectResults = _effect.playEffect(_game);
else {
_effect.setFailed();
return null;
}
_effectPlayed = true;
}
if (_effectResult != null) {
if (_effectResults != null) {
if (!_checkedRequiredWhenResponses) {
_checkedRequiredWhenResponses = true;
List<Action> requiredResponses = _game.getActionsEnvironment().getRequiredAfterTriggers(_effectResult);
List<Action> requiredResponses = _game.getActionsEnvironment().getRequiredAfterTriggers(_effectResults);
if (requiredResponses.size() > 0) {
DefaultCostToEffectAction action = new DefaultCostToEffectAction(null, null, null);
action.addEffect(new PlayoutAllActionsIfEffectNotCancelledEffect(action, _effect, requiredResponses));
@@ -130,7 +130,7 @@ public class TurnProcedure {
_checkedOptionalWhenResponses = true;
DefaultCostToEffectAction action = new DefaultCostToEffectAction(null, null, null);
action.addEffect(
new PlayoutOptionalAfterResponsesEffect(action, new HashSet<PhysicalCard>(), _game.getGameState().getPlayerOrder().getCounterClockwisePlayOrder(_game.getGameState().getCurrentPlayerId(), true), 0, _effect, _effectResult));
new PlayoutOptionalAfterResponsesEffect(action, new HashSet<PhysicalCard>(), _game.getGameState().getPlayerOrder().getCounterClockwisePlayOrder(_game.getGameState().getCurrentPlayerId(), true), 0, _effect, _effectResults));
return new StackActionEffect(action);
}
}
@@ -204,29 +204,29 @@ public class TurnProcedure {
private PlayOrder _playOrder;
private int _passCount;
private Effect _effect;
private EffectResult _effectResult;
private EffectResult[] _effectResults;
private PlayoutOptionalAfterResponsesEffect(DefaultCostToEffectAction action, Set<PhysicalCard> cardTriggersUsed, PlayOrder playOrder, int passCount, Effect effect, EffectResult effectResult) {
private PlayoutOptionalAfterResponsesEffect(DefaultCostToEffectAction action, Set<PhysicalCard> cardTriggersUsed, PlayOrder playOrder, int passCount, Effect effect, EffectResult[] effectResults) {
_action = action;
_cardTriggersUsed = cardTriggersUsed;
_playOrder = playOrder;
_passCount = passCount;
_effect = effect;
_effectResult = effectResult;
_effectResults = effectResults;
}
@Override
public void doPlayEffect(LotroGame game) {
final String activePlayer = _playOrder.getNextPlayer();
final List<Action> optionalAfterTriggers = game.getActionsEnvironment().getOptionalAfterTriggers(activePlayer, _effectResult);
final List<Action> optionalAfterTriggers = game.getActionsEnvironment().getOptionalAfterTriggers(activePlayer, _effectResults);
// Remove triggers already resolved
final Iterator<Action> triggersIterator = optionalAfterTriggers.iterator();
while (triggersIterator.hasNext())
if (_cardTriggersUsed.contains(triggersIterator.next().getActionSource()))
triggersIterator.remove();
final List<Action> optionalAfterActions = _game.getActionsEnvironment().getOptionalAfterActions(activePlayer, _effectResult);
final List<Action> optionalAfterActions = _game.getActionsEnvironment().getOptionalAfterActions(activePlayer, _effectResults);
List<Action> possibleActions = new LinkedList<Action>(optionalAfterTriggers);
possibleActions.addAll(optionalAfterActions);
@@ -241,17 +241,17 @@ public class TurnProcedure {
_game.getActionsEnvironment().addActionToStack(action);
if (optionalAfterTriggers.contains(action))
_cardTriggersUsed.add(action.getActionSource());
_action.addEffect(new PlayoutOptionalAfterResponsesEffect(_action, _cardTriggersUsed, _playOrder, 0, _effect, _effectResult));
_action.addEffect(new PlayoutOptionalAfterResponsesEffect(_action, _cardTriggersUsed, _playOrder, 0, _effect, _effectResults));
} else {
if ((_passCount + 1) < _playOrder.getPlayerCount()) {
_action.addEffect(new PlayoutOptionalAfterResponsesEffect(_action, _cardTriggersUsed, _playOrder, _passCount + 1, _effect, _effectResult));
_action.addEffect(new PlayoutOptionalAfterResponsesEffect(_action, _cardTriggersUsed, _playOrder, _passCount + 1, _effect, _effectResults));
}
}
}
});
} else {
if ((_passCount + 1) < _playOrder.getPlayerCount()) {
_action.addEffect(new PlayoutOptionalAfterResponsesEffect(_action, _cardTriggersUsed, _playOrder, _passCount + 1, _effect, _effectResult));
_action.addEffect(new PlayoutOptionalAfterResponsesEffect(_action, _cardTriggersUsed, _playOrder, _passCount + 1, _effect, _effectResults));
}
}
}

View File

@@ -44,7 +44,7 @@ public abstract class UnrespondableEffect implements Effect {
protected abstract void doPlayEffect(LotroGame game);
@Override
public final EffectResult playEffect(LotroGame game) {
public final EffectResult[] playEffect(LotroGame game) {
doPlayEffect(game);
return null;
}

View File

@@ -3,15 +3,17 @@ package com.gempukku.lotro.logic.timing.results;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.logic.timing.EffectResult;
public class ExertResult extends EffectResult {
private PhysicalCard _card;
import java.util.List;
public ExertResult(PhysicalCard card) {
public class ExertResult extends EffectResult {
private List<PhysicalCard> _cards;
public ExertResult(List<PhysicalCard> cards) {
super(Type.EXERT);
_card = card;
_cards = cards;
}
public PhysicalCard getExertedCard() {
return _card;
public List<PhysicalCard> getExertedCards() {
return _cards;
}
}

View File

@@ -3,15 +3,17 @@ package com.gempukku.lotro.logic.timing.results;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.logic.timing.EffectResult;
public class KillResult extends EffectResult {
private PhysicalCard _killedCard;
import java.util.List;
public KillResult(PhysicalCard killedCard) {
public class KillResult extends EffectResult {
private List<PhysicalCard> _killedCards;
public KillResult(List<PhysicalCard> killedCards) {
super(EffectResult.Type.KILL);
_killedCard = killedCard;
_killedCards = killedCards;
}
public PhysicalCard getKilledCard() {
return _killedCard;
public List<PhysicalCard> getKilledCards() {
return _killedCards;
}
}

View File

@@ -1,18 +1,18 @@
package com.gempukku.lotro.logic.timing.rules;
import com.gempukku.lotro.common.CardType;
import com.gempukku.lotro.common.Side;
import com.gempukku.lotro.filters.Filters;
import com.gempukku.lotro.game.AbstractActionProxy;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.GameState;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.game.state.actions.DefaultActionsEnvironment;
import com.gempukku.lotro.logic.actions.DiscardMinionFromPlayAction;
import com.gempukku.lotro.logic.actions.KillAction;
import com.gempukku.lotro.logic.actions.RequiredTriggerAction;
import com.gempukku.lotro.logic.effects.KillEffect;
import com.gempukku.lotro.logic.timing.Action;
import com.gempukku.lotro.logic.timing.EffectResult;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -28,21 +28,24 @@ public class CharacterDeathRule {
new AbstractActionProxy() {
@Override
public List<? extends Action> getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) {
List<Action> actions = new LinkedList<Action>();
GameState gameState = game.getGameState();
List<PhysicalCard> deadCharacters = new LinkedList<PhysicalCard>();
List<PhysicalCard> characters = Filters.filterActive(gameState, game.getModifiersQuerying(),
Filters.or(Filters.type(CardType.ALLY), Filters.type(CardType.COMPANION), Filters.type(CardType.MINION)));
for (PhysicalCard character : characters)
if (gameState.getWounds(character) >= game.getModifiersQuerying().getVitality(gameState, character))
if (character.getBlueprint().getSide() == Side.FREE_PEOPLE) {
actions.add(new KillAction(character));
} else {
actions.add(new DiscardMinionFromPlayAction(character));
}
deadCharacters.add(character);
return actions;
if (deadCharacters.size() > 0) {
RequiredTriggerAction action = new RequiredTriggerAction(null, null, "Character death from wounds");
action.addEffect(
new KillEffect(deadCharacters));
return Collections.singletonList(action);
}
return null;
}
}
);

View File

@@ -7,14 +7,16 @@ import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.GameState;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.game.state.actions.DefaultActionsEnvironment;
import com.gempukku.lotro.logic.actions.KillAction;
import com.gempukku.lotro.logic.actions.RequiredTriggerAction;
import com.gempukku.lotro.logic.actions.WoundAction;
import com.gempukku.lotro.logic.effects.KillEffect;
import com.gempukku.lotro.logic.modifiers.ModifiersQuerying;
import com.gempukku.lotro.logic.timing.Action;
import com.gempukku.lotro.logic.timing.EffectResult;
import com.gempukku.lotro.logic.timing.results.NormalSkirmishResult;
import com.gempukku.lotro.logic.timing.results.OverwhelmSkirmishResult;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -51,13 +53,12 @@ public class ResolveSkirmishRule {
OverwhelmSkirmishResult skirmishResult = (OverwhelmSkirmishResult) effectResult;
List<PhysicalCard> losers = skirmishResult.getLosers();
List<Action> actions = new LinkedList<Action>();
for (PhysicalCard loser : losers)
actions.add(new KillAction(loser));
return actions;
} else {
return null;
RequiredTriggerAction action = new RequiredTriggerAction(null, null, "Kill overwhelmed characters");
action.addEffect(new KillEffect(losers));
return Collections.singletonList(action);
}
return null;
}
}
);