* 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

@ -1,16 +1,16 @@
/*
* 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
@ -20,16 +20,16 @@
* 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.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;
@ -51,13 +52,17 @@ import mage.players.Player;
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");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{U}{U}");
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,31 +90,40 @@ class ConundrumSphinxEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Choice cardChoice = new ChoiceImpl();
cardChoice.setChoices(CardRepository.instance.getNames());
for (Player player: game.getPlayers().values()) {
if(player.getLibrary().hasCards()){
cardChoice.clearChoice();
while (!player.choose(Outcome.DrawCard, cardChoice, game) && player.canRespond()) {
if (!player.canRespond()) {
return false;
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());
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()) {
continue Players;
}
}
String cardName = cardChoice.getChoice();
game.informPlayers(sourceObject.getLogName() + ", player: " + player.getLogName() + ", named: [" + cardName + ']');
Card card = player.getLibrary().removeFromTop(game);
if (card != null) {
Cards cards = new CardsImpl(card);
player.revealCards(sourceObject.getIdName(), cards, game);
if (card.getName().equals(cardName)) {
player.moveCards(cards, Zone.HAND, source, game);
} else {
player.putCardsOnBottomOfLibrary(cards, game, source, false);
}
}
}
}
String cardName = cardChoice.getChoice();
game.informPlayers("Conundrum Sphinx, player: " + player.getLogName() + ", named card: [" + cardName + ']');
Card card = player.getLibrary().removeFromTop(game);
Cards cards = new CardsImpl();
cards.add(card);
player.revealCards("Conundrum Sphinx", cards, game);
if (card.getName().equals(cardName)) {
card.moveToZone(Zone.HAND, source.getSourceId(), game, true);
}
else {
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
}
}
return true;
}
return true;
return false;
}
@Override
@ -117,4 +131,4 @@ class ConundrumSphinxEffect extends OneShotEffect {
return new ConundrumSphinxEffect(this);
}
}
}

View file

@ -47,7 +47,7 @@ import mage.target.common.TargetCreatureOrPlayer;
public class Fireball extends CardImpl {
public Fireball(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{X}{R}");
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{X}{R}");
// Fireball deals X damage divided evenly, rounded down, among any number of target creatures and/or players.
// Fireball costs 1 more to cast for each target beyond the first.
@ -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
@ -36,7 +35,7 @@ import java.util.Objects;
*/
public class EpicEffect extends OneShotEffect {
static final String rule = "<br>Epic <i>(For the rest of the game, you can't cast spells. At the beginning of each of your upkeeps for the rest of the game, copy this spell except for its epic ability. If the spell has targets, you may choose new targets for the copy)";
static final String rule = "<br>Epic <i>(For the rest of the game, you can't cast spells. At the beginning of each of your upkeeps for the rest of the game, copy this spell except for its epic ability. If the spell has targets, you may choose new targets for the copy)";
public EpicEffect() {
super(Outcome.Benefit);
@ -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;