diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/effects/IncrementEffect.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/effects/IncrementEffect.java new file mode 100644 index 000000000..e93c0354e --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/effects/IncrementEffect.java @@ -0,0 +1,19 @@ +package com.gempukku.lotro.at.effects; + +import com.gempukku.lotro.game.state.LotroGame; +import com.gempukku.lotro.logic.timing.UnrespondableEffect; + +import java.util.concurrent.atomic.AtomicInteger; + +public class IncrementEffect extends UnrespondableEffect { + private AtomicInteger _atomicInteger; + + public IncrementEffect(AtomicInteger atomicInteger) { + _atomicInteger = atomicInteger; + } + + @Override + protected void doPlayEffect(LotroGame game) { + _atomicInteger.incrementAndGet(); + } +} diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/effects/WoundEffectAtTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/effects/WoundEffectAtTest.java index edf2ba0cc..ad008813d 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/effects/WoundEffectAtTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/effects/WoundEffectAtTest.java @@ -2,6 +2,7 @@ package com.gempukku.lotro.at.effects; import com.gempukku.lotro.at.AbstractAtTest; import com.gempukku.lotro.cards.TriggerConditions; +import com.gempukku.lotro.cards.effects.NegateWoundEffect; import com.gempukku.lotro.cards.effects.PreventCardEffect; import com.gempukku.lotro.common.Zone; import com.gempukku.lotro.game.AbstractActionProxy; @@ -12,6 +13,8 @@ import com.gempukku.lotro.logic.actions.SystemQueueAction; import com.gempukku.lotro.logic.decisions.CardActionSelectionDecision; import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException; import com.gempukku.lotro.logic.effects.WoundCharactersEffect; +import com.gempukku.lotro.logic.modifiers.ModifierFlag; +import com.gempukku.lotro.logic.modifiers.SpecialFlagModifier; import com.gempukku.lotro.logic.timing.Effect; import com.gempukku.lotro.logic.timing.EffectResult; import org.junit.Test; @@ -38,7 +41,10 @@ public class WoundEffectAtTest extends AbstractAtTest { @Override public List getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) { if (TriggerConditions.forEachWounded(game, effectResult, merry)) { - triggerCount.incrementAndGet(); + RequiredTriggerAction action = new RequiredTriggerAction(merry); + action.appendEffect( + new IncrementEffect(triggerCount)); + return Collections.singletonList(action); } return null; } @@ -72,7 +78,10 @@ public class WoundEffectAtTest extends AbstractAtTest { @Override public List getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) { if (TriggerConditions.forEachWounded(game, effectResult, merry)) { - triggerCount.incrementAndGet(); + RequiredTriggerAction action = new RequiredTriggerAction(merry); + action.appendEffect( + new IncrementEffect(triggerCount)); + return Collections.singletonList(action); } return null; } @@ -101,6 +110,7 @@ public class WoundEffectAtTest extends AbstractAtTest { final PhysicalCardImpl pippin = new PhysicalCardImpl(102, "1_306", P1, _library.getLotroCardBlueprint("1_306")); final AtomicInteger triggerCount = new AtomicInteger(0); + final AtomicInteger preventCount = new AtomicInteger(0); _game.getActionsEnvironment().addUntilEndOfTurnActionProxy( new AbstractActionProxy() { @@ -110,6 +120,8 @@ public class WoundEffectAtTest extends AbstractAtTest { RequiredTriggerAction action = new RequiredTriggerAction(merry); action.appendEffect( new PreventCardEffect((WoundCharactersEffect) effect, merry)); + action.appendEffect( + new IncrementEffect(preventCount)); return Collections.singletonList(action); } return null; @@ -118,7 +130,10 @@ public class WoundEffectAtTest extends AbstractAtTest { @Override public List getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) { if (TriggerConditions.forEachWounded(game, effectResult, merry)) { - triggerCount.incrementAndGet(); + RequiredTriggerAction action = new RequiredTriggerAction(merry); + action.appendEffect( + new IncrementEffect(triggerCount)); + return Collections.singletonList(action); } return null; } @@ -137,6 +152,117 @@ public class WoundEffectAtTest extends AbstractAtTest { assertFalse(woundEffect.wasCarriedOut()); assertEquals(0, triggerCount.get()); + assertEquals(1, preventCount.get()); + } + + @Test + public void insteadOfWoundWorksIfCantPrevent() throws DecisionResultInvalidException { + initializeSimplestGame(); + + skipMulligans(); + + final PhysicalCardImpl merry = new PhysicalCardImpl(101, "1_303", P1, _library.getLotroCardBlueprint("1_303")); + + final AtomicInteger triggerCount = new AtomicInteger(0); + final AtomicInteger negateCount = new AtomicInteger(0); + + _game.getModifiersEnvironment().addUntilEndOfTurnModifier( + new SpecialFlagModifier(null, ModifierFlag.CANT_PREVENT_WOUNDS)); + + _game.getActionsEnvironment().addUntilEndOfTurnActionProxy( + new AbstractActionProxy() { + @Override + public List getRequiredBeforeTriggers(LotroGame game, Effect effect) { + if (TriggerConditions.isGettingWounded(effect, game, merry)) { + RequiredTriggerAction action = new RequiredTriggerAction(merry); + action.appendEffect( + new NegateWoundEffect((WoundCharactersEffect) effect, merry)); + action.appendEffect( + new IncrementEffect(negateCount)); + return Collections.singletonList(action); + } + return null; + } + + @Override + public List getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) { + if (TriggerConditions.forEachWounded(game, effectResult, merry)) { + RequiredTriggerAction action = new RequiredTriggerAction(merry); + action.appendEffect( + new IncrementEffect(triggerCount)); + return Collections.singletonList(action); + } + return null; + } + }); + + _game.getGameState().addCardToZone(_game, merry, Zone.FREE_CHARACTERS); + + WoundCharactersEffect woundEffect = new WoundCharactersEffect(merry, merry); + + carryOutEffectInPhaseActionByPlayer(P1, woundEffect); + + assertEquals(0, _game.getGameState().getWounds(merry)); + assertTrue(woundEffect.wasSuccessful()); + assertFalse(woundEffect.wasCarriedOut()); + + assertEquals(0, triggerCount.get()); + assertEquals(1, negateCount.get()); + } + + @Test + public void cantPrevent() throws DecisionResultInvalidException { + initializeSimplestGame(); + + skipMulligans(); + + final PhysicalCardImpl merry = new PhysicalCardImpl(101, "1_303", P1, _library.getLotroCardBlueprint("1_303")); + + final AtomicInteger triggerCount = new AtomicInteger(0); + final AtomicInteger preventCount = new AtomicInteger(0); + + _game.getModifiersEnvironment().addUntilEndOfTurnModifier( + new SpecialFlagModifier(null, ModifierFlag.CANT_PREVENT_WOUNDS)); + + _game.getActionsEnvironment().addUntilEndOfTurnActionProxy( + new AbstractActionProxy() { + @Override + public List getRequiredBeforeTriggers(LotroGame game, Effect effect) { + if (TriggerConditions.isGettingWounded(effect, game, merry)) { + RequiredTriggerAction action = new RequiredTriggerAction(merry); + action.appendEffect( + new PreventCardEffect((WoundCharactersEffect) effect, merry)); + action.appendEffect( + new IncrementEffect(preventCount)); + return Collections.singletonList(action); + } + return null; + } + + @Override + public List getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) { + if (TriggerConditions.forEachWounded(game, effectResult, merry)) { + RequiredTriggerAction action = new RequiredTriggerAction(merry); + action.appendEffect( + new IncrementEffect(triggerCount)); + return Collections.singletonList(action); + } + return null; + } + }); + + _game.getGameState().addCardToZone(_game, merry, Zone.FREE_CHARACTERS); + + WoundCharactersEffect woundEffect = new WoundCharactersEffect(merry, merry); + + carryOutEffectInPhaseActionByPlayer(P1, woundEffect); + + assertEquals(1, _game.getGameState().getWounds(merry)); + assertTrue(woundEffect.wasSuccessful()); + assertTrue(woundEffect.wasCarriedOut()); + + assertEquals(1, triggerCount.get()); + assertEquals(1, preventCount.get()); } private void carryOutEffectInPhaseActionByPlayer(String playerId, Effect effect) throws DecisionResultInvalidException {