mirror of
https://github.com/correl/mage.git
synced 2025-01-11 11:05:23 +00:00
Added a lockedInCondition option for ConditionalContiniousEffect. Added test for issue #127.
This commit is contained in:
parent
1bdf2c96fe
commit
ce151982b6
3 changed files with 164 additions and 0 deletions
|
@ -0,0 +1,84 @@
|
|||
package org.mage.test.cards.conditional;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.abilities.keyword.FirstStrikeAbility;
|
||||
import mage.abilities.keyword.LifelinkAbility;
|
||||
import mage.game.permanent.Permanent;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public class TragicSlipTest extends CardTestPlayerBase {
|
||||
|
||||
@Test
|
||||
public void testNoCreatureDied() {
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Swamp");
|
||||
|
||||
// Tragic Slip - Instant, B - Target creature gets -1/-1 until end of turn.
|
||||
// Morbid — That creature gets -13/-13 until end of turn instead if a creature died this turn.
|
||||
addCard(Constants.Zone.HAND, playerA, "Tragic Slip");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Silvercoat Lion");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Pillarfield Ox");
|
||||
|
||||
castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Tragic Slip", "Pillarfield Ox");
|
||||
|
||||
setStopAt(1, Constants.PhaseStep.BEGIN_COMBAT);
|
||||
execute();
|
||||
|
||||
assertPowerToughness(playerA, "Pillarfield Ox", 1, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreatureDiedAfter() {
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Swamp");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain", 2);
|
||||
|
||||
// Tragic Slip - Instant, B - Target creature gets -1/-1 until end of turn.
|
||||
// Morbid — That creature gets -13/-13 until end of turn instead if a creature died this turn.
|
||||
addCard(Constants.Zone.HAND, playerA, "Tragic Slip");
|
||||
// Searing Spear - Instant, 1R - Searing Spear deals 3 damage to target creature or player.
|
||||
addCard(Constants.Zone.HAND, playerA, "Searing Spear");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Silvercoat Lion");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Pillarfield Ox");
|
||||
|
||||
castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Tragic Slip", "Pillarfield Ox");
|
||||
|
||||
castSpell(1, Constants.PhaseStep.POSTCOMBAT_MAIN, playerA, "Searing Spear", "Silvercoat Lion");
|
||||
|
||||
setStopAt(1, Constants.PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
assertPowerToughness(playerA, "Pillarfield Ox", 1, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreatureDiedBefore() {
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Swamp", 3);
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain", 2);
|
||||
|
||||
// Tragic Slip - Instant, B - Target creature gets -1/-1 until end of turn.
|
||||
// Morbid — That creature gets -13/-13 until end of turn instead if a creature died this turn.
|
||||
addCard(Constants.Zone.HAND, playerA, "Tragic Slip");
|
||||
// Searing Spear - Instant, 1R - Searing Spear deals 3 damage to target creature or player.
|
||||
addCard(Constants.Zone.HAND, playerA, "Searing Spear");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Silvercoat Lion");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Pillarfield Ox");
|
||||
|
||||
castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Searing Spear", "Silvercoat Lion");
|
||||
|
||||
castSpell(1, Constants.PhaseStep.POSTCOMBAT_MAIN, playerA, "Tragic Slip", "Pillarfield Ox");
|
||||
|
||||
setStopAt(1, Constants.PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
assertPermanentCount(playerA, "Silvercoat Lion", 0);
|
||||
assertPermanentCount(playerA, "Pillarfield Ox", 0);
|
||||
}
|
||||
}
|
53
Mage/src/mage/abilities/condition/common/FixedCondition.java
Normal file
53
Mage/src/mage/abilities/condition/common/FixedCondition.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
|
||||
public class FixedCondition implements Condition{
|
||||
|
||||
protected boolean conditionMet;
|
||||
|
||||
public FixedCondition(boolean conditionMet) {
|
||||
this.conditionMet = conditionMet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return conditionMet;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import mage.Constants;
|
|||
import mage.Constants.Duration;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.condition.common.FixedCondition;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.game.Game;
|
||||
|
@ -18,11 +19,16 @@ public class ConditionalContinousEffect extends ContinuousEffectImpl<Conditional
|
|||
protected ContinuousEffect effect;
|
||||
protected ContinuousEffect otherwiseEffect;
|
||||
protected Condition condition;
|
||||
protected boolean lockedInCondition;
|
||||
|
||||
public ConditionalContinousEffect(ContinuousEffect effect, Condition condition, String text) {
|
||||
this(effect, null, condition, text);
|
||||
}
|
||||
|
||||
public ConditionalContinousEffect(ContinuousEffect effect, Condition condition, String text, boolean lockedInCondition) {
|
||||
this(effect, null, condition, text, lockedInCondition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Only use this if both effects have the same layers
|
||||
*
|
||||
|
@ -32,11 +38,25 @@ public class ConditionalContinousEffect extends ContinuousEffectImpl<Conditional
|
|||
* @param text
|
||||
*/
|
||||
public ConditionalContinousEffect(ContinuousEffect effect, ContinuousEffect otherwiseEffect, Condition condition, String text) {
|
||||
this(effect, otherwiseEffect, condition, text, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Only use this if both effects have the same layers
|
||||
*
|
||||
* @param effect
|
||||
* @param otherwiseEffect
|
||||
* @param condition
|
||||
* @param text
|
||||
* @param lockedInCondition
|
||||
*/
|
||||
public ConditionalContinousEffect(ContinuousEffect effect, ContinuousEffect otherwiseEffect, Condition condition, String text, boolean lockedInCondition) {
|
||||
super(effect.getDuration(), effect.getLayer(), effect.getSublayer(), effect.getOutcome());
|
||||
this.effect = effect;
|
||||
this.otherwiseEffect = otherwiseEffect;
|
||||
this.condition = condition;
|
||||
this.staticText = text;
|
||||
this.lockedInCondition = lockedInCondition;
|
||||
}
|
||||
|
||||
public ConditionalContinousEffect(final ConditionalContinousEffect effect) {
|
||||
|
@ -44,10 +64,14 @@ public class ConditionalContinousEffect extends ContinuousEffectImpl<Conditional
|
|||
this.effect = effect.effect;
|
||||
this.otherwiseEffect = effect.otherwiseEffect;
|
||||
this.condition = effect.condition;
|
||||
this.lockedInCondition = effect.lockedInCondition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Constants.Layer layer, Constants.SubLayer sublayer, Ability source, Game game) {
|
||||
if (lockedInCondition && !(condition instanceof FixedCondition)) {
|
||||
condition = new FixedCondition(condition.apply(game, source));
|
||||
}
|
||||
if (condition.apply(game, source)) {
|
||||
effect.setTargetPointer(this.targetPointer);
|
||||
return effect.apply(layer, sublayer, source, game);
|
||||
|
@ -63,6 +87,9 @@ public class ConditionalContinousEffect extends ContinuousEffectImpl<Conditional
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
if (lockedInCondition && !(condition instanceof FixedCondition)) {
|
||||
condition = new FixedCondition(condition.apply(game, source));
|
||||
}
|
||||
if (condition.apply(game, source)) {
|
||||
effect.setTargetPointer(this.targetPointer);
|
||||
return effect.apply(game, source);
|
||||
|
|
Loading…
Reference in a new issue