Fixed NPE errors

This commit is contained in:
Oleg Agafonov 2019-12-15 15:00:31 +04:00
parent ca0297d7c8
commit be6a588a7f
19 changed files with 37 additions and 23 deletions

View file

@ -22,9 +22,9 @@ import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetControlledPermanent; import mage.target.common.TargetControlledPermanent;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
import mage.abilities.costs.Cost;
/** /**
* @author jeffwadsworth * @author jeffwadsworth
@ -97,7 +97,7 @@ class BolassCitadelPlayTheTopCardEffect extends AsThoughEffectImpl {
@Override @Override
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) { public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
Card cardToCheck = game.getCard(objectId); Card cardToCheck = game.getCard(objectId);
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
if (playerId.equals(source.getControllerId()) && cardToCheck.isOwnedBy(source.getControllerId())) { if (playerId.equals(source.getControllerId()) && cardToCheck.isOwnedBy(source.getControllerId())) {
Player controller = game.getPlayer(cardToCheck.getOwnerId()); Player controller = game.getPlayer(cardToCheck.getOwnerId());

View file

@ -18,6 +18,7 @@ import mage.target.common.TargetCardInGraveyard;
import mage.target.common.TargetCardInHand; import mage.target.common.TargetCardInHand;
import mage.target.common.TargetOpponent; import mage.target.common.TargetOpponent;
import mage.target.targetpointer.FixedTarget; import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
@ -156,7 +157,7 @@ class CovetousUrgeSpendAnyManaEffect extends AsThoughEffectImpl implements AsTho
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); FixedTarget fixedTarget = ((FixedTarget) getTargetPointer());
return source.isControlledBy(affectedControllerId) return source.isControlledBy(affectedControllerId)
&& Objects.equals(objectId, fixedTarget.getTarget()) && Objects.equals(objectId, fixedTarget.getTarget())

View file

@ -122,7 +122,7 @@ class CunningAbductionSpendAnyManaEffect extends AsThoughEffectImpl implements A
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget()) if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget())
&& game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) { && game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) {
// if the card moved from exile to spell the zone change counter is increased by 1 (effect must applies before and on stack, use isCheckPlayableMode?) // if the card moved from exile to spell the zone change counter is increased by 1 (effect must applies before and on stack, use isCheckPlayableMode?)

View file

@ -177,7 +177,7 @@ class DaxosOfMeletisSpendAnyManaEffect extends AsThoughEffectImpl implements AsT
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); FixedTarget fixedTarget = ((FixedTarget) getTargetPointer());
return source.isControlledBy(affectedControllerId) return source.isControlledBy(affectedControllerId)
&& Objects.equals(objectId, fixedTarget.getTarget()) && Objects.equals(objectId, fixedTarget.getTarget())

View file

@ -22,6 +22,7 @@ import mage.players.ManaPoolItem;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.target.targetpointer.FixedTarget; import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -169,7 +170,7 @@ class DeadMansChestSpendManaEffect extends AsThoughEffectImpl implements AsThoug
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget()) if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget())
&& game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) { && game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) {
// if the card moved from exile to spell the zone change counter is increased by 1 (effect must applies before and on stack, use isCheckPlayableMode?) // if the card moved from exile to spell the zone change counter is increased by 1 (effect must applies before and on stack, use isCheckPlayableMode?)

View file

@ -21,6 +21,7 @@ import mage.players.ManaPoolItem;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCardInOpponentsGraveyard; import mage.target.common.TargetCardInOpponentsGraveyard;
import mage.target.targetpointer.FixedTarget; import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
@ -133,7 +134,7 @@ class DireFleetDaredevilSpendAnyManaEffect extends AsThoughEffectImpl implements
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); FixedTarget fixedTarget = ((FixedTarget) getTargetPointer());
return source.isControlledBy(affectedControllerId) return source.isControlledBy(affectedControllerId)
&& Objects.equals(objectId, ((FixedTarget) getTargetPointer()).getTarget()) && Objects.equals(objectId, ((FixedTarget) getTargetPointer()).getTarget())

View file

@ -233,7 +233,7 @@ class GrenzoHavocRaiserSpendAnyManaEffect extends AsThoughEffectImpl implements
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); FixedTarget fixedTarget = ((FixedTarget) getTargetPointer());
return source.isControlledBy(affectedControllerId) return source.isControlledBy(affectedControllerId)
&& Objects.equals(objectId, ((FixedTarget) getTargetPointer()).getTarget()) && Objects.equals(objectId, ((FixedTarget) getTargetPointer()).getTarget())

View file

@ -173,7 +173,7 @@ class HostageTakerSpendAnyManaEffect extends AsThoughEffectImpl implements AsTho
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); FixedTarget fixedTarget = ((FixedTarget) getTargetPointer());
return source.isControlledBy(affectedControllerId) return source.isControlledBy(affectedControllerId)
&& Objects.equals(objectId, fixedTarget.getTarget()) && Objects.equals(objectId, fixedTarget.getTarget())

View file

@ -3,18 +3,20 @@ package mage.cards.m;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.DelayedTriggeredAbility; import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.effects.AsThoughEffectImpl; import mage.abilities.effects.AsThoughEffectImpl;
import mage.abilities.effects.AsThoughManaEffect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.cards.*; import mage.cards.*;
import mage.constants.*; import mage.constants.*;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.players.ManaPoolItem;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import mage.abilities.effects.AsThoughManaEffect;
import mage.players.ManaPoolItem;
/** /**
* @author TheElk801 * @author TheElk801
@ -156,7 +158,7 @@ class MnemonicBetrayalAnyColorEffect extends AsThoughEffectImpl implements AsTho
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
if (objectId.equals(card.getId()) if (objectId.equals(card.getId())
&& card.getZoneChangeCounter(game) <= zoneCounter + 1 && card.getZoneChangeCounter(game) <= zoneCounter + 1
&& affectedControllerId.equals(source.getControllerId())) { && affectedControllerId.equals(source.getControllerId())) {

View file

@ -16,6 +16,7 @@ import mage.game.Game;
import mage.players.ManaPoolItem; import mage.players.ManaPoolItem;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetCard; import mage.target.TargetCard;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
@ -127,7 +128,7 @@ class OathOfNissaSpendAnyManaEffect extends AsThoughEffectImpl implements AsThou
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
if (source.isControlledBy(affectedControllerId)) { if (source.isControlledBy(affectedControllerId)) {
MageObject mageObject = game.getObject(objectId); MageObject mageObject = game.getObject(objectId);
return mageObject != null && mageObject.isPlaneswalker(); return mageObject != null && mageObject.isPlaneswalker();

View file

@ -144,7 +144,7 @@ class PsychicIntrusionCastFromExileEffect extends AsThoughEffectImpl {
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
if (objectId.equals(getTargetPointer().getFirst(game, source))) { if (objectId.equals(getTargetPointer().getFirst(game, source))) {
return affectedControllerId.equals(source.getControllerId()); return affectedControllerId.equals(source.getControllerId());
} else { } else {
@ -180,7 +180,7 @@ class PsychicIntrusionSpendAnyManaEffect extends AsThoughEffectImpl implements A
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget()) if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget())
&& game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) { && game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) {
// if the card moved from exile to spell the zone change counter is increased by 1 (effect must applies before and on stack, use isCheckPlayableMode?) // if the card moved from exile to spell the zone change counter is increased by 1 (effect must applies before and on stack, use isCheckPlayableMode?)

View file

@ -18,6 +18,7 @@ import mage.game.permanent.Permanent;
import mage.players.ManaPoolItem; import mage.players.ManaPoolItem;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
import mage.target.targetpointer.FixedTarget; import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
@ -141,7 +142,7 @@ class QuickSilverElementalBlueManaEffect extends AsThoughEffectImpl implements A
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
if (objectId.equals(getTargetPointer().getFirst(game, source))) { if (objectId.equals(getTargetPointer().getFirst(game, source))) {
return affectedControllerId.equals(source.getControllerId()); return affectedControllerId.equals(source.getControllerId());
} }

View file

@ -194,7 +194,7 @@ class RobberOfTheRichSpendAnyManaEffect extends AsThoughEffectImpl implements As
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); FixedTarget fixedTarget = ((FixedTarget) getTargetPointer());
return source.isControlledBy(affectedControllerId) return source.isControlledBy(affectedControllerId)
&& Objects.equals(objectId, fixedTarget.getTarget()) && Objects.equals(objectId, fixedTarget.getTarget())

View file

@ -157,7 +157,7 @@ class StolenStrategySpendAnyManaEffect extends AsThoughEffectImpl implements AsT
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); FixedTarget fixedTarget = ((FixedTarget) getTargetPointer());
return source.isControlledBy(affectedControllerId) return source.isControlledBy(affectedControllerId)
&& Objects.equals(objectId, fixedTarget.getTarget()) && Objects.equals(objectId, fixedTarget.getTarget())

View file

@ -187,7 +187,7 @@ class ThiefOfSanitySpendAnyManaEffect extends AsThoughEffectImpl implements AsTh
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget()) if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget())
&& game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) { && game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) {
// if the card moved from exile to spell the zone change counter is increased by 1 (effect must applies before and on stack, use isCheckPlayableMode?) // if the card moved from exile to spell the zone change counter is increased by 1 (effect must applies before and on stack, use isCheckPlayableMode?)

View file

@ -172,7 +172,7 @@ class TobiasBeckettSpendAnyManaEffect extends AsThoughEffectImpl implements AsTh
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); FixedTarget fixedTarget = ((FixedTarget) getTargetPointer());
return source.isControlledBy(affectedControllerId) return source.isControlledBy(affectedControllerId)
&& Objects.equals(objectId, fixedTarget.getTarget()) && Objects.equals(objectId, fixedTarget.getTarget())

View file

@ -14,6 +14,7 @@ import mage.constants.*;
import mage.game.Game; import mage.game.Game;
import mage.players.ManaPoolItem; import mage.players.ManaPoolItem;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
@ -117,7 +118,7 @@ class VizierOfTheMenagerieManaEffect extends AsThoughEffectImpl implements AsTho
@Override @Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
if (source.isControlledBy(affectedControllerId)) { if (source.isControlledBy(affectedControllerId)) {
MageObject mageObject = game.getObject(objectId); MageObject mageObject = game.getObject(objectId);
return mageObject != null && mageObject.isCreature(); return mageObject != null && mageObject.isCreature();

View file

@ -9,6 +9,7 @@ import mage.constants.Outcome;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
@ -53,7 +54,7 @@ public class PlayTheTopCardEffect extends AsThoughEffectImpl {
@Override @Override
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) { public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
Card cardToCheck = game.getCard(objectId); Card cardToCheck = game.getCard(objectId);
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards objectId = CardUtil.getMainCardId(game, objectId); // for split cards
if (cardToCheck != null if (cardToCheck != null
&& playerId.equals(source.getControllerId()) && playerId.equals(source.getControllerId())

View file

@ -565,7 +565,7 @@ public final class CardUtil {
public static boolean haveSameNames(String name1, String name2, Boolean ignoreMtgRuleForEmptyNames) { public static boolean haveSameNames(String name1, String name2, Boolean ignoreMtgRuleForEmptyNames) {
if (ignoreMtgRuleForEmptyNames) { if (ignoreMtgRuleForEmptyNames) {
// simple compare for tests and engine // simple compare for tests and engine
return name1 != null && name2 != null && name1.equals(name2); return name1 != null && name1.equals(name2);
} else { } else {
// mtg logic compare for game (empty names can't be same) // mtg logic compare for game (empty names can't be same)
return !haveEmptyName(name1) && !haveEmptyName(name2) && name1.equals(name2); return !haveEmptyName(name1) && !haveEmptyName(name2) && name1.equals(name2);
@ -587,4 +587,9 @@ public final class CardUtil {
public static boolean haveEmptyName(MageObject object) { public static boolean haveEmptyName(MageObject object) {
return object == null || haveEmptyName(object.getName()); return object == null || haveEmptyName(object.getName());
} }
public static UUID getMainCardId(Game game, UUID objectId) {
Card card = game.getCard(objectId);
return card != null ? card.getMainCard().getId() : objectId;
}
} }