Skip to content

Commit

Permalink
fix & test Oath of Lim-Dul
Browse files Browse the repository at this point in the history
  • Loading branch information
Susucre committed Jun 2, 2024
1 parent afe1b56 commit 7d12394
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 29 deletions.
41 changes: 12 additions & 29 deletions Mage.Sets/src/mage/cards/o/OathOfLimDul.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@
import mage.abilities.Ability;
import mage.abilities.common.LoseLifeTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.DiscardTargetCost;
import mage.abilities.costs.common.DiscardCardCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.dynamicvalue.common.SavedLifeLossValue;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DoUnlessControllerPaysEffect;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.SacrificeControllerEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.StaticFilters;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetCardInHand;
import mage.target.common.TargetControlledPermanent;

import java.util.UUID;

Expand Down Expand Up @@ -53,7 +51,7 @@ public OathOfLimDul copy() {

class OathOfLimDulEffect extends OneShotEffect {

private static final FilterControlledPermanent filter = new FilterControlledPermanent("controlled permanent other than Oath of Lim-Dul to sacrifice");
private static final FilterControlledPermanent filter = new FilterControlledPermanent("controlled permanent other than {this} to sacrifice");

static {
filter.add(AnotherPredicate.instance);
Expand All @@ -75,29 +73,14 @@ public boolean apply(Game game, Ability source) {
if (amountDamage <= 0 || controller == null) {
return false;
}
boolean sacrificeDone = false;
int numberSacrificed = 0;
int numberToDiscard = 0;
int numberOfControlledPermanents = 0;
TargetControlledPermanent target = new TargetControlledPermanent(0, numberOfControlledPermanents, filter, true);
target.withNotTarget(true);
if (controller.choose(Outcome.Detriment, target, source, game)) {
for (UUID targetPermanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetPermanentId);
if (permanent != null
&& permanent.sacrifice(source, game)) {
numberSacrificed += 1;
sacrificeDone = true;
}
}
boolean didSomething = false;
for (int i = 0; i < amountDamage; ++i) {
didSomething |= new DoUnlessControllerPaysEffect(
new SacrificeControllerEffect(StaticFilters.FILTER_CONTROLLED_ANOTHER_PERMANENT, 1, ""),
new DiscardCardCost()
).apply(game, source);
}
numberToDiscard = amountDamage - numberSacrificed;
Cost cost = new DiscardTargetCost(new TargetCardInHand(numberToDiscard, new FilterCard("card(s) in your hand to discard")));
if (numberToDiscard > 0
&& cost.canPay(source, source, controller.getId(), game)) {
return cost.pay(source, game, source, controller.getId(), true); // discard cost paid simultaneously
}
return sacrificeDone;
return didSomething;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package org.mage.test.cards.single.ice;

import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;

/**
* @author Susucr
*/
public class OathOfLimDulTest extends CardTestPlayerBase {

/**
* {@link mage.cards.o.OathOfLimDul Oath of Lim-Dûl} {3}{B}
* Enchantment
* Whenever you lose life, for each 1 life you lost, sacrifice a permanent other than Oath of Lim-Dûl unless you discard a card. (Damage dealt to you causes you to lose life.)
* {B}{B}: Draw a card.
*/
private static final String oath = "Oath of Lim-Dul";

@Test
public void test_3Sacrifice() {
setStrictChooseMode(true);

addCard(Zone.BATTLEFIELD, playerA, oath, 1);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5);
addCard(Zone.HAND, playerA, "Swamp", 5);
addCard(Zone.HAND, playerA, "Lightning Bolt");

castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerA);
setChoice(playerA, false); // No to discard on first instance.
setChoice(playerA, "Mountain"); // sacrifice Mountain
setChoice(playerA, false); // No to discard on second instance.
setChoice(playerA, "Mountain"); // sacrifice Mountain
setChoice(playerA, false); // No to discard on third instance.
setChoice(playerA, "Mountain"); // sacrifice Mountain

setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();

assertLife(playerA, 20 - 3);
assertGraveyardCount(playerA, "Mountain", 3);
}

@Test
public void test_3Discard() {
setStrictChooseMode(true);

addCard(Zone.BATTLEFIELD, playerA, oath, 1);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5);
addCard(Zone.HAND, playerA, "Swamp", 5);
addCard(Zone.HAND, playerA, "Lightning Bolt");

castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerA);
setChoice(playerA, true); // Yes to discard on first instance.
setChoice(playerA, "Swamp"); // sacrifice Swamp
setChoice(playerA, true); // Yes to discard on second instance.
setChoice(playerA, "Swamp"); // sacrifice Swamp
setChoice(playerA, true); // Yes to discard on third instance.
setChoice(playerA, "Swamp"); // sacrifice Swamp

setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();

assertLife(playerA, 20 - 3);
assertGraveyardCount(playerA, "Swamp", 3);
}

@Test
public void test_1Sacrifice1Discard_NoOther() {
setStrictChooseMode(true);

addCard(Zone.BATTLEFIELD, playerA, oath, 1);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
addCard(Zone.HAND, playerA, "Swamp", 1);
addCard(Zone.HAND, playerA, "Lightning Bolt");

castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerA);
setChoice(playerA, true); // Yes to discard on first instance.
setChoice(playerA, "Swamp"); // discard Swamp
// No more possibility to Discard
setChoice(playerA, "Mountain"); // sacrifice Mountain
// No more things to Sacrifice

setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();

assertLife(playerA, 20 - 3);
assertGraveyardCount(playerA, "Mountain", 1);
assertGraveyardCount(playerA, "Swamp", 1);
}

@Test
public void test_AllSacrificeNoDiscard_KeepCardInHand() {
setStrictChooseMode(true);

addCard(Zone.BATTLEFIELD, playerA, oath, 1);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
addCard(Zone.HAND, playerA, "Swamp", 1);
addCard(Zone.HAND, playerA, "Lightning Bolt");

castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerA);
setChoice(playerA, false); // No to discard on first instance.
setChoice(playerA, "Mountain"); // sacrifice Mountain
setChoice(playerA, false); // No to discard on second instance.
setChoice(playerA, false); // No to discard on third instance.

setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();

assertLife(playerA, 20 - 3);
assertPermanentCount(playerA, oath, 1);
assertGraveyardCount(playerA, "Mountain", 1);
assertHandCount(playerA, "Swamp", 1);
}
}

0 comments on commit 7d12394

Please sign in to comment.