Fixed NPE errors for some cards (#5471)

This commit is contained in:
Oleg Agafonov 2019-01-02 20:06:01 +04:00
parent 6e2b6aa7a3
commit e9f9b05141
12 changed files with 69 additions and 142 deletions

View file

@ -1,28 +1,12 @@
package mage.player.ai;
import java.io.File;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.SpellAbility;
import mage.abilities.common.PassAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.SearchEffect;
import mage.abilities.keyword.DeathtouchAbility;
import mage.abilities.keyword.DoubleStrikeAbility;
import mage.abilities.keyword.ExaltedAbility;
import mage.abilities.keyword.FirstStrikeAbility;
import mage.abilities.keyword.FlyingAbility;
import mage.abilities.keyword.IndestructibleAbility;
import mage.abilities.keyword.ReachAbility;
import mage.abilities.keyword.*;
import mage.cards.Card;
import mage.cards.Cards;
import mage.choices.Choice;
@ -49,8 +33,11 @@ import mage.target.Targets;
import mage.util.RandomUtil;
import org.apache.log4j.Logger;
import java.io.File;
import java.util.*;
import java.util.concurrent.*;
/**
*
* @author nantuko
*/
public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
@ -180,10 +167,9 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
if (!suggested.isEmpty() && !(ability instanceof PassAbility)) {
Iterator<String> it = suggested.iterator();
while (it.hasNext()) {
Card card = game.getCard(ability.getSourceId());
String action = it.next();
logger.info("Suggested action=" + action + ";card=" + card);
if (action.equals(card.getName())) {
Card card = game.getCard(ability.getSourceId());
if (card != null && action.equals(card.getName())) {
logger.info("-> removed from suggested=" + action);
it.remove();
}
@ -930,7 +916,7 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
String line = scanner.nextLine();
if (line.startsWith("cast:")
|| line.startsWith("play:")) {
suggested.add(line.substring(5, line.length()));
suggested.add(line.substring(5));
}
}
System.out.println("suggested::");
@ -953,7 +939,7 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
if (action != null
&& (action.startsWith("cast:")
|| action.startsWith("play:"))) {
suggested.add(action.substring(5, action.length()));
suggested.add(action.substring(5));
}
}

View file

@ -1,7 +1,5 @@
package mage.cards.c;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.DelayedTriggeredAbility;
@ -27,8 +25,9 @@ import mage.game.stack.Spell;
import mage.target.common.TargetCreaturePermanent;
import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public final class CherishedHatchling extends CardImpl {
@ -113,48 +112,3 @@ class CherishedHatchlingTriggeredAbility extends DelayedTriggeredAbility {
return "and whenever you cast a Dinosaur spell this turn, " + super.getRule();
}
}
//class CherishedHatchlingGainAbilityEffect extends ContinuousEffectImpl {
//
// private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("another creature");
//
// static {
// filter.add(new AnotherPredicate());
// }
// private Ability abilityToAdd = null;
// private Card relatedCard = null;
//
// public CherishedHatchlingGainAbilityEffect() {
// super(Duration.EndOfTurn, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
// staticText = "it gains \"When this creature enters the battlefield, you may have it fight another target creature.\"";
// }
//
// public CherishedHatchlingGainAbilityEffect(final CherishedHatchlingGainAbilityEffect effect) {
// super(effect);
// this.abilityToAdd = effect.abilityToAdd;
// this.relatedCard = effect.relatedCard;
// }
//
// @Override
// public CherishedHatchlingGainAbilityEffect copy() {
// return new CherishedHatchlingGainAbilityEffect(this);
// }
//
// @Override
// public boolean apply(Game game, Ability source) {
// if (relatedCard == null) {
// Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source));
// if (spell != null) {
// relatedCard = game.getCard(spell.getSourceId());
// Effect effect = new FightTargetSourceEffect();
// effect.setText("you may have it fight another target creature");
// abilityToAdd = new EntersBattlefieldTriggeredAbility(effect, true);
// abilityToAdd.addTarget(new TargetCreaturePermanent(filter));
// }
// }
// if (relatedCard != null) {
// game.getState().addOtherAbility(relatedCard, abilityToAdd, false);
// }
// return true;
// }
//}

View file

@ -1,9 +1,5 @@
package mage.cards.c;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
@ -23,8 +19,11 @@ import mage.players.Player;
import mage.target.common.TargetPermanentOrSuspendedCard;
import mage.target.targetpointer.FixedTarget;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
*
* @author spjspj
*/
public final class Clockspinning extends CardImpl {
@ -133,7 +132,6 @@ class ClockspinningAddOrRemoveCounterEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getFirstTarget());
Card card = game.getCard(source.getFirstTarget());
if (player != null && permanent != null) {
if (player.chooseUse(Outcome.Neutral, "Do you want to to remove a counter?", source, game)) {
@ -151,6 +149,8 @@ class ClockspinningAddOrRemoveCounterEffect extends OneShotEffect {
}
return true;
}
Card card = game.getCard(source.getFirstTarget());
if (player != null && card != null) {
if (player.chooseUse(Outcome.Neutral, "Do you want to to remove a counter?", source, game)) {
Counter counter = selectCounterType(game, source, card);

View file

@ -1,8 +1,5 @@
package mage.cards.c;
import java.util.List;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DiesTriggeredAbility;
@ -20,6 +17,9 @@ import mage.players.Player;
import mage.target.TargetCard;
import mage.util.CardUtil;
import java.util.List;
import java.util.UUID;
/**
* @author nantuko
*/
@ -117,9 +117,11 @@ class CloneShellDiesEffect extends OneShotEffect {
List<UUID> imprinted = permanent.getImprinted();
if (!imprinted.isEmpty()) {
Card imprintedCard = game.getCard(imprinted.get(0));
imprintedCard.setFaceDown(false, game);
if (imprintedCard.isCreature()) {
controller.moveCards(imprintedCard, Zone.BATTLEFIELD, source, game);
if (imprinted != null) {
imprintedCard.setFaceDown(false, game);
if (imprintedCard.isCreature()) {
controller.moveCards(imprintedCard, Zone.BATTLEFIELD, source, game);
}
}
}
}

View file

@ -17,7 +17,6 @@ import java.util.Set;
import java.util.UUID;
/**
*
* @author jeffwadsworth
*/
public final class CommuneWithLava extends CardImpl {
@ -60,7 +59,7 @@ class CommuneWithLavaEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Card sourceCard = game.getCard(source.getSourceId());
if (controller != null) {
if (controller != null && sourceCard != null) {
int amount = source.getManaCostsToPay().getX();
Set<Card> cards = controller.getLibrary().getTopCards(game, amount);
controller.moveCardsToExile(cards, source, game, true, CardUtil.getCardExileZoneId(game, source), sourceCard.getIdName());
@ -105,9 +104,7 @@ class CommuneWithLavaMayPlayEffect extends AsThoughEffectImpl {
@Override
public boolean isInactive(Ability source, Game game) {
if (castOnTurn != game.getTurnNum() && game.getPhase().getStep().getType() == PhaseStep.END_TURN) {
if (game.isActivePlayer(source.getControllerId())) {
return true;
}
return game.isActivePlayer(source.getControllerId());
}
return false;
}

View file

@ -1,9 +1,5 @@
package mage.cards.c;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
@ -22,8 +18,11 @@ import mage.game.stack.StackObject;
import mage.players.Player;
import mage.util.SubTypeList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
/**
*
* @author anonymous
*/
public final class Conspiracy extends CardImpl {
@ -72,14 +71,14 @@ class ConspiracyEffect extends ContinuousEffectImpl {
// in graveyard
for (UUID cardId : controller.getGraveyard()) {
Card card = game.getCard(cardId);
if (card.isCreature()) {
if (card != null && card.isCreature()) {
setCreatureSubtype(card, subType, game);
}
}
// on Hand
for (UUID cardId : controller.getHand()) {
Card card = game.getCard(cardId);
if (card.isCreature()) {
if (card != null && card.isCreature()) {
setCreatureSubtype(card, subType, game);
}
}
@ -99,13 +98,13 @@ class ConspiracyEffect extends ContinuousEffectImpl {
for (UUID commanderId : controller.getCommandersIds()) {
if (game.getState().getZone(commanderId) == Zone.COMMAND) {
Card card = game.getCard(commanderId);
if (card.isCreature()) {
if (card != null && card.isCreature()) {
setCreatureSubtype(card, subType, game);
}
}
}
// creature spells you control
for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext();) {
for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext(); ) {
StackObject stackObject = iterator.next();
if (stackObject instanceof Spell
&& stackObject.isControlledBy(source.getControllerId())

View file

@ -1,6 +1,5 @@
package mage.cards.c;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
@ -10,19 +9,16 @@ import mage.abilities.keyword.TransformAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.constants.*;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.players.Player;
import mage.watchers.common.CreatureWasCastWatcher;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public final class ContainmentPriest extends CardImpl {
@ -94,16 +90,14 @@ class ContainmentPriestReplacementEffect extends ReplacementEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (((ZoneChangeEvent) event).getToZone() == Zone.BATTLEFIELD) {
Card card = game.getCard(event.getTargetId());
Object entersTransformed = game.getState().getValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + event.getTargetId());
if (entersTransformed instanceof Boolean && (Boolean) entersTransformed && card.getSecondCardFace() != null) {
Card card = game.getCard(event.getTargetId());
if (card != null && entersTransformed instanceof Boolean && (Boolean) entersTransformed && card.getSecondCardFace() != null) {
card = card.getSecondCardFace();
}
if (card.isCreature()) { // TODO: Bestow Card cast as Enchantment probably not handled correctly
if (card != null && card.isCreature()) { // TODO: Bestow Card cast as Enchantment probably not handled correctly
CreatureWasCastWatcher watcher = (CreatureWasCastWatcher) game.getState().getWatchers().get(CreatureWasCastWatcher.class.getSimpleName());
if (watcher != null && !watcher.wasCreatureCastThisTurn(event.getTargetId())) {
return true;
}
return watcher != null && !watcher.wasCreatureCastThisTurn(event.getTargetId());
}
}
return false;

View file

@ -93,9 +93,7 @@ class CouncilOfTheAbsoluteReplacementEffect extends ContinuousRuleModifyingEffec
if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
MageObject object = game.getObject(event.getSourceId());
String needName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (object != null && CardUtil.haveSameNames(object.getName(), needName)) {
return true;
}
return object != null && CardUtil.haveSameNames(object.getName(), needName);
}
return false;
}
@ -123,8 +121,10 @@ class CouncilOfTheAbsoluteCostReductionEffect extends CostModificationEffectImpl
if ((abilityToModify instanceof SpellAbility)
&& abilityToModify.isControlledBy(source.getControllerId())) {
Card card = game.getCard(abilityToModify.getSourceId());
String needName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
return CardUtil.haveSameNames(card.getName(), needName);
if (card != null) {
String needName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
return CardUtil.haveSameNames(card.getName(), needName);
}
}
return false;
}

View file

@ -1,7 +1,5 @@
package mage.cards.c;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
@ -21,8 +19,9 @@ import mage.game.permanent.Permanent;
import mage.target.TargetPermanent;
import mage.target.common.TargetCardInYourGraveyard;
import java.util.UUID;
/**
*
* @author jeffwadsworth
*/
public final class CruelRevival extends CardImpl {
@ -37,7 +36,7 @@ public final class CruelRevival extends CardImpl {
}
public CruelRevival(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{4}{B}");
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{4}{B}");
// Destroy target non-Zombie creature. It can't be regenerated. Return up to one target Zombie card from your graveyard to your hand.
@ -70,10 +69,11 @@ class CruelRevivalEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Permanent targetDestroy = game.getPermanent(source.getFirstTarget());
Card targetRetrieve = game.getCard(source.getTargets().get(1).getFirstTarget());
if (targetDestroy != null) {
targetDestroy.destroy(source.getSourceId(), game, true);
}
Card targetRetrieve = game.getCard(source.getTargets().get(1).getFirstTarget());
if (targetRetrieve != null) {
targetRetrieve.moveToZone(Zone.HAND, source.getSourceId(), game, true);
}

View file

@ -1,7 +1,5 @@
package mage.cards.c;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
@ -21,8 +19,9 @@ import mage.players.Player;
import mage.target.common.TargetCardInYourGraveyard;
import mage.target.common.TargetOpponent;
import java.util.UUID;
/**
*
* @author North
*/
public final class CruelUltimatum extends CardImpl {
@ -80,7 +79,8 @@ class CruelUltimatumEffect extends OneShotEffect {
if (card == null) {
return false;
}
controller.moveCards(card, Zone.HAND, source, game);
return controller.moveCards(card, Zone.HAND, source, game);
}
return true;
}

View file

@ -27,7 +27,6 @@
*/
package mage.cards.d;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.SpecialAction;
@ -39,11 +38,7 @@ import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.constants.*;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -51,8 +46,9 @@ import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetControlledPermanent;
import java.util.UUID;
/**
*
* @author jeffwadsworth
*/
public class DampingEngine extends CardImpl {
@ -119,8 +115,7 @@ class DampingEngineEffect extends ContinuousRuleModifyingEffectImpl {
Player player = game.getPlayer(event.getPlayerId());
Permanent dampingEngine = game.getPermanent(source.getSourceId());
final Card card = game.getCard(event.getSourceId());
if (player != null
|| card != null) {
if (player != null || card != null) {
// check type of spell
if (card.isCreature()
|| card.isArtifact()
@ -129,13 +124,10 @@ class DampingEngineEffect extends ContinuousRuleModifyingEffectImpl {
// check to see if the player has more permanents
if (new ControlsMorePermanentsThanEachOtherPlayer(player).apply(game, source)) {
// check to see if the player choose to ignore the effect
if (game.getState().getValue("ignoreEffect") != null
&& dampingEngine != null
&& game.getState().getValue("ignoreEffect").equals
(dampingEngine.getId() + "ignoreEffect" + game.getState().getPriorityPlayerId() + game.getState().getTurnNum())) {
return false;
}
return true;
return game.getState().getValue("ignoreEffect") == null
|| dampingEngine == null
|| !game.getState().getValue("ignoreEffect").equals
(dampingEngine.getId() + "ignoreEffect" + game.getState().getPriorityPlayerId() + game.getState().getTurnNum());
}
}
}

View file

@ -1,4 +1,3 @@
package mage.abilities.keyword;
import mage.MageObjectReference;
@ -84,7 +83,11 @@ class CascadeEffect extends OneShotEffect {
return false;
}
ExileZone exile = game.getExile().createZone(source.getSourceId(), controller.getName() + " Cascade");
int sourceCost = game.getCard(source.getSourceId()).getConvertedManaCost();
card = game.getCard(source.getSourceId());
if (card == null) {
return false;
}
int sourceCost = card.getConvertedManaCost();
do {
card = controller.getLibrary().getFromTop(game);
if (card == null) {