mirror of
https://github.com/correl/mage.git
synced 2024-11-16 03:00:12 +00:00
fix NPE when library is empty
This commit is contained in:
parent
1d22d59c42
commit
c38d49358c
1 changed files with 121 additions and 118 deletions
|
@ -29,6 +29,7 @@
|
||||||
package mage.sets.worldwake;
|
package mage.sets.worldwake;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import mage.Constants.CardType;
|
import mage.Constants.CardType;
|
||||||
import mage.Constants.Outcome;
|
import mage.Constants.Outcome;
|
||||||
import mage.Constants.Rarity;
|
import mage.Constants.Rarity;
|
||||||
|
@ -52,161 +53,163 @@ import mage.target.common.TargetCardInHand;
|
||||||
import mage.target.common.TargetCreaturePermanent;
|
import mage.target.common.TargetCreaturePermanent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class JaceTheMindSculptor extends CardImpl<JaceTheMindSculptor> {
|
public class JaceTheMindSculptor extends CardImpl<JaceTheMindSculptor> {
|
||||||
|
|
||||||
|
|
||||||
public JaceTheMindSculptor(UUID ownerId) {
|
public JaceTheMindSculptor(UUID ownerId) {
|
||||||
super(ownerId, 31, "Jace, the Mind Sculptor", Rarity.MYTHIC, new CardType[]{CardType.PLANESWALKER}, "{2}{U}{U}");
|
super(ownerId, 31, "Jace, the Mind Sculptor", Rarity.MYTHIC, new CardType[]{CardType.PLANESWALKER}, "{2}{U}{U}");
|
||||||
this.expansionSetCode = "WWK";
|
this.expansionSetCode = "WWK";
|
||||||
this.subtype.add("Jace");
|
this.subtype.add("Jace");
|
||||||
this.color.setBlue(true);
|
this.color.setBlue(true);
|
||||||
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.LOYALTY.createInstance(3)), ""));
|
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.LOYALTY.createInstance(3)), ""));
|
||||||
|
|
||||||
|
|
||||||
LoyaltyAbility ability1 = new LoyaltyAbility(new JaceTheMindSculptorEffect1(), 2);
|
LoyaltyAbility ability1 = new LoyaltyAbility(new JaceTheMindSculptorEffect1(), 2);
|
||||||
ability1.addTarget(new TargetPlayer());
|
ability1.addTarget(new TargetPlayer());
|
||||||
this.addAbility(ability1);
|
this.addAbility(ability1);
|
||||||
|
|
||||||
LoyaltyAbility ability2 = new LoyaltyAbility(new JaceTheMindSculptorEffect2(), 0);
|
LoyaltyAbility ability2 = new LoyaltyAbility(new JaceTheMindSculptorEffect2(), 0);
|
||||||
this.addAbility(ability2);
|
this.addAbility(ability2);
|
||||||
|
|
||||||
LoyaltyAbility ability3 = new LoyaltyAbility(new ReturnToHandTargetEffect(), -1);
|
LoyaltyAbility ability3 = new LoyaltyAbility(new ReturnToHandTargetEffect(), -1);
|
||||||
ability3.addTarget(new TargetCreaturePermanent());
|
ability3.addTarget(new TargetCreaturePermanent());
|
||||||
this.addAbility(ability3);
|
this.addAbility(ability3);
|
||||||
|
|
||||||
LoyaltyAbility ability4 = new LoyaltyAbility(new JaceTheMindSculptorEffect3(), -12);
|
LoyaltyAbility ability4 = new LoyaltyAbility(new JaceTheMindSculptorEffect3(), -12);
|
||||||
ability4.addTarget(new TargetPlayer());
|
ability4.addTarget(new TargetPlayer());
|
||||||
this.addAbility(ability4);
|
this.addAbility(ability4);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JaceTheMindSculptor(final JaceTheMindSculptor card) {
|
public JaceTheMindSculptor(final JaceTheMindSculptor card) {
|
||||||
super(card);
|
super(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JaceTheMindSculptor copy() {
|
public JaceTheMindSculptor copy() {
|
||||||
return new JaceTheMindSculptor(this);
|
return new JaceTheMindSculptor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class JaceTheMindSculptorEffect1 extends OneShotEffect<JaceTheMindSculptorEffect1> {
|
class JaceTheMindSculptorEffect1 extends OneShotEffect<JaceTheMindSculptorEffect1> {
|
||||||
|
|
||||||
public JaceTheMindSculptorEffect1() {
|
public JaceTheMindSculptorEffect1() {
|
||||||
super(Outcome.Detriment);
|
super(Outcome.Detriment);
|
||||||
staticText = "Look at the top card of target player's library. You may put that card on the bottom of that player's library";
|
staticText = "Look at the top card of target player's library. You may put that card on the bottom of that player's library";
|
||||||
}
|
}
|
||||||
|
|
||||||
public JaceTheMindSculptorEffect1(final JaceTheMindSculptorEffect1 effect) {
|
public JaceTheMindSculptorEffect1(final JaceTheMindSculptorEffect1 effect) {
|
||||||
super(effect);
|
super(effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JaceTheMindSculptorEffect1 copy() {
|
public JaceTheMindSculptorEffect1 copy() {
|
||||||
return new JaceTheMindSculptorEffect1(this);
|
return new JaceTheMindSculptorEffect1(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 player = game.getPlayer(source.getFirstTarget());
|
Player player = game.getPlayer(source.getFirstTarget());
|
||||||
if (controller != null && player != null) {
|
if (controller != null && player != null) {
|
||||||
Cards cards = new CardsImpl();
|
Card c = player.getLibrary().getFromTop(game);
|
||||||
cards.add(player.getLibrary().getFromTop(game));
|
if (c != null) {
|
||||||
controller.lookAtCards("Jace, the Mind Sculptor",cards, game);
|
Cards cards = new CardsImpl();
|
||||||
if (controller.chooseUse(outcome, "Do you wish to put card on the bottom of player's library?", game)) {
|
cards.add(c);
|
||||||
Card card = player.getLibrary().removeFromTop(game);
|
controller.lookAtCards("Jace, the Mind Sculptor", cards, game);
|
||||||
if (card != null) {
|
if (controller.chooseUse(outcome, "Do you wish to put card on the bottom of player's library?", game)) {
|
||||||
card.moveToZone(Zone.LIBRARY, source.getId(), game, false);
|
Card card = player.getLibrary().removeFromTop(game);
|
||||||
}
|
if (card != null) {
|
||||||
}
|
card.moveToZone(Zone.LIBRARY, source.getId(), game, false);
|
||||||
return true;
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class JaceTheMindSculptorEffect2 extends OneShotEffect<JaceTheMindSculptorEffect2> {
|
class JaceTheMindSculptorEffect2 extends OneShotEffect<JaceTheMindSculptorEffect2> {
|
||||||
|
|
||||||
public JaceTheMindSculptorEffect2() {
|
public JaceTheMindSculptorEffect2() {
|
||||||
super(Outcome.DrawCard);
|
super(Outcome.DrawCard);
|
||||||
staticText = "Draw three cards, then put two cards from your hand on top of your library in any order";
|
staticText = "Draw three cards, then put two cards from your hand on top of your library in any order";
|
||||||
}
|
}
|
||||||
|
|
||||||
public JaceTheMindSculptorEffect2(final JaceTheMindSculptorEffect2 effect) {
|
public JaceTheMindSculptorEffect2(final JaceTheMindSculptorEffect2 effect) {
|
||||||
super(effect);
|
super(effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JaceTheMindSculptorEffect2 copy() {
|
public JaceTheMindSculptorEffect2 copy() {
|
||||||
return new JaceTheMindSculptorEffect2(this);
|
return new JaceTheMindSculptorEffect2(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player player = game.getPlayer(source.getControllerId());
|
Player player = game.getPlayer(source.getControllerId());
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.drawCards(3, game);
|
player.drawCards(3, game);
|
||||||
putOnLibrary(player, source, game);
|
putOnLibrary(player, source, game);
|
||||||
putOnLibrary(player, source, game);
|
putOnLibrary(player, source, game);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean putOnLibrary(Player player, Ability source, Game game) {
|
private boolean putOnLibrary(Player player, Ability source, Game game) {
|
||||||
TargetCardInHand target = new TargetCardInHand();
|
TargetCardInHand target = new TargetCardInHand();
|
||||||
target.setRequired(true);
|
target.setRequired(true);
|
||||||
player.chooseTarget(Outcome.ReturnToHand, target, source, game);
|
player.chooseTarget(Outcome.ReturnToHand, target, source, game);
|
||||||
Card card = player.getHand().get(target.getFirstTarget(), game);
|
Card card = player.getHand().get(target.getFirstTarget(), game);
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
player.getHand().remove(card);
|
player.getHand().remove(card);
|
||||||
card.moveToZone(Zone.LIBRARY, source.getId(), game, true);
|
card.moveToZone(Zone.LIBRARY, source.getId(), game, true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class JaceTheMindSculptorEffect3 extends OneShotEffect<JaceTheMindSculptorEffect3> {
|
class JaceTheMindSculptorEffect3 extends OneShotEffect<JaceTheMindSculptorEffect3> {
|
||||||
|
|
||||||
public JaceTheMindSculptorEffect3() {
|
public JaceTheMindSculptorEffect3() {
|
||||||
super(Outcome.DrawCard);
|
super(Outcome.DrawCard);
|
||||||
staticText = "Exile all cards from target player's library, then that player shuffles his or her hand into his or her library";
|
staticText = "Exile all cards from target player's library, then that player shuffles his or her hand into his or her library";
|
||||||
}
|
}
|
||||||
|
|
||||||
public JaceTheMindSculptorEffect3(final JaceTheMindSculptorEffect3 effect) {
|
public JaceTheMindSculptorEffect3(final JaceTheMindSculptorEffect3 effect) {
|
||||||
super(effect);
|
super(effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JaceTheMindSculptorEffect3 copy() {
|
public JaceTheMindSculptorEffect3 copy() {
|
||||||
return new JaceTheMindSculptorEffect3(this);
|
return new JaceTheMindSculptorEffect3(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player player = game.getPlayer(source.getFirstTarget());
|
Player player = game.getPlayer(source.getFirstTarget());
|
||||||
ExileZone exile = game.getExile().getPermanentExile();
|
ExileZone exile = game.getExile().getPermanentExile();
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (player.getLibrary().getFromTop(game) == null)
|
if (player.getLibrary().getFromTop(game) == null)
|
||||||
break;
|
break;
|
||||||
Card card = player.getLibrary().removeFromTop(game);
|
Card card = player.getLibrary().removeFromTop(game);
|
||||||
exile.add(card);
|
exile.add(card);
|
||||||
game.setZone(card.getId(), Zone.EXILED);
|
game.setZone(card.getId(), Zone.EXILED);
|
||||||
}
|
}
|
||||||
for (Card card : player.getHand().getCards(game)) {
|
for (Card card : player.getHand().getCards(game)) {
|
||||||
card.moveToZone(Zone.LIBRARY, source.getId(), game, false);
|
card.moveToZone(Zone.LIBRARY, source.getId(), game, false);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue