Added DynamicManaEffect and DynamicManaAbility (refactored cards to use them)

This commit is contained in:
North 2011-06-30 23:47:16 +03:00
parent e988468a87
commit 4adb9f5118
9 changed files with 226 additions and 347 deletions

View file

@ -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<ElvishArchdruid> {
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<ElvishArchdruid> {
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<ElvishArchdruid> {
public ElvishArchdruid copy() {
return new ElvishArchdruid(this);
}
class ElvishArchdruidAbility extends ManaAbility<ElvishArchdruidAbility> {
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";
}
}
}

View file

@ -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<OvergrownBattlement> {
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<OvergrownBattlement> {
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<OvergrownBattlement> {
return new OvergrownBattlement(this);
}
}
class OvergrownBattlementEffect extends OneShotEffect<OvergrownBattlementEffect> {
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.";
}
}

View file

@ -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<KothoftheHammer> {
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<KothoftheHammer> {
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<KothoftheHammerFir
}
}
class KothoftheHammerSecondEffect extends OneShotEffect<KothoftheHammerSecondEffect> {
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<KothoftheHammerThirdEffect> {
public KothoftheHammerThirdEffect() {
super(Duration.EndOfGame, Constants.Outcome.AddAbility);

View file

@ -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<ClawsofValakut> {
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<ClawsofValakut> {
TargetPermanent auraTarget = new TargetCreaturePermanent();
this.getSpellAbility().addTarget(auraTarget);
this.getSpellAbility().addEffect(new AttachEffect(Constants.Outcome.BoostCreature));
Ability ability = new EnchantAbility(auraTarget.getTargetName());
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);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ClawsofValakutEffect()));
}
public ClawsofValakut (final ClawsofValakut card) {
@ -80,66 +87,3 @@ public class ClawsofValakut extends CardImpl<ClawsofValakut> {
}
}
class ClawsofValakutEffect extends ContinuousEffectImpl<ClawsofValakutEffect> {
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.";
}
}

View file

@ -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<EverflowingChalice> {
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<EverflowingChalice> {
}
}
class EverflowingChaliceAbility extends ManaAbility<EverflowingChaliceAbility> {
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}";
}
}

View file

@ -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<CryptOfAgadeem> {
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<CryptOfAgadeem> {
return new CryptOfAgadeem(this);
}
}
class CryptOfAgadeemAbility extends ManaAbility<CryptOfAgadeemAbility> {
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";
}
}

View file

@ -38,7 +38,7 @@ public class CountersCount implements DynamicValue {
@Override
public String toString() {
return "X";
return "1";
}
@Override

View file

@ -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;
}
}

View file

@ -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<DynamicManaAbility> {
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));
}
}