* Fixed some mana handling problems of conditionalMana (GemstoneCavern) and possible exception of ChromeMox.Fixed some tests.

This commit is contained in:
LevelX2 2018-06-05 23:59:39 +02:00
parent 0051f70b8a
commit df341bd0d6
9 changed files with 85 additions and 56 deletions

View file

@ -1,5 +1,6 @@
package mage.abilities.decorator;
import java.util.List;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
@ -47,10 +48,10 @@ public class ConditionalManaEffect extends ManaEffect {
return false;
}
Mana mana = getMana(game, source);
controller.getManaPool().addMana(mana, game, source);
if (produceMana(true, game, source).getAny() > 0) {
checkToFirePossibleEvents(mana, game, source);
}
controller.getManaPool().addMana(mana, game, source);
return true;
}
@ -64,6 +65,16 @@ public class ConditionalManaEffect extends ManaEffect {
return produceMana(false, game, source);
}
@Override
public List<Mana> getNetMana(Game game, Ability source) {
if (condition.apply(game, source)) {
return effect.getNetMana(game, source);
} else if (otherwiseEffect != null) {
return otherwiseEffect.getNetMana(game, source);
}
return null;
}
@Override
public Mana produceMana(boolean netMana, Game game, Ability source) {
Mana mana = new Mana();

View file

@ -1,6 +1,7 @@
package mage.abilities.effects.mana;
import java.util.ArrayList;
import java.util.List;
import mage.Mana;
import mage.abilities.Ability;
import mage.choices.ChoiceColor;
@ -13,25 +14,28 @@ import mage.util.CardUtil;
*/
public class AddManaOfAnyColorEffect extends BasicManaEffect {
protected int amount;
protected final int amount;
protected final ArrayList<Mana> netMana = new ArrayList<>();
public AddManaOfAnyColorEffect() {
this(1);
}
public AddManaOfAnyColorEffect(final int amount) {
public AddManaOfAnyColorEffect(int amount) {
super(new Mana(0, 0, 0, 0, 0, 0, amount, 0));
this.amount = amount;
this.staticText = new StringBuilder("add ")
.append(CardUtil.numberToText(amount))
.append(" mana of any ")
.append(amount > 1 ? "one " : "")
.append("color").toString();
netMana.add(Mana.GreenMana(amount));
netMana.add(Mana.BlueMana(amount));
netMana.add(Mana.BlackMana(amount));
netMana.add(Mana.WhiteMana(amount));
netMana.add(Mana.RedMana(amount));
this.staticText = "add " + CardUtil.numberToText(amount) + " mana of any " + (amount > 1 ? "one " : "") + "color";
}
public AddManaOfAnyColorEffect(final AddManaOfAnyColorEffect effect) {
super(effect);
this.amount = effect.amount;
this.netMana.addAll(effect.netMana);
}
@Override
@ -41,23 +45,33 @@ public class AddManaOfAnyColorEffect extends BasicManaEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
checkToFirePossibleEvents(getMana(game, source), game, source);
controller.getManaPool().addMana(getMana(game, source), game, source);
return true;
}
return false;
}
@Override
public List<Mana> getNetMana(Game game, Ability source) {
return netMana;
}
@Override
public Mana produceMana(boolean netMana, Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
String mes = String.format("Select color of %d mana to add it", this.amount);
ChoiceColor choice = new ChoiceColor(true, mes, game.getObject(source.getSourceId()));
if (controller.choose(outcome, choice, game)) {
if (choice.getColor() == null) {
return false;
if (choice.getColor() != null) {
return choice.getMana(amount);
}
Mana createdMana = choice.getMana(amount);
if (createdMana != null) {
checkToFirePossibleEvents(createdMana, game, source);
controller.getManaPool().addMana(createdMana, game, source);
}
return true;
}
}
return false;
return null;
}
public int getAmount() {

View file

@ -1,5 +1,3 @@
package mage.abilities.mana;
import java.util.ArrayList;
@ -14,7 +12,6 @@ import mage.game.Game;
*
* @author LevelX2
*/
public class ConditionalManaAbility extends ActivatedManaAbilityImpl {
ConditionalManaEffect conditionalManaEffect;
@ -37,7 +34,7 @@ public class ConditionalManaAbility extends ActivatedManaAbilityImpl {
@Override
public List<Mana> getNetMana(Game game) {
List<Mana> newNetMana = new ArrayList<>();
newNetMana.add(conditionalManaEffect.getMana(game, this));
newNetMana.addAll(conditionalManaEffect.getNetMana(game, this));
return newNetMana;
}
}

View file

@ -1,4 +1,3 @@
package mage.players;
import java.io.Serializable;
@ -366,25 +365,27 @@ public class ManaPool implements Serializable {
}
public void addMana(Mana manaToAdd, Game game, Ability source, boolean emptyOnTurnsEnd) {
Mana mana = manaToAdd.copy();
if (!game.replaceEvent(new ManaEvent(EventType.ADD_MANA, source.getId(), source.getSourceId(), playerId, mana))) {
if (mana instanceof ConditionalMana) {
ManaPoolItem item = new ManaPoolItem((ConditionalMana) mana, source.getSourceObject(game),
((ConditionalMana) mana).getManaProducerOriginalId() != null ? ((ConditionalMana) mana).getManaProducerOriginalId() : source.getOriginalId());
if (emptyOnTurnsEnd) {
item.setDuration(Duration.EndOfTurn);
if (manaToAdd != null) {
Mana mana = manaToAdd.copy();
if (!game.replaceEvent(new ManaEvent(EventType.ADD_MANA, source.getId(), source.getSourceId(), playerId, mana))) {
if (mana instanceof ConditionalMana) {
ManaPoolItem item = new ManaPoolItem((ConditionalMana) mana, source.getSourceObject(game),
((ConditionalMana) mana).getManaProducerOriginalId() != null ? ((ConditionalMana) mana).getManaProducerOriginalId() : source.getOriginalId());
if (emptyOnTurnsEnd) {
item.setDuration(Duration.EndOfTurn);
}
this.manaItems.add(item);
} else {
ManaPoolItem item = new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getGeneric() + mana.getColorless(), source.getSourceObject(game), source.getOriginalId(), mana.getFlag());
if (emptyOnTurnsEnd) {
item.setDuration(Duration.EndOfTurn);
}
this.manaItems.add(item);
}
this.manaItems.add(item);
} else {
ManaPoolItem item = new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getGeneric() + mana.getColorless(), source.getSourceObject(game), source.getOriginalId(), mana.getFlag());
if (emptyOnTurnsEnd) {
item.setDuration(Duration.EndOfTurn);
}
this.manaItems.add(item);
ManaEvent manaEvent = new ManaEvent(EventType.MANA_ADDED, source.getId(), source.getSourceId(), playerId, mana);
manaEvent.setData(mana.toString());
game.fireEvent(manaEvent);
}
ManaEvent manaEvent = new ManaEvent(EventType.MANA_ADDED, source.getId(), source.getSourceId(), playerId, mana);
manaEvent.setData(mana.toString());
game.fireEvent(manaEvent);
}
}