diff --git a/Mage.Sets/src/mage/sets/magic2010/ElvishArchdruid.java b/Mage.Sets/src/mage/sets/magic2010/ElvishArchdruid.java index 96b969f713..dad71fcd7a 100644 --- a/Mage.Sets/src/mage/sets/magic2010/ElvishArchdruid.java +++ b/Mage.Sets/src/mage/sets/magic2010/ElvishArchdruid.java @@ -35,26 +35,26 @@ import mage.Constants.Rarity; import mage.Constants.Zone; import mage.MageInt; import mage.Mana; -import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; import mage.abilities.effects.common.continious.BoostControlledEffect; -import mage.abilities.effects.common.ManaEffect; -import mage.abilities.mana.ManaAbility; +import mage.abilities.mana.DynamicManaAbility; import mage.cards.CardImpl; +import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterCreaturePermanent; -import mage.game.Game; /** * - * @author BetaSteward_at_googlemail.com + * @author BetaSteward_at_googlemail.com, North */ public class ElvishArchdruid extends CardImpl { private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("Elf creatures"); + private static final FilterControlledCreaturePermanent filterCount = new FilterControlledCreaturePermanent("Elf you control"); static { filter.getSubtype().add("Elf"); + filterCount.getSubtype().add("Elf"); } public ElvishArchdruid(UUID ownerId) { @@ -67,7 +67,7 @@ public class ElvishArchdruid extends CardImpl { this.toughness = new MageInt(2); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostControlledEffect(1, 1, Duration.WhileOnBattlefield, filter, true))); - this.addAbility(new ElvishArchdruidAbility()); + this.addAbility(new DynamicManaAbility(Mana.GreenMana, new PermanentsOnBattlefieldCount(filterCount))); } public ElvishArchdruid(final ElvishArchdruid card) { @@ -78,59 +78,4 @@ public class ElvishArchdruid extends CardImpl { public ElvishArchdruid copy() { return new ElvishArchdruid(this); } - - class ElvishArchdruidAbility extends ManaAbility { - - public ElvishArchdruidAbility() { - super(Zone.BATTLEFIELD, new ElvishArchdruidEffect(), new TapSourceCost()); - } - - public ElvishArchdruidAbility(final ElvishArchdruidAbility ability) { - super(ability); - } - - @Override - public ElvishArchdruidAbility copy() { - return new ElvishArchdruidAbility(this); - } - - @Override - public Mana getNetMana(Game game) { - if (game == null) - return new Mana(); - return Mana.GreenMana(game.getBattlefield().countAll(filter, controllerId)); - } - - } - - class ElvishArchdruidEffect extends ManaEffect { - - public ElvishArchdruidEffect() { - super(new Mana()); - } - - public ElvishArchdruidEffect(final ElvishArchdruidEffect effect) { - super(effect); - } - - @Override - public ElvishArchdruidEffect copy() { - return new ElvishArchdruidEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - this.mana.clear(); - int amount = game.getBattlefield().countAll(filter, source.getControllerId()); - this.mana.setGreen(amount); - return super.apply(game, source); - } - - @Override - public String getText(Ability source) { - return "Add {G} to your mana pool for each Elf you control"; - } - - } } - diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/OvergrownBattlement.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/OvergrownBattlement.java index 444c839436..06ded54003 100644 --- a/Mage.Sets/src/mage/sets/riseoftheeldrazi/OvergrownBattlement.java +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/OvergrownBattlement.java @@ -29,19 +29,14 @@ package mage.sets.riseoftheeldrazi; import java.util.UUID; import mage.Constants.CardType; -import mage.Constants.Outcome; import mage.Constants.Rarity; -import mage.Constants.Zone; import mage.MageInt; import mage.Mana; -import mage.abilities.Ability; -import mage.abilities.common.SimpleActivatedAbility; -import mage.abilities.costs.common.TapSourceCost; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; import mage.abilities.keyword.DefenderAbility; +import mage.abilities.mana.DynamicManaAbility; import mage.cards.CardImpl; import mage.filter.common.FilterControlledCreaturePermanent; -import mage.game.Game; /** * @@ -49,6 +44,12 @@ import mage.game.Game; */ public class OvergrownBattlement extends CardImpl { + private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature with defender you control"); + + static { + filter.getAbilities().add(DefenderAbility.getInstance()); + } + public OvergrownBattlement(UUID ownerId) { super(ownerId, 203, "Overgrown Battlement", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{1}{G}"); this.expansionSetCode = "ROE"; @@ -59,7 +60,7 @@ public class OvergrownBattlement extends CardImpl { this.toughness = new MageInt(4); this.addAbility(DefenderAbility.getInstance()); - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new OvergrownBattlementEffect(), new TapSourceCost())); + this.addAbility(new DynamicManaAbility(Mana.GreenMana, new PermanentsOnBattlefieldCount(filter))); } public OvergrownBattlement(final OvergrownBattlement card) { @@ -71,37 +72,3 @@ public class OvergrownBattlement extends CardImpl { return new OvergrownBattlement(this); } } - -class OvergrownBattlementEffect extends OneShotEffect { - - private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature with defender you control"); - - static { - filter.getAbilities().add(DefenderAbility.getInstance()); - } - - public OvergrownBattlementEffect() { - super(Outcome.PutManaInPool); - } - - public OvergrownBattlementEffect(final OvergrownBattlementEffect effect) { - super(effect); - } - - @Override - public OvergrownBattlementEffect copy() { - return new OvergrownBattlementEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - int amount = game.getBattlefield().countAll(filter, source.getControllerId()); - game.getPlayer(source.getControllerId()).getManaPool().changeMana(Mana.GreenMana(amount)); - return true; - } - - @Override - public String getText(Ability source) { - return "Add {G} to your mana pool for each creature with defender you control."; - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/KothoftheHammer.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/KothoftheHammer.java index e75b1939b6..aa94739210 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/KothoftheHammer.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/KothoftheHammer.java @@ -35,21 +35,20 @@ import mage.Constants.CardType; import mage.Constants.Duration; import mage.Constants.Rarity; import mage.Constants.Zone; -import mage.MageInt; +import mage.Mana; import mage.abilities.Ability; import mage.abilities.LoyaltyAbility; import mage.abilities.common.EntersBattlefieldAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; import mage.abilities.effects.ContinuousEffectImpl; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.DamageTargetEffect; -import mage.abilities.effects.common.ManaEffect; +import mage.abilities.effects.common.DynamicManaEffect; import mage.abilities.effects.common.UntapTargetEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.cards.CardImpl; import mage.counters.CounterType; -import mage.filter.Filter; import mage.filter.common.FilterLandPermanent; import mage.game.Game; import mage.game.permanent.Permanent; @@ -58,14 +57,16 @@ import mage.target.common.TargetLandPermanent; /** * - * @author Loki + * @author Loki, North */ public class KothoftheHammer extends CardImpl { - static FilterLandPermanent filter = new FilterLandPermanent("Mountain"); + static final FilterLandPermanent filter = new FilterLandPermanent("Mountain"); + private static final FilterLandPermanent filterCount = new FilterLandPermanent("Mountain you control"); static { filter.getSubtype().add("Mountain"); - filter.setScopeSubtype(Filter.ComparisonScope.Any); + filterCount.getSubtype().add("Mountain"); + filterCount.setTargetController(Constants.TargetController.YOU); } public KothoftheHammer (UUID ownerId) { @@ -79,7 +80,7 @@ public class KothoftheHammer extends CardImpl { ability.addEffect(new KothoftheHammerFirstEffect()); ability.addTarget(new TargetLandPermanent(filter)); this.addAbility(ability); - this.addAbility(new LoyaltyAbility(new KothoftheHammerSecondEffect(), -2)); + this.addAbility(new LoyaltyAbility(new DynamicManaEffect(Mana.RedMana, new PermanentsOnBattlefieldCount(filterCount)), -2)); this.addAbility(new LoyaltyAbility(new KothoftheHammerThirdEffect(), -5)); } @@ -151,34 +152,6 @@ class KothoftheHammerFirstEffect extends ContinuousEffectImpl { - public KothoftheHammerSecondEffect() { - super(Constants.Outcome.PutManaInPool); - } - - public KothoftheHammerSecondEffect(final KothoftheHammerSecondEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - int count = game.getBattlefield().count(KothoftheHammer.filter, source.getControllerId(), game); - int current = game.getPlayer(source.getControllerId()).getManaPool().getRed(); - game.getPlayer(source.getControllerId()).getManaPool().setRed(count + current); - return true; - } - - @Override - public KothoftheHammerSecondEffect copy() { - return new KothoftheHammerSecondEffect(this); - } - - @Override - public String getText(Ability source) { - return "Add {R} to your mana pool for each Mountain you control"; - } -} - class KothoftheHammerThirdEffect extends ContinuousEffectImpl { public KothoftheHammerThirdEffect() { super(Duration.EndOfGame, Constants.Outcome.AddAbility); diff --git a/Mage.Sets/src/mage/sets/worldwake/ClawsofValakut.java b/Mage.Sets/src/mage/sets/worldwake/ClawsofValakut.java index c246c7979b..2239248e75 100644 --- a/Mage.Sets/src/mage/sets/worldwake/ClawsofValakut.java +++ b/Mage.Sets/src/mage/sets/worldwake/ClawsofValakut.java @@ -35,26 +35,31 @@ import mage.Constants.CardType; import mage.Constants.Duration; import mage.Constants.Rarity; import mage.Constants.Zone; -import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.continious.BoostEnchantedEffect; +import mage.abilities.effects.common.continious.GainAbilityAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.FirstStrikeAbility; -import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.filter.common.FilterLandPermanent; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; /** * - * @author Loki + * @author Loki, North */ public class ClawsofValakut extends CardImpl { + private static final FilterLandPermanent filter = new FilterLandPermanent("Mountain you control"); + + static { + filter.getSubtype().add("Mountain"); + filter.setTargetController(Constants.TargetController.YOU); + } + public ClawsofValakut (UUID ownerId) { super(ownerId, 75, "Claws of Valakut", Rarity.COMMON, new CardType[]{CardType.ENCHANTMENT}, "{1}{R}{R}"); this.expansionSetCode = "WWK"; @@ -64,10 +69,12 @@ public class ClawsofValakut extends CardImpl { TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Constants.Outcome.BoostCreature)); - Ability ability = new EnchantAbility(auraTarget.getTargetName()); - this.addAbility(ability); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ClawsofValakutEffect())); - + this.addAbility(new EnchantAbility(auraTarget.getTargetName())); + SimpleStaticAbility ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(new PermanentsOnBattlefieldCount(filter, 1), + new PermanentsOnBattlefieldCount(filter, 0), + Duration.WhileOnBattlefield)); + ability.addEffect(new GainAbilityAttachedEffect(FirstStrikeAbility.getInstance(), Constants.AttachmentType.AURA)); + this.addAbility(ability); } public ClawsofValakut (final ClawsofValakut card) { @@ -80,66 +87,3 @@ public class ClawsofValakut extends CardImpl { } } - -class ClawsofValakutEffect extends ContinuousEffectImpl { - - private static FilterLandPermanent filter = new FilterLandPermanent("Mountain"); - - static { - filter.getSubtype().add("Mountain"); - } - - public ClawsofValakutEffect() { - super(Duration.WhileOnBattlefield, Constants.Outcome.BoostCreature); - } - - public ClawsofValakutEffect(final ClawsofValakutEffect effect) { - super(effect); - } - - @Override - public ClawsofValakutEffect copy() { - return new ClawsofValakutEffect(this); - } - - @Override - public boolean apply(Constants.Layer layer, Constants.SubLayer sublayer, Ability source, Game game) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null) { - Permanent creature = game.getPermanent(enchantment.getAttachedTo()); - if (creature != null) { - switch (layer) { - case PTChangingEffects_7: - if (sublayer == Constants.SubLayer.ModifyPT_7c) { - int amount = game.getBattlefield().countAll(filter, source.getControllerId()); - creature.addPower(amount); - } - break; - case AbilityAddingRemovingEffects_6: - if (sublayer == Constants.SubLayer.NA) { - creature.addAbility(FirstStrikeAbility.getInstance()); - } - break; - } - return true; - } - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - return false; - } - - @Override - public boolean hasLayer(Constants.Layer layer) { - return layer == Constants.Layer.AbilityAddingRemovingEffects_6 || layer == layer.PTChangingEffects_7; - } - - @Override - public String getText(Ability source) { - return "Enchanted creature gets +1/+0 for each Mountain you control and has first strike."; - } - -} diff --git a/Mage.Sets/src/mage/sets/worldwake/EverflowingChalice.java b/Mage.Sets/src/mage/sets/worldwake/EverflowingChalice.java index 8237c07878..53899c1f92 100644 --- a/Mage.Sets/src/mage/sets/worldwake/EverflowingChalice.java +++ b/Mage.Sets/src/mage/sets/worldwake/EverflowingChalice.java @@ -32,36 +32,35 @@ import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Duration; import mage.Constants.Rarity; -import mage.Constants.Zone; import mage.Mana; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; -import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.dynamicvalue.common.CountersCount; import mage.abilities.effects.common.continious.GainAbilitySourceEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; -import mage.abilities.effects.common.ManaEffect; import mage.abilities.keyword.MultikickerAbility; -import mage.abilities.mana.ManaAbility; +import mage.abilities.mana.DynamicManaAbility; import mage.cards.CardImpl; import mage.counters.CounterType; import mage.counters.common.ChargeCounter; -import mage.game.Game; /** * - * @author BetaSteward_at_googlemail.com + * @author BetaSteward_at_googlemail.com, North */ public class EverflowingChalice extends CardImpl { public EverflowingChalice(UUID ownerId) { super(ownerId, 123, "Everflowing Chalice", Rarity.UNCOMMON, new CardType[]{CardType.ARTIFACT}, "{0}"); this.expansionSetCode = "WWK"; + Ability ability1 = new EntersBattlefieldTriggeredAbility(new AddCountersSourceEffect(new ChargeCounter())); MultikickerAbility ability = new MultikickerAbility(new GainAbilitySourceEffect(ability1, Duration.WhileOnBattlefield), false); ability.addManaCost(new GenericManaCost(2)); this.addAbility(ability); - this.addAbility(new EverflowingChaliceAbility()); + + this.addAbility(new DynamicManaAbility(Mana.ColorlessMana, new CountersCount(CounterType.CHARGE))); } public EverflowingChalice(final EverflowingChalice card) { @@ -74,56 +73,3 @@ public class EverflowingChalice extends CardImpl { } } - -class EverflowingChaliceAbility extends ManaAbility { - - public EverflowingChaliceAbility() { - super(Zone.BATTLEFIELD, new EverflowingChaliceEffect(), new TapSourceCost()); - } - - public EverflowingChaliceAbility(final EverflowingChaliceAbility ability) { - super(ability); - } - - @Override - public EverflowingChaliceAbility copy() { - return new EverflowingChaliceAbility(this); - } - - @Override - public Mana getNetMana(Game game) { - if (game == null) - return new Mana(); - return Mana.ColorlessMana(game.getPermanent(this.getSourceId()).getCounters().getCount(CounterType.CHARGE)); - } - -} - -class EverflowingChaliceEffect extends ManaEffect { - - public EverflowingChaliceEffect() { - super(new Mana()); - } - - public EverflowingChaliceEffect(final EverflowingChaliceEffect effect) { - super(effect); - } - - @Override - public EverflowingChaliceEffect copy() { - return new EverflowingChaliceEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - this.mana.clear(); - this.mana.setColorless(game.getPermanent(source.getSourceId()).getCounters().getCount(CounterType.CHARGE)); - return super.apply(game, source); - } - - @Override - public String getText(Ability source) { - return "Add {1} to your mana pool for each charge counter on {this}"; - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/zendikar/CryptOfAgadeem.java b/Mage.Sets/src/mage/sets/zendikar/CryptOfAgadeem.java index 3757957bec..439f063fb7 100644 --- a/Mage.Sets/src/mage/sets/zendikar/CryptOfAgadeem.java +++ b/Mage.Sets/src/mage/sets/zendikar/CryptOfAgadeem.java @@ -30,21 +30,16 @@ package mage.sets.zendikar; import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Rarity; -import mage.Constants.Zone; import mage.Mana; import mage.ObjectColor; -import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTappedAbility; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.GenericManaCost; -import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.CardsInControllerGraveyardCount; -import mage.abilities.effects.common.ManaEffect; import mage.abilities.mana.BlackManaAbility; -import mage.abilities.mana.ManaAbility; +import mage.abilities.mana.DynamicManaAbility; import mage.cards.CardImpl; import mage.filter.common.FilterCreatureCard; -import mage.game.Game; /** * @@ -52,13 +47,22 @@ import mage.game.Game; */ public class CryptOfAgadeem extends CardImpl { + private static final FilterCreatureCard filter = new FilterCreatureCard("black creature card"); + + static { + filter.setColor(ObjectColor.BLACK); + filter.setUseColor(true); + } + public CryptOfAgadeem(UUID ownerId) { super(ownerId, 212, "Crypt of Agadeem", Rarity.RARE, new CardType[]{CardType.LAND}, ""); this.expansionSetCode = "ZEN"; this.addAbility(new EntersBattlefieldTappedAbility()); this.addAbility(new BlackManaAbility()); - this.addAbility(new CryptOfAgadeemAbility()); + DynamicManaAbility ability = new DynamicManaAbility(Mana.BlackMana, new CardsInControllerGraveyardCount(filter), new GenericManaCost(2)); + ability.addCost(new TapSourceCost()); + this.addAbility(ability); } public CryptOfAgadeem(final CryptOfAgadeem card) { @@ -70,69 +74,3 @@ public class CryptOfAgadeem extends CardImpl { return new CryptOfAgadeem(this); } } - -class CryptOfAgadeemAbility extends ManaAbility { - - private static final DynamicValue amount; - - static { - FilterCreatureCard filter = new FilterCreatureCard(); - filter.setColor(ObjectColor.BLACK); - filter.setUseColor(true); - amount = new CardsInControllerGraveyardCount(filter); - } - - public CryptOfAgadeemAbility() { - super(Zone.BATTLEFIELD, new CryptOfAgadeemAbilityEffect(amount), new TapSourceCost()); - addCost(new GenericManaCost(2)); - } - - public CryptOfAgadeemAbility(final CryptOfAgadeemAbility ability) { - super(ability); - } - - @Override - public CryptOfAgadeemAbility copy() { - return new CryptOfAgadeemAbility(this); - } - - @Override - public Mana getNetMana(Game game) { - if (game == null) { - return new Mana(); - } - return Mana.BlackMana(amount.calculate(game, this)); - } -} - -class CryptOfAgadeemAbilityEffect extends ManaEffect { - - private DynamicValue amount; - - public CryptOfAgadeemAbilityEffect(DynamicValue amount) { - super(new Mana()); - this.amount = amount; - } - - public CryptOfAgadeemAbilityEffect(final CryptOfAgadeemAbilityEffect effect) { - super(effect); - this.amount = effect.amount.clone(); - } - - @Override - public CryptOfAgadeemAbilityEffect copy() { - return new CryptOfAgadeemAbilityEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - this.mana.clear(); - this.mana.setBlack(amount.calculate(game, source)); - return super.apply(game, source); - } - - @Override - public String getText(Ability source) { - return "Add {B} to your mana pool for each black creature card in your graveyard"; - } -} \ No newline at end of file diff --git a/Mage/src/mage/abilities/dynamicvalue/common/CountersCount.java b/Mage/src/mage/abilities/dynamicvalue/common/CountersCount.java index b68b9b239d..1f7243eeb9 100644 --- a/Mage/src/mage/abilities/dynamicvalue/common/CountersCount.java +++ b/Mage/src/mage/abilities/dynamicvalue/common/CountersCount.java @@ -38,7 +38,7 @@ public class CountersCount implements DynamicValue { @Override public String toString() { - return "X"; + return "1"; } @Override diff --git a/Mage/src/mage/abilities/effects/common/DynamicManaEffect.java b/Mage/src/mage/abilities/effects/common/DynamicManaEffect.java new file mode 100644 index 0000000000..c887c399db --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/DynamicManaEffect.java @@ -0,0 +1,92 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * 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; +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.counters.CounterType; +import mage.game.Game; + +/** + * + * @author North + */ +public class DynamicManaEffect extends ManaEffect { + + private Mana computedMana; + private DynamicValue amount; + + public DynamicManaEffect(Mana mana, DynamicValue amount) { + super(mana); + this.amount = amount; + computedMana = new Mana(); + } + + public DynamicManaEffect(final DynamicManaEffect effect) { + super(effect); + this.computedMana = effect.computedMana.copy(); + this.amount = effect.amount.clone(); + } + + @Override + public DynamicManaEffect copy() { + return new DynamicManaEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + computeMana(game, source); + game.getPlayer(source.getControllerId()).getManaPool().changeMana(computedMana); + return true; + } + + @Override + public String getText(Ability source) { + return super.getText(source) + " for each " + amount.getMessage(); + } + + public Mana computeMana(Game game, Ability source){ + this.computedMana.clear(); + int count = amount.calculate(game, source); + if (mana.getBlack() > 0) { + computedMana.setBlack(count); + } else if (mana.getBlue() > 0) { + computedMana.setBlue(count); + } else if (mana.getGreen() > 0) { + computedMana.setGreen(count); + } else if (mana.getRed() > 0) { + computedMana.setRed(count); + } else if (mana.getWhite() > 0) { + computedMana.setWhite(count); + } else { + computedMana.setColorless(count); + } + return computedMana; + } +} diff --git a/Mage/src/mage/abilities/mana/DynamicManaAbility.java b/Mage/src/mage/abilities/mana/DynamicManaAbility.java new file mode 100644 index 0000000000..b96ad4099b --- /dev/null +++ b/Mage/src/mage/abilities/mana/DynamicManaAbility.java @@ -0,0 +1,74 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.abilities.mana; + +import mage.Constants.Zone; +import mage.Mana; +import mage.abilities.costs.Cost; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.effects.common.DynamicManaEffect; +import mage.game.Game; + +/** + * + * @author North + */ +public class DynamicManaAbility extends ManaAbility { + + private DynamicManaEffect manaEffect; + + /** + * TapSourceCost added by default + */ + public DynamicManaAbility(Mana mana, DynamicValue amount) { + this(mana, amount, new TapSourceCost()); + } + + public DynamicManaAbility(Mana mana, DynamicValue amount, Cost cost) { + super(Zone.BATTLEFIELD, new DynamicManaEffect(mana, amount), cost); + manaEffect = (DynamicManaEffect) this.getEffects().get(0); + } + + public DynamicManaAbility(final DynamicManaAbility ability) { + super(ability); + } + + @Override + public DynamicManaAbility copy() { + return new DynamicManaAbility(this); + } + + @Override + public Mana getNetMana(Game game) { + if (game == null) { + return new Mana(); + } + return new Mana(manaEffect.computeMana(game, this)); + } +}