[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.
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;

View file

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

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.common;
import mage.Mana;
@ -66,23 +65,24 @@ public class AddManaOfAnyColorEffect extends ManaEffect<AddManaOfAnyColorEffect>
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;
}
}
}