Cost increasing effects - refactor, removed redundant custom effects (related to #6684 and #6698);

This commit is contained in:
Oleg Agafonov 2020-06-29 15:39:58 +04:00
parent 4bdd8910a8
commit 90965802d0
28 changed files with 363 additions and 655 deletions

View file

@ -1,66 +0,0 @@
package mage.abilities.effects.common.cost;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.cards.Card;
import mage.constants.CostModificationType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.util.CardUtil;
/**
*
* @author Plopman
*/
public class SpellsCostIncreasementAllEffect extends CostModificationEffectImpl {
private FilterCard filter;
private int amount;
public SpellsCostIncreasementAllEffect(int amount) {
this(new FilterCard("Spells"), amount);
}
public SpellsCostIncreasementAllEffect(FilterCard filter, int amount) {
super(Duration.WhileOnBattlefield, Outcome.Benefit, CostModificationType.INCREASE_COST);
this.filter = filter;
this.amount = amount;
this.staticText = new StringBuilder(filter.getMessage()).append(" cost {").append(amount).append("} more to cast").toString();
}
protected SpellsCostIncreasementAllEffect(SpellsCostIncreasementAllEffect effect) {
super(effect);
this.filter = effect.filter;
this.amount = effect.amount;
}
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
CardUtil.increaseCost(abilityToModify, this.amount);
return true;
}
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility) {
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
if (spell != null) {
return this.filter.match(spell, game);
} else {
// used at least for flashback ability because Flashback ability doesn't use stack
Card sourceCard = game.getCard(abilityToModify.getSourceId());
return sourceCard != null && this.filter.match(sourceCard, game);
}
}
return false;
}
@Override
public SpellsCostIncreasementAllEffect copy() {
return new SpellsCostIncreasementAllEffect(this);
}
}

View file

@ -1,90 +0,0 @@
package mage.abilities.effects.common.cost;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.cards.Card;
import mage.constants.CostModificationType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.util.CardUtil;
/**
*
* @author Quercitron
*/
public class SpellsCostIncreasementControllerEffect extends CostModificationEffectImpl {
private final FilterCard filter;
private final int amount;
private ManaCosts<ManaCost> manaCostsToIncrease = null;
public SpellsCostIncreasementControllerEffect(FilterCard filter, ManaCosts<ManaCost> manaCostsToReduce) {
super(Duration.WhileOnBattlefield, Outcome.Detriment, CostModificationType.INCREASE_COST);
this.filter = filter;
this.amount = 0;
this.manaCostsToIncrease = manaCostsToReduce;
StringBuilder sb = new StringBuilder();
sb.append(filter.getMessage()).append(" you cast cost ");
for (String manaSymbol : manaCostsToReduce.getSymbols()) {
sb.append(manaSymbol);
}
sb.append(" more to cast");
this.staticText = sb.toString();
}
public SpellsCostIncreasementControllerEffect(FilterCard filter, int amount) {
super(Duration.WhileOnBattlefield, Outcome.Detriment, CostModificationType.INCREASE_COST);
this.filter = filter;
this.amount = amount;
StringBuilder sb = new StringBuilder();
sb.append(filter.getMessage()).append(" you cast cost {").append(amount).append("} more to cast");
this.staticText = sb.toString();
}
protected SpellsCostIncreasementControllerEffect(SpellsCostIncreasementControllerEffect effect) {
super(effect);
this.filter = effect.filter;
this.amount = effect.amount;
this.manaCostsToIncrease = effect.manaCostsToIncrease;
}
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
if (manaCostsToIncrease != null) {
CardUtil.increaseCost((SpellAbility) abilityToModify, manaCostsToIncrease);
} else {
CardUtil.increaseCost(abilityToModify, this.amount);
}
return true;
}
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility) {
if (abilityToModify.isControlledBy(source.getControllerId())) {
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
if (spell != null) {
return this.filter.match(spell, game);
} else {
// used at least for flashback ability because Flashback ability doesn't use stack
Card sourceCard = game.getCard(abilityToModify.getSourceId());
return sourceCard != null && this.filter.match(sourceCard, game);
}
}
}
return false;
}
@Override
public SpellsCostIncreasementControllerEffect copy() {
return new SpellsCostIncreasementControllerEffect(this);
}
}

