Implemented Bazaar of Wonders

This commit is contained in:
Evan Kranzler 2018-06-05 18:18:36 -04:00
parent 9742a92aa7
commit aa3c860e23
3 changed files with 101 additions and 3 deletions

View file

@ -0,0 +1,98 @@
package mage.cards.b;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.SpellCastAllTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ExileGraveyardAllPlayersEffect;
import mage.constants.SuperType;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SetTargetPointer;
import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
import mage.filter.StaticFilters;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.players.Player;
/**
*
* @author TheElk801
*/
public final class BazaarOfWonders extends CardImpl {
public BazaarOfWonders(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{U}");
this.addSuperType(SuperType.WORLD);
// When Bazaar of Wonders enters the battlefield, exile all cards from all graveyards.
this.addAbility(new EntersBattlefieldTriggeredAbility(new ExileGraveyardAllPlayersEffect()));
// Whenever a player casts a spell, counter it if a card with the same name is in a graveyard or a nontoken permanent with the same name is on the battlefield.
this.addAbility(new SpellCastAllTriggeredAbility(new BazaarOfWondersEffect(), StaticFilters.FILTER_SPELL_A, false, SetTargetPointer.SPELL));
}
public BazaarOfWonders(final BazaarOfWonders card) {
super(card);
}
@Override
public BazaarOfWonders copy() {
return new BazaarOfWonders(this);
}
}
class BazaarOfWondersEffect extends OneShotEffect {
public BazaarOfWondersEffect() {
super(Outcome.Benefit);
this.staticText = "counter it if a card with the same name is in a graveyard "
+ "or a nontoken permanent with the same name is on the battlefield";
}
public BazaarOfWondersEffect(final BazaarOfWondersEffect effect) {
super(effect);
}
@Override
public BazaarOfWondersEffect copy() {
return new BazaarOfWondersEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getSpell(targetPointer.getFirst(game, source));
if (spell == null) {
return false;
}
String spellName = spell.getName();
FilterPermanent filter1 = new FilterPermanent();
filter1.add(new NamePredicate(spellName));
filter1.add(Predicates.not(new TokenPredicate()));
if (!game.getBattlefield().getActivePermanents(filter1, source.getControllerId(), game).isEmpty()) {
spell.counter(source.getControllerId(), game);
return true;
}
FilterCard filter2 = new FilterCard();
filter2.add(new NamePredicate(spellName));
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
if (player.getGraveyard().count(filter2, game) > 0) {
spell.counter(source.getControllerId(), game);
return true;
}
}
return false;
}
}

View file

@ -44,6 +44,7 @@ public final class Mirage extends ExpansionSet {
cards.add(new SetCardInfo("Barbed Foliage", 207, Rarity.UNCOMMON, mage.cards.b.BarbedFoliage.class));
cards.add(new SetCardInfo("Barbed-Back Wurm", 105, Rarity.UNCOMMON, mage.cards.b.BarbedBackWurm.class));
cards.add(new SetCardInfo("Bay Falcon", 54, Rarity.COMMON, mage.cards.b.BayFalcon.class));
cards.add(new SetCardInfo("Bazaar of Wonders", 55, Rarity.RARE, mage.cards.b.BazaarOfWonders.class));
cards.add(new SetCardInfo("Benthic Djinn", 257, Rarity.RARE, mage.cards.b.BenthicDjinn.class));
cards.add(new SetCardInfo("Binding Agony", 106, Rarity.COMMON, mage.cards.b.BindingAgony.class));
cards.add(new SetCardInfo("Blighted Shaman", 107, Rarity.UNCOMMON, mage.cards.b.BlightedShaman.class));

View file

@ -1,4 +1,3 @@
package mage.abilities.common;
import mage.abilities.TriggeredAbilityImpl;
@ -6,6 +5,7 @@ import mage.abilities.effects.Effect;
import mage.constants.SetTargetPointer;
import mage.constants.Zone;
import mage.filter.FilterSpell;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.stack.Spell;
@ -17,13 +17,12 @@ import mage.target.targetpointer.FixedTarget;
*/
public class SpellCastAllTriggeredAbility extends TriggeredAbilityImpl {
private static final FilterSpell spellCard = new FilterSpell("a spell");
protected FilterSpell filter;
protected String rule;
protected SetTargetPointer setTargetPointer;
public SpellCastAllTriggeredAbility(Effect effect, boolean optional) {
this(Zone.BATTLEFIELD, effect, spellCard, optional, SetTargetPointer.NONE);
this(Zone.BATTLEFIELD, effect, StaticFilters.FILTER_SPELL_A, optional, SetTargetPointer.NONE);
}
public SpellCastAllTriggeredAbility(Effect effect, FilterSpell filter, boolean optional) {