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

View file

@ -1,7 +1,5 @@
package mage.cards.a;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.common.SourceIsSpellCondition;
@ -17,6 +15,8 @@ import mage.filter.predicate.mageobject.ConvertedManaCostPredicate;
import mage.game.Game;
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,
* even though you did not pay the cost.
@ -39,7 +39,7 @@ public final class Aluren extends CardImpl {
}
public Aluren(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{G}{G}");
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{G}{G}");
// Any player may play creature cards with converted mana cost 3 or less without paying their mana cost
@ -90,7 +90,7 @@ class AlurenRuleEffect extends ContinuousEffectImpl {
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId: game.getState().getPlayersInRange(controller.getId(), game)){
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.getAlternativeSourceCosts().add(alternativeCastingCostAbility);
@ -111,46 +111,3 @@ class AlurenRuleEffect extends ContinuousEffectImpl {
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;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
@ -20,8 +16,11 @@ import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.players.Player;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
/**
*
* @author TheElk801
*/
public final class ArcaneAdaptation extends CardImpl {
@ -70,14 +69,14 @@ class ConspyEffect extends ContinuousEffectImpl {
// in graveyard
for (UUID cardId : controller.getGraveyard()) {
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);
}
}
// on Hand
for (UUID cardId : controller.getHand()) {
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);
}
}
@ -97,13 +96,13 @@ class ConspyEffect extends ContinuousEffectImpl {
for (UUID commanderId : controller.getCommandersIds()) {
if (game.getState().getZone(commanderId) == Zone.COMMAND) {
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);
}
}
}
// 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,4 +1,3 @@
package mage.cards.a;
import mage.MageInt;
@ -97,10 +96,11 @@ class ArcaneArtisanCreateTokenEffect extends OneShotEffect {
return false;
}
Card card = game.getCard(target.getFirstTarget());
player.moveCards(card, Zone.EXILED, source, game);
if (!card.isCreature()) {
if (!player.moveCards(card, Zone.EXILED, source, game)) {
return false;
}
if (card.isCreature()) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(player.getId());
effect.setTargetPointer(new FixedTarget(card.getId(), game));
effect.apply(game, source);
@ -117,6 +117,8 @@ class ArcaneArtisanCreateTokenEffect extends OneShotEffect {
}
}
game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated);
}
return true;
}
}

View file

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

View file

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

View file

@ -1,10 +1,5 @@
package mage.game;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import mage.MageItem;
import mage.MageObject;
import mage.abilities.Ability;
@ -45,6 +40,10 @@ import mage.players.Players;
import mage.util.MessageToClient;
import mage.util.functions.ApplyToPermanent;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
public interface Game extends MageItem, Serializable {
MatchType getGameType();
@ -98,6 +97,7 @@ public interface Game extends MageItem, Serializable {
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);
Optional<Ability> getAbility(UUID abilityId, UUID sourceId);
@ -106,6 +106,7 @@ public interface Game extends MageItem, Serializable {
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 getPlayerOrPlaneswalkerController(UUID playerId);
@ -130,7 +131,7 @@ public interface Game extends MageItem, Serializable {
}
default boolean isActivePlayer(UUID playerId){
default boolean isActivePlayer(UUID playerId) {
return getActivePlayerId().equals(playerId);
}