From 79eb8cede76248a17f0e691609589b3d3dfd6a9c Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Wed, 1 Dec 2010 01:59:13 +0000 Subject: [PATCH] added getMana method to card --- .../sets/magic2011/ElixirOfImmortality.java | 19 +++++++++++-------- .../sets/worldwake/EverflowingChalice.java | 2 ++ Mage/src/mage/cards/Card.java | 3 +++ Mage/src/mage/cards/CardImpl.java | 13 ++++++++++++- Mage/src/mage/game/stack/Spell.java | 6 ++++++ 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Mage.Sets/src/mage/sets/magic2011/ElixirOfImmortality.java b/Mage.Sets/src/mage/sets/magic2011/ElixirOfImmortality.java index a08d9c1457..4c48c58d41 100644 --- a/Mage.Sets/src/mage/sets/magic2011/ElixirOfImmortality.java +++ b/Mage.Sets/src/mage/sets/magic2011/ElixirOfImmortality.java @@ -44,6 +44,7 @@ import mage.abilities.effects.common.GainLifeEffect; import mage.cards.Card; import mage.cards.CardImpl; import mage.game.Game; +import mage.game.permanent.Permanent; import mage.players.Player; /** @@ -92,14 +93,16 @@ class ElixerOfImmortalityEffect extends OneShotEffect @Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); - player.gainLife(5, game); - player.removeFromBattlefield(game.getPermanent(source.getSourceId()), game); - Card card = game.getCard(source.getSourceId()); - card.moveToZone(Zone.LIBRARY, source.getId(), game, true); - player.getLibrary().addAll(player.getGraveyard().getCards(game), game); - player.getGraveyard().clear(); - player.getLibrary().shuffle(); - return true; + Permanent permanent = game.getPermanent(source.getSourceId()); + if (player != null && permanent != null) { + player.gainLife(5, game); + permanent.moveToZone(Zone.LIBRARY, source.getId(), game, true); + player.getLibrary().addAll(player.getGraveyard().getCards(game), game); + player.getGraveyard().clear(); + player.getLibrary().shuffle(); + return true; + } + return false; } @Override diff --git a/Mage.Sets/src/mage/sets/worldwake/EverflowingChalice.java b/Mage.Sets/src/mage/sets/worldwake/EverflowingChalice.java index 0a11df8ad3..23dabfcfff 100644 --- a/Mage.Sets/src/mage/sets/worldwake/EverflowingChalice.java +++ b/Mage.Sets/src/mage/sets/worldwake/EverflowingChalice.java @@ -91,6 +91,8 @@ class EverflowingChaliceAbility extends ManaAbility { @Override public Mana getNetMana(Game game) { + if (game == null) + return new Mana(); return Mana.ColorlessMana(game.getPermanent(this.getSourceId()).getCounters().getCount("charge")); } diff --git a/Mage/src/mage/cards/Card.java b/Mage/src/mage/cards/Card.java index bc78cf0995..13fab1dac9 100644 --- a/Mage/src/mage/cards/Card.java +++ b/Mage/src/mage/cards/Card.java @@ -33,6 +33,7 @@ import java.util.UUID; import mage.Constants.Rarity; import mage.Constants.Zone; import mage.MageObject; +import mage.Mana; import mage.abilities.Ability; import mage.abilities.SpellAbility; import mage.game.Game; @@ -60,6 +61,8 @@ public interface Card extends MageObject { public boolean putOntoBattlefield(Game game, Zone fromZone, UUID sourceId, UUID controllerId); public void checkTriggers(Zone zone, GameEvent event, Game game); + public List getMana(); + @Override public Card copy(); } diff --git a/Mage/src/mage/cards/CardImpl.java b/Mage/src/mage/cards/CardImpl.java index a61408e2c4..c3be9238f1 100644 --- a/Mage/src/mage/cards/CardImpl.java +++ b/Mage/src/mage/cards/CardImpl.java @@ -29,6 +29,7 @@ package mage.cards; import java.lang.reflect.Constructor; +import java.util.ArrayList; import java.util.List; import java.util.UUID; import java.util.logging.Level; @@ -37,10 +38,12 @@ import mage.Constants.CardType; import mage.Constants.Rarity; import mage.Constants.Zone; import mage.MageObjectImpl; +import mage.Mana; import mage.abilities.Ability; import mage.abilities.PlayLandAbility; import mage.abilities.SpellAbility; import mage.abilities.TriggeredAbility; +import mage.abilities.mana.ManaAbility; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.ZoneChangeEvent; @@ -97,7 +100,6 @@ public abstract class CardImpl> extends MageObjectImpl Class theClass = Class.forName(name); Constructor con = theClass.getConstructor(new Class[]{UUID.class}); Card card = (Card) con.newInstance(new Object[] {null}); -// card.setZone(Zone.OUTSIDE); return card; } catch (Exception e) { @@ -183,6 +185,15 @@ public abstract class CardImpl> extends MageObjectImpl this.expansionSetCode = expansionSetCode; } + @Override + public List getMana() { + List mana = new ArrayList(); + for (ManaAbility ability: this.abilities.getManaAbilities(Zone.BATTLEFIELD)) { + mana.add(ability.getNetMana(null)); + } + return mana; + } + @Override public boolean moveToZone(Zone toZone, UUID sourceId, Game game, boolean flag) { Zone fromZone = game.getZone(objectId); diff --git a/Mage/src/mage/game/stack/Spell.java b/Mage/src/mage/game/stack/Spell.java index fdd9203679..8df5e48d18 100644 --- a/Mage/src/mage/game/stack/Spell.java +++ b/Mage/src/mage/game/stack/Spell.java @@ -28,6 +28,7 @@ package mage.game.stack; +import mage.Mana; import mage.abilities.SpellAbility; import mage.game.*; import java.util.List; @@ -313,4 +314,9 @@ public class Spell> implements StackObject, Card { public int getCardNumber() { return card.getCardNumber(); } + + @Override + public List getMana() { + throw new UnsupportedOperationException("Not supported yet."); + } }