Improved DevotionCount DynamicValue to support a list of mana types.

This commit is contained in:
LevelX2 2014-01-14 17:03:05 +01:00
parent 1c5f0c8b7f
commit caa32f6eb6
18 changed files with 67 additions and 63 deletions

View file

@ -4,9 +4,11 @@
*/
package mage.abilities.dynamicvalue.common;
import java.util.ArrayList;
import java.util.Arrays;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.constants.ManaType;
import mage.constants.ColoredManaSymbol;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -17,37 +19,22 @@ import mage.game.permanent.Permanent;
*/
public class DevotionCount implements DynamicValue {
private ManaType devotionColor;
private ArrayList<ColoredManaSymbol> devotionColors = new ArrayList();
public DevotionCount(ManaType devotionColor) {
this.devotionColor = devotionColor;
public DevotionCount(ColoredManaSymbol... devotionColor) {
this.devotionColors.addAll(Arrays.asList(devotionColor));
}
public DevotionCount(final DevotionCount dynamicValue) {
this.devotionColor = dynamicValue.devotionColor;
this.devotionColors = dynamicValue.devotionColors;
}
@Override
public int calculate(Game game, Ability sourceAbility) {
int devotion = 0;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(sourceAbility.getControllerId())) {
switch (devotionColor) {
case BLACK:
devotion += permanent.getManaCost().getMana().getBlack();
break;
case BLUE:
devotion += permanent.getManaCost().getMana().getBlue();
break;
case GREEN:
devotion += permanent.getManaCost().getMana().getGreen();
break;
case RED:
devotion += permanent.getManaCost().getMana().getRed();
break;
case WHITE:
devotion += permanent.getManaCost().getMana().getWhite();
break;
for(ColoredManaSymbol coloredManaSymbol: devotionColors) {
devotion += permanent.getManaCost().getMana().getColor(coloredManaSymbol);
}
}
return devotion;
@ -65,6 +52,15 @@ public class DevotionCount implements DynamicValue {
@Override
public String getMessage() {
return new StringBuilder("devotion to ").append(devotionColor.toString()).toString();
StringBuilder sb = new StringBuilder("devotion to ");
int count = 0;
for (ColoredManaSymbol coloredManaSymbol:devotionColors) {
if (count > 0) {
sb.append(" and ");
}
sb.append(coloredManaSymbol.getColorName());
count++;
}
return sb.toString();
}
}

View file

@ -5,19 +5,27 @@ package mage.constants;
* @author North
*/
public enum ColoredManaSymbol {
W("W"), U("U"), B("B"), R("R"), G("G");
W("W","white"), U("U","blue"), B("B","black"), R("R","red"), G("G","green");
private final String text;
private final String colorName;
ColoredManaSymbol(String text) {
ColoredManaSymbol(String text, String colorName) {
this.text = text;
this.colorName = colorName;
}
@Override
public String toString() {
return text;
}
public String getColorName() {
return colorName;
}
public static ColoredManaSymbol lookup(char c) {
switch (c) {
case 'W':