* Opal Palcar - Fixed a bug that the first mana ability also wrongly gave the commander boost.

This commit is contained in:
LevelX2 2013-12-27 19:14:17 +01:00
parent a1ba324dba
commit acc3ac7b60
4 changed files with 105 additions and 48 deletions

View file

@ -133,22 +133,27 @@ class OpalPalaceManaEffect extends ManaEffect<OpalPalaceManaEffect> {
choice.getChoices().add("White");
}
if (choice.getChoices().size() > 0) {
Mana mana = new Mana();
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
controller.choose(outcome, choice, game);
}
if (choice.getChoice().equals("Black")) {
controller.getManaPool().addMana(Mana.BlackMana, game, source);
mana.addBlack();
} else if (choice.getChoice().equals("Blue")) {
controller.getManaPool().addMana(Mana.BlueMana, game, source);
mana.addBlue();
} else if (choice.getChoice().equals("Red")) {
controller.getManaPool().addMana(Mana.RedMana, game, source);
mana.addRed();
} else if (choice.getChoice().equals("Green")) {
controller.getManaPool().addMana(Mana.GreenMana, game, source);
mana.addGreen();
} else if (choice.getChoice().equals("White")) {
controller.getManaPool().addMana(Mana.WhiteMana, game, source);
mana.addWhite();
}
// set to indicate, that the mana can boost the commander
mana.setFlag(true);
controller.getManaPool().addMana(mana, game, source);
}
return true;
}
@ -177,7 +182,7 @@ class OpalPalaceWatcher extends WatcherImpl<OpalPalaceWatcher> {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.MANA_PAYED) {
if (event.getSourceId().equals(this.getSourceId())) {
if (event.getSourceId().equals(this.getSourceId()) && event.getFlag()) { // flag indicates that mana was produced with second ability
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null) {
Card card = spell.getCard();

View file

@ -28,13 +28,12 @@
package mage;
import java.io.Serializable;
import mage.constants.ColoredManaSymbol;
import mage.constants.ManaType;
import mage.filter.FilterMana;
import mage.util.Copyable;
import java.io.Serializable;
/**
*
* @author BetaSteward_at_googlemail.com
@ -48,6 +47,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
protected int black;
protected int colorless;
protected int any;
protected boolean flag = false;
public static final Mana RedMana = RedMana(1);
public static final Mana GreenMana = GreenMana(1);
@ -59,13 +59,14 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
public Mana() {}
public Mana(final Mana mana) {
red = mana.red;
green = mana.green;
blue = mana.blue;
white = mana.white;
black = mana.black;
colorless = mana.colorless;
any = mana.any;
this.red = mana.red;
this.green = mana.green;
this.blue = mana.blue;
this.white = mana.white;
this.black = mana.black;
this.colorless = mana.colorless;
this.any = mana.any;
this.flag = mana.flag;
}
public Mana(ColoredManaSymbol color) {
@ -175,12 +176,24 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
return count();
}
int count = 0;
if (filter.isBlack()) count += black;
if (filter.isBlue()) count += blue;
if (filter.isWhite()) count += white;
if (filter.isGreen()) count += green;
if (filter.isRed()) count += red;
if (filter.isColorless()) count += colorless;
if (filter.isBlack()) {
count += black;
}
if (filter.isBlue()) {
count += blue;
}
if (filter.isWhite()) {
count += white;
}
if (filter.isGreen()) {
count += green;
}
if (filter.isRed()) {
count += red;
}
if (filter.isColorless()) {
count += colorless;
}
return count;
}
@ -198,18 +211,24 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
public String toString() {
StringBuilder sbMana = new StringBuilder();
for (int i = 0; i < red; i++)
for (int i = 0; i < red; i++) {
sbMana.append("{R}");
for (int i = 0; i < green; i++)
}
for (int i = 0; i < green; i++) {
sbMana.append("{G}");
for (int i = 0; i < blue; i++)
}
for (int i = 0; i < blue; i++) {
sbMana.append("{U}");
for (int i = 0; i < black; i++)
}
for (int i = 0; i < black; i++) {
sbMana.append("{B}");
for (int i = 0; i < white; i++)
}
for (int i = 0; i < white; i++) {
sbMana.append("{W}");
for (int i = 0; i < any; i++)
}
for (int i = 0; i < any; i++) {
sbMana.append("{Any}");
}
if (colorless > 0) {
sbMana.append("{").append(Integer.toString(colorless)).append("}");
}
@ -226,38 +245,44 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
compare.subtract(this);
if (compare.getRed() < 0) {
compare.setAny(compare.getAny() + compare.getRed());
if (compare.getAny() < 0)
if (compare.getAny() < 0) {
return false;
}
compare.setRed(0);
}
if (compare.getGreen() < 0) {
compare.setAny(compare.getAny() + compare.getGreen());
if (compare.getAny() < 0)
if (compare.getAny() < 0) {
return false;
}
compare.setGreen(0);
}
if (compare.getBlue() < 0) {
compare.setAny(compare.getAny() + compare.getBlue());
if (compare.getAny() < 0)
if (compare.getAny() < 0) {
return false;
}
compare.setBlue(0);
}
if (compare.getBlack() < 0) {
compare.setAny(compare.getAny() + compare.getBlack());
if (compare.getAny() < 0)
if (compare.getAny() < 0) {
return false;
}
compare.setBlack(0);
}
if (compare.getWhite() < 0) {
compare.setAny(compare.getAny() + compare.getWhite());
if (compare.getAny() < 0)
if (compare.getAny() < 0) {
return false;
}
compare.setWhite(0);
}
if (compare.getColorless() < 0) {
int remaining = compare.getRed() + compare.getGreen() + compare.getBlack() + compare.getBlue() + compare.getWhite() + compare.getAny();
if (compare.getColorless() + remaining < 0)
if (compare.getColorless() + remaining < 0) {
return false;
}
}
return true;
}
@ -304,18 +329,24 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
}
}
Mana needed = new Mana();
if (compare.getRed() < 0)
if (compare.getRed() < 0) {
needed.setRed(Math.abs(compare.getRed()));
if (compare.getWhite() < 0)
}
if (compare.getWhite() < 0) {
needed.setWhite(Math.abs(compare.getWhite()));
if (compare.getGreen() < 0)
}
if (compare.getGreen() < 0) {
needed.setGreen(Math.abs(compare.getGreen()));
if (compare.getBlack() < 0)
}
if (compare.getBlack() < 0) {
needed.setBlack(Math.abs(compare.getBlack()));
if (compare.getBlue() < 0)
}
if (compare.getBlue() < 0) {
needed.setBlue(Math.abs(compare.getBlue()));
if (compare.getColorless() < 0)
}
if (compare.getColorless() < 0) {
needed.setColorless(Math.abs(compare.getColorless()));
}
return needed;
}
@ -386,18 +417,24 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
* @return true if this contains any values that mana has
*/
public boolean contains(Mana mana) {
if (mana.black > 0 && this.black > 0)
if (mana.black > 0 && this.black > 0) {
return true;
if (mana.blue > 0 && this.blue > 0)
}
if (mana.blue > 0 && this.blue > 0) {
return true;
if (mana.red > 0 && this.red > 0)
}
if (mana.red > 0 && this.red > 0) {
return true;
if (mana.white > 0 && this.white > 0)
}
if (mana.white > 0 && this.white > 0) {
return true;
if (mana.green > 0 && this.green > 0)
}
if (mana.green > 0 && this.green > 0) {
return true;
if (mana.colorless > 0 && this.count() > 0)
}
if (mana.colorless > 0 && this.count() > 0) {
return true;
}
return false;
}
@ -462,4 +499,12 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
}
}
public void setFlag(boolean flag) {
this.flag = flag;
}
public boolean getFlag() {
return flag;
}
}

