[AFC] Implemented Bag of Devouring

This commit is contained in:
Evan Kranzler 2021-08-20 09:27:30 -04:00
parent f740cf0d12
commit cb5d873fea
3 changed files with 138 additions and 4 deletions

View file

@ -0,0 +1,120 @@
package mage.cards.b;
import mage.abilities.Ability;
import mage.abilities.common.SacrificePermanentTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.SacrificeSourceCost;
import mage.abilities.costs.common.SacrificeTargetCost;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.ExileTargetForSourceEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.StaticFilters;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetCard;
import mage.target.common.TargetCardInExile;
import mage.target.common.TargetControlledPermanent;
import mage.util.CardUtil;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class BagOfDevouring extends CardImpl {
private static final FilterPermanent filter
= new FilterPermanent("another nontoken artifact or creature");
private static final FilterControlledPermanent filter2
= new FilterControlledPermanent("another artifact or creature");
static {
filter.add(Predicates.not(TokenPredicate.instance));
filter.add(AnotherPredicate.instance);
filter.add(Predicates.or(
CardType.ARTIFACT.getPredicate(),
CardType.CREATURE.getPredicate()
));
filter2.add(AnotherPredicate.instance);
filter2.add(Predicates.or(
CardType.ARTIFACT.getPredicate(),
CardType.CREATURE.getPredicate()
));
}
public BagOfDevouring(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{B}");
// Whenever you sacrifice another nontoken artifact or creature, exile it.
this.addAbility(new SacrificePermanentTriggeredAbility(new ExileTargetForSourceEffect(), filter, true));
// {2}, {T}, Sacrifice another artifact or creature: Draw a card.
Ability ability = new SimpleActivatedAbility(new DrawCardSourceControllerEffect(1), new GenericManaCost(2));
ability.addCost(new TapSourceCost());
ability.addCost(new SacrificeTargetCost(new TargetControlledPermanent(filter2)));
this.addAbility(ability);
// {3}, {T}, Sacrifice Bag of Devouring: Roll a d10. Return up to X cards from among cards exiled with Bag of Devouring to their owners' hands, where X is the result.
ability = new SimpleActivatedAbility(new BagOfDevouringEffect(), new GenericManaCost(3));
ability.addCost(new TapSourceCost());
ability.addCost(new SacrificeSourceCost());
this.addAbility(ability);
}
private BagOfDevouring(final BagOfDevouring card) {
super(card);
}
@Override
public BagOfDevouring copy() {
return new BagOfDevouring(this);
}
}
class BagOfDevouringEffect extends OneShotEffect {
BagOfDevouringEffect() {
super(Outcome.ReturnToHand);
staticText = "roll a d10. Return up to X cards from among cards " +
"exiled with {this} to their owners' hands, where X is the result";
}
private BagOfDevouringEffect(final BagOfDevouringEffect effect) {
super(effect);
}
@Override
public BagOfDevouringEffect copy() {
return new BagOfDevouringEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int result = player.rollDice(source, game, 10);
TargetCard target = new TargetCardInExile(
0, result, StaticFilters.FILTER_CARD,
CardUtil.getExileZoneId(game, source)
);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
player.moveCards(new CardsImpl(target.getTargets()), Zone.HAND, source, game);
return true;
}
}

View file

