From 6e3c4cc8e201a0f5c2cb1df4e10692391ddd07f2 Mon Sep 17 00:00:00 2001 From: North Date: Mon, 20 Aug 2012 23:07:49 +0300 Subject: [PATCH] [refactoring][minor] minimized duplicate code for any color mana effects --- .../sets/darkascension/AltarOfTheLost.java | 21 +------- .../AddConditionalManaOfAnyColorEffect.java | 53 +++++++++---------- .../common/AddManaOfAnyColorEffect.java | 24 ++++----- 3 files changed, 39 insertions(+), 59 deletions(-) diff --git a/Mage.Sets/src/mage/sets/darkascension/AltarOfTheLost.java b/Mage.Sets/src/mage/sets/darkascension/AltarOfTheLost.java index 3981238852..fbfda70d55 100644 --- a/Mage.Sets/src/mage/sets/darkascension/AltarOfTheLost.java +++ b/Mage.Sets/src/mage/sets/darkascension/AltarOfTheLost.java @@ -59,24 +59,6 @@ public class AltarOfTheLost extends CardImpl { // {tap}: Add two mana in any combination of colors to your mana pool. Spend this mana only to cast spells with flashback from a graveyard. this.addAbility(new ConditionalAnyColorManaAbility(2, new AltarOfTheLostManaBuilder())); - - /* - this.addAbility(new AltarOfTheLostManaAbility(Mana.BlackMana(2))); - this.addAbility(new AltarOfTheLostManaAbility(Mana.BlueMana(2))); - this.addAbility(new AltarOfTheLostManaAbility(Mana.RedMana(2))); - this.addAbility(new AltarOfTheLostManaAbility(Mana.GreenMana(2))); - this.addAbility(new AltarOfTheLostManaAbility(Mana.WhiteMana(2))); - this.addAbility(new AltarOfTheLostManaAbility(new Mana(1, 1, 0, 0, 0, 0, 0))); - this.addAbility(new AltarOfTheLostManaAbility(new Mana(1, 0, 1, 0, 0, 0, 0))); - this.addAbility(new AltarOfTheLostManaAbility(new Mana(1, 0, 0, 1, 0, 0, 0))); - this.addAbility(new AltarOfTheLostManaAbility(new Mana(1, 0, 0, 0, 1, 0, 0))); - this.addAbility(new AltarOfTheLostManaAbility(new Mana(0, 1, 1, 0, 0, 0, 0))); - this.addAbility(new AltarOfTheLostManaAbility(new Mana(0, 1, 0, 1, 0, 0, 0))); - this.addAbility(new AltarOfTheLostManaAbility(new Mana(0, 1, 0, 0, 1, 0, 0))); - this.addAbility(new AltarOfTheLostManaAbility(new Mana(0, 0, 1, 1, 0, 0, 0))); - this.addAbility(new AltarOfTheLostManaAbility(new Mana(0, 0, 1, 0, 1, 0, 0))); - this.addAbility(new AltarOfTheLostManaAbility(new Mana(0, 0, 0, 1, 1, 0, 0))); - */ } public AltarOfTheLost(final AltarOfTheLost card) { @@ -116,8 +98,9 @@ class AltarOfTheLostManaCondition implements Condition { MageObject object = game.getObject(source.getSourceId()); if (object != null && game.getState().getZone(object.getId()) == Zone.GRAVEYARD) { for (Ability ability: object.getAbilities()) { - if (ability instanceof FlashbackAbility) + if (ability instanceof FlashbackAbility) { return true; + } } } return false; diff --git a/Mage/src/mage/abilities/effects/common/AddConditionalManaOfAnyColorEffect.java b/Mage/src/mage/abilities/effects/common/AddConditionalManaOfAnyColorEffect.java index 7cb6003b00..5853daf043 100644 --- a/Mage/src/mage/abilities/effects/common/AddConditionalManaOfAnyColorEffect.java +++ b/Mage/src/mage/abilities/effects/common/AddConditionalManaOfAnyColorEffect.java @@ -27,7 +27,6 @@ */ package mage.abilities.effects.common; -import mage.ConditionalMana; import mage.Mana; import mage.abilities.Ability; import mage.abilities.mana.builder.ConditionalManaBuilder; @@ -41,7 +40,6 @@ import mage.players.Player; public class AddConditionalManaOfAnyColorEffect extends ManaEffect { private int amount; - private ConditionalMana conditionalMana; private ConditionalManaBuilder manaBuilder; public AddConditionalManaOfAnyColorEffect(int amount, ConditionalManaBuilder manaBuilder) { @@ -65,34 +63,33 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect ChoiceColor choice = (ChoiceColor) source.getChoices().get(0); Player player = game.getPlayer(source.getControllerId()); + Mana mana = null; if (choice.getColor().isBlack()) { - player.getManaPool().addMana(Mana.BlackMana(amount), game, source); - return true; + mana = Mana.BlackMana(amount); } else if (choice.getColor().isBlue()) { - player.getManaPool().addMana(Mana.BlueMana(amount), game, source); - return true; + mana = Mana.BlueMana(amount); } else if (choice.getColor().isRed()) { - player.getManaPool().addMana(Mana.RedMana(amount), game, source); - return true; + mana = Mana.RedMana(amount); } else if (choice.getColor().isGreen()) { - player.getManaPool().addMana(Mana.GreenMana(amount), game, source); - return true; + mana = Mana.GreenMana(amount); } else if (choice.getColor().isWhite()) { - player.getManaPool().addMana(Mana.WhiteMana(amount), game, source); + mana = Mana.WhiteMana(amount); + } + + if (player != null && mana != null) { + player.getManaPool().addMana(mana, game, source); return true; } + return false; } - -} \ No newline at end of file +}