mirror of
https://github.com/correl/mage.git
synced 2024-12-26 11:09:27 +00:00
[refactoring][minor] minimized duplicate code for any color mana effects
This commit is contained in:
parent
0575034084
commit
6e3c4cc8e2
3 changed files with 39 additions and 59 deletions
|
@ -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,8 +98,9 @@ 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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player != null && mana != null) {
|
||||||
|
player.getManaPool().addMana(mana, game, source);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue