begin refactor of Devotion to enum
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package mage.abilities.dynamicvalue.common;
-import java.util.ArrayList;
-import java.util.Arrays;
+import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.constants.ColoredManaSymbol;
import mage.game.Game;
-import mage.game.permanent.Permanent;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
/**
* Each colored mana symbol (e.g. {U}) in the mana costs of permanents you
@@ -20,37 +18,47 @@ import mage.game.permanent.Permanent;
*
* @author LevelX2
*/
-public class DevotionCount implements DynamicValue {
+public enum DevotionCount implements DynamicValue {
+ W(ColoredManaSymbol.W),
+ U(ColoredManaSymbol.U),
+ B(ColoredManaSymbol.B),
+ R(ColoredManaSymbol.R),
+ G(ColoredManaSymbol.G),
+ WU(ColoredManaSymbol.W, ColoredManaSymbol.U),
+ WB(ColoredManaSymbol.W, ColoredManaSymbol.B),
+ UB(ColoredManaSymbol.U, ColoredManaSymbol.B),
+ UR(ColoredManaSymbol.U, ColoredManaSymbol.R),
+ BR(ColoredManaSymbol.B, ColoredManaSymbol.R),
+ BG(ColoredManaSymbol.B, ColoredManaSymbol.G),
+ RG(ColoredManaSymbol.R, ColoredManaSymbol.G),
+ RW(ColoredManaSymbol.R, ColoredManaSymbol.W),
+ GW(ColoredManaSymbol.G, ColoredManaSymbol.W),
+ GU(ColoredManaSymbol.G, ColoredManaSymbol.U);
private ArrayList<ColoredManaSymbol> devotionColors = new ArrayList<>();
- public DevotionCount(ColoredManaSymbol... devotionColor) {
+ DevotionCount(ColoredManaSymbol... devotionColor) {
this.devotionColors.addAll(Arrays.asList(devotionColor));
}
- public DevotionCount(final DevotionCount dynamicValue) {
- this.devotionColors = dynamicValue.devotionColors;
- }
-
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
- int devotion = 0;
- for (Permanent permanent : game.getBattlefield().getAllActivePermanents(sourceAbility.getControllerId())) {
- for (ManaCost manaCost : permanent.getManaCost()) {
- for (ColoredManaSymbol coloredManaSymbol : devotionColors) {
- if (manaCost.containsColor(coloredManaSymbol)) {
- devotion++;
- break; // count each manaCost maximum of one time (Hybrid don't count for multiple colors of devotion)
- }
+ return game.getBattlefield()
+ .getAllActivePermanents(sourceAbility.getControllerId())
+ .stream()
+ .map(MageObject::getManaCost)
+ .flatMap(Collection::stream)
+ .mapToInt(this::checkCost)
+ .sum();
}
- }
- }
- return devotion;
+
+ private int checkCost(ManaCost manaCost) {
+ return devotionColors.stream().anyMatch(manaCost::containsColor) ? 1 : 0;
}
@Override
public DevotionCount copy() {
- return new DevotionCount(this);
+ return this;
}
@Override
