Extracting rules for playing required triggers
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
package com.gempukku.lotro.cards.set11.site;
|
package com.gempukku.lotro.cards.set11.site;
|
||||||
|
|
||||||
import com.gempukku.lotro.logic.cardtype.AbstractShadowsSite;
|
|
||||||
import com.gempukku.lotro.logic.effects.AddUntilStartOfPhaseModifierEffect;
|
|
||||||
import com.gempukku.lotro.common.CardType;
|
import com.gempukku.lotro.common.CardType;
|
||||||
import com.gempukku.lotro.common.Culture;
|
import com.gempukku.lotro.common.Culture;
|
||||||
import com.gempukku.lotro.common.Keyword;
|
import com.gempukku.lotro.common.Keyword;
|
||||||
@@ -11,6 +9,8 @@ import com.gempukku.lotro.game.AbstractActionProxy;
|
|||||||
import com.gempukku.lotro.game.PhysicalCard;
|
import com.gempukku.lotro.game.PhysicalCard;
|
||||||
import com.gempukku.lotro.game.state.LotroGame;
|
import com.gempukku.lotro.game.state.LotroGame;
|
||||||
import com.gempukku.lotro.logic.actions.RequiredTriggerAction;
|
import com.gempukku.lotro.logic.actions.RequiredTriggerAction;
|
||||||
|
import com.gempukku.lotro.logic.cardtype.AbstractShadowsSite;
|
||||||
|
import com.gempukku.lotro.logic.effects.AddUntilStartOfPhaseModifierEffect;
|
||||||
import com.gempukku.lotro.logic.modifiers.RemoveKeywordModifier;
|
import com.gempukku.lotro.logic.modifiers.RemoveKeywordModifier;
|
||||||
import com.gempukku.lotro.logic.timing.EffectResult;
|
import com.gempukku.lotro.logic.timing.EffectResult;
|
||||||
import com.gempukku.lotro.logic.timing.UnrespondableEffect;
|
import com.gempukku.lotro.logic.timing.UnrespondableEffect;
|
||||||
@@ -37,40 +37,53 @@ public class Card11_243 extends AbstractShadowsSite {
|
|||||||
public List<RequiredTriggerAction> getRequiredAfterTriggers(LotroGame game, EffectResult effectResult, final PhysicalCard self) {
|
public List<RequiredTriggerAction> getRequiredAfterTriggers(LotroGame game, EffectResult effectResult, final PhysicalCard self) {
|
||||||
if (game.getModifiersQuerying().getUntilStartOfPhaseLimitCounter(self, Phase.REGROUP).getUsedLimit() < 1
|
if (game.getModifiersQuerying().getUntilStartOfPhaseLimitCounter(self, Phase.REGROUP).getUsedLimit() < 1
|
||||||
&& !game.getGameState().getCurrentPhase().equals(Phase.REGROUP)) {
|
&& !game.getGameState().getCurrentPhase().equals(Phase.REGROUP)) {
|
||||||
game.getActionsEnvironment().addUntilStartOfPhaseActionProxy(
|
RequiredTriggerAction action = new RequiredTriggerAction(self);
|
||||||
new AbstractActionProxy() {
|
action.appendEffect(
|
||||||
private Set<Integer> _minionsMarked = new HashSet<Integer>();
|
new UnrespondableEffect() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends RequiredTriggerAction> getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) {
|
protected void doPlayEffect(LotroGame game) {
|
||||||
Set<PhysicalCard> toLose = new HashSet<PhysicalCard>();
|
game.getModifiersQuerying().getUntilStartOfPhaseLimitCounter(self, Phase.REGROUP).incrementToLimit(1, 1);
|
||||||
final Set<Integer> toLoseInts = new HashSet<Integer>();
|
|
||||||
for (PhysicalCard minion : Filters.filterActive(game, Filters.inSkirmishAgainst(Culture.ROHAN, CardType.COMPANION))) {
|
|
||||||
if (!_minionsMarked.contains(minion.getCardId())) {
|
|
||||||
toLose.add(minion);
|
|
||||||
toLoseInts.add(minion.getCardId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toLose.size() > 0) {
|
|
||||||
RequiredTriggerAction action = new RequiredTriggerAction(self);
|
|
||||||
action.appendEffect(
|
|
||||||
new UnrespondableEffect() {
|
|
||||||
@Override
|
|
||||||
protected void doPlayEffect(LotroGame game) {
|
|
||||||
_minionsMarked.addAll(toLoseInts);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
action.appendEffect(
|
|
||||||
new AddUntilStartOfPhaseModifierEffect(
|
|
||||||
new RemoveKeywordModifier(self, Filters.in(toLose), Keyword.FIERCE), Phase.REGROUP));
|
|
||||||
return Collections.singletonList(action);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}, Phase.REGROUP);
|
});
|
||||||
|
action.appendEffect(
|
||||||
|
new UnrespondableEffect() {
|
||||||
|
@Override
|
||||||
|
protected void doPlayEffect(LotroGame game) {
|
||||||
|
game.getActionsEnvironment().addUntilStartOfPhaseActionProxy(
|
||||||
|
new AbstractActionProxy() {
|
||||||
|
private Set<Integer> _minionsMarked = new HashSet<Integer>();
|
||||||
|
|
||||||
game.getModifiersQuerying().getUntilStartOfPhaseLimitCounter(self, Phase.REGROUP).incrementToLimit(1, 1);
|
@Override
|
||||||
|
public List<? extends RequiredTriggerAction> getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) {
|
||||||
|
Set<PhysicalCard> toLose = new HashSet<PhysicalCard>();
|
||||||
|
final Set<Integer> toLoseInts = new HashSet<Integer>();
|
||||||
|
for (PhysicalCard minion : Filters.filterActive(game, Filters.inSkirmishAgainst(Culture.ROHAN, CardType.COMPANION))) {
|
||||||
|
if (!_minionsMarked.contains(minion.getCardId())) {
|
||||||
|
toLose.add(minion);
|
||||||
|
toLoseInts.add(minion.getCardId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toLose.size() > 0) {
|
||||||
|
RequiredTriggerAction action = new RequiredTriggerAction(self);
|
||||||
|
action.appendEffect(
|
||||||
|
new UnrespondableEffect() {
|
||||||
|
@Override
|
||||||
|
protected void doPlayEffect(LotroGame game) {
|
||||||
|
_minionsMarked.addAll(toLoseInts);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
action.appendEffect(
|
||||||
|
new AddUntilStartOfPhaseModifierEffect(
|
||||||
|
new RemoveKeywordModifier(self, Filters.in(toLose), Keyword.FIERCE), Phase.REGROUP));
|
||||||
|
return Collections.singletonList(action);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, Phase.REGROUP);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Collections.singletonList(action);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -649,6 +649,10 @@ public class GameState {
|
|||||||
return Collections.unmodifiableList(_adventureDecks.get(playerId));
|
return Collections.unmodifiableList(_adventureDecks.get(playerId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<? extends PhysicalCard> getInPlay() {
|
||||||
|
return Collections.unmodifiableList(_inPlay);
|
||||||
|
}
|
||||||
|
|
||||||
public String getCurrentPlayerId() {
|
public String getCurrentPlayerId() {
|
||||||
return _currentPlayerId;
|
return _currentPlayerId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,11 +123,7 @@ public class DefaultActionsEnvironment implements ActionsEnvironment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Action> getRequiredBeforeTriggers(Effect effect) {
|
public List<Action> getRequiredBeforeTriggers(Effect effect) {
|
||||||
GatherRequiredBeforeTriggers gatherActions = new GatherRequiredBeforeTriggers(effect);
|
List<Action> gatheredActions = new LinkedList<>();
|
||||||
|
|
||||||
_lotroGame.getGameState().iterateActiveTextCards(gatherActions);
|
|
||||||
|
|
||||||
List<Action> gatheredActions = gatherActions.getActions();
|
|
||||||
|
|
||||||
for (ActionProxy actionProxy : _actionProxies) {
|
for (ActionProxy actionProxy : _actionProxies) {
|
||||||
List<? extends RequiredTriggerAction> actions = actionProxy.getRequiredBeforeTriggers(_lotroGame, effect);
|
List<? extends RequiredTriggerAction> actions = actionProxy.getRequiredBeforeTriggers(_lotroGame, effect);
|
||||||
@@ -180,11 +176,7 @@ public class DefaultActionsEnvironment implements ActionsEnvironment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Action> getRequiredAfterTriggers(Collection<? extends EffectResult> effectResults) {
|
public List<Action> getRequiredAfterTriggers(Collection<? extends EffectResult> effectResults) {
|
||||||
GatherRequiredAfterTriggers gatherActions = new GatherRequiredAfterTriggers(effectResults);
|
List<Action> gatheredActions = new LinkedList<>();
|
||||||
|
|
||||||
_lotroGame.getGameState().iterateActiveTextCards(gatherActions);
|
|
||||||
|
|
||||||
List<Action> gatheredActions = gatherActions.getActions();
|
|
||||||
|
|
||||||
if (effectResults != null) {
|
if (effectResults != null) {
|
||||||
for (ActionProxy actionProxy : _actionProxies) {
|
for (ActionProxy actionProxy : _actionProxies) {
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ public class RuleSet {
|
|||||||
|
|
||||||
new ActivateResponseAbilitiesRule(_actionsEnvironment).applyRule();
|
new ActivateResponseAbilitiesRule(_actionsEnvironment).applyRule();
|
||||||
|
|
||||||
|
new RequiredTriggersRule(_actionsEnvironment).applyRule();
|
||||||
|
|
||||||
new TakeOffRingRule(_actionsEnvironment).applyRule();
|
new TakeOffRingRule(_actionsEnvironment).applyRule();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class ActivateResponseAbilitiesRule {
|
|||||||
@Override
|
@Override
|
||||||
public List<? extends Action> getOptionalBeforeActions(String playerId, LotroGame game, Effect effect) {
|
public List<? extends Action> getOptionalBeforeActions(String playerId, LotroGame game, Effect effect) {
|
||||||
List<Action> result = new LinkedList<>();
|
List<Action> result = new LinkedList<>();
|
||||||
for (PhysicalCard activableCard : Filters.filterActive(game, getActivatableCardsFilter(playerId))) {
|
for (PhysicalCard activableCard : Filters.filter(game.getGameState().getInPlay(), game, getActivatableCardsFilter(playerId))) {
|
||||||
if (!game.getModifiersQuerying().hasTextRemoved(game, activableCard)) {
|
if (!game.getModifiersQuerying().hasTextRemoved(game, activableCard)) {
|
||||||
final List<? extends ActivateCardAction> actions = activableCard.getBlueprint().getOptionalInPlayBeforeActions(playerId, game, effect, activableCard);
|
final List<? extends ActivateCardAction> actions = activableCard.getBlueprint().getOptionalInPlayBeforeActions(playerId, game, effect, activableCard);
|
||||||
if (actions != null)
|
if (actions != null)
|
||||||
@@ -45,7 +45,7 @@ public class ActivateResponseAbilitiesRule {
|
|||||||
@Override
|
@Override
|
||||||
public List<? extends Action> getOptionalAfterActions(String playerId, LotroGame game, EffectResult effectResult) {
|
public List<? extends Action> getOptionalAfterActions(String playerId, LotroGame game, EffectResult effectResult) {
|
||||||
List<Action> result = new LinkedList<>();
|
List<Action> result = new LinkedList<>();
|
||||||
for (PhysicalCard activableCard : Filters.filterActive(game, getActivatableCardsFilter(playerId))) {
|
for (PhysicalCard activableCard : Filters.filter(game.getGameState().getInPlay(), game, getActivatableCardsFilter(playerId))) {
|
||||||
if (!game.getModifiersQuerying().hasTextRemoved(game, activableCard)) {
|
if (!game.getModifiersQuerying().hasTextRemoved(game, activableCard)) {
|
||||||
final List<? extends ActivateCardAction> actions = activableCard.getBlueprint().getOptionalInPlayAfterActions(playerId, game, effectResult, activableCard);
|
final List<? extends ActivateCardAction> actions = activableCard.getBlueprint().getOptionalInPlayAfterActions(playerId, game, effectResult, activableCard);
|
||||||
if (actions != null)
|
if (actions != null)
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package com.gempukku.lotro.logic.timing.rules;
|
||||||
|
|
||||||
|
import com.gempukku.lotro.common.CardType;
|
||||||
|
import com.gempukku.lotro.common.Phase;
|
||||||
|
import com.gempukku.lotro.filters.Filter;
|
||||||
|
import com.gempukku.lotro.filters.Filters;
|
||||||
|
import com.gempukku.lotro.game.AbstractActionProxy;
|
||||||
|
import com.gempukku.lotro.game.PhysicalCard;
|
||||||
|
import com.gempukku.lotro.game.state.LotroGame;
|
||||||
|
import com.gempukku.lotro.game.state.actions.DefaultActionsEnvironment;
|
||||||
|
import com.gempukku.lotro.logic.actions.RequiredTriggerAction;
|
||||||
|
import com.gempukku.lotro.logic.modifiers.condition.OrCondition;
|
||||||
|
import com.gempukku.lotro.logic.modifiers.condition.PhaseCondition;
|
||||||
|
import com.gempukku.lotro.logic.timing.Effect;
|
||||||
|
import com.gempukku.lotro.logic.timing.EffectResult;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class RequiredTriggersRule {
|
||||||
|
private DefaultActionsEnvironment actionsEnvironment;
|
||||||
|
|
||||||
|
public RequiredTriggersRule(DefaultActionsEnvironment actionsEnvironment) {
|
||||||
|
this.actionsEnvironment = actionsEnvironment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void applyRule() {
|
||||||
|
actionsEnvironment.addAlwaysOnActionProxy(
|
||||||
|
new AbstractActionProxy() {
|
||||||
|
@Override
|
||||||
|
public List<? extends RequiredTriggerAction> getRequiredBeforeTriggers(LotroGame game, Effect effect) {
|
||||||
|
List<RequiredTriggerAction> result = new LinkedList<>();
|
||||||
|
for (PhysicalCard activableCard : Filters.filter(game.getGameState().getInPlay(), game, getActivatableCardsFilter())) {
|
||||||
|
if (!game.getModifiersQuerying().hasTextRemoved(game, activableCard)) {
|
||||||
|
final List<? extends RequiredTriggerAction> actions = activableCard.getBlueprint().getRequiredBeforeTriggers(game, effect, activableCard);
|
||||||
|
if (actions != null)
|
||||||
|
result.addAll(actions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends RequiredTriggerAction> getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) {
|
||||||
|
List<RequiredTriggerAction> result = new LinkedList<>();
|
||||||
|
for (PhysicalCard activableCard : Filters.filter(game.getGameState().getInPlay(), game, getActivatableCardsFilter())) {
|
||||||
|
if (!game.getModifiersQuerying().hasTextRemoved(game, activableCard)) {
|
||||||
|
final List<? extends RequiredTriggerAction> actions = activableCard.getBlueprint().getRequiredAfterTriggers(game, effectResult, activableCard);
|
||||||
|
if (actions != null)
|
||||||
|
result.addAll(actions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Filter getActivatableCardsFilter() {
|
||||||
|
return Filters.conditionFilter(
|
||||||
|
Filters.or(Filters.currentSite, Filters.and(Filters.not(CardType.SITE))),
|
||||||
|
new OrCondition(new PhaseCondition(Phase.PUT_RING_BEARER), new PhaseCondition(Phase.PLAY_STARTING_FELLOWSHIP)),
|
||||||
|
Filters.and(Filters.not(CardType.SITE)));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user