[ALL] some reworking of Helm of Obedience

This commit is contained in:
Evan Kranzler 2021-06-21 08:50:24 -04:00
parent 124eaf936c
commit 899be878c4

View file

@ -1,30 +1,26 @@
package mage.cards.h;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.VariableManaCost;
import mage.abilities.dynamicvalue.common.ManacostVariableValue;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.Cards;
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.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetCardInGraveyard;
import mage.target.common.TargetOpponent;
import java.util.UUID;
/**
* @author Plopman
* @author TheElk801
*/
public final class HelmOfObedience extends CardImpl {
@ -34,10 +30,10 @@ public final class HelmOfObedience extends CardImpl {
// {X}, {T}: Target opponent puts cards from the top of their library into their graveyard until a creature card or X cards are put into that graveyard this way, whichever comes first. If a creature card is put into that graveyard this way, sacrifice Helm of Obedience and put that card onto the battlefield under your control. X can't be 0.
VariableManaCost xCosts = new VariableManaCost();
xCosts.setMinX(1);
SimpleActivatedAbility abilitiy = new SimpleActivatedAbility(new HelmOfObedienceEffect(), xCosts);
abilitiy.addCost(new TapSourceCost());
abilitiy.addTarget(new TargetOpponent());
this.addAbility(abilitiy);
Ability ability = new SimpleActivatedAbility(new HelmOfObedienceEffect(), xCosts);
ability.addCost(new TapSourceCost());
ability.addTarget(new TargetOpponent());
this.addAbility(ability);
}
private HelmOfObedience(final HelmOfObedience card) {
@ -52,8 +48,6 @@ public final class HelmOfObedience extends CardImpl {
class HelmOfObedienceEffect extends OneShotEffect {
private static final ManacostVariableValue amount = ManacostVariableValue.instance;
HelmOfObedienceEffect() {
super(Outcome.Detriment);
staticText = "Target opponent mills a card, then repeats this process until a creature card "
@ -74,36 +68,41 @@ class HelmOfObedienceEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetOpponent = game.getPlayer(targetPointer.getFirst(game, source));
int max = amount.calculate(game, source, this);
if (targetOpponent == null || controller == null || max <= 0) {
Player targetOpponent = game.getPlayer(source.getFirstTarget());
int max = ManacostVariableValue.instance.calculate(game, source, this);
if (targetOpponent == null || controller == null || max < 1) {
return false;
}
int numberOfCard = 0;
Cards cards = new CardsImpl();
while (targetOpponent.getLibrary().hasCards()) {
Cards cards = targetOpponent.millCards(1, source, game);
cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.GRAVEYARD);
numberOfCard += cards.size();
Set<Card> creatures = cards
.getCards(game)
.stream()
.filter(Objects::nonNull)
.filter(MageObject::isCreature)
.collect(Collectors.toSet());
if (!creatures.isEmpty()) {
controller.moveCards(creatures, Zone.BATTLEFIELD, source, game);
}
if (!creatures.isEmpty()) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
permanent.sacrifice(source, game);
}
break;
}
if (numberOfCard >= max) {
cards.addAll(targetOpponent.millCards(1, source, game));
cards.retainZone(Zone.GRAVEYARD, game);
if (cards.size() >= max || cards.count(StaticFilters.FILTER_CARD_CREATURE, game) > 0) {
break;
}
}
Card card;
switch (cards.count(StaticFilters.FILTER_CARD_CREATURE, game)) {
case 0:
return true;
case 1:
card = cards
.getCards(StaticFilters.FILTER_CARD_CREATURE, game)
.stream()
.findFirst()
.orElse(null);
break;
default:
TargetCardInGraveyard target = new TargetCardInGraveyard(StaticFilters.FILTER_CARD_CREATURE);
target.setNotTarget(true);
controller.choose(Outcome.PutCreatureInPlay, cards, target, game);
card = game.getCard(target.getFirstTarget());
}
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent != null) {
permanent.sacrifice(source, game);
}
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
return true;
}