* Some minor reworks to prevent exceptions.

This commit is contained in:
LevelX2 2017-07-23 23:16:22 +02:00
parent b948a8255a
commit 2efc666f8d
3 changed files with 51 additions and 35 deletions

View file

@ -25,11 +25,11 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.cards.c;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.AttacksTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
@ -40,6 +40,7 @@ import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
@ -52,12 +53,16 @@ public class ConundrumSphinx extends CardImpl {
public ConundrumSphinx(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{U}{U}");
this.subtype.add("Sphinx");
this.subtype.add(SubType.SPHINX);
this.power = new MageInt(4);
this.toughness = new MageInt(4);
//Flying
this.addAbility(FlyingAbility.getInstance());
// Whenever Conundrum Sphinx attacks, each player names a card. Then each player reveals the top card of his or her library.
// If the card a player revealed is the card he or she named, that player puts it into his or her hand.
// If it's not, that player puts it on the bottom of his or her library.
this.addAbility(new AttacksTriggeredAbility(new ConundrumSphinxEffect(), false));
}
@ -85,32 +90,41 @@ class ConundrumSphinxEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = source.getSourceObject(game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && sourceObject != null) {
Choice cardChoice = new ChoiceImpl();
cardChoice.setChoices(CardRepository.instance.getNames());
for (Player player: game.getPlayers().values()) {
Players:
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
if (player.getLibrary().hasCards()) {
cardChoice.clearChoice();
while (!player.choose(Outcome.DrawCard, cardChoice, game) && player.canRespond()) {
if (!player.canRespond()) {
return false;
continue Players;
}
}
String cardName = cardChoice.getChoice();
game.informPlayers("Conundrum Sphinx, player: " + player.getLogName() + ", named card: [" + cardName + ']');
game.informPlayers(sourceObject.getLogName() + ", player: " + player.getLogName() + ", named: [" + cardName + ']');
Card card = player.getLibrary().removeFromTop(game);
Cards cards = new CardsImpl();
cards.add(card);
player.revealCards("Conundrum Sphinx", cards, game);
if (card != null) {
Cards cards = new CardsImpl(card);
player.revealCards(sourceObject.getIdName(), cards, game);
if (card.getName().equals(cardName)) {
card.moveToZone(Zone.HAND, source.getSourceId(), game, true);
player.moveCards(cards, Zone.HAND, source, game);
} else {
player.putCardsOnBottomOfLibrary(cards, game, source, false);
}
}
else {
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
}
}
}
return true;
}
return false;
}
@Override
public ConundrumSphinxEffect copy() {

View file

@ -57,7 +57,7 @@ public class Fireball extends CardImpl {
@Override
public void adjustCosts(Ability ability, Game game) {
int numTargets = ability.getTargets().get(0).getTargets().size();
int numTargets = ability.getTargets().isEmpty() ? 0 : ability.getTargets().get(0).getTargets().size();
if (numTargets > 1) {
ability.getManaCostsToPay().add(new GenericManaCost(numTargets - 1));
}

View file

@ -4,6 +4,7 @@
*/
package mage.abilities.effects.common;
import java.util.Objects;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.DelayedTriggeredAbility;
@ -19,8 +20,6 @@ import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.players.Player;
import java.util.Objects;
/**
*
* @author jeffwadsworth
@ -53,6 +52,9 @@ public class EpicEffect extends OneShotEffect {
if (controller != null) {
StackObject stackObject = game.getStack().getStackObject(source.getId());
Spell spell = (Spell) stackObject;
if (spell == null) {
return false;
}
spell = spell.copySpell(source.getControllerId());
// Remove Epic effect from the spell
Effect epicEffect = null;