View file

@ -87,7 +87,7 @@ public class ManaPool implements Serializable {
if (filter == null || filter.match(game.getObject(mana.getSourceId()), game)) {
boolean spendAnyMana = spendAnyMana(ability, game);
if (mana.get(manaType) > 0 || (spendAnyMana && mana.count() > 0)) {
game.fireEvent(new GameEvent(GameEvent.EventType.MANA_PAYED, ability.getId(), mana.getSourceId(), ability.getControllerId()));
game.fireEvent(new GameEvent(GameEvent.EventType.MANA_PAYED, ability.getId(), mana.getSourceId(), ability.getControllerId(), 0, mana.getFlag()));
if (spendAnyMana) {
mana.removeAny();
} else {
@ -290,7 +290,7 @@ public class ManaPool implements Serializable {
if (mana instanceof ConditionalMana) {
this.manaItems.add(new ManaPoolItem((ConditionalMana)mana, source.getSourceId()));
} else {
this.manaItems.add(new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getColorless(), source.getSourceId()));
this.manaItems.add(new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getColorless(), source.getSourceId(), mana.getFlag()));
}
GameEvent event = GameEvent.getEvent(GameEvent.EventType.MANA_ADDED, source.getSourceId(), source.getId(), source.getControllerId());
event.setData(mana.toString());

View file

@ -47,10 +47,11 @@ public class ManaPoolItem implements Serializable {
private int colorless = 0;
private ConditionalMana conditionalMana;
private UUID sourceId;
private boolean flag = false;
public ManaPoolItem() {}
public ManaPoolItem(int red, int green, int blue, int white, int black, int colorless, UUID sourceId) {
public ManaPoolItem(int red, int green, int blue, int white, int black, int colorless, UUID sourceId, boolean flag) {
this.red = red;
this.green = green;
this.blue = blue;
@ -58,6 +59,7 @@ public class ManaPoolItem implements Serializable {
this.black = black;
this.colorless = colorless;
this.sourceId = sourceId;
this.flag = flag;
}
public ManaPoolItem(ConditionalMana conditionalMana, UUID sourceId) {
@ -77,6 +79,7 @@ public class ManaPoolItem implements Serializable {
this.conditionalMana = item.conditionalMana.copy();
}
this.sourceId = item.sourceId;
this.flag = item.flag;
}
public ManaPoolItem copy() {
@ -87,6 +90,10 @@ public class ManaPoolItem implements Serializable {
return sourceId;
}
public boolean getFlag() {
return flag;
}
public int getRed() {
return red;
}