[refactoring][minor] minimized duplicate code for any color mana effects

This commit is contained in:
North 2012-08-20 23:07:49 +03:00
parent 0575034084
commit 6e3c4cc8e2
3 changed files with 39 additions and 59 deletions

View file

@ -59,24 +59,6 @@ public class AltarOfTheLost extends CardImpl<AltarOfTheLost> {
// {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. // {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 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) { public AltarOfTheLost(final AltarOfTheLost card) {
@ -116,10 +98,11 @@ class AltarOfTheLostManaCondition implements Condition {
MageObject object = game.getObject(source.getSourceId()); MageObject object = game.getObject(source.getSourceId());
if (object != null && game.getState().getZone(object.getId()) == Zone.GRAVEYARD) { if (object != null && game.getState().getZone(object.getId()) == Zone.GRAVEYARD) {
for (Ability ability: object.getAbilities()) { for (Ability ability: object.getAbilities()) {
if (ability instanceof FlashbackAbility) if (ability instanceof FlashbackAbility) {
return true; return true;
} }
} }
}
return false; return false;
} }
} }

View file

@ -27,7 +27,6 @@
*/ */
package mage.abilities.effects.common; package mage.abilities.effects.common;
import mage.ConditionalMana;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.mana.builder.ConditionalManaBuilder; import mage.abilities.mana.builder.ConditionalManaBuilder;
@ -41,7 +40,6 @@ import mage.players.Player;
public class AddConditionalManaOfAnyColorEffect extends ManaEffect<AddConditionalManaOfAnyColorEffect> { public class AddConditionalManaOfAnyColorEffect extends ManaEffect<AddConditionalManaOfAnyColorEffect> {
private int amount; private int amount;
private ConditionalMana conditionalMana;
private ConditionalManaBuilder manaBuilder; private ConditionalManaBuilder manaBuilder;
public AddConditionalManaOfAnyColorEffect(int amount, ConditionalManaBuilder manaBuilder) { public AddConditionalManaOfAnyColorEffect(int amount, ConditionalManaBuilder manaBuilder) {
@ -65,34 +63,33 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect<AddConditiona
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
if (player != null) { boolean result = false;
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
addMana(game, player, source, (ChoiceColor) source.getChoices().get(i)); ChoiceColor choice = (ChoiceColor) source.getChoices().get(i);
}
}
return false; Mana mana = null;
}
private boolean addMana(Game game, Player player, Ability source, ChoiceColor choice) {
if (choice.getColor().isBlack()) { if (choice.getColor().isBlack()) {
player.getManaPool().addMana(manaBuilder.setMana(Mana.BlackMana(1)).build(), game, source); mana = manaBuilder.setMana(Mana.BlackMana(1)).build();
return true;
} else if (choice.getColor().isBlue()) { } else if (choice.getColor().isBlue()) {
player.getManaPool().addMana(manaBuilder.setMana(Mana.BlueMana(1)).build(), game, source); mana = manaBuilder.setMana(Mana.BlueMana(1)).build();
return true;
} else if (choice.getColor().isRed()) { } else if (choice.getColor().isRed()) {
player.getManaPool().addMana(manaBuilder.setMana(Mana.RedMana(1)).build(), game, source); mana = manaBuilder.setMana(Mana.RedMana(1)).build();
return true;
} else if (choice.getColor().isGreen()) { } else if (choice.getColor().isGreen()) {
player.getManaPool().addMana(manaBuilder.setMana(Mana.GreenMana(1)).build(), game, source); mana = manaBuilder.setMana(Mana.GreenMana(1)).build();
return true;
} else if (choice.getColor().isWhite()) { } else if (choice.getColor().isWhite()) {
player.getManaPool().addMana(manaBuilder.setMana(Mana.WhiteMana(1)).build(), game, source); mana = manaBuilder.setMana(Mana.WhiteMana(1)).build();
return true;
}
return false;
} }
if (mana != null) {
player.getManaPool().addMana(mana, game, source);
result = true;
}
}
return result;
}
} }

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.effects.common; package mage.abilities.effects.common;
import mage.Mana; import mage.Mana;
@ -66,23 +65,24 @@ public class AddManaOfAnyColorEffect extends ManaEffect<AddManaOfAnyColorEffect>
ChoiceColor choice = (ChoiceColor) source.getChoices().get(0); ChoiceColor choice = (ChoiceColor) source.getChoices().get(0);
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
Mana mana = null;
if (choice.getColor().isBlack()) { if (choice.getColor().isBlack()) {
player.getManaPool().addMana(Mana.BlackMana(amount), game, source); mana = Mana.BlackMana(amount);
return true;
} else if (choice.getColor().isBlue()) { } else if (choice.getColor().isBlue()) {
player.getManaPool().addMana(Mana.BlueMana(amount), game, source); mana = Mana.BlueMana(amount);
return true;
} else if (choice.getColor().isRed()) { } else if (choice.getColor().isRed()) {
player.getManaPool().addMana(Mana.RedMana(amount), game, source); mana = Mana.RedMana(amount);
return true;
} else if (choice.getColor().isGreen()) { } else if (choice.getColor().isGreen()) {
player.getManaPool().addMana(Mana.GreenMana(amount), game, source); mana = Mana.GreenMana(amount);
return true;
} else if (choice.getColor().isWhite()) { } else if (choice.getColor().isWhite()) {
player.getManaPool().addMana(Mana.WhiteMana(amount), game, source); mana = Mana.WhiteMana(amount);
return true;
}
return false;
} }
if (player != null && mana != null) {
player.getManaPool().addMana(mana, game, source);
return true;
}
return false;
}
} }