forked from External/mage
Reworking effects which allow casting spells from a selection of cards (ready for review) (#8136)
* added function for casting spells with specific attributes from a selection of cards * updated cascade to use new method * refactored various cards to use new methods * added TestPlayer method * fixed a small error * text fix * broke out some repeated code * added missing notTarget setting * add additional retain zone check * some more cards refactored * more refactoring * added interface for split/modal cards * reworked spell casting methods * reworked multiple cast to prevent unnecessary dialogs * fixed test failures due to change in functionality * add AI code * small nonfunctional change * reworked Kaya, the Inexorable * added currently failing test * added more tests * updated Geode Golem implementation * fixed adventure/cascade interaction, added/updated tests * some nonfunctional refactoring * added interface for subcards * [AFC] Implemented Fevered Suspicion * [AFC] Implemented Extract Brain * [AFC] updated Arcane Endeavor implementation * [C17] reworked implementation of Izzet Chemister * [ZEN] reworked implemented of Chandra Ablaze * additional merge fix * [SLD] updated Eleven, the Mage * [NEO] Implemented Discover the Impossible * [NEO] Implemented The Dragon-Kami Reborn / Dragon-Kami's Egg * [NEO] Implemented Invoke Calamity * [AFR] Implemented Rod of Absorption * [VOC] Implemented Spectral Arcanist * [VOC] added additional printings * [NEO] added all variants * [SLD] updated implementation of Ken, Burning Brawler
This commit is contained in:
parent
7fb089db48
commit
bbb9382150
83 changed files with 2551 additions and 2059 deletions
|
|
@ -0,0 +1,48 @@
|
|||
package mage.abilities.effects.common.cost;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* @author fireshoes - Original Code
|
||||
* @author JRHerlehy - Implement as seperate class
|
||||
* <p>
|
||||
* Allows player to choose to cast as card from hand without paying its mana
|
||||
* cost.
|
||||
* </p>
|
||||
*/
|
||||
public class CastFromHandForFreeEffect extends OneShotEffect {
|
||||
|
||||
private final FilterCard filter;
|
||||
|
||||
public CastFromHandForFreeEffect(FilterCard filter) {
|
||||
super(Outcome.PlayForFree);
|
||||
this.filter = filter;
|
||||
this.staticText = "you may cast " + filter.getMessage() + " from your hand without paying its mana cost";
|
||||
}
|
||||
|
||||
public CastFromHandForFreeEffect(final CastFromHandForFreeEffect effect) {
|
||||
super(effect);
|
||||
this.filter = effect.filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
return CardUtil.castSpellWithAttributesForFree(controller, source, game, new CardsImpl(controller.getHand()), filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CastFromHandForFreeEffect copy() {
|
||||
return new CastFromHandForFreeEffect(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
package mage.abilities.effects.common.cost;
|
||||
|
||||
import mage.ApprovingObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.ComparisonType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.filter.common.FilterNonlandCard;
|
||||
import mage.filter.predicate.mageobject.ManaValuePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.common.TargetCardInHand;
|
||||
import mage.util.CardUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* @author fireshoes - Original Code
|
||||
* @author JRHerlehy - Implement as seperate class
|
||||
* <p>
|
||||
* Allows player to choose to cast as card from hand without paying its mana
|
||||
* cost.
|
||||
* </p>
|
||||
* TODO: this doesn't work correctly with MDFCs or Adventures (see https://github.com/magefree/mage/issues/7742)
|
||||
*/
|
||||
public class CastWithoutPayingManaCostEffect extends OneShotEffect {
|
||||
|
||||
private final DynamicValue manaCost;
|
||||
private final FilterCard filter;
|
||||
private static final FilterCard defaultFilter
|
||||
= new FilterNonlandCard("card with mana value %mv or less from your hand");
|
||||
|
||||
/**
|
||||
* @param maxCost Maximum converted mana cost for this effect to apply to
|
||||
*/
|
||||
public CastWithoutPayingManaCostEffect(int maxCost) {
|
||||
this(StaticValue.get(maxCost));
|
||||
}
|
||||
|
||||
public CastWithoutPayingManaCostEffect(DynamicValue maxCost) {
|
||||
this(maxCost, defaultFilter);
|
||||
}
|
||||
|
||||
public CastWithoutPayingManaCostEffect(DynamicValue maxCost, FilterCard filter) {
|
||||
super(Outcome.PlayForFree);
|
||||
this.manaCost = maxCost;
|
||||
this.filter = filter;
|
||||
this.staticText = "you may cast a spell with mana value "
|
||||
+ maxCost + " or less from your hand without paying its mana cost";
|
||||
}
|
||||
|
||||
public CastWithoutPayingManaCostEffect(final CastWithoutPayingManaCostEffect effect) {
|
||||
super(effect);
|
||||
this.manaCost = effect.manaCost;
|
||||
this.filter = effect.filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
int cmc = manaCost.calculate(game, source, this);
|
||||
FilterCard filter = this.filter.copy();
|
||||
filter.setMessage(filter.getMessage().replace("%mv", "" + cmc));
|
||||
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
|
||||
Target target = new TargetCardInHand(filter);
|
||||
if (!target.canChoose(
|
||||
source.getSourceId(), controller.getId(), game
|
||||
) || !controller.chooseUse(
|
||||
Outcome.PlayForFree,
|
||||
"Cast " + CardUtil.addArticle(filter.getMessage())
|
||||
+ " without paying its mana cost?", source, game
|
||||
)) {
|
||||
return true;
|
||||
}
|
||||
Card cardToCast = null;
|
||||
boolean cancel = false;
|
||||
while (controller.canRespond()
|
||||
&& !cancel) {
|
||||
if (controller.chooseTarget(Outcome.PlayForFree, target, source, game)) {
|
||||
cardToCast = game.getCard(target.getFirstTarget());
|
||||
if (cardToCast != null) {
|
||||
if (cardToCast.getSpellAbility() == null) {
|
||||
Logger.getLogger(CastWithoutPayingManaCostEffect.class).fatal("Card: "
|
||||
+ cardToCast.getName() + " is no land and has no spell ability!");
|
||||
cancel = true;
|
||||
}
|
||||
if (cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
|
||||
cancel = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cancel = true;
|
||||
}
|
||||
}
|
||||
if (cardToCast != null) {
|
||||
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
|
||||
controller.cast(controller.chooseAbilityForCast(cardToCast, game, true),
|
||||
game, true, new ApprovingObject(source, game));
|
||||
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CastWithoutPayingManaCostEffect copy() {
|
||||
return new CastWithoutPayingManaCostEffect(this);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue