From acc3ac7b60092a03cf68fc497099327dcf8344d0 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 27 Dec 2013 19:14:17 +0100 Subject: [PATCH] * Opal Palcar - Fixed a bug that the first mana ability also wrongly gave the commander boost. --- .../mage/sets/commander2013/OpalPalace.java | 17 ++- Mage/src/mage/Mana.java | 123 ++++++++++++------ Mage/src/mage/players/ManaPool.java | 4 +- Mage/src/mage/players/ManaPoolItem.java | 9 +- 4 files changed, 105 insertions(+), 48 deletions(-) diff --git a/Mage.Sets/src/mage/sets/commander2013/OpalPalace.java b/Mage.Sets/src/mage/sets/commander2013/OpalPalace.java index d84d5491d5..27c2f88a8b 100644 --- a/Mage.Sets/src/mage/sets/commander2013/OpalPalace.java +++ b/Mage.Sets/src/mage/sets/commander2013/OpalPalace.java @@ -133,22 +133,27 @@ class OpalPalaceManaEffect extends ManaEffect { 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 { @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(); diff --git a/Mage/src/mage/Mana.java b/Mage/src/mage/Mana.java index 6e5d6cfc16..337b619421 100644 --- a/Mage/src/mage/Mana.java +++ b/Mage/src/mage/Mana.java @@ -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, Serializable, Copyable { 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, Serializable, Copyable { 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, Serializable, Copyable { 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, Serializable, Copyable { 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, Serializable, Copyable { 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, Serializable, Copyable { } } 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, Serializable, Copyable { * @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, Serializable, Copyable { } } + public void setFlag(boolean flag) { + this.flag = flag; + } + + public boolean getFlag() { + return flag; + } + } diff --git a/Mage/src/mage/players/ManaPool.java b/Mage/src/mage/players/ManaPool.java index ab8e54535e..18e9923f4a 100644 --- a/Mage/src/mage/players/ManaPool.java +++ b/Mage/src/mage/players/ManaPool.java @@ -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()); diff --git a/Mage/src/mage/players/ManaPoolItem.java b/Mage/src/mage/players/ManaPoolItem.java index 8e5fbaa7e0..822cfdda13 100644 --- a/Mage/src/mage/players/ManaPoolItem.java +++ b/Mage/src/mage/players/ManaPoolItem.java @@ -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; }