1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-02 11:25:59 -09:00

Hellcarver Demon fix

Was able to cast previously exiled cards
This commit is contained in:
L_J 2018-02-17 23:13:19 +00:00 committed by GitHub
parent 1f5e2f1bed
commit 2e827a50ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,35 +27,34 @@
*/
package mage.cards.h;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.cards.CardSetInfo;
import mage.constants.AsThoughEffectType;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.common.FilterNonlandCard;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetCardInExile;
import mage.target.targetpointer.FixedTarget;
import mage.target.TargetCard;
/**
*
* @author jeffwadsworth
* @author jeffwadsworth & L_J
*/
public class HellcarverDemon extends CardImpl {
@ -84,9 +83,6 @@ public class HellcarverDemon extends CardImpl {
class HellcarverDemonEffect extends OneShotEffect {
private static final FilterControlledPermanent filterPermanents = new FilterControlledPermanent("Permanent");
private static FilterNonlandCard filter = new FilterNonlandCard("nonland card exiled with Hellcarver Demon");
public HellcarverDemonEffect() {
super(Outcome.PlayForFree);
staticText = "sacrifice all other permanents you control and discard your hand. Exile the top six cards of your library. You may cast any number of nonland cards exiled this way without paying their mana costs.";
@ -99,41 +95,43 @@ class HellcarverDemonEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent hellcarverDemon = game.getPermanent(source.getSourceId());
for (Permanent permanent : game.getBattlefield().getActivePermanents(filterPermanents, source.getControllerId(), game)) {
if (!Objects.equals(permanent, hellcarverDemon)) {
permanent.sacrifice(source.getSourceId(), game);
}
}
if (controller != null && !controller.getHand().isEmpty()) {
int cardsInHand = controller.getHand().size();
controller.discard(cardsInHand, false, source, game);
}
for (int i = 0; i < 6; i++) {
if (controller != null
&& controller.getLibrary().hasCards()) {
Card topCard = controller.getLibrary().getFromTop(game);
topCard.moveToExile(source.getSourceId(), "Cards exiled by Hellcarver Demon", source.getSourceId(), game);
}
}
while (controller != null
&& controller.canRespond()
&& controller.chooseUse(Outcome.PlayForFree, controller.getLogName() + " can cast another nonland card exiled with Hellcarver Demon without paying that card's mana cost.", source, game)) {
TargetCardInExile target = new TargetCardInExile(filter, source.getSourceId());
while (controller.chooseUse(Outcome.PlayForFree, "Cast another spell exiled by Hellcarver Demon?", source, game)) {
controller.choose(Outcome.PlayForFree, game.getExile().getExileZone(source.getSourceId()), target, game);
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
ContinuousEffect effect = new HellcarverDemonCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(card.getId()));
game.addEffect(effect, source);
controller.cast(card.getSpellAbility(), game, true);
Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourceObject != null) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) {
if (!Objects.equals(permanent, sourceObject)) {
permanent.sacrifice(source.getSourceId(), game);
}
}
if (!controller.getHand().isEmpty()) {
int cardsInHand = controller.getHand().size();
controller.discard(cardsInHand, false, source, game);
}
// move cards from library to exile
Set<Card> currentExiledCards = new HashSet<>();
currentExiledCards.addAll(controller.getLibrary().getTopCards(game, 6));
controller.moveCardsToExile(currentExiledCards, source, game, true, source.getSourceId(), sourceObject.getIdName());
// cast the possible cards without paying the mana
Cards cardsToCast = new CardsImpl();
cardsToCast.addAll(currentExiledCards);
boolean alreadyCast = false;
while (!cardsToCast.isEmpty()
&& controller.canRespond()) {
if (!controller.chooseUse(outcome, "Cast a" + (alreadyCast ? "nother" : "" ) + " card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
break;
}
TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterCard("nonland card to cast for free"));
if (controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
alreadyCast = true;
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
if (controller.cast(card.getSpellAbility(), game, true)) {
cardsToCast.remove(card);
} else {
game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
}
}
}
target.clearChosen();
}
return true;
}
@ -145,33 +143,3 @@ class HellcarverDemonEffect extends OneShotEffect {
return new HellcarverDemonEffect(this);
}
}
class HellcarverDemonCastFromExileEffect extends AsThoughEffectImpl {
public HellcarverDemonCastFromExileEffect() {
super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.Custom, Outcome.Benefit);
staticText = "You may play the card from exile without paying its mana cost";
}
public HellcarverDemonCastFromExileEffect(final HellcarverDemonCastFromExileEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public HellcarverDemonCastFromExileEffect copy() {
return new HellcarverDemonCastFromExileEffect(this);
}
@Override
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
if (targetPointer.getTargets(game, source).contains(sourceId)) {
return game.getState().getZone(sourceId) == Zone.EXILED;
}
return false;
}
}