mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
[NEO] fixed implementation of March additional costs (#8524)
This commit is contained in:
parent
8f693bf75e
commit
cff38b74b9
9 changed files with 72 additions and 89 deletions
|
|
@ -3,10 +3,13 @@ package mage.abilities.costs;
|
|||
import mage.abilities.Ability;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public interface CostAdjuster {
|
||||
@FunctionalInterface
|
||||
public interface CostAdjuster extends Serializable {
|
||||
|
||||
/**
|
||||
* Must check playable and real cast states.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
package mage.abilities.costs.costadjusters;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.costs.CostAdjuster;
|
||||
import mage.abilities.costs.common.ExileFromHandCost;
|
||||
import mage.abilities.effects.common.InfoEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetCardInHand;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class ExileCardsFromHandAdjuster implements CostAdjuster {
|
||||
|
||||
private final FilterCard filter;
|
||||
|
||||
private ExileCardsFromHandAdjuster(FilterCard filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void adjustCosts(Ability ability, Game game) {
|
||||
if (game.inCheckPlayableState()) {
|
||||
return;
|
||||
}
|
||||
Player player = game.getPlayer(ability.getControllerId());
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
int cardCount = player.getHand().count(filter, game);
|
||||
int toExile = cardCount > 0 ? player.getAmount(
|
||||
0, cardCount, "Choose how many " + filter.getMessage() + " to exile", game
|
||||
) : 0;
|
||||
if (toExile > 0) {
|
||||
ability.addCost(new ExileFromHandCost(new TargetCardInHand(toExile, filter)));
|
||||
CardUtil.reduceCost(ability, 2 * toExile);
|
||||
}
|
||||
}
|
||||
|
||||
public static final void addAdjusterAndMessage(Card card, FilterCard filter) {
|
||||
card.addAbility(new SimpleStaticAbility(
|
||||
Zone.ALL,
|
||||
new InfoEffect("you may exile any number of " + filter.getMessage()
|
||||
+ ". This spell costs {2} less to cast for each card exiled this way")
|
||||
));
|
||||
card.getSpellAbility().setCostAdjuster(new ExileCardsFromHandAdjuster(filter));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
package mage.abilities.effects;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.common.ExileFromHandCost;
|
||||
import mage.abilities.effects.common.cost.CostModificationEffectImpl;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.CostModificationType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.game.Game;
|
||||
import mage.target.common.TargetCardInHand;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class CostsLessForExiledCardsEffect extends CostModificationEffectImpl {
|
||||
|
||||
private final FilterCard filter;
|
||||
|
||||
private CostsLessForExiledCardsEffect(FilterCard filter) {
|
||||
super(Duration.WhileOnStack, Outcome.Benefit, CostModificationType.REDUCE_COST);
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
private CostsLessForExiledCardsEffect(final CostsLessForExiledCardsEffect effect) {
|
||||
super(effect);
|
||||
this.filter = effect.filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source, Ability abilityToModify) {
|
||||
SpellAbility spellAbility = (SpellAbility) abilityToModify;
|
||||
for (Cost cost : spellAbility.getCosts()) {
|
||||
if (!(cost instanceof ExileFromHandCost)) {
|
||||
continue;
|
||||
}
|
||||
ExileFromHandCost eCost = (ExileFromHandCost) cost;
|
||||
int reduction;
|
||||
if (game.inCheckPlayableState()) {
|
||||
reduction = game.getPlayer(spellAbility.getControllerId()).getHand().count(filter, game);
|
||||
} else {
|
||||
reduction = eCost.getCards().size();
|
||||
}
|
||||
CardUtil.adjustCost(spellAbility, reduction * 2);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
||||
return abilityToModify instanceof SpellAbility
|
||||
&& abilityToModify.getSourceId().equals(source.getSourceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CostsLessForExiledCardsEffect copy() {
|
||||
return new CostsLessForExiledCardsEffect(this);
|
||||
}
|
||||
|
||||
public static void addCostAndEffect(Card card, FilterCard filter) {
|
||||
card.getSpellAbility().addCost(new ExileFromHandCost(
|
||||
new TargetCardInHand(0, Integer.MAX_VALUE, filter)
|
||||
).setText("you may exile any number of " + filter.getMessage()
|
||||
+ ". This spell costs {2} less to cast for each card exiled this way"));
|
||||
Ability ability = new SimpleStaticAbility(Zone.ALL, new CostsLessForExiledCardsEffect(filter));
|
||||
ability.setRuleVisible(false);
|
||||
card.addAbility(ability);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,11 +3,13 @@ package mage.target.targetadjustment;
|
|||
import mage.abilities.Ability;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public interface TargetAdjuster {
|
||||
@FunctionalInterface
|
||||
public interface TargetAdjuster extends Serializable {
|
||||
|
||||
void adjustTargets(Ability ability, Game game);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue