diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index 8c6be134af..54a3782ef8 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -55,6 +55,7 @@ import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.PhyrexianManaCost; import mage.abilities.costs.mana.VariableManaCost; import mage.abilities.effects.ReplacementEffect; +import mage.abilities.mana.ManaAbility; import mage.cards.Card; import mage.cards.Cards; import mage.cards.decks.Deck; @@ -379,39 +380,18 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> { MageObject object = game.getObject(response.getUUID()); if (object != null) { Map<UUID, ActivatedAbility> useableAbilities = null; - switch (game.getZone(object.getId())) { - case HAND: - useableAbilities = getUseableAbilities(object.getAbilities().getActivatedAbilities(Zone.HAND), game); - break; - case BATTLEFIELD: - useableAbilities = getUseableAbilities(object.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD), game); - break; - case GRAVEYARD: - useableAbilities = getUseableAbilities(object.getAbilities().getActivatedAbilities(Zone.GRAVEYARD), game); - playAsThoughInYourHand(game, object, useableAbilities); - break; - case LIBRARY: - useableAbilities = getUseableAbilities(object.getAbilities().getActivatedAbilities(Zone.LIBRARY), game); - playAsThoughInYourHand(game, object, useableAbilities); - break; - } - if (useableAbilities != null && useableAbilities.size() > 0) { - activateAbility(useableAbilities, game); - } + Zone zone = game.getZone(object.getId()); + if (zone != null) { + useableAbilities = getUseableActivatedAbilities(object, zone, game); + if (useableAbilities != null && useableAbilities.size() > 0) { + activateAbility(useableAbilities, game); + } + } } } } } - // not sure it is the best to implement such stuff this way - private void playAsThoughInYourHand(Game game, MageObject object, Map<UUID, ActivatedAbility> useableAbilities) { - if (game.getContinuousEffects().asThough(object.getId(), Constants.AsThoughEffectType.CAST, game)) { - for (Map.Entry<UUID, ActivatedAbility> entry : getUseableAbilities(object.getAbilities().getActivatedAbilities(Zone.HAND), game).entrySet()) { - useableAbilities.put(entry.getKey(), entry.getValue()); - } - } - } - @Override public TriggeredAbility chooseTriggeredAbility(TriggeredAbilities abilities, Game game) { game.getState().setPriorityPlayerId(getId()); @@ -473,27 +453,14 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> { game.getState().setPriorityPlayerId(getId()); MageObject object = game.getObject(response.getUUID()); if (object == null) return; - Map<UUID, ActivatedAbility> useableAbilities; - switch (game.getZone(object.getId())) { - case HAND: - useableAbilities = getUseableAbilities(object.getAbilities().getManaAbilities(Zone.HAND), game); - if (useableAbilities.size() > 0) { - activateAbility(useableAbilities, game); - } - break; - case BATTLEFIELD: - useableAbilities = getUseableAbilities(object.getAbilities().getManaAbilities(Zone.BATTLEFIELD), game); - if (useableAbilities.size() > 0) { - activateAbility(useableAbilities, game); - } - break; - case GRAVEYARD: - useableAbilities = getUseableAbilities(object.getAbilities().getManaAbilities(Zone.GRAVEYARD), game); - if (useableAbilities.size() > 0) { - activateAbility(useableAbilities, game); - } - break; - } + Map<UUID, ManaAbility> useableAbilities = null; + Zone zone = game.getZone(object.getId()); + if (zone != null) { + useableAbilities = getUseableManaAbilities(object, zone, game); + if (useableAbilities != null && useableAbilities.size() > 0) { + activateAbility(useableAbilities, game); + } + } } @Override diff --git a/Mage.Server/plugins/mage-player-human.jar b/Mage.Server/plugins/mage-player-human.jar index ca4d50c078..2e36625617 100644 Binary files a/Mage.Server/plugins/mage-player-human.jar and b/Mage.Server/plugins/mage-player-human.jar differ diff --git a/Mage.Sets/src/mage/sets/newphyrexia/PraetorsGrasp.java b/Mage.Sets/src/mage/sets/newphyrexia/PraetorsGrasp.java new file mode 100644 index 0000000000..57943774a7 --- /dev/null +++ b/Mage.Sets/src/mage/sets/newphyrexia/PraetorsGrasp.java @@ -0,0 +1,154 @@ +/* + * 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.newphyrexia; + +import java.util.UUID; +import mage.Constants.AsThoughEffectType; +import mage.Constants.CardType; +import mage.Constants.Duration; +import mage.Constants.Outcome; +import mage.Constants.Rarity; +import mage.Constants.Zone; +import mage.abilities.Ability; +import mage.abilities.effects.AsThoughEffectImpl; +import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.Cards; +import mage.cards.CardsImpl; +import mage.game.Game; +import mage.players.Player; +import mage.target.common.TargetCardInLibrary; +import mage.target.common.TargetOpponent; + +/** + * + * @author BetaSteward + */ +public class PraetorsGrasp extends CardImpl<PraetorsGrasp> { + + public PraetorsGrasp(UUID ownerId) { + super(ownerId, 71, "Praetor's Grasp", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{1}{B}{B}"); + this.expansionSetCode = "NPH"; + + this.color.setBlack(true); + + // Search target opponent's library for a card and exile it face down. Then that player shuffles his or her library. You may look at and play that card for as long as it remains exiled. + this.getSpellAbility().addEffect(new PraetorsGraspEffect()); + this.getSpellAbility().addTarget(new TargetOpponent()); + + } + + public PraetorsGrasp(final PraetorsGrasp card) { + super(card); + } + + @Override + public PraetorsGrasp copy() { + return new PraetorsGrasp(this); + } +} + +class PraetorsGraspEffect extends OneShotEffect<PraetorsGraspEffect> { + + public PraetorsGraspEffect() { + super(Outcome.PlayForFree); + staticText = "Search target opponent's library for a card and exile it face down. Then that player shuffles his or her library. You may look at and play that card for as long as it remains exiled"; + } + + public PraetorsGraspEffect(final PraetorsGraspEffect effect) { + super(effect); + } + + @Override + public PraetorsGraspEffect copy() { + return new PraetorsGraspEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player opponent = game.getPlayer(source.getFirstTarget()); + Player player = game.getPlayer(source.getControllerId()); + if (player != null && opponent != null) { + Cards opponentLibrary = new CardsImpl(); + opponentLibrary.addAll(opponent.getLibrary().getCardList()); + + TargetCardInLibrary target = new TargetCardInLibrary(); + if (player.choose(Outcome.Benefit, opponentLibrary, target, game)) { + UUID targetId = target.getFirstTarget(); + Card card = opponent.getLibrary().remove(targetId, game); + if (card != null) { + card.setFaceDown(true); + card.moveToExile(getId(), "Praetor's Grasp", source.getSourceId(), game); + game.addEffect(new PraetorsGraspPlayEffect(card.getId()), source); + } + } + } + + opponent.shuffleLibrary(game); + return true; + } +} + +class PraetorsGraspPlayEffect extends AsThoughEffectImpl<PraetorsGraspPlayEffect> { + + private UUID cardId; + + public PraetorsGraspPlayEffect(UUID cardId) { + super(AsThoughEffectType.CAST, Duration.EndOfGame, Outcome.Benefit); + this.cardId = cardId; + staticText = "You may look at and play that card for as long as it remains exiled"; + } + + public PraetorsGraspPlayEffect(final PraetorsGraspPlayEffect effect) { + super(effect); + this.cardId = effect.cardId; + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public PraetorsGraspPlayEffect copy() { + return new PraetorsGraspPlayEffect(this); + } + + @Override + public boolean applies(UUID sourceId, Ability source, Game game) { + if (sourceId.equals(cardId)) { + Card card = game.getCard(cardId); + if (card != null && game.getZone(cardId) == Zone.EXILED) { + return true; + } + } + return false; + } + +} \ No newline at end of file diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index b33e27a4cf..3881743f9d 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -38,6 +38,7 @@ import java.util.Map; import java.util.Random; import java.util.Set; import java.util.UUID; +import mage.Constants.AsThoughEffectType; import mage.Constants.Outcome; import mage.Constants.RangeOfInfluence; import mage.Constants.Zone; @@ -604,15 +605,29 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser return false; } - protected Map<UUID, ActivatedAbility> getUseableAbilities(List<? extends ActivatedAbility> abilities, Game game) { + protected Map<UUID, ActivatedAbility> getUseableActivatedAbilities(MageObject object, Zone zone, Game game) { Map<UUID, ActivatedAbility> useable = new HashMap<UUID, ActivatedAbility>(); - for (ActivatedAbility ability: abilities) { + for (ActivatedAbility ability: object.getAbilities().getActivatedAbilities(zone)) { + if (ability.canActivate(playerId, game)) + useable.put(ability.getId(), ability); + } + if (zone != Zone.HAND && game.getContinuousEffects().asThough(object.getId(), AsThoughEffectType.CAST, game)) { + for (ActivatedAbility ability: object.getAbilities().getActivatedAbilities(Zone.HAND)) { + useable.put(ability.getId(), ability); + } + } + return useable; + } + + protected Map<UUID, ManaAbility> getUseableManaAbilities(MageObject object, Zone zone, Game game) { + Map<UUID, ManaAbility> useable = new HashMap<UUID, ManaAbility>(); + for (ManaAbility ability: object.getAbilities().getManaAbilities(zone)) { if (ability.canActivate(playerId, game)) useable.put(ability.getId(), ability); } return useable; } - + @Override public int getLandsPlayed() { return landsPlayed;