- Fixed #5653. Refactored The Tabernacle at Pendrell Vale. It works better in cases where the user leaves the game.

This commit is contained in:
Jeff 2019-03-25 15:51:34 -05:00
parent 1e40f80e57
commit 167deb812e
2 changed files with 69 additions and 16 deletions

View file

@ -1,4 +1,3 @@
package mage.cards.k;
import java.util.LinkedHashSet;
@ -16,8 +15,8 @@ import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.common.FilterCreatureCard;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.game.Game;
import mage.players.Player;
@ -74,7 +73,7 @@ class KindredSummonsEffect extends OneShotEffect {
if (subType == null) {
return false;
}
FilterCreaturePermanent filterPermanent = new FilterCreaturePermanent("creature you control of the chosen type");
FilterControlledCreaturePermanent filterPermanent = new FilterControlledCreaturePermanent("creature you control of the chosen type");
filterPermanent.add(new SubtypePredicate(subType));
int numberOfCards = game.getBattlefield().countAll(filterPermanent, source.getControllerId(), game);
Cards revealed = new CardsImpl();
@ -82,9 +81,14 @@ class KindredSummonsEffect extends OneShotEffect {
Cards otherCards = new CardsImpl();
FilterCreatureCard filterCard = new FilterCreatureCard("creature card of the chosen type");
filterCard.add(new SubtypePredicate(subType));
if (numberOfCards == 0) { // no matches so nothing is revealed
game.informPlayers("There are 0 creature cards of the chosen type in " + controller.getName() + "'s library.");
return true;
}
for (Card card : controller.getLibrary().getCards(game)) {
revealed.add(card);
if (card != null && filterCard.match(card, game)) {
if (card != null
&& filterCard.match(card, game)) {
chosenSubtypeCreatureCards.add(card);
if (chosenSubtypeCreatureCards.size() == numberOfCards) {
break;

View file

@ -1,4 +1,3 @@
package mage.cards.t;
import java.util.UUID;
@ -8,12 +7,11 @@ import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.GainAbilityAllEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -29,14 +27,10 @@ public final class TheTabernacleAtPendrellVale extends CardImpl {
addSuperType(SuperType.LEGENDARY);
// All creatures have "At the beginning of your upkeep, destroy this creature unless you pay {1}."
Ability ability = new BeginningOfUpkeepTriggeredAbility(new DestroySourceUnlessPaysEffect(new ManaCostsImpl("{1}")), TargetController.YOU, false);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD,
new GainAbilityAllEffect(
ability,
Duration.WhileOnBattlefield,
new FilterCreaturePermanent("All creatures")
)
));
this.addAbility(new SimpleStaticAbility(
Zone.BATTLEFIELD,
new TheTabernacleAtPendrellValeEffect())
);
}
public TheTabernacleAtPendrellVale(final TheTabernacleAtPendrellVale card) {
@ -49,6 +43,59 @@ public final class TheTabernacleAtPendrellVale extends CardImpl {
}
}
class TheTabernacleAtPendrellValeEffect extends ContinuousEffectImpl {
Ability ability = new BeginningOfUpkeepTriggeredAbility(
new DestroySourceUnlessPaysEffect(
new ManaCostsImpl("{1}")),
TargetController.YOU,
false);
public TheTabernacleAtPendrellValeEffect() {
super(Duration.WhileOnBattlefield, Outcome.AddAbility);
ability = ability.copy();
this.ability.newId();
staticText = "All creatures have \"At the beginning of your upkeep, destroy this creature unless you pay {1}";
}
public TheTabernacleAtPendrellValeEffect(final TheTabernacleAtPendrellValeEffect effect) {
super(effect);
this.ability = effect.ability.copy();
}
@Override
public TheTabernacleAtPendrellValeEffect copy() {
return new TheTabernacleAtPendrellValeEffect(this);
}
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(CardType.CREATURE)) {
if (permanent != null) {
switch (layer) {
case AbilityAddingRemovingEffects_6:
if (sublayer == SubLayer.NA
&& !permanent.getAbilities().contains(ability)) {
permanent.addAbility(ability, source.getSourceId(), game);
}
break;
}
}
}
return true;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean hasLayer(Layer layer) {
return layer == Layer.AbilityAddingRemovingEffects_6;
}
}
class DestroySourceUnlessPaysEffect extends OneShotEffect {
protected Cost cost;
@ -67,7 +114,9 @@ class DestroySourceUnlessPaysEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player != null && permanent != null && source.getSourceObjectZoneChangeCounter() == permanent.getZoneChangeCounter(game)) {
if (player != null
&& permanent != null
&& source.getSourceObjectZoneChangeCounter() == permanent.getZoneChangeCounter(game)) {
if (player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + '?', source, game)) {
cost.clearPaid();
if (cost.pay(source, game, source.getSourceId(), source.getControllerId(), false, null)) {