mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
fixed NPE for LookLibraryControllerEffect
This commit is contained in:
parent
b31c23d686
commit
053c630b3c
1 changed files with 91 additions and 96 deletions
|
@ -1,31 +1,30 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are
|
* Redistribution and use in source and binary forms, with or without modification, are
|
||||||
* permitted provided that the following conditions are met:
|
* permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
* conditions and the following disclaimer.
|
* conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
* 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
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
* provided with the distribution.
|
* provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
* 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
|
* 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
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* 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
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* The views and conclusions contained in the software and documentation are those of the
|
* 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
|
* authors and should not be interpreted as representing official policies, either expressed
|
||||||
* or implied, of BetaSteward_at_googlemail.com.
|
* or implied, of BetaSteward_at_googlemail.com.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package mage.abilities.effects.common;
|
package mage.abilities.effects.common;
|
||||||
|
|
||||||
import mage.Constants;
|
import mage.Constants;
|
||||||
|
@ -55,63 +54,64 @@ public class LookLibraryControllerEffect extends OneShotEffect<LookLibraryContro
|
||||||
protected DynamicValue numberOfCards;
|
protected DynamicValue numberOfCards;
|
||||||
protected boolean mayShuffleAfter = false;
|
protected boolean mayShuffleAfter = false;
|
||||||
protected boolean putOnTop = true; // if false on put back on bottom of library
|
protected boolean putOnTop = true; // if false on put back on bottom of library
|
||||||
|
|
||||||
public LookLibraryControllerEffect() {
|
public LookLibraryControllerEffect() {
|
||||||
this(1);
|
this(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LookLibraryControllerEffect(int numberOfCards) {
|
public LookLibraryControllerEffect(int numberOfCards) {
|
||||||
this(numberOfCards, false, true);
|
this(numberOfCards, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LookLibraryControllerEffect(DynamicValue numberOfCards) {
|
public LookLibraryControllerEffect(DynamicValue numberOfCards) {
|
||||||
this(numberOfCards, false, true);
|
this(numberOfCards, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LookLibraryControllerEffect(int numberOfCards, boolean mayShuffleAfter) {
|
public LookLibraryControllerEffect(int numberOfCards, boolean mayShuffleAfter) {
|
||||||
this(numberOfCards, mayShuffleAfter, true);
|
this(numberOfCards, mayShuffleAfter, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LookLibraryControllerEffect(int numberOfCards, boolean mayShuffleAfter, boolean putOnTop) {
|
public LookLibraryControllerEffect(int numberOfCards, boolean mayShuffleAfter, boolean putOnTop) {
|
||||||
this(new StaticValue(numberOfCards), mayShuffleAfter, putOnTop);
|
this(new StaticValue(numberOfCards), mayShuffleAfter, putOnTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LookLibraryControllerEffect(DynamicValue numberOfCards, boolean mayShuffleAfter, boolean putOnTop) {
|
public LookLibraryControllerEffect(DynamicValue numberOfCards, boolean mayShuffleAfter, boolean putOnTop) {
|
||||||
super(Outcome.Benefit);
|
super(Outcome.Benefit);
|
||||||
this.numberOfCards = numberOfCards;
|
this.numberOfCards = numberOfCards;
|
||||||
this.mayShuffleAfter = mayShuffleAfter;
|
this.mayShuffleAfter = mayShuffleAfter;
|
||||||
this.putOnTop = putOnTop;
|
this.putOnTop = putOnTop;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LookLibraryControllerEffect(final LookLibraryControllerEffect effect) {
|
public LookLibraryControllerEffect(final LookLibraryControllerEffect effect) {
|
||||||
super(effect);
|
super(effect);
|
||||||
this.numberOfCards = effect.numberOfCards.clone();
|
this.numberOfCards = effect.numberOfCards.clone();
|
||||||
this.mayShuffleAfter = effect.mayShuffleAfter;
|
this.mayShuffleAfter = effect.mayShuffleAfter;
|
||||||
this.putOnTop = effect.putOnTop;
|
this.putOnTop = effect.putOnTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LookLibraryControllerEffect copy() {
|
public LookLibraryControllerEffect copy() {
|
||||||
return new LookLibraryControllerEffect(this);
|
return new LookLibraryControllerEffect(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
String windowName ="Reveal";
|
String windowName = "Reveal";
|
||||||
|
|
||||||
if (source instanceof SpellAbility) {
|
if (source instanceof SpellAbility) {
|
||||||
Card sourceCard = game.getCard(source.getSourceId());
|
Card sourceCard = game.getCard(source.getSourceId());
|
||||||
if (sourceCard != null)
|
if (sourceCard != null) {
|
||||||
windowName = sourceCard.getName();
|
windowName = sourceCard.getName();
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
|
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
|
||||||
if (sourcePermanent != null)
|
if (sourcePermanent != null) {
|
||||||
windowName = sourcePermanent.getName();
|
windowName = sourcePermanent.getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = game.getPlayer(source.getControllerId());
|
Player player = game.getPlayer(source.getControllerId());
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -131,34 +131,27 @@ public class LookLibraryControllerEffect extends OneShotEffect<LookLibraryContro
|
||||||
player.lookAtCards(windowName, cards, game);
|
player.lookAtCards(windowName, cards, game);
|
||||||
|
|
||||||
this.actionWithSelectedCards(cards, game, source, windowName);
|
this.actionWithSelectedCards(cards, game, source, windowName);
|
||||||
|
|
||||||
this.putCardsBack(source, player, cards, game);
|
this.putCardsBack(source, player, cards, game);
|
||||||
|
|
||||||
this.mayShuffle(player, game);
|
this.mayShuffle(player, game);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param card
|
|
||||||
* @param game
|
|
||||||
* @param source
|
|
||||||
*/
|
|
||||||
protected void cardLooked(Card card, Game game, Ability source) {
|
protected void cardLooked(Card card, Game game, Ability source) {
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void actionWithSelectedCards(Cards cards, Game game, Ability source, String windowName) {
|
protected void actionWithSelectedCards(Cards cards, Game game, Ability source, String windowName) {
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put the rest of the cards back to library
|
* Put the rest of the cards back to library
|
||||||
*
|
*
|
||||||
* @param source
|
* @param source
|
||||||
* @param player
|
* @param player
|
||||||
* @param cards
|
* @param cards
|
||||||
* @param game
|
* @param game
|
||||||
*/
|
*/
|
||||||
protected void putCardsBack(Ability source, Player player, Cards cards, Game game) {
|
protected void putCardsBack(Ability source, Player player, Cards cards, Game game) {
|
||||||
TargetCard target = new TargetCard(Zone.PICK, new FilterCard(this.getPutBackText()));
|
TargetCard target = new TargetCard(Zone.PICK, new FilterCard(this.getPutBackText()));
|
||||||
|
@ -180,40 +173,43 @@ public class LookLibraryControllerEffect extends OneShotEffect<LookLibraryContro
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check to shuffle library if allowed
|
* Check to shuffle library if allowed
|
||||||
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param game
|
* @param game
|
||||||
*/
|
*/
|
||||||
protected void mayShuffle(Player player, Game game) {
|
protected void mayShuffle(Player player, Game game) {
|
||||||
if (this.mayShuffleAfter) {
|
if (this.mayShuffleAfter && player.chooseUse(Constants.Outcome.Benefit, "Shuffle you library?", game)) {
|
||||||
if (player.chooseUse(Constants.Outcome.Benefit, "Shuffle you library?", game)) {
|
player.shuffleLibrary(game);
|
||||||
player.shuffleLibrary(game);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getPutBackText() {
|
protected String getPutBackText() {
|
||||||
StringBuilder sb = new StringBuilder("card to put ");
|
StringBuilder sb = new StringBuilder("card to put ");
|
||||||
if (putOnTop)
|
if (putOnTop) {
|
||||||
sb.append("on your library (last chosen will be on top)");
|
sb.append("on your library (last chosen will be on top)");
|
||||||
else
|
} else {
|
||||||
sb.append("on bottom of your library (last chosen will be on bottom)");
|
sb.append("on bottom of your library (last chosen will be on bottom)");
|
||||||
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getText(Mode mode) {
|
public String getText(Mode mode) {
|
||||||
return setText(mode, "");
|
return setText(mode, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String setText(Mode mode, String middleText) {
|
public String setText(Mode mode, String middleText) {
|
||||||
int numberLook = numberOfCards.calculate(null, null);
|
int numberLook;
|
||||||
// int numberPick = numberToPick.calculate(null, null) ;
|
try {
|
||||||
|
numberLook = Integer.parseInt(numberOfCards.toString());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
numberLook = 0;
|
||||||
|
}
|
||||||
StringBuilder sb = new StringBuilder("Look at the top ");
|
StringBuilder sb = new StringBuilder("Look at the top ");
|
||||||
switch(numberLook) {
|
switch (numberLook) {
|
||||||
case 0:
|
case 0:
|
||||||
sb.append(" X ");
|
sb.append(" X ");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
sb.append("card ");
|
sb.append("card ");
|
||||||
break;
|
break;
|
||||||
|
@ -233,26 +229,25 @@ public class LookLibraryControllerEffect extends OneShotEffect<LookLibraryContro
|
||||||
sb.append(numberLook);
|
sb.append(numberLook);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (numberLook != 1)
|
if (numberLook != 1) {
|
||||||
sb.append(" cards ");
|
sb.append(" cards ");
|
||||||
|
}
|
||||||
|
|
||||||
sb.append("of your Library");
|
sb.append("of your Library");
|
||||||
if (numberLook == 0)
|
if (numberLook == 0) {
|
||||||
sb.append(", where {X} is the number of cards ").append(numberOfCards.getMessage());
|
sb.append(", where {X} is the number of cards ").append(numberOfCards.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!middleText.isEmpty()) {
|
if (!middleText.isEmpty()) {
|
||||||
sb.append(middleText);
|
sb.append(middleText);
|
||||||
|
} else if (numberLook > 1) {
|
||||||
|
sb.append(", then put them back in any order");
|
||||||
}
|
}
|
||||||
else {
|
if (this.mayShuffleAfter) {
|
||||||
if (numberLook > 1)
|
|
||||||
sb.append(", then put them back in any order");
|
|
||||||
}
|
|
||||||
if (this.mayShuffleAfter)
|
|
||||||
sb.append(". You may shuffle your library");
|
sb.append(". You may shuffle your library");
|
||||||
|
}
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue