From 625aa29d6e7ac9476c363efb3698156134286a66 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 6 Oct 2015 17:28:59 +0200 Subject: [PATCH] Rework of "spend mana as though it were mana of" handling. --- .../java/mage/player/ai/ComputerPlayer.java | 2 +- .../mage/sets/darksteel/MycosynthLattice.java | 12 +- .../src/mage/sets/theros/DaxosOfMeletis.java | 17 +-- .../mage/sets/theros/PsychicIntrusion.java | 15 +-- .../mage/sets/timeshifted/CelestialDawn.java | 30 ++--- .../abilities/effects/AsThoughEffect.java | 4 - .../abilities/effects/AsThoughEffectImpl.java | 7 -- .../abilities/effects/AsThoughManaEffect.java | 45 +++++++ .../abilities/effects/ContinuousEffects.java | 35 ++++-- .../mage/constants/AsThoughEffectType.java | 4 +- Mage/src/mage/players/ManaPool.java | 48 ++----- Mage/src/mage/players/ManaPoolItem.java | 117 +++++++++--------- 12 files changed, 184 insertions(+), 152 deletions(-) create mode 100644 Mage/src/mage/abilities/effects/AsThoughManaEffect.java diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index c9913b4f11..f866669756 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -1135,7 +1135,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { protected boolean playManaHandling(Ability ability, ManaCost unpaid, Game game) { // log.info("paying for " + unpaid.getText()); - boolean spendAnyMana = game.getContinuousEffects().asThough(ability.getSourceId(), AsThoughEffectType.SPEND_ANY_MANA, ability, ability.getControllerId(), game); + boolean spendAnyMana = game.getContinuousEffects().asThough(ability.getSourceId(), AsThoughEffectType.SPEND_OTHER_MANA, ability, ability.getControllerId(), game); ManaCost cost; List producers; if (unpaid instanceof ManaCosts) { diff --git a/Mage.Sets/src/mage/sets/darksteel/MycosynthLattice.java b/Mage.Sets/src/mage/sets/darksteel/MycosynthLattice.java index fa2aa3f3c0..b4932f8900 100644 --- a/Mage.Sets/src/mage/sets/darksteel/MycosynthLattice.java +++ b/Mage.Sets/src/mage/sets/darksteel/MycosynthLattice.java @@ -34,6 +34,7 @@ import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.AsThoughEffectImpl; +import mage.abilities.effects.AsThoughManaEffect; import mage.abilities.effects.ContinuousEffectImpl; import mage.cards.Card; import mage.cards.CardImpl; @@ -170,10 +171,10 @@ class EverythingIsColorlessEffect extends ContinuousEffectImpl { } } -class ManaCanBeSpentAsAnyColorEffect extends AsThoughEffectImpl { +class ManaCanBeSpentAsAnyColorEffect extends AsThoughEffectImpl implements AsThoughManaEffect { public ManaCanBeSpentAsAnyColorEffect() { - super(AsThoughEffectType.SPEND_ANY_MANA, Duration.WhileOnBattlefield, Outcome.Benefit); + super(AsThoughEffectType.SPEND_OTHER_MANA, Duration.WhileOnBattlefield, Outcome.Benefit); staticText = "Players may spend mana as though it were mana of any color"; } @@ -184,12 +185,13 @@ class ManaCanBeSpentAsAnyColorEffect extends AsThoughEffectImpl { @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - return true; // not used for mana thought as effects + Player controller = game.getPlayer(source.getControllerId()); + return controller != null && controller.getInRange().contains(affectedControllerId); } @Override - public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana) { - return true; + public ManaType getAsThoughtManaType(ManaType manaType, ManaPoolItem mana, UUID affectedControllerId, Ability source, Game game) { + return mana.getFirstAvailable(); } @Override diff --git a/Mage.Sets/src/mage/sets/theros/DaxosOfMeletis.java b/Mage.Sets/src/mage/sets/theros/DaxosOfMeletis.java index e0208b506f..adc2d74bae 100644 --- a/Mage.Sets/src/mage/sets/theros/DaxosOfMeletis.java +++ b/Mage.Sets/src/mage/sets/theros/DaxosOfMeletis.java @@ -34,6 +34,7 @@ import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.common.SimpleEvasionAbility; import mage.abilities.effects.AsThoughEffectImpl; +import mage.abilities.effects.AsThoughManaEffect; import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.combat.CantBeBlockedByCreaturesSourceEffect; @@ -183,10 +184,10 @@ class DaxosOfMeletisCastFromExileEffect extends AsThoughEffectImpl { } } -class DaxosOfMeletisSpendAnyManaEffect extends AsThoughEffectImpl { +class DaxosOfMeletisSpendAnyManaEffect extends AsThoughEffectImpl implements AsThoughManaEffect { public DaxosOfMeletisSpendAnyManaEffect() { - super(AsThoughEffectType.SPEND_ANY_MANA, Duration.EndOfTurn, Outcome.Benefit); + super(AsThoughEffectType.SPEND_OTHER_MANA, Duration.EndOfTurn, Outcome.Benefit); staticText = "you may spend mana as though it were mana of any color to cast it"; } @@ -206,14 +207,16 @@ class DaxosOfMeletisSpendAnyManaEffect extends AsThoughEffectImpl { @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - return true; // not used for mana thought as effects - } - - @Override - public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana) { return source.getControllerId().equals(affectedControllerId) && objectId == ((FixedTarget) getTargetPointer()).getTarget() && ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(objectId) + && (((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(objectId)) && game.getState().getZone(objectId).equals(Zone.STACK); } + + @Override + public ManaType getAsThoughtManaType(ManaType manaType, ManaPoolItem mana, UUID affectedControllerId, Ability source, Game game) { + return mana.getFirstAvailable(); + } + } diff --git a/Mage.Sets/src/mage/sets/theros/PsychicIntrusion.java b/Mage.Sets/src/mage/sets/theros/PsychicIntrusion.java index ed5d78e197..d8e0268ba8 100644 --- a/Mage.Sets/src/mage/sets/theros/PsychicIntrusion.java +++ b/Mage.Sets/src/mage/sets/theros/PsychicIntrusion.java @@ -31,6 +31,7 @@ import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.abilities.effects.AsThoughEffectImpl; +import mage.abilities.effects.AsThoughManaEffect; import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; @@ -190,10 +191,10 @@ class PsychicIntrusionCastFromExileEffect extends AsThoughEffectImpl { } } -class PsychicIntrusionSpendAnyManaEffect extends AsThoughEffectImpl { +class PsychicIntrusionSpendAnyManaEffect extends AsThoughEffectImpl implements AsThoughManaEffect { public PsychicIntrusionSpendAnyManaEffect() { - super(AsThoughEffectType.SPEND_ANY_MANA, Duration.Custom, Outcome.Benefit); + super(AsThoughEffectType.SPEND_OTHER_MANA, Duration.Custom, Outcome.Benefit); staticText = "you may spend mana as though it were mana of any color to cast it"; } @@ -213,11 +214,6 @@ class PsychicIntrusionSpendAnyManaEffect extends AsThoughEffectImpl { @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - return true; // not used for mana thought as effects - } - - @Override - public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana) { if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget()) && game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) { @@ -236,4 +232,9 @@ class PsychicIntrusionSpendAnyManaEffect extends AsThoughEffectImpl { } return false; } + + @Override + public ManaType getAsThoughtManaType(ManaType manaType, ManaPoolItem mana, UUID affectedControllerId, Ability source, Game game) { + return mana.getFirstAvailable(); + } } diff --git a/Mage.Sets/src/mage/sets/timeshifted/CelestialDawn.java b/Mage.Sets/src/mage/sets/timeshifted/CelestialDawn.java index e899f506b6..5bd296b708 100644 --- a/Mage.Sets/src/mage/sets/timeshifted/CelestialDawn.java +++ b/Mage.Sets/src/mage/sets/timeshifted/CelestialDawn.java @@ -33,6 +33,7 @@ import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.AsThoughEffectImpl; +import mage.abilities.effects.AsThoughManaEffect; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.mana.WhiteManaAbility; import mage.cards.Card; @@ -146,7 +147,6 @@ class CelestialDawnToWhiteEffect extends ContinuousEffectImpl { public CelestialDawnToWhiteEffect() { super(Duration.WhileOnBattlefield, Layer.ColorChangingEffects_5, SubLayer.NA, Outcome.Benefit); staticText = "Nonland cards you own that aren't on the battlefield, spells you control, and nonland permanents you control are white"; - staticText = "All cards that aren't on the battlefield, spells, and permanents are the chosen color in addition to their other colors"; } @Override @@ -213,10 +213,10 @@ class CelestialDawnToWhiteEffect extends ContinuousEffectImpl { } -class CelestialDawnSpendAnyManaEffect extends AsThoughEffectImpl { +class CelestialDawnSpendAnyManaEffect extends AsThoughEffectImpl implements AsThoughManaEffect { public CelestialDawnSpendAnyManaEffect() { - super(AsThoughEffectType.SPEND_ANY_MANA, Duration.Custom, Outcome.Benefit); + super(AsThoughEffectType.SPEND_OTHER_MANA, Duration.Custom, Outcome.Benefit); staticText = "You may spend white mana as though it were mana of any color"; } @@ -236,22 +236,22 @@ class CelestialDawnSpendAnyManaEffect extends AsThoughEffectImpl { @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - return true; // not used for mana thought as effects + return affectedControllerId.equals(source.getControllerId()); } @Override - public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana) { - if (affectedControllerId.equals(source.getControllerId())) { - return mana.getWhite() > 0; + public ManaType getAsThoughtManaType(ManaType manaType, ManaPoolItem mana, UUID affectedControllerId, Ability source, Game game) { + if (mana.getWhite() > 0) { + return ManaType.WHITE; } - return false; + return null; } } -class CelestialDawnSpendColorlessManaEffect extends AsThoughEffectImpl { +class CelestialDawnSpendColorlessManaEffect extends AsThoughEffectImpl implements AsThoughManaEffect { public CelestialDawnSpendColorlessManaEffect() { - super(AsThoughEffectType.SPEND_COLORLESS_MANA, Duration.Custom, Outcome.Detriment); + super(AsThoughEffectType.SPEND_ONLY_MANA, Duration.Custom, Outcome.Detriment); staticText = "You may spend other mana only as though it were colorless mana"; } @@ -271,14 +271,14 @@ class CelestialDawnSpendColorlessManaEffect extends AsThoughEffectImpl { @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - return true; // not used for mana thought as effects + return affectedControllerId.equals(source.getControllerId()); } @Override - public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana) { - if (affectedControllerId.equals(source.getControllerId())) { - return mana.getWhite() == 0; + public ManaType getAsThoughtManaType(ManaType manaType, ManaPoolItem mana, UUID affectedControllerId, Ability source, Game game) { + if (mana.getWhite() == 0 && !ManaType.COLORLESS.equals(manaType)) { + return null; } - return false; + return manaType; } } diff --git a/Mage/src/mage/abilities/effects/AsThoughEffect.java b/Mage/src/mage/abilities/effects/AsThoughEffect.java index 21d77b1bfd..a134aa53b7 100644 --- a/Mage/src/mage/abilities/effects/AsThoughEffect.java +++ b/Mage/src/mage/abilities/effects/AsThoughEffect.java @@ -30,9 +30,7 @@ package mage.abilities.effects; import java.util.UUID; import mage.abilities.Ability; import mage.constants.AsThoughEffectType; -import mage.constants.ManaType; import mage.game.Game; -import mage.players.ManaPoolItem; /** * @@ -44,8 +42,6 @@ public interface AsThoughEffect extends ContinuousEffect { boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game); - boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana); - AsThoughEffectType getAsThoughEffectType(); @Override diff --git a/Mage/src/mage/abilities/effects/AsThoughEffectImpl.java b/Mage/src/mage/abilities/effects/AsThoughEffectImpl.java index eb72239187..bd1448d8e9 100644 --- a/Mage/src/mage/abilities/effects/AsThoughEffectImpl.java +++ b/Mage/src/mage/abilities/effects/AsThoughEffectImpl.java @@ -32,10 +32,8 @@ import mage.abilities.Ability; import mage.constants.AsThoughEffectType; import mage.constants.Duration; import mage.constants.EffectType; -import mage.constants.ManaType; import mage.constants.Outcome; import mage.game.Game; -import mage.players.ManaPoolItem; /** * @@ -61,11 +59,6 @@ public abstract class AsThoughEffectImpl extends ContinuousEffectImpl implements return applies(objectId, source, affectedAbility.getControllerId(), game); } - @Override - public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana) { - return false; - } - @Override public AsThoughEffectType getAsThoughEffectType() { return type; diff --git a/Mage/src/mage/abilities/effects/AsThoughManaEffect.java b/Mage/src/mage/abilities/effects/AsThoughManaEffect.java new file mode 100644 index 0000000000..4ff137fc8e --- /dev/null +++ b/Mage/src/mage/abilities/effects/AsThoughManaEffect.java @@ -0,0 +1,45 @@ +/* + * 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; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.constants.ManaType; +import mage.game.Game; +import mage.players.ManaPoolItem; + +/** + * + * @author LevelX2 + */ +public interface AsThoughManaEffect extends AsThoughEffect { + + // return a mana type that can be used to pay a mana cost instead of the normally needed mana type + ManaType getAsThoughtManaType(ManaType manaType, ManaPoolItem mana, UUID affectedControllerId, Ability source, Game game); + +} diff --git a/Mage/src/mage/abilities/effects/ContinuousEffects.java b/Mage/src/mage/abilities/effects/ContinuousEffects.java index 00133342fc..003f61542b 100644 --- a/Mage/src/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/mage/abilities/effects/ContinuousEffects.java @@ -548,24 +548,35 @@ public class ContinuousEffects implements Serializable { } - public boolean asThoughMana(UUID objectId, AsThoughEffectType type, Ability affectedAbility, UUID controllerId, Game game, ManaType manaType, ManaPoolItem mana) { - List asThoughEffectsList = getApplicableAsThoughEffects(type, game); + public ManaType asThoughMana(ManaType manaType, ManaPoolItem mana, UUID objectId, Ability affectedAbility, UUID controllerId, Game game) { + // First check existing only effects + List asThoughEffectsList = getApplicableAsThoughEffects(AsThoughEffectType.SPEND_ONLY_MANA, game); for (AsThoughEffect effect : asThoughEffectsList) { - HashSet abilities = asThoughEffectsMap.get(type).getAbility(effect.getId()); + HashSet abilities = asThoughEffectsMap.get(AsThoughEffectType.SPEND_ONLY_MANA).getAbility(effect.getId()); for (Ability ability : abilities) { - if (affectedAbility == null) { - if (effect.applies(objectId, ability, controllerId, game)) { - return true; - } - } else { - if (effect.applies(objectId, affectedAbility, ability, game)) { - return true; + if ((affectedAbility == null && effect.applies(objectId, ability, controllerId, game)) + || effect.applies(objectId, affectedAbility, ability, game)) { + if (((AsThoughManaEffect) effect).getAsThoughtManaType(manaType, mana, controllerId, ability, game) == null) { + return null; } } } } - return false; - + // then check effects that allow to use other mana types to pay the current mana type to pay + asThoughEffectsList = getApplicableAsThoughEffects(AsThoughEffectType.SPEND_OTHER_MANA, game); + for (AsThoughEffect effect : asThoughEffectsList) { + HashSet abilities = asThoughEffectsMap.get(AsThoughEffectType.SPEND_OTHER_MANA).getAbility(effect.getId()); + for (Ability ability : abilities) { + if ((affectedAbility == null && effect.applies(objectId, ability, controllerId, game)) + || effect.applies(objectId, affectedAbility, ability, game)) { + ManaType usableManaType = ((AsThoughManaEffect) effect).getAsThoughtManaType(manaType, mana, controllerId, ability, game); + if (usableManaType != null) { + return usableManaType; + } + } + } + } + return manaType; } /** diff --git a/Mage/src/mage/constants/AsThoughEffectType.java b/Mage/src/mage/constants/AsThoughEffectType.java index 768d14f37b..546483c9d7 100644 --- a/Mage/src/mage/constants/AsThoughEffectType.java +++ b/Mage/src/mage/constants/AsThoughEffectType.java @@ -19,7 +19,7 @@ public enum AsThoughEffectType { HEXPROOF, PAY, LOOK_AT_FACE_DOWN, - SPEND_ANY_MANA, - SPEND_COLORLESS_MANA, + SPEND_OTHER_MANA, + SPEND_ONLY_MANA, TARGET } diff --git a/Mage/src/mage/players/ManaPool.java b/Mage/src/mage/players/ManaPool.java index e2fe28e201..04aec4fa84 100644 --- a/Mage/src/mage/players/ManaPool.java +++ b/Mage/src/mage/players/ManaPool.java @@ -38,7 +38,6 @@ import mage.ConditionalMana; import mage.MageObject; import mage.Mana; import mage.abilities.Ability; -import mage.constants.AsThoughEffectType; import mage.constants.Duration; import mage.constants.ManaType; import mage.constants.TurnPhase; @@ -65,13 +64,6 @@ public class ManaPool implements Serializable { private final Set doNotEmptyManaTypes = new HashSet<>(); - private enum SpendType { - - NORMAL, - ANY, - COLORLESS - } - public ManaPool(UUID playerId) { this.playerId = playerId; autoPayment = true; @@ -145,39 +137,25 @@ public class ManaPool implements Serializable { // no mana added beyond the stock so don't auto pay this continue; } - SpendType spendType = getSpendType(ability, game, manaType, mana); - if (!SpendType.COLORLESS.equals(spendType) || ManaType.COLORLESS.equals(manaType)) { - if (mana.get(manaType) > 0 || (spendType.equals(SpendType.ANY) && mana.count() > 0)) { - GameEvent event = new GameEvent(GameEvent.EventType.MANA_PAYED, ability.getId(), mana.getSourceId(), ability.getControllerId(), 0, mana.getFlag()); - event.setData(mana.getOriginalId().toString()); - game.fireEvent(event); - if (!SpendType.NORMAL.equals(spendType)) { - mana.removeAny(); - } else { - mana.remove(manaType); - } - if (mana.count() == 0) { // so no items with count 0 stay in list - manaItems.remove(mana); - } - lockManaType(); // pay only one mana if mana payment is set to manually - return true; + ManaType usableManaType = game.getContinuousEffects().asThoughMana(manaType, mana, ability.getSourceId(), ability, ability.getControllerId(), game); + if (usableManaType == null) { + continue; + } + if (mana.get(usableManaType) > 0) { + GameEvent event = new GameEvent(GameEvent.EventType.MANA_PAYED, ability.getId(), mana.getSourceId(), ability.getControllerId(), 0, mana.getFlag()); + event.setData(mana.getOriginalId().toString()); + game.fireEvent(event); + mana.remove(usableManaType); + if (mana.count() == 0) { // so no items with count 0 stay in list + manaItems.remove(mana); } + lockManaType(); // pay only one mana if mana payment is set to manually + return true; } } return false; } - // check if any mana can be spend to cast the mana cost of an ability - private SpendType getSpendType(Ability ability, Game game, ManaType manaType, ManaPoolItem mana) { - if (game.getContinuousEffects().asThoughMana(ability.getSourceId(), AsThoughEffectType.SPEND_ANY_MANA, ability, ability.getControllerId(), game, manaType, mana)) { - return SpendType.ANY; - } - if (game.getContinuousEffects().asThoughMana(ability.getSourceId(), AsThoughEffectType.SPEND_COLORLESS_MANA, ability, ability.getControllerId(), game, manaType, mana)) { - return SpendType.COLORLESS; - } - return SpendType.NORMAL; - } - public int get(ManaType manaType) { return getMana().get(manaType); } diff --git a/Mage/src/mage/players/ManaPoolItem.java b/Mage/src/mage/players/ManaPoolItem.java index b6a8f796b9..9c380389a3 100644 --- a/Mage/src/mage/players/ManaPoolItem.java +++ b/Mage/src/mage/players/ManaPoolItem.java @@ -1,30 +1,30 @@ /* -* Copyright 2011 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. -*/ + * Copyright 2011 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.players; import java.io.Serializable; @@ -53,7 +53,8 @@ public class ManaPoolItem implements Serializable { private Duration duration; private int stock; // amount the item had at the start of casting something - public ManaPoolItem() {} + public ManaPoolItem() { + } public ManaPoolItem(int red, int green, int blue, int white, int black, int colorless, UUID sourceId, UUID originalId, boolean flag) { this.red = red; @@ -75,7 +76,7 @@ public class ManaPoolItem implements Serializable { this.conditionalMana.setManaProducerId(sourceId); this.conditionalMana.setManaProducerOriginalId(originalId); this.flag = conditionalMana.getFlag(); - this.duration = Duration.EndOfStep; + this.duration = Duration.EndOfStep; } public ManaPoolItem(final ManaPoolItem item) { @@ -191,7 +192,7 @@ public class ManaPoolItem implements Serializable { } public int get(ManaType manaType) { - switch(manaType) { + switch (manaType) { case BLACK: return black; case BLUE: @@ -208,29 +209,26 @@ public class ManaPoolItem implements Serializable { return 0; } - public void removeAny() { - int oldCount = count(); + public ManaType getFirstAvailable() { if (black > 0) { - black--; + return ManaType.BLACK; } else if (blue > 0) { - blue--; + return ManaType.BLUE; } else if (green > 0) { - green--; + return ManaType.GREEN; } else if (red > 0) { - red--; + return ManaType.RED; } else if (white > 0) { - white--; + return ManaType.WHITE; } else if (colorless > 0) { - colorless--; - } - if (stock == oldCount && oldCount > count()) { - stock--; - } + return ManaType.COLORLESS; + } + return null; } - + public void remove(ManaType manaType) { int oldCount = count(); - switch(manaType) { + switch (manaType) { case BLACK: if (black > 0) { black--; @@ -264,11 +262,11 @@ public class ManaPoolItem implements Serializable { } if (stock == oldCount && oldCount > count()) { stock--; - } + } } - + public void clear(ManaType manaType) { - switch(manaType) { + switch (manaType) { case BLACK: black = 0; break; @@ -287,31 +285,36 @@ public class ManaPoolItem implements Serializable { case COLORLESS: colorless = 0; break; - } + } } - + public void add(ManaType manaType, int amount) { - switch(manaType) { + switch (manaType) { case BLACK: black += amount; break; case BLUE: - blue += amount;; + blue += amount; + ; break; case GREEN: - green += amount;; + green += amount; + ; break; case RED: - red += amount;; + red += amount; + ; break; case WHITE: - white += amount;; + white += amount; + ; break; case COLORLESS: - colorless += amount;; + colorless += amount; + ; break; - } - } + } + } public Duration getDuration() { return duration; @@ -328,5 +331,5 @@ public class ManaPoolItem implements Serializable { public void setStock(int stock) { this.stock = stock; } - + }