Fixed some possible exceptions.

This commit is contained in:
LevelX2 2015-09-13 09:48:35 +02:00
parent a505173854
commit 3d8494edb5
7 changed files with 72 additions and 58 deletions

View file

@ -27,21 +27,24 @@
*/
package mage.sets.avacynrestored;
import mage.constants.*;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardsImpl;
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.game.Game;
import mage.players.Library;
import mage.players.Player;
import mage.target.common.TargetOpponent;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.effects.ContinuousEffect;
import mage.target.targetpointer.FixedTarget;
/**
@ -54,7 +57,6 @@ public class StolenGoods extends CardImpl {
super(ownerId, 78, "Stolen Goods", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{3}{U}");
this.expansionSetCode = "AVR";
// Target opponent exiles cards from the top of his or her library until he or she exiles a nonland card. Until end of turn, you may cast that card without paying its mana cost.
this.getSpellAbility().addEffect(new StolenGoodsEffect());
this.getSpellAbility().addTarget(new TargetOpponent());
@ -96,14 +98,13 @@ class StolenGoodsEffect extends OneShotEffect {
do {
card = library.removeFromTop(game);
if (card != null) {
opponent.moveCardToExileWithInfo(card, source.getSourceId(), sourceObject.getIdName(), source.getSourceId(), game, Zone.LIBRARY, true);
opponent.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
}
} while (library.size() > 0 && card != null && card.getCardType().contains(CardType.LAND));
if (card != null) {
opponent.revealCards("Card to cast", new CardsImpl(card), game);
ContinuousEffect effect = new StolenGoodsCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(card.getId()));
effect.setTargetPointer(new FixedTarget(card.getId(), card.getZoneChangeCounter(game)));
game.addEffect(effect, source);
}
return true;
@ -135,7 +136,8 @@ class StolenGoodsCastFromExileEffect extends AsThoughEffectImpl {
@Override
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
if (getTargetPointer().getFirst(game, source).equals(sourceId) && affectedControllerId.equals(source.getControllerId())) {
if (sourceId != null && sourceId.equals(getTargetPointer().getFirst(game, source))
&& affectedControllerId.equals(source.getControllerId())) {
Card card = game.getCard(sourceId);
if (card != null && game.getState().getZone(sourceId) == Zone.EXILED) {
Player player = game.getPlayer(affectedControllerId);

View file

@ -28,16 +28,15 @@
package mage.sets.exodus;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.DiscardTargetCost;
import mage.abilities.costs.mana.ColoredManaCost;
import mage.abilities.effects.common.search.SearchLibraryPutInHandEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.ColoredManaSymbol;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.CardTypePredicate;
@ -49,9 +48,9 @@ import mage.target.common.TargetCardInLibrary;
* @author jeffwadsworth
*/
public class SurvivalOfTheFittest extends CardImpl {
private static final FilterCard filter = new FilterCard("creature card");
static {
filter.add(new CardTypePredicate(CardType.CREATURE));
}
@ -60,7 +59,6 @@ public class SurvivalOfTheFittest extends CardImpl {
super(ownerId, 129, "Survival of the Fittest", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{1}{G}");
this.expansionSetCode = "EXO";
// {G}, Discard a creature card: Search your library for a creature card, reveal that card, and put it into your hand. Then shuffle your library.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true), new ColoredManaCost(ColoredManaSymbol.G));
ability.addCost(new DiscardTargetCost(new TargetCardInHand(filter)));

View file

@ -29,11 +29,8 @@ package mage.sets.riseoftheeldrazi;
import java.util.List;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.LoyaltyAbility;
import mage.abilities.common.EntersBattlefieldAbility;
@ -41,8 +38,11 @@ import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.CardTypePredicate;
@ -67,7 +67,6 @@ public class SarkhanTheMad extends CardImpl {
this.subtype.add("Sarkhan");
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.LOYALTY.createInstance(7)), false));
this.addAbility(new LoyaltyAbility(new SarkhanTheMadRevealAndDrawEffect(), 0));
Target targetCreature = new TargetCreaturePermanent();
@ -94,29 +93,28 @@ class SarkhanTheMadRevealAndDrawEffect extends OneShotEffect {
private static final String effectText = "Reveal the top card of your library and put it into your hand. {this} deals damage to himself equal to that card's converted mana cost";
SarkhanTheMadRevealAndDrawEffect ( ) {
SarkhanTheMadRevealAndDrawEffect() {
super(Outcome.DrawCard);
staticText = effectText;
}
SarkhanTheMadRevealAndDrawEffect ( SarkhanTheMadRevealAndDrawEffect effect ) {
SarkhanTheMadRevealAndDrawEffect(SarkhanTheMadRevealAndDrawEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null && player.getLibrary().size() > 0) {
Card card = player.getLibrary().removeFromTop(game);
Permanent permanent = game.getPermanent(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
Card card = controller.getLibrary().getFromTop(game);
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (card != null) {
card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
permanent.damage(card.getManaCost().convertedManaCost(), this.getId(), game, false, false);
Cards cards = new CardsImpl();
cards.add(card);
player.revealCards("Sarkhan the Mad", cards, game);
return true;
controller.moveCards(card, null, Zone.HAND, source, game);
sourcePermanent.damage(card.getManaCost().convertedManaCost(), source.getSourceId(), game, false, false);
controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
}
return true;
}
return false;
}
@ -132,19 +130,19 @@ class SarkhanTheMadSacEffect extends OneShotEffect {
private static final String effectText = "Target creature's controller sacrifices it, then that player puts a 5/5 red Dragon creature token with flying onto the battlefield";
SarkhanTheMadSacEffect ( ) {
SarkhanTheMadSacEffect() {
super(Outcome.Sacrifice);
staticText = effectText;
}
SarkhanTheMadSacEffect ( SarkhanTheMadSacEffect effect ) {
SarkhanTheMadSacEffect(SarkhanTheMadSacEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getTargets().getFirstTarget());
if ( permanent != null ) {
if (permanent != null) {
Player player = game.getPlayer(permanent.getControllerId());
permanent.sacrifice(this.getId(), game);
Token dragonToken = new DragonToken();
@ -171,12 +169,12 @@ class SarkhanTheMadDragonDamageEffect extends OneShotEffect {
filter.add(new SubtypePredicate("Dragon"));
}
SarkhanTheMadDragonDamageEffect ( ) {
SarkhanTheMadDragonDamageEffect() {
super(Outcome.Damage);
staticText = effectText;
}
SarkhanTheMadDragonDamageEffect ( SarkhanTheMadDragonDamageEffect effect ) {
SarkhanTheMadDragonDamageEffect(SarkhanTheMadDragonDamageEffect effect) {
super(effect);
}
@ -184,8 +182,8 @@ class SarkhanTheMadDragonDamageEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
List<Permanent> dragons = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
Player player = game.getPlayer(source.getTargets().getFirstTarget());
if ( player != null && dragons != null && !dragons.isEmpty() ) {
for ( Permanent dragon : dragons ) {
if (player != null && dragons != null && !dragons.isEmpty()) {
for (Permanent dragon : dragons) {
player.damage(dragon.getPower().getValue(), dragon.getId(), game, true, false);
}
return true;
@ -202,7 +200,8 @@ class SarkhanTheMadDragonDamageEffect extends OneShotEffect {
}
class DragonToken extends mage.game.permanent.token.DragonToken {
DragonToken ( ) {
DragonToken() {
super();
this.power = new MageInt(5);
this.toughness = new MageInt(5);