From 0df1e178207d467eb2fe1af357728e3f6dfd650a Mon Sep 17 00:00:00 2001 From: magenoxx Date: Sat, 20 Aug 2011 17:31:14 +0400 Subject: [PATCH] [M12] Consume Spirit --- .../mage/sets/magic2010/ConsumeSpirit.java | 112 ++++++++++++++++++ .../mage/sets/magic2012/ConsumeSpirit.java | 52 ++++++++ .../src/mage/sets/mirrodin/ConsumeSpirit.java | 54 +++++++++ .../mage/sets/planechase/ConsumeSpirit.java | 52 ++++++++ .../src/mage/sets/tenth/ConsumeSpirit.java | 52 ++++++++ Mage/src/mage/Mana.java | 15 +++ .../mage/abilities/costs/VariableCost.java | 4 +- .../costs/common/PayVariableLoyaltyCost.java | 5 + .../costs/common/TapVariableTargetCost.java | 5 + .../abilities/costs/mana/ManaCostImpl.java | 2 +- .../costs/mana/VariableManaCost.java | 14 ++- .../LoseAllAbilitiesTargetEffect.java | 2 +- Mage/src/mage/filter/FilterMana.java | 105 ++++++++++++++++ Mage/src/mage/players/ManaPool.java | 67 ++++++++++- 14 files changed, 532 insertions(+), 9 deletions(-) create mode 100644 Mage.Sets/src/mage/sets/magic2010/ConsumeSpirit.java create mode 100644 Mage.Sets/src/mage/sets/magic2012/ConsumeSpirit.java create mode 100644 Mage.Sets/src/mage/sets/mirrodin/ConsumeSpirit.java create mode 100644 Mage.Sets/src/mage/sets/planechase/ConsumeSpirit.java create mode 100644 Mage.Sets/src/mage/sets/tenth/ConsumeSpirit.java create mode 100644 Mage/src/mage/filter/FilterMana.java diff --git a/Mage.Sets/src/mage/sets/magic2010/ConsumeSpirit.java b/Mage.Sets/src/mage/sets/magic2010/ConsumeSpirit.java new file mode 100644 index 0000000000..ba9ab6d221 --- /dev/null +++ b/Mage.Sets/src/mage/sets/magic2010/ConsumeSpirit.java @@ -0,0 +1,112 @@ +/* + * 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.sets.magic2010; + +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.cards.CardImpl; +import mage.filter.FilterMana; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.common.TargetCreatureOrPlayer; + +import java.util.UUID; + +/** + * @author nantuko + */ +public class ConsumeSpirit extends CardImpl { + + public static final FilterMana filterBlack = new FilterMana(); + + static { + filterBlack.setBlack(true); + } + + public ConsumeSpirit(UUID ownerId) { + super(ownerId, 89, "Consume Spirit", Rarity.UNCOMMON, new CardType[]{CardType.SORCERY}, "{X}{1}{B}"); + this.expansionSetCode = "M10"; + + this.color.setBlack(true); + + // Spend only black mana on X. + // Consume Spirit deals X damage to target creature or player and you gain X life. + this.getSpellAbility().addTarget(new TargetCreatureOrPlayer()); + this.getSpellAbility().addEffect(new ConsumeSpiritEffect()); + this.getSpellAbility().getManaCostsToPay().getVariableCosts().get(0).setFilter(filterBlack); + } + + public ConsumeSpirit(final ConsumeSpirit card) { + super(card); + } + + @Override + public ConsumeSpirit copy() { + return new ConsumeSpirit(this); + } +} + +class ConsumeSpiritEffect extends OneShotEffect { + + public ConsumeSpiritEffect() { + super(Constants.Outcome.Damage); + staticText = "Consume Spirit deals X damage to target creature or player and you gain X life.Spend only black mana on X"; + } + + public ConsumeSpiritEffect(final ConsumeSpiritEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + int damage = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); + if (damage > 0) { + Permanent permanent = game.getPermanent(getTargetPointer().getFirst(source)); + if (permanent != null) { + permanent.damage(damage, source.getSourceId(), game, true, false); + } else { + Player player = game.getPlayer(getTargetPointer().getFirst(source)); + if (player != null) { + player.damage(damage, source.getSourceId(), game, false, true); + } + } + return true; + } + return false; + } + + @Override + public ConsumeSpiritEffect copy() { + return new ConsumeSpiritEffect(this); + } + +} diff --git a/Mage.Sets/src/mage/sets/magic2012/ConsumeSpirit.java b/Mage.Sets/src/mage/sets/magic2012/ConsumeSpirit.java new file mode 100644 index 0000000000..38fa43260f --- /dev/null +++ b/Mage.Sets/src/mage/sets/magic2012/ConsumeSpirit.java @@ -0,0 +1,52 @@ +/* + * 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.sets.magic2012; + +import java.util.UUID; + +/** + * + * @author nantuko + */ +public class ConsumeSpirit extends mage.sets.magic2010.ConsumeSpirit { + + public ConsumeSpirit(UUID ownerId) { + super(ownerId); + this.cardNumber = 88; + this.expansionSetCode = "M12"; + } + + public ConsumeSpirit(final ConsumeSpirit card) { + super(card); + } + + @Override + public ConsumeSpirit copy() { + return new ConsumeSpirit(this); + } +} diff --git a/Mage.Sets/src/mage/sets/mirrodin/ConsumeSpirit.java b/Mage.Sets/src/mage/sets/mirrodin/ConsumeSpirit.java new file mode 100644 index 0000000000..d35362cab3 --- /dev/null +++ b/Mage.Sets/src/mage/sets/mirrodin/ConsumeSpirit.java @@ -0,0 +1,54 @@ +/* + * 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.sets.mirrodin; + +import java.util.UUID; +import mage.Constants.Rarity; + +/** + * + * @author nantuko + */ +public class ConsumeSpirit extends mage.sets.magic2010.ConsumeSpirit { + + public ConsumeSpirit(UUID ownerId) { + super(ownerId); + this.cardNumber = 60; + this.expansionSetCode = "MRD"; + this.rarity = Rarity.COMMON; + } + + public ConsumeSpirit(final ConsumeSpirit card) { + super(card); + } + + @Override + public ConsumeSpirit copy() { + return new ConsumeSpirit(this); + } +} diff --git a/Mage.Sets/src/mage/sets/planechase/ConsumeSpirit.java b/Mage.Sets/src/mage/sets/planechase/ConsumeSpirit.java new file mode 100644 index 0000000000..c1b628ddab --- /dev/null +++ b/Mage.Sets/src/mage/sets/planechase/ConsumeSpirit.java @@ -0,0 +1,52 @@ +/* + * 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.sets.planechase; + +import java.util.UUID; + +/** + * + * @author nantuko + */ +public class ConsumeSpirit extends mage.sets.magic2010.ConsumeSpirit { + + public ConsumeSpirit(UUID ownerId) { + super(ownerId); + this.cardNumber = 21; + this.expansionSetCode = "HOP"; + } + + public ConsumeSpirit(final ConsumeSpirit card) { + super(card); + } + + @Override + public ConsumeSpirit copy() { + return new ConsumeSpirit(this); + } +} diff --git a/Mage.Sets/src/mage/sets/tenth/ConsumeSpirit.java b/Mage.Sets/src/mage/sets/tenth/ConsumeSpirit.java new file mode 100644 index 0000000000..238187766c --- /dev/null +++ b/Mage.Sets/src/mage/sets/tenth/ConsumeSpirit.java @@ -0,0 +1,52 @@ +/* + * 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.sets.tenth; + +import java.util.UUID; + +/** + * + * @author nantuko + */ +public class ConsumeSpirit extends mage.sets.magic2010.ConsumeSpirit { + + public ConsumeSpirit(UUID ownerId) { + super(ownerId); + this.cardNumber = 131; + this.expansionSetCode = "10E"; + } + + public ConsumeSpirit(final ConsumeSpirit card) { + super(card); + } + + @Override + public ConsumeSpirit copy() { + return new ConsumeSpirit(this); + } +} diff --git a/Mage/src/mage/Mana.java b/Mage/src/mage/Mana.java index 8a87577111..7cb8c5fedf 100644 --- a/Mage/src/mage/Mana.java +++ b/Mage/src/mage/Mana.java @@ -31,6 +31,7 @@ package mage; import java.io.Serializable; import mage.Constants.ColoredManaSymbol; +import mage.filter.FilterMana; import mage.util.Copyable; /** @@ -168,6 +169,20 @@ public class Mana implements Comparable, Serializable, Copyable { return red + green + blue + white + black + colorless + any; } + public int count(FilterMana filter) { + if (filter == null) { + return count(); + } + int count = 0; + if (filter.isBlack()) count += black; + if (filter.isBlue()) count += blue; + if (filter.isWhite()) count += white; + if (filter.isGreen()) count += green; + if (filter.isRed()) count += red; + if (filter.isColorless()) count += colorless; + return count; + } + public void clear() { red = 0; green = 0; diff --git a/Mage/src/mage/abilities/costs/VariableCost.java b/Mage/src/mage/abilities/costs/VariableCost.java index 9ce15abf9d..755ec593bd 100644 --- a/Mage/src/mage/abilities/costs/VariableCost.java +++ b/Mage/src/mage/abilities/costs/VariableCost.java @@ -28,6 +28,8 @@ package mage.abilities.costs; +import mage.filter.FilterMana; + /** * * @author BetaSteward_at_googlemail.com @@ -35,5 +37,5 @@ package mage.abilities.costs; public interface VariableCost { public int getAmount(); - + public void setFilter(FilterMana filter); } diff --git a/Mage/src/mage/abilities/costs/common/PayVariableLoyaltyCost.java b/Mage/src/mage/abilities/costs/common/PayVariableLoyaltyCost.java index ad724a7ae4..6f8d31ecb4 100644 --- a/Mage/src/mage/abilities/costs/common/PayVariableLoyaltyCost.java +++ b/Mage/src/mage/abilities/costs/common/PayVariableLoyaltyCost.java @@ -34,6 +34,7 @@ import mage.abilities.Ability; import mage.abilities.costs.CostImpl; import mage.abilities.costs.VariableCost; import mage.counters.CounterType; +import mage.filter.FilterMana; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; @@ -87,6 +88,10 @@ public class PayVariableLoyaltyCost extends CostImpl imp return amountPaid; } + @Override + public void setFilter(FilterMana filter) { + } + @Override public PayVariableLoyaltyCost copy() { return new PayVariableLoyaltyCost(this); diff --git a/Mage/src/mage/abilities/costs/common/TapVariableTargetCost.java b/Mage/src/mage/abilities/costs/common/TapVariableTargetCost.java index dc6829c677..891387850c 100644 --- a/Mage/src/mage/abilities/costs/common/TapVariableTargetCost.java +++ b/Mage/src/mage/abilities/costs/common/TapVariableTargetCost.java @@ -33,6 +33,7 @@ import mage.Constants.Outcome; import mage.abilities.Ability; import mage.abilities.costs.CostImpl; import mage.abilities.costs.VariableCost; +import mage.filter.FilterMana; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.common.TargetControlledPermanent; @@ -92,6 +93,10 @@ public class TapVariableTargetCost extends CostImpl imple return amountPaid; } + @Override + public void setFilter(FilterMana filter) { + } + @Override public TapVariableTargetCost copy() { return new TapVariableTargetCost(this); diff --git a/Mage/src/mage/abilities/costs/mana/ManaCostImpl.java b/Mage/src/mage/abilities/costs/mana/ManaCostImpl.java index 651162a251..b15b68982e 100644 --- a/Mage/src/mage/abilities/costs/mana/ManaCostImpl.java +++ b/Mage/src/mage/abilities/costs/mana/ManaCostImpl.java @@ -182,7 +182,7 @@ public abstract class ManaCostImpl> extends CostImpl payment.count() && (pool.count() > 0 || conditionalCount > 0)) { if (payConditionalColorless(ability, game, pool)) continue; if (payConditionalBlack(ability, game, pool)) continue; diff --git a/Mage/src/mage/abilities/costs/mana/VariableManaCost.java b/Mage/src/mage/abilities/costs/mana/VariableManaCost.java index 362716599e..df352c618b 100644 --- a/Mage/src/mage/abilities/costs/mana/VariableManaCost.java +++ b/Mage/src/mage/abilities/costs/mana/VariableManaCost.java @@ -31,6 +31,7 @@ package mage.abilities.costs.mana; import mage.Mana; import mage.abilities.Ability; import mage.abilities.costs.VariableCost; +import mage.filter.FilterMana; import mage.game.Game; import mage.players.ManaPool; @@ -41,6 +42,7 @@ import mage.players.ManaPool; public class VariableManaCost extends ManaCostImpl implements VariableCost { protected int multiplier; + protected FilterMana filter; public VariableManaCost() { this(1); @@ -55,6 +57,7 @@ public class VariableManaCost extends ManaCostImpl implements public VariableManaCost(VariableManaCost manaCost) { super(manaCost); this.multiplier = manaCost.multiplier; + if (manaCost.filter != null) this.filter = manaCost.filter.copy(); } @Override @@ -64,9 +67,9 @@ public class VariableManaCost extends ManaCostImpl implements @Override public void assignPayment(Game game, Ability ability, ManaPool pool) { - payment.add(pool.getMana()); - payment.add(pool.getAllConditionalMana(ability, game)); - pool.emptyPoolConditional(ability, game); + payment.add(pool.getMana(filter)); + payment.add(pool.getAllConditionalMana(ability, game, filter)); + pool.emptyPoolConditional(ability, game, filter); } @Override @@ -98,6 +101,11 @@ public class VariableManaCost extends ManaCostImpl implements return true; } + @Override + public void setFilter(FilterMana filter) { + this.filter = filter; + } + @Override public VariableManaCost copy() { return new VariableManaCost(this); diff --git a/Mage/src/mage/abilities/effects/common/continious/LoseAllAbilitiesTargetEffect.java b/Mage/src/mage/abilities/effects/common/continious/LoseAllAbilitiesTargetEffect.java index 8f0f3b5268..78860298cc 100644 --- a/Mage/src/mage/abilities/effects/common/continious/LoseAllAbilitiesTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/LoseAllAbilitiesTargetEffect.java @@ -75,7 +75,7 @@ public class LoseAllAbilitiesTargetEffect extends ContinuousEffectImpl { @Override public String getText(Mode mode) { StringBuilder sb = new StringBuilder(); - sb.append("Target ").append(mode.getTargets().get(0).getTargetName()).append(" loses all abilities").append(duration.toString()); + sb.append("Target ").append(mode.getTargets().get(0).getTargetName()).append(" loses all abilities ").append(duration.toString()); return sb.toString(); } diff --git a/Mage/src/mage/filter/FilterMana.java b/Mage/src/mage/filter/FilterMana.java new file mode 100644 index 0000000000..a03d18b725 --- /dev/null +++ b/Mage/src/mage/filter/FilterMana.java @@ -0,0 +1,105 @@ +/* + * 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.filter; + +/** + * @author nantuko + */ +public class FilterMana { + + protected boolean black; + protected boolean green; + protected boolean white; + protected boolean red; + protected boolean blue; + protected boolean colorless; + + public FilterMana() { + } + + public FilterMana(FilterMana filter) { + black = filter.black; + green = filter.green; + white = filter.white; + red = filter.red; + blue = filter.blue; + colorless = filter.colorless; + } + + public boolean isBlack() { + return black; + } + + public void setBlack(boolean black) { + this.black = black; + } + + public boolean isGreen() { + return green; + } + + public void setGreen(boolean green) { + this.green = green; + } + + public boolean isWhite() { + return white; + } + + public void setWhite(boolean white) { + this.white = white; + } + + public boolean isRed() { + return red; + } + + public void setRed(boolean red) { + this.red = red; + } + + public boolean isBlue() { + return blue; + } + + public void setBlue(boolean blue) { + this.blue = blue; + } + + public boolean isColorless() { + return colorless; + } + + public void setColorless(boolean colorless) { + this.colorless = colorless; + } + + public FilterMana copy() { + return new FilterMana(this); + } +} diff --git a/Mage/src/mage/players/ManaPool.java b/Mage/src/mage/players/ManaPool.java index 2f791c35a1..94388cfb69 100644 --- a/Mage/src/mage/players/ManaPool.java +++ b/Mage/src/mage/players/ManaPool.java @@ -36,6 +36,8 @@ import java.util.List; import mage.ConditionalMana; import mage.Mana; import mage.abilities.Ability; +import mage.filter.Filter; +import mage.filter.FilterMana; import mage.game.Game; /** @@ -268,14 +270,14 @@ public class ManaPool implements Serializable { } - public int getConditionalCount(Ability ability, Game game) { + public int getConditionalCount(Ability ability, Game game, FilterMana filter) { if (ability == null || conditionalMana.size() == 0) { return 0; } int count = 0; for (ConditionalMana mana : conditionalMana) { if (mana.apply(ability, game)) { - count += mana.count(); + count += mana.count(filter); } } return count; @@ -329,6 +331,31 @@ public class ManaPool implements Serializable { return total; } + public int emptyPoolConditional(Ability ability, Game game, FilterMana filter) { + if (filter == null) { + return emptyPoolConditional(ability, game); + } + int total = count(filter); + if (filter.isBlack()) black = 0; + if (filter.isBlue()) blue = 0; + if (filter.isWhite()) white = 0; + if (filter.isRed()) red = 0; + if (filter.isGreen()) green = 0; + if (filter.isColorless()) colorless = 0; + // remove only those mana that can be spent for ability + Iterator it = conditionalMana.iterator(); + while (it.hasNext()) { + ConditionalMana mana = it.next(); + if (mana.apply(ability, game)) { + if (mana.count(filter) > 0) { + total += mana.count(); + it.remove(); + } + } + } + return total; + } + public Mana getMana() { Mana mana = new Mana(); mana.setBlack(black); @@ -340,9 +367,29 @@ public class ManaPool implements Serializable { return mana; } + public Mana getMana(FilterMana filter) { + if (filter == null) { + return getMana(); + } + Mana mana = new Mana(); + if (filter.isBlack()) mana.setBlack(black); + if (filter.isBlue()) mana.setBlue(blue); + if (filter.isColorless()) mana.setColorless(colorless); + if (filter.isGreen()) mana.setGreen(green); + if (filter.isRed()) mana.setRed(red); + if (filter.isWhite()) mana.setWhite(white); + return mana; + } + public Mana getAllConditionalMana(Ability ability, Game game) { Mana mana = new Mana(); - mana.setColorless(getConditionalCount(ability, game)); + mana.setColorless(getConditionalCount(ability, game, null)); + return mana; + } + + public Mana getAllConditionalMana(Ability ability, Game game, FilterMana filter) { + Mana mana = new Mana(); + mana.setColorless(getConditionalCount(ability, game, filter)); return mana; } @@ -385,6 +432,20 @@ public class ManaPool implements Serializable { return red + green + blue + white + black + colorless; } + public int count(FilterMana filter) { + if (filter == null) { + return count(); + } + int count = 0; + if (filter.isBlack()) count += black; + if (filter.isBlue()) count += blue; + if (filter.isWhite()) count += white; + if (filter.isGreen()) count += green; + if (filter.isRed()) count += red; + if (filter.isColorless()) count += colorless; + return count; + } + public ManaPool copy() { return new ManaPool(this); }