Merge pull request #3662 from spjspj/master

Implement Memory Crystal (EXO)
This commit is contained in:
spjspj 2017-07-12 12:41:31 +10:00 committed by GitHub
commit b9f4adaf44

View file

@ -28,7 +28,6 @@
package mage.abilities.keyword; package mage.abilities.keyword;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.SpellAbility; import mage.abilities.SpellAbility;
import mage.abilities.StaticAbility; import mage.abilities.StaticAbility;
@ -38,7 +37,6 @@ import mage.abilities.costs.OptionalAdditionalCost;
import mage.abilities.costs.OptionalAdditionalCostImpl; import mage.abilities.costs.OptionalAdditionalCostImpl;
import mage.abilities.costs.OptionalAdditionalSourceCosts; import mage.abilities.costs.OptionalAdditionalSourceCosts;
import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.ReplacementEffectImpl;
import mage.cards.Card; import mage.cards.Card;
@ -107,12 +105,14 @@ public class BuybackAbility extends StaticAbility implements OptionalAdditionalS
// Called by Memory Crystal to reduce mana costs. // Called by Memory Crystal to reduce mana costs.
public int reduceCost(int genericManaToReduce) { public int reduceCost(int genericManaToReduce) {
int amountToReduce = genericManaToReduce; int amountToReduce = genericManaToReduce;
boolean foundCostToReduce = false;
if (buybackCost != null) { if (buybackCost != null) {
for (Object cost : ((Costs) buybackCost)) { for (Object cost : ((Costs) buybackCost)) {
if (cost instanceof ManaCostsImpl) { if (cost instanceof ManaCostsImpl) {
for (Object c : (ManaCostsImpl) cost) { for (Object c : (ManaCostsImpl) cost) {
if (c instanceof GenericManaCost) { if (c instanceof GenericManaCost) {
int newCostCMC = ((GenericManaCost) c).convertedManaCost() - amountToReduceBy - genericManaToReduce; int newCostCMC = ((GenericManaCost) c).convertedManaCost() - amountToReduceBy - genericManaToReduce;
foundCostToReduce = true;
if (newCostCMC > 0) { if (newCostCMC > 0) {
amountToReduceBy += genericManaToReduce; amountToReduceBy += genericManaToReduce;
} else { } else {
@ -124,8 +124,11 @@ public class BuybackAbility extends StaticAbility implements OptionalAdditionalS
} }
} }
} }
if (foundCostToReduce) {
return amountToReduce; return amountToReduce;
} }
return 0;
}
@Override @Override
public boolean isActivated() { public boolean isActivated() {