Wound AT tests.

This commit is contained in:
marcins78@gmail.com
2012-01-17 17:36:59 +00:00
parent 15ee20247d
commit 7e1e8b72d0
2 changed files with 162 additions and 2 deletions

View File

@@ -3,16 +3,17 @@ package com.gempukku.lotro.logic.decisions;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.timing.Action;
import java.util.LinkedList;
import java.util.List;
public abstract class CardActionSelectionDecision extends AbstractAwaitingDecision {
private LotroGame _game;
private List<? extends Action> _actions;
private List<Action> _actions;
public CardActionSelectionDecision(LotroGame game, int decisionId, String text, List<? extends Action> actions) {
super(decisionId, text, AwaitingDecisionType.CARD_ACTION_CHOICE);
_game = game;
_actions = actions;
_actions = new LinkedList<Action>(actions);
setParam("actionId", getActionIds(actions));
setParam("cardId", getCardIds(actions));
@@ -20,6 +21,15 @@ public abstract class CardActionSelectionDecision extends AbstractAwaitingDecisi
setParam("actionText", getActionTexts(actions));
}
/**
* For testing, being able to inject an extra action at any point
*
* @param action
*/
public void addAction(Action action) {
_actions.add(action);
}
private String[] getActionIds(List<? extends Action> actions) {
String[] result = new String[actions.size()];
for (int i = 0; i < result.length; i++)

View File

@@ -0,0 +1,150 @@
package com.gempukku.lotro.at.effects;
import com.gempukku.lotro.at.AbstractAtTest;
import com.gempukku.lotro.cards.TriggerConditions;
import com.gempukku.lotro.cards.effects.PreventCardEffect;
import com.gempukku.lotro.common.Zone;
import com.gempukku.lotro.game.AbstractActionProxy;
import com.gempukku.lotro.game.PhysicalCardImpl;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.actions.RequiredTriggerAction;
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.timing.Effect;
import com.gempukku.lotro.logic.timing.EffectResult;
import org.junit.Test;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.*;
public class WoundEffectAtTest extends AbstractAtTest {
@Test
public void woundSuccessful() throws DecisionResultInvalidException {
initializeSimplestGame();
skipMulligans();
final PhysicalCardImpl merry = new PhysicalCardImpl(101, "1_303", P1, _library.getLotroCardBlueprint("1_303"));
final AtomicInteger triggerCount = new AtomicInteger(0);
_game.getActionsEnvironment().addUntilEndOfTurnActionProxy(
new AbstractActionProxy() {
@Override
public List<? extends RequiredTriggerAction> getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) {
if (TriggerConditions.forEachWounded(game, effectResult, merry)) {
triggerCount.incrementAndGet();
}
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());
}
@Test
public void woundUnsuccessful() throws DecisionResultInvalidException {
initializeSimplestGame();
skipMulligans();
final PhysicalCardImpl merry = new PhysicalCardImpl(101, "1_303", P1, _library.getLotroCardBlueprint("1_303"));
final AtomicInteger triggerCount = new AtomicInteger(0);
_game.getActionsEnvironment().addUntilEndOfTurnActionProxy(
new AbstractActionProxy() {
@Override
public List<? extends RequiredTriggerAction> getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) {
if (TriggerConditions.forEachWounded(game, effectResult, merry)) {
triggerCount.incrementAndGet();
}
return null;
}
});
_game.getGameState().addCardToZone(_game, merry, Zone.DISCARD);
WoundCharactersEffect woundEffect = new WoundCharactersEffect(merry, merry);
carryOutEffectInPhaseActionByPlayer(P1, woundEffect);
assertEquals(0, _game.getGameState().getWounds(merry));
assertFalse(woundEffect.wasSuccessful());
assertFalse(woundEffect.wasCarriedOut());
assertEquals(0, triggerCount.get());
}
@Test
public void woundPrevention() throws DecisionResultInvalidException {
initializeSimplestGame();
skipMulligans();
final PhysicalCardImpl merry = new PhysicalCardImpl(101, "1_303", P1, _library.getLotroCardBlueprint("1_303"));
final PhysicalCardImpl pippin = new PhysicalCardImpl(102, "1_306", P1, _library.getLotroCardBlueprint("1_306"));
final AtomicInteger triggerCount = new AtomicInteger(0);
_game.getActionsEnvironment().addUntilEndOfTurnActionProxy(
new AbstractActionProxy() {
@Override
public List<? extends RequiredTriggerAction> getRequiredBeforeTriggers(LotroGame game, Effect effect) {
if (TriggerConditions.isGettingWounded(effect, game, merry)) {
RequiredTriggerAction action = new RequiredTriggerAction(merry);
action.appendEffect(
new PreventCardEffect((WoundCharactersEffect) effect, merry));
return Collections.singletonList(action);
}
return null;
}
@Override
public List<? extends RequiredTriggerAction> getRequiredAfterTriggers(LotroGame game, EffectResult effectResult) {
if (TriggerConditions.forEachWounded(game, effectResult, merry)) {
triggerCount.incrementAndGet();
}
return null;
}
});
_game.getGameState().addCardToZone(_game, merry, Zone.FREE_CHARACTERS);
_game.getGameState().addCardToZone(_game, pippin, Zone.FREE_CHARACTERS);
WoundCharactersEffect woundEffect = new WoundCharactersEffect(merry, merry, pippin);
carryOutEffectInPhaseActionByPlayer(P1, woundEffect);
assertEquals(0, _game.getGameState().getWounds(merry));
assertEquals(1, _game.getGameState().getWounds(pippin));
assertTrue(woundEffect.wasSuccessful());
assertFalse(woundEffect.wasCarriedOut());
assertEquals(0, triggerCount.get());
}
private void carryOutEffectInPhaseActionByPlayer(String playerId, Effect effect) throws DecisionResultInvalidException {
CardActionSelectionDecision awaitingDecision = (CardActionSelectionDecision) _userFeedback.getAwaitingDecision(playerId);
SystemQueueAction action = new SystemQueueAction();
action.appendEffect(effect);
awaitingDecision.addAction(action);
playerDecided(playerId, "0");
}
}