View file

@ -0,0 +1,139 @@
package mage.abilities.effects.common.cost;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.cards.Card;
import mage.constants.CostModificationType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.players.Player;
import mage.util.CardUtil;
/**
* @author JayDi85
*/
public class SpellsCostIncreasingAllEffect extends CostModificationEffectImpl {
private final FilterCard filter;
private final TargetController targetController;
private final int increaseGenericCost;
private ManaCosts<ManaCost> increaseManaCosts;
public SpellsCostIncreasingAllEffect(int increaseGenericCost, FilterCard filter, TargetController targetController) {
super(Duration.WhileOnBattlefield, Outcome.Detriment, CostModificationType.INCREASE_COST);
this.filter = filter;
this.targetController = targetController;
this.increaseGenericCost = increaseGenericCost;
this.increaseManaCosts = null;
setText();
}
public SpellsCostIncreasingAllEffect(ManaCosts<ManaCost> increaseManaCosts, FilterCard filter, TargetController targetController) {
super(Duration.WhileOnBattlefield, Outcome.Detriment, CostModificationType.INCREASE_COST);
this.filter = filter;
this.targetController = targetController;
this.increaseGenericCost = 0;
this.increaseManaCosts = increaseManaCosts;
setText();
}
private void setText() {
StringBuilder sb = new StringBuilder();
sb.append(filter.getMessage());
switch (this.targetController) {
case YOU:
sb.append(" you cast");
break;
case OPPONENT:
sb.append(" your opponents cast");
break;
case ANY:
break;
default:
throw new IllegalArgumentException("Unsupported TargetController " + this.targetController);
}
sb.append(" cost ");
if (this.increaseManaCosts != null) {
for (String manaSymbol : this.increaseManaCosts.getSymbols()) {
sb.append(manaSymbol);
}
} else {
sb.append("{").append(increaseGenericCost).append("}");
}
sb.append(" more to cast");
this.staticText = sb.toString();
}
protected SpellsCostIncreasingAllEffect(SpellsCostIncreasingAllEffect effect) {
super(effect);
this.filter = effect.filter;
this.targetController = effect.targetController;
this.increaseGenericCost = effect.increaseGenericCost;
this.increaseManaCosts = effect.increaseManaCosts;
}
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
if (increaseManaCosts != null) {
CardUtil.increaseCost((SpellAbility) abilityToModify, increaseManaCosts);
} else {
CardUtil.increaseCost(abilityToModify, this.increaseGenericCost);
}
return true;
}
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility) {
Player abilityController = game.getPlayer(abilityToModify.getControllerId());
Player sourceController = game.getPlayer(source.getControllerId());
if (abilityController == null || sourceController == null) {
return false;
}
switch (this.targetController) {
case YOU:
if (!sourceController.getId().equals(abilityController.getId())) {
return false;
}
break;
case OPPONENT:
if (!sourceController.hasOpponent(abilityController.getId(), game)) {
return false;
}
break;
case ANY:
break;
default:
throw new IllegalArgumentException("Unsupported TargetController " + this.targetController);
}
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
if (spell != null) {
// real cast with put on stack
return this.filter.match(spell, game);
} else {
// get playable and other staff without put on stack
// used at least for flashback ability because Flashback ability doesn't use stack
Card sourceCard = game.getCard(abilityToModify.getSourceId());
return sourceCard != null && this.filter.match(sourceCard, game);
}
}
return false;
}
@Override
public SpellsCostIncreasingAllEffect copy() {
return new SpellsCostIncreasingAllEffect(this);
}
}