[CLB] Implemented Wand of Wonder

This commit is contained in:
Evan Kranzler 2022-03-25 18:09:18 -04:00
parent 57cf2b64e2
commit 0bfce64ede
3 changed files with 118 additions and 2 deletions

View file

@ -0,0 +1,115 @@
package mage.cards.w;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.RollDieWithResultTableEffect;
import mage.cards.*;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class WandOfWonder extends CardImpl {
public WandOfWonder(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{3}{R}");
// {4}, {T}: Roll a d20. Each opponent exiles cards from the top of their library until they exile an instant or sorcery card, then shuffles the rest into their library. You may cast up to X instant and/or sorcery spells from among cards exiled this way without paying their mana costs.
RollDieWithResultTableEffect effect = new RollDieWithResultTableEffect(
20, "roll a d20. Each opponent exiles cards from the top of their library " +
"until they exile an instant or sorcery card, then shuffles the rest into their library. " +
"You may cast up to X instant and/or sorcery spells from among cards exiled this way " +
"without paying their mana costs"
);
// 1-9 | X is one
effect.addTableEntry(1, 9, new WandOfWonderEffect(1));
// 10-19 | X is two.
effect.addTableEntry(10, 19, new WandOfWonderEffect(2));
// 20 | X is three.
effect.addTableEntry(20, 20, new WandOfWonderEffect(3));
Ability ability = new SimpleActivatedAbility(effect, new GenericManaCost(4));
ability.addCost(new TapSourceCost());
this.addAbility(ability);
}
private WandOfWonder(final WandOfWonder card) {
super(card);
}
@Override
public WandOfWonder copy() {
return new WandOfWonder(this);
}
}
class WandOfWonderEffect extends OneShotEffect {
private final int xValue;
WandOfWonderEffect(int xValue) {
super(Outcome.Benefit);
staticText = "X is " + CardUtil.numberToText(xValue);
this.xValue = xValue;
}
private WandOfWonderEffect(final WandOfWonderEffect effect) {
super(effect);
this.xValue = effect.xValue;
}
@Override
public WandOfWonderEffect copy() {
return new WandOfWonderEffect(this);
}
// {4}, {T}: Roll a d20. Each opponent exiles cards from the top of their library until
// they exile an instant or sorcery card, then shuffles the rest into their library.
// You may cast up to X instant and/or sorcery spells from among cards exiled this way without paying their mana costs.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Cards cards = new CardsImpl();
Cards toCast = new CardsImpl();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player opponent = game.getPlayer(playerId);
if (opponent == null) {
continue;
}
for (Card card : opponent.getLibrary().getCards(game)) {
opponent.moveCards(card, Zone.EXILED, source, game);
if (card.isInstantOrSorcery(game)) {
toCast.add(card);
break;
} else {
cards.add(card);
}
}
opponent.putCardsOnBottomOfLibrary(cards, game, source, false);
opponent.shuffleLibrary(source, game);
cards.clear();
}
CardUtil.castMultipleWithAttributeForFree(
controller, source, game, toCast,
StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY, xValue
);
return true;
}
}

View file

@ -30,5 +30,6 @@ public final class CommanderLegendsBattleForBaldursGate extends ExpansionSet {
cards.add(new SetCardInfo("Reflecting Pool", 358, Rarity.RARE, mage.cards.r.ReflectingPool.class)); cards.add(new SetCardInfo("Reflecting Pool", 358, Rarity.RARE, mage.cards.r.ReflectingPool.class));
cards.add(new SetCardInfo("Sea of Clouds", 360, Rarity.RARE, mage.cards.s.SeaOfClouds.class)); cards.add(new SetCardInfo("Sea of Clouds", 360, Rarity.RARE, mage.cards.s.SeaOfClouds.class));
cards.add(new SetCardInfo("Spire Garden", 361, Rarity.RARE, mage.cards.s.SpireGarden.class)); cards.add(new SetCardInfo("Spire Garden", 361, Rarity.RARE, mage.cards.s.SpireGarden.class));
cards.add(new SetCardInfo("Wand of Wonder", 204, Rarity.RARE, mage.cards.w.WandOfWonder.class));
} }
} }

View file

@ -89,8 +89,8 @@ public class RollDieWithResultTableEffect extends OneShotEffect {
@Override @Override
public String getText(Mode mode) { public String getText(Mode mode) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder(prefixText);
sb.append(prefixText).append('.'); sb.append('.');
for (TableEntry tableEntry : this.resultsTable) { for (TableEntry tableEntry : this.resultsTable) {
sb.append("<br>"); sb.append("<br>");
if (tableEntry.max == Integer.MAX_VALUE) { if (tableEntry.max == Integer.MAX_VALUE) {