From 93ca287478bf6338259e35df6410cd2b7736e0c8 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 4 Sep 2013 17:14:41 +0200 Subject: [PATCH] [THS] Added DynamicValue for Devotion. --- .../dynamicvalue/common/DevotionCount.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Mage/src/mage/abilities/dynamicvalue/common/DevotionCount.java diff --git a/Mage/src/mage/abilities/dynamicvalue/common/DevotionCount.java b/Mage/src/mage/abilities/dynamicvalue/common/DevotionCount.java new file mode 100644 index 00000000000..e0a4392e657 --- /dev/null +++ b/Mage/src/mage/abilities/dynamicvalue/common/DevotionCount.java @@ -0,0 +1,70 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package mage.abilities.dynamicvalue.common; + +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.constants.ManaType; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * Each colored mana symbol (e.g. {U}) in the mana costs of permanents you control counts toward your devotion to that color. + * + * @author LevelX2 + */ +public class DevotionCount implements DynamicValue { + + private ManaType devotionColor; + + + public DevotionCount(ManaType devotionColor) { + this.devotionColor = devotionColor; + } + + public DevotionCount(final DevotionCount dynamicValue) { + this.devotionColor = dynamicValue.devotionColor; + } + + @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; + } + } + return devotion; + } + + @Override + public DynamicValue copy() { + return new DevotionCount(this); + } + + @Override + public String toString() { + return new StringBuilder("devotion to ").append(devotionColor.toString()).toString(); + } + + @Override + public String getMessage() { + return toString(); + } +}