Fixed NPE errors on missing card (game.getCard can't find card);

This commit is contained in:
Oleg Agafonov 2020-01-15 07:08:56 +04:00
parent c30316512b
commit 745bfa2836
9 changed files with 25 additions and 13 deletions

View file

@ -99,6 +99,7 @@ class DanceOfTheManseEffect extends OneShotEffect {
.map(Target::getTargets)
.flatMap(Collection::stream)
.map(game::getCard)
.filter(Objects::nonNull)
.collect(Collectors.toSet()));
player.moveCards(cards, Zone.BATTLEFIELD, source, game);
if (source.getManaCostsToPay().getX() < 6) {

View file

@ -13,6 +13,7 @@ import mage.filter.common.FilterCreatureCard;
import mage.game.Game;
import mage.target.common.TargetCardInLibrary;
import java.util.Objects;
import java.util.UUID;
/**
@ -68,6 +69,7 @@ class DeathbellowWarCryTarget extends TargetCardInLibrary {
.getTargets()
.stream()
.map(game::getCard)
.filter(Objects::nonNull)
.map(Card::getName)
.noneMatch(card.getName()::equals);
}

View file

@ -1,6 +1,5 @@
package mage.cards.d;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
@ -8,7 +7,6 @@ import mage.abilities.costs.common.SacrificeSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
@ -23,8 +21,10 @@ import mage.players.Player;
import mage.target.TargetCard;
import mage.target.common.TargetOpponent;
import java.util.Objects;
import java.util.UUID;
/**
*
* @author jeffwadsworth
*/
public final class DiscordantDirge extends CardImpl {
@ -81,9 +81,9 @@ class DiscordantDirgeEffect extends OneShotEffect {
TargetCard target = new TargetCard(0, verseCounters, Zone.HAND, new FilterCard());
target.setNotTarget(true);
if (controller.choose(Outcome.Benefit, targetOpponent.getHand(), target, game)) {
target.getTargets().stream().map(game::getCard).filter((card) -> (card != null
&& targetOpponent.getHand().contains(card.getId()))).forEachOrdered((card) -> {
targetOpponent.discard(card, source, game);
target.getTargets().stream().map(game::getCard).filter(Objects::nonNull).filter((card) -> (card != null
&& targetOpponent.getHand().contains(card.getId()))).forEachOrdered((card) -> {
targetOpponent.discard(card, source, game);
});
return true;
}

View file

@ -15,6 +15,7 @@ import mage.target.Target;
import mage.target.common.TargetCardInYourGraveyard;
import java.util.Collection;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
@ -74,6 +75,7 @@ class ForeverYoungEffect extends OneShotEffect {
.map(Target::getTargets)
.flatMap(Collection::stream)
.map(game::getCard)
.filter(Objects::nonNull)
.collect(Collectors.toSet())
), game, source, true);
}

View file

@ -18,6 +18,7 @@ import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInYourGraveyard;
import java.util.Objects;
import java.util.UUID;
/**
@ -88,6 +89,7 @@ class KethisTheHiddenHandEffect extends ContinuousEffectImpl {
player.getGraveyard()
.stream()
.map(game::getCard)
.filter(Objects::nonNull)
.filter(Card::isLegendary)
.forEach(card -> affectedObjectList.add(new MageObjectReference(card, game)));
}

View file

@ -17,10 +17,12 @@ import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInHand;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import mage.target.common.TargetCardInHand;
/**
* @author TheElk801
@ -31,7 +33,7 @@ public final class ScrollOfFate extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{3}");
// {T}: Manifest a card from your hand.
this.addAbility(new SimpleActivatedAbility(new ScrollOfFateEffect(),
this.addAbility(new SimpleActivatedAbility(new ScrollOfFateEffect(),
new TapSourceCost()));
}
@ -69,7 +71,7 @@ class ScrollOfFateEffect extends OneShotEffect {
return false;
}
TargetCardInHand targetCard = new TargetCardInHand();
if (!controller.chooseTarget(Outcome.PutCardInPlay, controller.getHand(),
if (!controller.chooseTarget(Outcome.PutCardInPlay, controller.getHand(),
targetCard, source, game)) {
return false;
}
@ -79,6 +81,7 @@ class ScrollOfFateEffect extends OneShotEffect {
.getTargets()
.stream()
.map(game::getCard)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
cards.stream().forEach(card -> {
ManaCosts manaCosts = null;
@ -88,9 +91,9 @@ class ScrollOfFateEffect extends OneShotEffect {
manaCosts = new ManaCostsImpl("{0}");
}
}
MageObjectReference objectReference = new MageObjectReference(card.getId(),
MageObjectReference objectReference = new MageObjectReference(card.getId(),
card.getZoneChangeCounter(game) + 1, game);
game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference,
game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference,
Duration.Custom, BecomesFaceDownCreatureEffect.FaceDownType.MANIFESTED), newSource);
});
controller.moveCards(cards, Zone.BATTLEFIELD, source, game, false, true, false, null);

View file

@ -12,6 +12,7 @@ import mage.filter.common.FilterCreatureCard;
import mage.game.Game;
import mage.target.common.TargetCardInLibrary;
import java.util.Objects;
import java.util.UUID;
/**
@ -70,6 +71,7 @@ class SharedSummonsTarget extends TargetCardInLibrary {
.getTargets()
.stream()
.map(game::getCard)
.filter(Objects::nonNull)
.noneMatch(c -> c != null && c.getName().equals(card.getName()));
}
}

View file

@ -129,7 +129,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
@Override
public Set<Card> getCards(FilterCard filter, Game game) {
return stream().map(game::getCard).filter(card -> filter.match(card, game)).collect(Collectors.toSet());
return stream().map(game::getCard).filter(Objects::nonNull).filter(card -> filter.match(card, game)).collect(Collectors.toSet());
}
@Override

View file

@ -164,7 +164,7 @@ public class Library implements Serializable {
* @return
*/
public List<Card> getCards(Game game) {
return library.stream().map(game::getCard).collect(Collectors.toList());
return library.stream().map(game::getCard).filter(Objects::nonNull).collect(Collectors.toList());
}
public Set<Card> getTopCards(Game game, int amount) {