mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Fixed NPE errors
This commit is contained in:
parent
ca0297d7c8
commit
be6a588a7f
19 changed files with 37 additions and 23 deletions
|
@ -22,9 +22,9 @@ import mage.filter.predicate.mageobject.CardTypePredicate;
|
|||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetControlledPermanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.costs.Cost;
|
||||
|
||||
/**
|
||||
* @author jeffwadsworth
|
||||
|
@ -97,7 +97,7 @@ class BolassCitadelPlayTheTopCardEffect extends AsThoughEffectImpl {
|
|||
@Override
|
||||
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
|
||||
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())) {
|
||||
Player controller = game.getPlayer(cardToCheck.getOwnerId());
|
||||
|
|
|
@ -18,6 +18,7 @@ import mage.target.common.TargetCardInGraveyard;
|
|||
import mage.target.common.TargetCardInHand;
|
||||
import mage.target.common.TargetOpponent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
@ -156,7 +157,7 @@ class CovetousUrgeSpendAnyManaEffect extends AsThoughEffectImpl implements AsTho
|
|||
|
||||
@Override
|
||||
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());
|
||||
return source.isControlledBy(affectedControllerId)
|
||||
&& Objects.equals(objectId, fixedTarget.getTarget())
|
||||
|
|
|
@ -122,7 +122,7 @@ class CunningAbductionSpendAnyManaEffect extends AsThoughEffectImpl implements A
|
|||
|
||||
@Override
|
||||
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())
|
||||
&& 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?)
|
||||
|
|
|
@ -177,7 +177,7 @@ class DaxosOfMeletisSpendAnyManaEffect extends AsThoughEffectImpl implements AsT
|
|||
|
||||
@Override
|
||||
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());
|
||||
return source.isControlledBy(affectedControllerId)
|
||||
&& Objects.equals(objectId, fixedTarget.getTarget())
|
||||
|
|
|
@ -22,6 +22,7 @@ import mage.players.ManaPoolItem;
|
|||
import mage.players.Player;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
@ -169,7 +170,7 @@ class DeadMansChestSpendManaEffect extends AsThoughEffectImpl implements AsThoug
|
|||
|
||||
@Override
|
||||
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())
|
||||
&& 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?)
|
||||
|
|
|
@ -21,6 +21,7 @@ import mage.players.ManaPoolItem;
|
|||
import mage.players.Player;
|
||||
import mage.target.common.TargetCardInOpponentsGraveyard;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
@ -133,7 +134,7 @@ class DireFleetDaredevilSpendAnyManaEffect extends AsThoughEffectImpl implements
|
|||
|
||||
@Override
|
||||
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());
|
||||
return source.isControlledBy(affectedControllerId)
|
||||
&& Objects.equals(objectId, ((FixedTarget) getTargetPointer()).getTarget())
|
||||
|
|
|
@ -233,7 +233,7 @@ class GrenzoHavocRaiserSpendAnyManaEffect extends AsThoughEffectImpl implements
|
|||
|
||||
@Override
|
||||
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());
|
||||
return source.isControlledBy(affectedControllerId)
|
||||
&& Objects.equals(objectId, ((FixedTarget) getTargetPointer()).getTarget())
|
||||
|
|
|
@ -173,7 +173,7 @@ class HostageTakerSpendAnyManaEffect extends AsThoughEffectImpl implements AsTho
|
|||
|
||||
@Override
|
||||
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());
|
||||
return source.isControlledBy(affectedControllerId)
|
||||
&& Objects.equals(objectId, fixedTarget.getTarget())
|
||||
|
|
|
@ -3,18 +3,20 @@ package mage.cards.m;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.DelayedTriggeredAbility;
|
||||
import mage.abilities.effects.AsThoughEffectImpl;
|
||||
import mage.abilities.effects.AsThoughManaEffect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.ExileSpellEffect;
|
||||
import mage.cards.*;
|
||||
import mage.constants.*;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.players.ManaPoolItem;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.effects.AsThoughManaEffect;
|
||||
import mage.players.ManaPoolItem;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
|
@ -156,7 +158,7 @@ class MnemonicBetrayalAnyColorEffect extends AsThoughEffectImpl implements AsTho
|
|||
|
||||
@Override
|
||||
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())
|
||||
&& card.getZoneChangeCounter(game) <= zoneCounter + 1
|
||||
&& affectedControllerId.equals(source.getControllerId())) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import mage.game.Game;
|
|||
import mage.players.ManaPoolItem;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetCard;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -127,7 +128,7 @@ class OathOfNissaSpendAnyManaEffect extends AsThoughEffectImpl implements AsThou
|
|||
|
||||
@Override
|
||||
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)) {
|
||||
MageObject mageObject = game.getObject(objectId);
|
||||
return mageObject != null && mageObject.isPlaneswalker();
|
||||
|
|
|
@ -144,7 +144,7 @@ class PsychicIntrusionCastFromExileEffect extends AsThoughEffectImpl {
|
|||
|
||||
@Override
|
||||
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))) {
|
||||
return affectedControllerId.equals(source.getControllerId());
|
||||
} else {
|
||||
|
@ -180,7 +180,7 @@ class PsychicIntrusionSpendAnyManaEffect extends AsThoughEffectImpl implements A
|
|||
|
||||
@Override
|
||||
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())
|
||||
&& 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?)
|
||||
|
|
|
@ -18,6 +18,7 @@ import mage.game.permanent.Permanent;
|
|||
import mage.players.ManaPoolItem;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -141,7 +142,7 @@ class QuickSilverElementalBlueManaEffect extends AsThoughEffectImpl implements A
|
|||
|
||||
@Override
|
||||
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))) {
|
||||
return affectedControllerId.equals(source.getControllerId());
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ class RobberOfTheRichSpendAnyManaEffect extends AsThoughEffectImpl implements As
|
|||
|
||||
@Override
|
||||
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());
|
||||
return source.isControlledBy(affectedControllerId)
|
||||
&& Objects.equals(objectId, fixedTarget.getTarget())
|
||||
|
|
|
@ -157,7 +157,7 @@ class StolenStrategySpendAnyManaEffect extends AsThoughEffectImpl implements AsT
|
|||
|
||||
@Override
|
||||
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());
|
||||
return source.isControlledBy(affectedControllerId)
|
||||
&& Objects.equals(objectId, fixedTarget.getTarget())
|
||||
|
|
|
@ -187,7 +187,7 @@ class ThiefOfSanitySpendAnyManaEffect extends AsThoughEffectImpl implements AsTh
|
|||
|
||||
@Override
|
||||
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())
|
||||
&& 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?)
|
||||
|
|
|
@ -172,7 +172,7 @@ class TobiasBeckettSpendAnyManaEffect extends AsThoughEffectImpl implements AsTh
|
|||
|
||||
@Override
|
||||
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());
|
||||
return source.isControlledBy(affectedControllerId)
|
||||
&& Objects.equals(objectId, fixedTarget.getTarget())
|
||||
|
|
|
@ -14,6 +14,7 @@ import mage.constants.*;
|
|||
import mage.game.Game;
|
||||
import mage.players.ManaPoolItem;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -117,7 +118,7 @@ class VizierOfTheMenagerieManaEffect extends AsThoughEffectImpl implements AsTho
|
|||
|
||||
@Override
|
||||
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)) {
|
||||
MageObject mageObject = game.getObject(objectId);
|
||||
return mageObject != null && mageObject.isCreature();
|
||||
|
|
|
@ -9,6 +9,7 @@ import mage.constants.Outcome;
|
|||
import mage.filter.FilterCard;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -53,7 +54,7 @@ public class PlayTheTopCardEffect extends AsThoughEffectImpl {
|
|||
@Override
|
||||
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
|
||||
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
|
||||
&& playerId.equals(source.getControllerId())
|
||||
|
|
|
@ -565,7 +565,7 @@ public final class CardUtil {
|
|||
public static boolean haveSameNames(String name1, String name2, Boolean ignoreMtgRuleForEmptyNames) {
|
||||
if (ignoreMtgRuleForEmptyNames) {
|
||||
// simple compare for tests and engine
|
||||
return name1 != null && name2 != null && name1.equals(name2);
|
||||
return name1 != null && name1.equals(name2);
|
||||
} else {
|
||||
// mtg logic compare for game (empty names can't be same)
|
||||
return !haveEmptyName(name1) && !haveEmptyName(name2) && name1.equals(name2);
|
||||
|
@ -587,4 +587,9 @@ public final class CardUtil {
|
|||
public static boolean haveEmptyName(MageObject object) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue