mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
- Fixed #5515
This commit is contained in:
parent
045c2f094d
commit
b98bddb600
1 changed files with 27 additions and 95 deletions
|
@ -2,23 +2,22 @@ package mage.cards.a;
|
|||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.VariableCostImpl;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.costs.CostAdjuster;
|
||||
import mage.abilities.costs.common.DiscardTargetCost;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.common.InfoEffect;
|
||||
import mage.abilities.effects.common.ReturnToHandTargetEffect;
|
||||
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.common.FilterCreatureCard;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.target.common.TargetCardInHand;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
import mage.target.targetadjustment.TargetAdjuster;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -30,10 +29,16 @@ public final class AetherTide extends CardImpl {
|
|||
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{X}{U}");
|
||||
|
||||
// As an additional cost to cast Aether Tide, discard X creature cards.
|
||||
this.getSpellAbility().addCost(new AetherTideCost());
|
||||
Ability ability = new SimpleStaticAbility(Zone.ALL, new InfoEffect("As an additional cost to cast {this}, discard X creature cards"));
|
||||
ability.setRuleAtTheTop(true);
|
||||
this.addAbility(ability);
|
||||
|
||||
// Return X target creatures to their owners' hands.
|
||||
this.getSpellAbility().addEffect(new ReturnToHandTargetPermanentEffect());
|
||||
Effect effect = new ReturnToHandTargetEffect(true);
|
||||
effect.setText("Return X target creatures to their owners' hands");
|
||||
this.getSpellAbility().addEffect(effect);
|
||||
this.getSpellAbility().setTargetAdjuster(AetherTideTargetAdjuster.instance);
|
||||
this.getSpellAbility().setCostAdjuster(AetherTideCostAdjuster.instance);
|
||||
|
||||
}
|
||||
|
||||
|
@ -47,98 +52,25 @@ public final class AetherTide extends CardImpl {
|
|||
}
|
||||
}
|
||||
|
||||
class AetherTideCost extends VariableCostImpl {
|
||||
|
||||
public AetherTideCost() {
|
||||
super("discard X creature cards");
|
||||
text = "As an additional cost to cast {this}, discard X creature cards";
|
||||
}
|
||||
|
||||
public AetherTideCost(AetherTideCost cost) {
|
||||
super(cost);
|
||||
}
|
||||
enum AetherTideTargetAdjuster implements TargetAdjuster {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) {
|
||||
return (game.getPlayer(controllerId).getHand().count(new FilterCreatureCard(), game) > 0);
|
||||
public void adjustTargets(Ability ability, Game game) {
|
||||
ability.getTargets().clear();
|
||||
int xValue = ability.getManaCostsToPay().getX();
|
||||
ability.addTarget(new TargetCreaturePermanent(xValue, xValue, new FilterCreaturePermanent(), false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxValue(Ability source, Game game) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
return controller.getHand().count(new FilterCreatureCard(), game);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinValue(Ability source, Game game) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cost getFixedCostsFromAnnouncedValue(int xValue) {
|
||||
TargetCardInHand target = new TargetCardInHand(xValue, new FilterCreatureCard());
|
||||
return new DiscardTargetCost(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int announceXValue(Ability source, Game game) {
|
||||
int xValue = 0;
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
StackObject stackObject = game.getStack().getStackObject(source.getId());
|
||||
if (controller != null
|
||||
&& stackObject != null) {
|
||||
xValue = controller.announceXCost(getMinValue(source, game), getMaxValue(source, game),
|
||||
"Announce the number of creature cards to discard", game, source, this);
|
||||
}
|
||||
return xValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AetherTideCost copy() {
|
||||
return new AetherTideCost(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ReturnToHandTargetPermanentEffect extends OneShotEffect {
|
||||
|
||||
public ReturnToHandTargetPermanentEffect() {
|
||||
super(Outcome.ReturnToHand);
|
||||
setText("Return X target creatures to their owners' hands");
|
||||
}
|
||||
|
||||
public ReturnToHandTargetPermanentEffect(final ReturnToHandTargetPermanentEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
enum AetherTideCostAdjuster implements CostAdjuster {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public ReturnToHandTargetPermanentEffect copy() {
|
||||
return new ReturnToHandTargetPermanentEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
int xPaid = source.getCosts().getVariableCosts().get(0).getAmount();
|
||||
if (controller != null
|
||||
&& xPaid > 0) {
|
||||
int available = game.getBattlefield().count(new FilterCreaturePermanent(),
|
||||
source.getSourceId(),
|
||||
source.getControllerId(), game);
|
||||
if (available > 0) {
|
||||
TargetPermanent target = new TargetPermanent(Math.min(xPaid, available),
|
||||
xPaid,
|
||||
new FilterCreaturePermanent("creatures to return to their owner's hands"),
|
||||
true);
|
||||
if (controller.chooseTarget(outcome.Detriment, target, source, game)) {
|
||||
controller.moveCards(new CardsImpl(target.getTargets()), Zone.HAND, source, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void adjustCosts(Ability ability, Game game) {
|
||||
int xValue = ability.getManaCostsToPay().getX();
|
||||
if (xValue > 0) {
|
||||
ability.addCost(new DiscardTargetCost(new TargetCardInHand(xValue, xValue, new FilterCreatureCard("creature cards"))));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue