refactor: improved Aladdin's Lamp

This commit is contained in:
Oleg Agafonov 2025-04-08 23:02:49 +04:00
parent 36cec8961e
commit 6cf1f4af3d
3 changed files with 48 additions and 4 deletions

View file

@ -3,6 +3,7 @@ package mage.cards.a;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.CostAdjuster;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.ReplacementEffectImpl;
@ -35,8 +36,8 @@ public final class AladdinsLamp extends CardImpl {
// {X}, {T}: The next time you would draw a card this turn, instead look at the top X cards of your library, put all but one of them on the bottom of your library in a random order, then draw a card. X can't be 0.
Ability ability = new SimpleActivatedAbility(new AladdinsLampEffect(), new ManaCostsImpl<>("{X}"));
ability.addCost(new TapSourceCost());
ability.setVariableCostsMinMax(1, Integer.MAX_VALUE);
// TODO: add costAdjuster for min/max values due library size
ability.setCostAdjuster(AladdinsLampCostAdjuster.instance);
this.addAbility(ability);
}
@ -96,3 +97,17 @@ class AladdinsLampEffect extends ReplacementEffectImpl {
return source.isControlledBy(event.getPlayerId());
}
}
enum AladdinsLampCostAdjuster implements CostAdjuster {
instance;
@Override
public void prepareX(Ability ability, Game game) {
Player controller = game.getPlayer(ability.getControllerId());
if (controller == null) {
return;
}
ability.setVariableCostsMinMax(1, Math.max(1, controller.getLibrary().size()));
}
}

View file

@ -1,4 +1,3 @@
package mage.cards.a;
import java.util.UUID;

View file

@ -467,6 +467,36 @@ public class AdjusterCostTest extends CardTestPlayerBaseWithAIHelps {
assertLife(playerB, 20 - 3);
}
@Test
public void test_prepareX_AladdinsLamp() {
skipInitShuffling();
// {X}, {T}: The next time you would draw a card this turn, instead look at the top X cards of your library,
// put all but one of them on the bottom of your library in a random order, then draw a card. X can't be 0.
addCard(Zone.BATTLEFIELD, playerA, "Aladdin's Lamp");
addCard(Zone.BATTLEFIELD, playerA, "Forest", 5);
// {T}: Draw a card.
addCard(Zone.BATTLEFIELD, playerA, "Archivist");
addCard(Zone.LIBRARY, playerA, "Island", 1);
addCard(Zone.LIBRARY, playerA, "Grizzly Bears", 1);
addCard(Zone.LIBRARY, playerA, "Island", 3);
// prepare effect
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{X}, {T}: The next time");
setChoice(playerA, "X=5");
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
// improved draw
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Draw");
setChoice(playerA, "Grizzly Bears"); // keep on top and draw
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertHandCount(playerA, "Grizzly Bears", 1);
}
@Test
public void test_modifyCost_Fireball() {
// This spell costs {1} more to cast for each target beyond the first.