* Thoughtpicker Witch - Fixed a bug that could produce a null pointer exception.

This commit is contained in:
LevelX2 2016-11-06 23:18:47 +01:00
parent 618ee3698b
commit 964bf63524

View file

@ -58,7 +58,7 @@ import mage.target.common.TargetOpponent;
public class ThoughtpickerWitch extends CardImpl { public class ThoughtpickerWitch extends CardImpl {
public ThoughtpickerWitch(UUID ownerId, CardSetInfo setInfo) { public ThoughtpickerWitch(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{B}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{B}");
this.subtype.add("Human"); this.subtype.add("Human");
this.subtype.add("Wizard"); this.subtype.add("Wizard");
@ -83,40 +83,36 @@ public class ThoughtpickerWitch extends CardImpl {
} }
class ThoughtpickerWitchEffect extends OneShotEffect { class ThoughtpickerWitchEffect extends OneShotEffect {
ThoughtpickerWitchEffect() { ThoughtpickerWitchEffect() {
super(Outcome.Exile); super(Outcome.Exile);
this.staticText = "Look at the top two cards of target opponent's library, then exile one of them"; this.staticText = "Look at the top two cards of target opponent's library, then exile one of them";
} }
ThoughtpickerWitchEffect(final ThoughtpickerWitchEffect effect) { ThoughtpickerWitchEffect(final ThoughtpickerWitchEffect effect) {
super(effect); super(effect);
} }
@Override @Override
public ThoughtpickerWitchEffect copy() { public ThoughtpickerWitchEffect copy() {
return new ThoughtpickerWitchEffect(this); return new ThoughtpickerWitchEffect(this);
} }
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source)); Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (controller != null && opponent != null) { if (controller != null && opponent != null) {
Cards cards = new CardsImpl(); Cards cards = new CardsImpl();
int numLooked = Math.min(2, opponent.getLibrary().size()); cards.addAll(opponent.getLibrary().getTopCards(game, 2));
if (numLooked > 0) { if (cards.size() > 0) {
for (int i = 0; i < numLooked; i++) {
cards.add(opponent.getLibrary().removeFromTop(game));
}
TargetCard target = new TargetCardInLibrary(new FilterCard("card to exile")); TargetCard target = new TargetCardInLibrary(new FilterCard("card to exile"));
controller.choose(Outcome.Exile, cards, target, game); if (controller.choose(Outcome.Exile, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game); Card card = cards.get(target.getFirstTarget(), game);
cards.remove(card); if (card != null) {
opponent.moveCardToExileWithInfo(card, null, "", source.getSourceId(), game, Zone.LIBRARY, true); cards.remove(card);
if (cards.size() == 1) { opponent.moveCards(card, Zone.EXILED, source, game);
card = cards.get(cards.iterator().next(), game); }
opponent.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.LIBRARY, true, false);
} }
} }
return true; return true;