@ -31,6 +31,7 @@ public final class ForgottenRealmsCommander extends ExpansionSet {
cards.add(new SetCardInfo("Ashen Rider", 175, Rarity.MYTHIC, mage.cards.a.AshenRider.class)); cards.add(new SetCardInfo("Ashen Rider", 175, Rarity.MYTHIC, mage.cards.a.AshenRider.class));
cards.add(new SetCardInfo("Atarka, World Render", 176, Rarity.RARE, mage.cards.a.AtarkaWorldRender.class)); cards.add(new SetCardInfo("Atarka, World Render", 176, Rarity.RARE, mage.cards.a.AtarkaWorldRender.class));
cards.add(new SetCardInfo("Azorius Chancery", 224, Rarity.UNCOMMON, mage.cards.a.AzoriusChancery.class)); cards.add(new SetCardInfo("Azorius Chancery", 224, Rarity.UNCOMMON, mage.cards.a.AzoriusChancery.class));
cards.add(new SetCardInfo("Bag of Devouring", 21, Rarity.RARE, mage.cards.b.BagOfDevouring.class));
cards.add(new SetCardInfo("Bag of Tricks", 37, Rarity.RARE, mage.cards.b.BagOfTricks.class)); cards.add(new SetCardInfo("Bag of Tricks", 37, Rarity.RARE, mage.cards.b.BagOfTricks.class));
cards.add(new SetCardInfo("Baleful Strix", 177, Rarity.RARE, mage.cards.b.BalefulStrix.class)); cards.add(new SetCardInfo("Baleful Strix", 177, Rarity.RARE, mage.cards.b.BalefulStrix.class));
cards.add(new SetCardInfo("Bant Charm", 178, Rarity.UNCOMMON, mage.cards.b.BantCharm.class)); cards.add(new SetCardInfo("Bant Charm", 178, Rarity.UNCOMMON, mage.cards.b.BantCharm.class));

View file

@ -1,4 +1,3 @@
package mage.abilities.common; package mage.abilities.common;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
@ -8,6 +7,7 @@ import mage.filter.FilterPermanent;
import mage.filter.StaticFilters; import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.target.targetpointer.FixedTarget;
/** /**
* @author TheElk801 * @author TheElk801
@ -15,20 +15,27 @@ import mage.game.events.GameEvent;
public class SacrificePermanentTriggeredAbility extends TriggeredAbilityImpl { public class SacrificePermanentTriggeredAbility extends TriggeredAbilityImpl {
private final FilterPermanent filter; private final FilterPermanent filter;
private final boolean setTargetPointer;
public SacrificePermanentTriggeredAbility(Effect effect) { public SacrificePermanentTriggeredAbility(Effect effect) {
this(effect, StaticFilters.FILTER_PERMANENT_A); this(effect, StaticFilters.FILTER_PERMANENT_A);
} }
public SacrificePermanentTriggeredAbility(Effect effect, FilterPermanent filter) { public SacrificePermanentTriggeredAbility(Effect effect, FilterPermanent filter) {
this(effect, filter, false);
}
public SacrificePermanentTriggeredAbility(Effect effect, FilterPermanent filter, boolean setTargetPointer) {
super(Zone.BATTLEFIELD, effect); super(Zone.BATTLEFIELD, effect);
setLeavesTheBattlefieldTrigger(true); setLeavesTheBattlefieldTrigger(true);
this.filter = filter; this.filter = filter;
this.setTargetPointer = setTargetPointer;
} }
public SacrificePermanentTriggeredAbility(final SacrificePermanentTriggeredAbility ability) { public SacrificePermanentTriggeredAbility(final SacrificePermanentTriggeredAbility ability) {
super(ability); super(ability);
this.filter = ability.filter; this.filter = ability.filter;
this.setTargetPointer = ability.setTargetPointer;
} }
@Override @Override
@ -43,12 +50,18 @@ public class SacrificePermanentTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
return isControlledBy(event.getPlayerId()) if (isControlledBy(event.getPlayerId())
&& filter.match(game.getPermanentOrLKIBattlefield(event.getTargetId()), getSourceId(), getControllerId(), game); && filter.match(game.getPermanentOrLKIBattlefield(event.getTargetId()), getSourceId(), getControllerId(), game)) {
if (setTargetPointer) {
this.getEffects().setTargetPointer(new FixedTarget(event.getTargetId(), game));
}
return true;
}
return false;
} }
@Override @Override
public String getTriggerPhrase() { public String getTriggerPhrase() {
return "Whenever you sacrifice " + filter.getMessage() + ", " ; return "Whenever you sacrifice " + filter.getMessage() + ", ";
} }
} }