Fixed NPE errors for some cards (#5471)

This commit is contained in:
Oleg Agafonov 2018-12-23 20:24:20 +04:00
parent e75e2324c7
commit d36cca02aa
7 changed files with 91 additions and 127 deletions

View file

@ -1,7 +1,5 @@
package mage.cards.a; package mage.cards.a;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
@ -21,8 +19,9 @@ import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.target.TargetPlayer; import mage.target.TargetPlayer;
import java.util.UUID;
/** /**
*
* @author Styxo * @author Styxo
*/ */
public final class AAT1 extends CardImpl { public final class AAT1 extends CardImpl {
@ -74,7 +73,8 @@ public final class AAT1 extends CardImpl {
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
Card card = game.getCard(event.getTargetId()); Card card = game.getCard(event.getTargetId());
if (event.getPlayerId().equals(game.getControllerId(sourceId)) if (card != null
&& event.getPlayerId().equals(game.getControllerId(sourceId))
&& card.isCreature() && card.isCreature()
&& game.getState().getZone(card.getId()) == Zone.GRAVEYARD && game.getState().getZone(card.getId()) == Zone.GRAVEYARD
&& event.getData().equals("repair")) { && event.getData().equals("repair")) {

View file

@ -1,7 +1,5 @@
package mage.cards.a; package mage.cards.a;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.common.SourceIsSpellCondition; import mage.abilities.condition.common.SourceIsSpellCondition;
@ -17,6 +15,8 @@ import mage.filter.predicate.mageobject.ConvertedManaCostPredicate;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import java.util.UUID;
/** /**
* 10/4/2004 The mana cost of the creatures being cast is still the stated cost on the card, * 10/4/2004 The mana cost of the creatures being cast is still the stated cost on the card,
* even though you did not pay the cost. * even though you did not pay the cost.
@ -111,46 +111,3 @@ class AlurenRuleEffect extends ContinuousEffectImpl {
return layer == Layer.RulesEffects; return layer == Layer.RulesEffects;
} }
} }
//class AlurenEffect extends CostModificationEffectImpl {
//
// AlurenEffect() {
// super(Duration.WhileOnBattlefield, Outcome.PlayForFree, CostModificationType.SET_COST);
// this.staticText = "Any player may play creature cards with converted mana cost 3 or less without paying their mana cost";
// }
//
// AlurenEffect(final AlurenEffect effect) {
// super(effect);
// }
//
// @Override
// public boolean apply(Game game, Ability source, Ability abilityToModify) {
// SpellAbility spellAbility = (SpellAbility) abilityToModify;
// spellAbility.getManaCostsToPay().clear();
// return true;
// }
//
// @Override
// public boolean applies(Ability abilityToModify, Ability source, Game game) {
// if (abilityToModify instanceof SpellAbility) {
// Card sourceCard = game.getCard(abilityToModify.getSourceId());
// StackObject stackObject = game.getStack().getStackObject(abilityToModify.getSourceId());
// if (stackObject != null && stackObject instanceof Spell) {
// if (sourceCard != null && sourceCard.isCreature() && sourceCard.getConvertedManaCost() <= 3) {
// Player player = game.getPlayer(stackObject.getControllerId());
// String message = "Cast " + sourceCard.getName() + " without paying its mana costs?";
// if (player != null &&
// (CardUtil.isCheckPlayableMode(abilityToModify) || player.chooseUse(outcome, message, game))) {
// return true;
// }
// }
// }
// }
// return false;
// }
//
// @Override
// public AlurenEffect copy() {
// return new AlurenEffect(this);
// }
//}

View file

@ -1,9 +1,5 @@
package mage.cards.a; package mage.cards.a;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
@ -20,8 +16,11 @@ import mage.game.stack.Spell;
import mage.game.stack.StackObject; import mage.game.stack.StackObject;
import mage.players.Player; import mage.players.Player;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
/** /**
*
* @author TheElk801 * @author TheElk801
*/ */
public final class ArcaneAdaptation extends CardImpl { public final class ArcaneAdaptation extends CardImpl {
@ -70,14 +69,14 @@ class ConspyEffect extends ContinuousEffectImpl {
// in graveyard // in graveyard
for (UUID cardId : controller.getGraveyard()) { for (UUID cardId : controller.getGraveyard()) {
Card card = game.getCard(cardId); Card card = game.getCard(cardId);
if (card.isCreature() && !card.hasSubtype(subType, game)) { if (card != null && card.isCreature() && !card.hasSubtype(subType, game)) {
game.getState().getCreateCardAttribute(card, game).getSubtype().add(subType); game.getState().getCreateCardAttribute(card, game).getSubtype().add(subType);
} }
} }
// on Hand // on Hand
for (UUID cardId : controller.getHand()) { for (UUID cardId : controller.getHand()) {
Card card = game.getCard(cardId); Card card = game.getCard(cardId);
if (card.isCreature() && !card.hasSubtype(subType, game)) { if (card != null && card.isCreature() && !card.hasSubtype(subType, game)) {
game.getState().getCreateCardAttribute(card, game).getSubtype().add(subType); game.getState().getCreateCardAttribute(card, game).getSubtype().add(subType);
} }
} }
@ -97,7 +96,7 @@ class ConspyEffect extends ContinuousEffectImpl {
for (UUID commanderId : controller.getCommandersIds()) { for (UUID commanderId : controller.getCommandersIds()) {
if (game.getState().getZone(commanderId) == Zone.COMMAND) { if (game.getState().getZone(commanderId) == Zone.COMMAND) {
Card card = game.getCard(commanderId); Card card = game.getCard(commanderId);
if (card.isCreature() && !card.hasSubtype(subType, game)) { if (card != null && card.isCreature() && !card.hasSubtype(subType, game)) {
game.getState().getCreateCardAttribute(card, game).getSubtype().add(subType); game.getState().getCreateCardAttribute(card, game).getSubtype().add(subType);
} }
} }

View file

@ -1,4 +1,3 @@
package mage.cards.a; package mage.cards.a;
import mage.MageInt; import mage.MageInt;
@ -97,10 +96,11 @@ class ArcaneArtisanCreateTokenEffect extends OneShotEffect {
return false; return false;
} }
Card card = game.getCard(target.getFirstTarget()); Card card = game.getCard(target.getFirstTarget());
player.moveCards(card, Zone.EXILED, source, game); if (!player.moveCards(card, Zone.EXILED, source, game)) {
if (!card.isCreature()) {
return false; return false;
} }
if (card.isCreature()) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(player.getId()); CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(player.getId());
effect.setTargetPointer(new FixedTarget(card.getId(), game)); effect.setTargetPointer(new FixedTarget(card.getId(), game));
effect.apply(game, source); effect.apply(game, source);
@ -117,6 +117,8 @@ class ArcaneArtisanCreateTokenEffect extends OneShotEffect {
} }
} }
game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated); game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated);
}
return true; return true;
} }
} }

View file

@ -1,7 +1,5 @@
package mage.cards.b; package mage.cards.b;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
@ -26,6 +24,8 @@ import mage.players.Player;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
import mage.target.targetpointer.FixedTarget; import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
/** /**
* 10/4/2004: If the creature regenerates, the fuse counters are still removed and * 10/4/2004: If the creature regenerates, the fuse counters are still removed and
* the four damage is still dealt. * the four damage is still dealt.
@ -150,6 +150,7 @@ class BombSquadDamgeEffect extends OneShotEffect {
class BombSquadBeginningEffect extends OneShotEffect { class BombSquadBeginningEffect extends OneShotEffect {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with a fuse counter on it"); private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with a fuse counter on it");
static { static {
filter.add(new CounterPredicate(CounterType.FUSE)); filter.add(new CounterPredicate(CounterType.FUSE));
} }
@ -171,6 +172,9 @@ class BombSquadBeginningEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId()); Card card = game.getCard(source.getSourceId());
if (card == null) {
return false;
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) { for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
permanent.addCounters(CounterType.FUSE.createInstance(), source, game); permanent.addCounters(CounterType.FUSE.createInstance(), source, game);

View file

@ -1,9 +1,5 @@
package mage.cards.b; package mage.cards.b;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -22,8 +18,11 @@ import mage.target.Target;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import mage.target.common.TargetDiscard; import mage.target.common.TargetDiscard;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/** /**
*
* @author fireshoes * @author fireshoes
*/ */
public final class BorderlandExplorer extends CardImpl { public final class BorderlandExplorer extends CardImpl {
@ -127,8 +126,9 @@ class BorderlandExplorerEffect extends OneShotEffect {
Cards cardsPlayer = cardsToReveal.get(playerId); Cards cardsPlayer = cardsToReveal.get(playerId);
if (cardsPlayer != null) { if (cardsPlayer != null) {
for (UUID cardId : cardsPlayer) { for (UUID cardId : cardsPlayer) {
Cards cards = new CardsImpl(game.getCard(cardId));
Card card = game.getCard(cardId); Card card = game.getCard(cardId);
Cards cards = new CardsImpl(game.getCard(cardId));
if (card != null && !cards.isEmpty()) {
player.revealCards(sourceObject.getIdName() + " (" + player.getName() + ')', cards, game); player.revealCards(sourceObject.getIdName() + " (" + player.getName() + ')', cards, game);
player.moveCards(card, Zone.HAND, source, game); player.moveCards(card, Zone.HAND, source, game);
player.shuffleLibrary(source, game); player.shuffleLibrary(source, game);
@ -136,6 +136,7 @@ class BorderlandExplorerEffect extends OneShotEffect {
} }
} }
} }
}
return true; return true;
} }
return false; return false;

View file

@ -1,10 +1,5 @@
package mage.game; package mage.game;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import mage.MageItem; import mage.MageItem;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -45,6 +40,10 @@ import mage.players.Players;
import mage.util.MessageToClient; import mage.util.MessageToClient;
import mage.util.functions.ApplyToPermanent; import mage.util.functions.ApplyToPermanent;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
public interface Game extends MageItem, Serializable { public interface Game extends MageItem, Serializable {
MatchType getGameType(); MatchType getGameType();
@ -98,6 +97,7 @@ public interface Game extends MageItem, Serializable {
Map<Zone, HashMap<UUID, MageObject>> getLKI(); Map<Zone, HashMap<UUID, MageObject>> getLKI();
// Result must be checked for null. Possible errors search pattern: (\S*) = game.getCard.+\n(?!.+\1 != null)
Card getCard(UUID cardId); Card getCard(UUID cardId);
Optional<Ability> getAbility(UUID abilityId, UUID sourceId); Optional<Ability> getAbility(UUID abilityId, UUID sourceId);
@ -106,6 +106,7 @@ public interface Game extends MageItem, Serializable {
void addPlayer(Player player, Deck deck); void addPlayer(Player player, Deck deck);
// Result must be checked for null. Possible errors search pattern: (\S*) = game.getPlayer.+\n(?!.+\1 != null)
Player getPlayer(UUID playerId); Player getPlayer(UUID playerId);
Player getPlayerOrPlaneswalkerController(UUID playerId); Player getPlayerOrPlaneswalkerController(UUID playerId);