add nullchecks for game.getObject

This commit is contained in:
Ingmar Goudt 2018-12-31 16:03:36 +01:00
parent 09dd9d5a26
commit da3c861344
80 changed files with 408 additions and 354 deletions

View file

@ -78,6 +78,9 @@ class AbeyanceEffect extends ContinuousRuleModifyingEffectImpl {
public boolean applies(GameEvent event, Ability source, Game game) {
if (source.getFirstTarget() != null && source.getFirstTarget().equals(event.getPlayerId())) {
MageObject object = game.getObject(event.getSourceId());
if(object == null){
return false;
}
if (event.getType() == GameEvent.EventType.CAST_SPELL) {
if (object.isInstant() || object.isSorcery()) {
return true;

View file

@ -98,19 +98,19 @@ class AcolytesRewardEffect extends PreventionEffectImpl {
result = true;
}
if (toPrevent > 0) {
game.informPlayers(new StringBuilder("Acolyte's Reward ").append("prevented ").append(toPrevent).append(" to ").append(targetCreature.getName()).toString());
game.informPlayers("Acolyte's Reward prevented " + toPrevent + " to " + targetCreature.getName());
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE,
source.getControllerId(), source.getSourceId(), source.getControllerId(), toPrevent));
Player targetPlayer = game.getPlayer(source.getTargets().get(1).getFirstTarget());
if (targetPlayer != null) {
targetPlayer.damage(toPrevent, source.getSourceId(), game, false, true);
game.informPlayers(new StringBuilder("Acolyte's Reward ").append("deals ").append(toPrevent).append(" damage to ").append(targetPlayer.getLogName()).toString());
game.informPlayers("Acolyte's Reward deals " + toPrevent + " damage to " + targetPlayer.getLogName());
} else {
Permanent targetDamageCreature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (targetDamageCreature != null) {
targetDamageCreature.damage(toPrevent, source.getSourceId(), game, false, true);
game.informPlayers(new StringBuilder("Acolyte's Reward ").append("deals ").append(toPrevent).append(" damage to ").append(targetDamageCreature.getName()).toString());
game.informPlayers("Acolyte's Reward deals " + toPrevent + " damage to " + targetDamageCreature.getName());
}
}
}

View file

@ -64,7 +64,7 @@ class AdviceFromTheFaeEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null) {
if (controller != null && mageObject != null) {
Set<Card> topCards = controller.getLibrary().getTopCards(game, 5);
Cards cardsFromLibrary = new CardsImpl();
for (Card card : topCards) {

View file

@ -100,7 +100,7 @@ class AllianceOfArmsEffect extends OneShotEffect {
payed = true;
}
}
game.informPlayers(new StringBuilder(player.getLogName()).append(" pays {").append(xValue).append("}.").toString());
game.informPlayers(player.getLogName() + " pays {" + xValue + "}.");
return xValue;
}
}

View file

@ -91,9 +91,7 @@ class AvenEffect extends ContinuousEffectImpl {
@Override
public String getText(Mode mode) {
StringBuilder sb = new StringBuilder();
sb.append("If you do, that creature has base power and toughness 3/1 and has flying for as long as it has a feather counter on it");
return sb.toString();
return "If you do, that creature has base power and toughness 3/1 and has flying for as long as it has a feather counter on it";
}
}

View file

@ -67,7 +67,7 @@ class AvenShrineTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getStack().getSpell(event.getTargetId());
MageObject mageObject = game.getObject(sourceId);
if (spell != null) {
if (spell != null && mageObject != null) {
game.getState().setValue("avenShrine" + mageObject, spell);
return true;
}
@ -91,6 +91,7 @@ class AvenShrineEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
int count = 0;
MageObject mageObject = game.getObject(source.getSourceId());
if(mageObject != null) {
Spell spell = (Spell) game.getState().getValue("avenShrine" + mageObject);
if (spell != null) {
Player controller = game.getPlayer(spell.getControllerId());
@ -108,6 +109,7 @@ class AvenShrineEffect extends OneShotEffect {
return true;
}
}
}
return false;
}

View file

@ -106,7 +106,7 @@ class BalaGedThiefEffect extends OneShotEffect {
Card card = revealedCards.get(targetInHand.getFirstTarget(), game);
if (card != null) {
targetPlayer.discard(card, source, game);
game.informPlayers(new StringBuilder("Bala Ged Thief: ").append(targetPlayer.getLogName()).append(" discarded ").append(card.getName()).toString());
game.informPlayers("Bala Ged Thief: " + targetPlayer.getLogName() + " discarded " + card.getName());
}
}
return true;

View file

@ -112,7 +112,7 @@ class BaneAlleyBrokerDrawExileEffect extends OneShotEffect {
Card card = game.getCard(target.getFirstTarget());
MageObject sourceObject = game.getObject(source.getSourceId());
if (card != null && sourceObject != null) {
if (card.moveToExile(CardUtil.getCardExileZoneId(game, source), new StringBuilder(sourceObject.getName()).toString(), source.getSourceId(), game)) {
if (card.moveToExile(CardUtil.getCardExileZoneId(game, source), sourceObject.getName(), source.getSourceId(), game)) {
card.setFaceDown(true, game);
return true;
}

View file

@ -105,6 +105,6 @@ class BlazeCommandoTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
return new StringBuilder("Whenever an instant or sorcery spell you control deals damage, ").append(super.getRule()).toString();
return "Whenever an instant or sorcery spell you control deals damage, " + super.getRule();
}
}

View file

@ -75,6 +75,7 @@ class BlazingHopeTarget extends TargetCreaturePermanent {
int count = 0;
Player controller = game.getPlayer(sourceControllerId);
MageObject targetSource = game.getObject(sourceId);
if(targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId())) {
if (notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
@ -87,6 +88,7 @@ class BlazingHopeTarget extends TargetCreaturePermanent {
}
}
}
}
return false;
}

View file

@ -70,7 +70,7 @@ class BloodlineShamanEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
Choice typeChoice = new ChoiceCreatureType(sourceObject);
if (controller != null && controller.choose(outcome, typeChoice, game)) {
if (controller != null && sourceObject != null && controller.choose(outcome, typeChoice, game)) {
game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice());
FilterCard filterSubtype = new FilterCard();
filterSubtype.add(new SubtypePredicate(SubType.byDescription(typeChoice.getChoice())));

View file

@ -178,7 +178,7 @@ class BombSquadBeginningEffect extends OneShotEffect {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
permanent.addCounters(CounterType.FUSE.createInstance(), source, game);
game.informPlayers(new StringBuilder(card.getName()).append(" puts a fuse counter on ").append(permanent.getName()).toString());
game.informPlayers(card.getName() + " puts a fuse counter on " + permanent.getName());
}
return true;
}

View file

@ -82,7 +82,7 @@ class BraceForImpactPreventDamageTargetEffect extends PreventionEffectImpl {
Permanent targetPermanent = game.getPermanent(source.getTargets().getFirstTarget());
if (targetPermanent != null) {
targetPermanent.addCounters(CounterType.P1P1.createInstance(prevented), source, game);
game.informPlayers(new StringBuilder("Brace for Impact: Prevented ").append(prevented).append(" damage ").toString());
game.informPlayers("Brace for Impact: Prevented " + prevented + " damage ");
game.informPlayers("Brace for Impact: Adding " + prevented + " +1/+1 counters to " + targetPermanent.getName());
}
}

View file

@ -64,7 +64,7 @@ class BrandedBrawlersCantBlockEffect extends RestrictionEffect {
public BrandedBrawlersCantBlockEffect(FilterPermanent filter) {
super(Duration.WhileOnBattlefield);
this.filter = filter;
staticText = new StringBuilder("{this} can't attack if you control ").append(filter.getMessage()).toString();
staticText = "{this} can't attack if you control " + filter.getMessage();
}
public BrandedBrawlersCantBlockEffect(final BrandedBrawlersCantBlockEffect effect) {

View file

@ -67,7 +67,7 @@ class CabalShrineTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getStack().getSpell(event.getTargetId());
MageObject mageObject = game.getObject(sourceId);
if (spell != null) {
if (spell != null && mageObject != null) {
game.getState().setValue("cabalShrine" + mageObject, spell);
return true;
}
@ -91,6 +91,7 @@ class CabalShrineEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
int count = 0;
MageObject mageObject = game.getObject(source.getSourceId());
if(mageObject != null) {
Spell spell = (Spell) game.getState().getValue("cabalShrine" + mageObject);
if (spell != null) {
Player controller = game.getPlayer(spell.getControllerId());
@ -108,6 +109,7 @@ class CabalShrineEffect extends OneShotEffect {
return true;
}
}
}
return false;
}

View file

@ -92,8 +92,8 @@ class CandlesGlowPreventDamageTargetEffect extends PreventionEffectImpl {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.gainLife(prevented, game, source);
game.informPlayers(new StringBuilder("Candles' Glow: Prevented ").append(prevented).append(" damage ").toString());
game.informPlayers(new StringBuilder("Candles' Glow: ").append(controller.getLogName()).append(" gained ").append(prevented).append("life").toString());
game.informPlayers("Candles' Glow: Prevented " + prevented + " damage ");
game.informPlayers("Candles' Glow: " + controller.getLogName() + " gained " + prevented + "life");
}
}
}

View file

@ -98,8 +98,7 @@ class CarpetOfFlowersTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
StringBuilder sb = new StringBuilder("At the beginning of each of your main phases, if you haven't added mana with this ability this turn, ");
return sb.append(super.getRule()).toString();
return "At the beginning of each of your main phases, if you haven't added mana with this ability this turn, " + super.getRule();
}
}

View file

@ -111,7 +111,7 @@ class CavernOfSoulsManaCondition extends CreatureCastManaCondition {
if (super.apply(game, source)) {
// check: ... of the chosen type
MageObject object = game.getObject(source.getSourceId());
if (creatureType != null && object.hasSubtype(creatureType, game)) {
if (creatureType != null && object != null && object.hasSubtype(creatureType, game)) {
return true;
}
}

View file

@ -69,7 +69,7 @@ class CephalidShrineTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getStack().getSpell(event.getTargetId());
MageObject mageObject = game.getObject(sourceId);
if (spell != null) {
if (spell != null && mageObject != null) {
game.getState().setValue("cephalidShrine" + mageObject, spell);
return true;
}
@ -93,6 +93,7 @@ class CephalidShrineEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
int count = 0;
MageObject mageObject = game.getObject(source.getSourceId());
if(mageObject != null) {
Spell spell = (Spell) game.getState().getValue("cephalidShrine" + mageObject);
if (spell != null) {
Player controller = game.getPlayer(spell.getControllerId());
@ -121,6 +122,7 @@ class CephalidShrineEffect extends OneShotEffect {
}
}
}
}
return false;
}

View file

@ -90,7 +90,7 @@ class CharmbreakerDevilsEffect extends OneShotEffect {
if (cards.length > 0) {
Card card = cards[RandomUtil.nextInt(cards.length)];
card.moveToZone(Zone.HAND, source.getSourceId(), game, true);
game.informPlayers(new StringBuilder("Charmbreaker Devils: ").append(card.getName()).append(" returned to the hand of ").append(player.getLogName()).toString());
game.informPlayers("Charmbreaker Devils: " + card.getName() + " returned to the hand of " + player.getLogName());
return true;
}
}

View file

@ -110,7 +110,7 @@ class CollectiveVoyageEffect extends OneShotEffect {
game.removeBookmark(bookmark);
}
}
game.informPlayers(new StringBuilder(player.getLogName()).append(" pays {").append(xValue).append("}.").toString());
game.informPlayers(player.getLogName() + " pays {" + xValue + "}.");
return xValue;
}
}

View file

@ -89,7 +89,7 @@ class ColossalWhaleAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
return new StringBuilder("Whenever {this} attacks, ").append(super.getRule()).toString();
return "Whenever {this} attacks, " + super.getRule();
}
@Override

View file

@ -2,6 +2,7 @@
package mage.cards.c;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
@ -27,7 +28,6 @@ import mage.target.Target;
import mage.target.TargetPermanent;
/**
*
* @author spjspj
*/
public final class CrownOfTheAges extends CardImpl {
@ -107,7 +107,7 @@ class CrownOfTheAgesEffect extends OneShotEffect {
}
// Check for protection
MageObject auraObject = game.getObject(aura.getId());
if (creatureToAttachAura.cantBeAttachedBy(auraObject, game)) {
if (auraObject != null && creatureToAttachAura.cantBeAttachedBy(auraObject, game)) {
passed = false;
}
}

View file

@ -77,7 +77,7 @@ class CrushUnderfootEffect extends OneShotEffect {
&& controller.chooseTarget(outcome, target, source, game)) {
Permanent giant = game.getPermanent(target.getFirstTarget());
if (giant != null) {
game.informPlayers(new StringBuilder("Crush Underfoot: Choosen Giant is").append(giant.getName()).toString());
game.informPlayers("Crush Underfoot: Chosen Giant is " + giant.getName());
Permanent targetCreature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (targetCreature != null) {
targetCreature.damage(giant.getPower().getValue(), source.getSourceId(), game, false, true);

View file

@ -85,7 +85,7 @@ class CurseOfChaosTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
return new StringBuilder("Whenever a player attacks enchanted player with one or more creatures, ").append(super.getRule()).toString();
return "Whenever a player attacks enchanted player with one or more creatures, " + super.getRule();
}
@Override

View file

@ -5,6 +5,7 @@ import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
@ -27,13 +28,12 @@ import mage.target.TargetPermanent;
import mage.target.common.TargetControlledPermanent;
/**
*
* @author LevelX2
*/
public final class DaringThief extends CardImpl {
public DaringThief(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{U}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{U}");
this.subtype.add(SubType.HUMAN);
this.subtype.add(SubType.ROGUE);
@ -91,7 +91,8 @@ class TargetControlledPermanentSharingOpponentPermanentCardType extends TargetCo
Set<CardType> cardTypes = getOpponentPermanentCardTypes(sourceId, sourceControllerId, game);
Set<UUID> possibleTargets = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
for (CardType type : permanent.getCardType()) {
if (cardTypes.contains(type)) {
@ -101,6 +102,7 @@ class TargetControlledPermanentSharingOpponentPermanentCardType extends TargetCo
}
}
}
}
return possibleTargets;
}
@ -111,9 +113,9 @@ class TargetControlledPermanentSharingOpponentPermanentCardType extends TargetCo
private EnumSet<CardType> getOpponentPermanentCardTypes(UUID sourceId, UUID sourceControllerId, Game game) {
Player controller = game.getPlayer(sourceControllerId);
EnumSet<CardType> cardTypes =EnumSet.noneOf(CardType.class);
EnumSet<CardType> cardTypes = EnumSet.noneOf(CardType.class);
if (controller != null) {
for (Permanent permanent: game.getBattlefield().getActivePermanents(sourceControllerId, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(sourceControllerId, game)) {
if (controller.hasOpponent(permanent.getControllerId(), game)) {
cardTypes.addAll(permanent.getCardType());
}
@ -158,6 +160,7 @@ class DaringThiefSecondTarget extends TargetPermanent {
Set<UUID> possibleTargets = new HashSet<>();
if (firstTarget != null) {
MageObject targetSource = game.getObject(sourceId);
if (targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
if (permanent.shareTypes(firstTarget)) {
@ -166,6 +169,7 @@ class DaringThiefSecondTarget extends TargetPermanent {
}
}
}
}
return possibleTargets;
}

View file

@ -89,7 +89,7 @@ class DaxosOfMeletisEffect extends OneShotEffect {
MageObject sourceObject = game.getObject(source.getSourceId());
UUID exileId = CardUtil.getCardExileZoneId(game, source);
Card card = damagedPlayer.getLibrary().getFromTop(game);
if (card != null) {
if (card != null && sourceObject != null) {
// move card to exile
controller.moveCardsToExile(card, source, game, true, exileId, sourceObject.getIdName());
// player gains life

View file

@ -75,7 +75,7 @@ class DeadbridgeChantEffect extends OneShotEffect {
text = " put onto battlefield for ";
}
card.moveToZone(targetZone, source.getSourceId(), game, false);
game.informPlayers(new StringBuilder("Deadbridge Chant: ").append(card.getName()).append(text).append(player.getLogName()).toString());
game.informPlayers("Deadbridge Chant: " + card.getName() + text + player.getLogName());
return true;
}
}

View file

@ -39,7 +39,7 @@ public final class DeathDenied extends CardImpl {
if (ability instanceof SpellAbility) {
ability.getTargets().clear();
int xValue = ability.getManaCostsToPay().getX();
Target target = new TargetCardInYourGraveyard(xValue, new FilterCreatureCard(new StringBuilder(xValue).append(xValue != 1 ? " creature cards" : "creature card").append(" from your graveyard").toString()));
Target target = new TargetCardInYourGraveyard(xValue, new FilterCreatureCard((xValue != 1 ? " creature cards" : "creature card") + " from your graveyard"));
ability.addTarget(target);
}
}

View file

@ -119,7 +119,7 @@ class DecayingSoilTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
return new StringBuilder("Whenever a ").append(filter.getMessage()).append(" is put into your graveyard from the battlefield, ").append(super.getRule()).toString();
return "Whenever a " + filter.getMessage() + " is put into your graveyard from the battlefield, " + super.getRule();
}
}

View file

@ -84,7 +84,7 @@ class DiscipleOfDeceitEffect extends OneShotEffect {
if (card == null) {
return false;
}
String targetName = new StringBuilder("card with converted mana cost of ").append(card.getConvertedManaCost()).toString();
String targetName = "card with converted mana cost of " + card.getConvertedManaCost();
FilterCard filter = new FilterCard(targetName);
filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, card.getConvertedManaCost()));
return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true).apply(game, source);

View file

@ -96,7 +96,7 @@ class DropOfHoneyEffect extends OneShotEffect {
}
}
if (permanentToDestroy != null) {
game.informPlayers(new StringBuilder(sourcePermanent.getName()).append(" chosen creature: ").append(permanentToDestroy.getName()).toString());
game.informPlayers(sourcePermanent.getName() + " chosen creature: " + permanentToDestroy.getName());
return permanentToDestroy.destroy(source.getSourceId(), game, true);
}
return true;
@ -128,6 +128,6 @@ class DropOfHoneyStateTriggeredAbility extends StateTriggeredAbility {
@Override
public String getRule() {
return new StringBuilder("When there are no creatures on the battlefield, ").append(super.getRule()).toString() ;
return "When there are no creatures on the battlefield, " + super.getRule();
}
}

View file

@ -119,10 +119,10 @@ public final class DustOfMoments extends CardImpl {
card.addCounters(counter, source, game);
}
if (!game.isSimulation()) {
game.informPlayers(new StringBuilder(sourceObject.getName()).append(": ")
.append(controller.getLogName()).append(getActionStr()).append('s')
.append(counter.getCount()).append(' ').append(counterName.toLowerCase(Locale.ENGLISH))
.append(" counter on ").append(card.getName()).toString());
game.informPlayers(sourceObject.getName() + ": " +
controller.getLogName() + getActionStr() + 's' +
counter.getCount() + ' ' + counterName.toLowerCase(Locale.ENGLISH) +
" counter on " + card.getName());
}
}
}
@ -144,10 +144,10 @@ public final class DustOfMoments extends CardImpl {
card.addCounters(counter, source, game);
}
if (!game.isSimulation()) {
game.informPlayers(new StringBuilder(sourceObject.getName()).append(": ")
.append(controller.getLogName()).append(getActionStr()).append("s ")
.append(counter.getCount()).append(' ').append(counterName.toLowerCase(Locale.ENGLISH))
.append(" counter on ").append(card.getName()).toString());
game.informPlayers(sourceObject.getName() + ": " +
controller.getLogName() + getActionStr() + "s " +
counter.getCount() + ' ' + counterName.toLowerCase(Locale.ENGLISH) +
" counter on " + card.getName());
}
}
}

View file

@ -67,7 +67,7 @@ class DwarvenShrineTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getStack().getSpell(event.getTargetId());
MageObject mageObject = game.getObject(sourceId);
if (spell != null) {
if (spell != null && mageObject != null) {
game.getState().setValue("dwarvenShrine" + mageObject, spell);
return true;
}
@ -90,6 +90,7 @@ class DwarvenShrineEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
int count = 0;
MageObject mageObject = game.getObject(source.getSourceId());
if(mageObject != null) {
Spell spell = (Spell) game.getState().getValue("dwarvenShrine" + mageObject);
if (spell != null) {
Player controller = game.getPlayer(spell.getControllerId());
@ -107,6 +108,7 @@ class DwarvenShrineEffect extends OneShotEffect {
return true;
}
}
}
return false;
}

View file

@ -71,7 +71,7 @@ class ElbrusTheBindingBladeEffect extends OneShotEffect {
if (attachedTo != null) {
attachedTo.removeAttachment(equipment.getId(), game);
equipment.transform(game);
game.informPlayers(new StringBuilder(equipment.getName()).append(" transforms into ").append(equipment.getSecondCardFace().getName()).toString());
game.informPlayers(equipment.getName() + " transforms into " + equipment.getSecondCardFace().getName());
}
}

View file

@ -2,6 +2,7 @@
package mage.cards.e;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
@ -22,7 +23,6 @@ import mage.game.Game;
import mage.players.Player;
/**
*
* @author LevelX2
*/
public final class ElvishSoultiller extends CardImpl {
@ -69,8 +69,9 @@ class ElvishSoultillerEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null && mageObject != null) {
Choice typeChoice = new ChoiceCreatureType(mageObject);
if (controller != null && mageObject != null && controller.choose(outcome, typeChoice, game)) {
if (controller.choose(outcome, typeChoice, game)) {
if (!game.isSimulation()) {
game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
}
@ -82,6 +83,7 @@ class ElvishSoultillerEffect extends OneShotEffect {
controller.shuffleLibrary(source, game);
return true;
}
}
return false;
}
}

View file

@ -74,7 +74,7 @@ class TargetCreaturePermanentThatDealtDamageThisTurn extends TargetPermanent {
int count = 0;
MageObject targetSource = game.getObject(sourceId);
SourceDidDamageWatcher watcher = (SourceDidDamageWatcher) game.getState().getWatchers().get(SourceDidDamageWatcher.class.getSimpleName());
if (watcher != null) {
if (watcher != null && targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && watcher.damageSources.contains(permanent.getId())) {
if (!notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {

View file

@ -56,8 +56,10 @@ class ExtinctionEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (player != null && sourceObject != null) {
Choice typeChoice = new ChoiceCreatureType(sourceObject);
if (player != null && player.choose(outcome, typeChoice, game)) {
if (player.choose(outcome, typeChoice, game)) {
game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice());
FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent();
filterCreaturePermanent.add(new SubtypePredicate(SubType.byDescription(typeChoice.getChoice())));
@ -66,6 +68,7 @@ class ExtinctionEffect extends OneShotEffect {
}
return true;
}
}
return false;
}

View file

@ -1,10 +1,6 @@
package mage.cards.g;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
@ -13,11 +9,7 @@ import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.common.continuous.ExchangeControlTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.constants.*;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
@ -27,14 +19,18 @@ import mage.players.Player;
import mage.target.TargetPermanent;
import mage.target.common.TargetControlledPermanent;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
*
* @author LevelX2 & L_J
*/
public final class GauntletsOfChaos extends CardImpl {
public GauntletsOfChaos(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{5}");
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{5}");
// {5}, Sacrifice Gauntlets of Chaos: Exchange control of target artifact, creature, or land you control and target permanent an opponent controls that shares one of those types with it. If those permanents are exchanged this way, destroy all Auras attached to them.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ExchangeControlTargetEffect(Duration.EndOfGame,
@ -94,7 +90,8 @@ class GauntletsOfChaosFirstTarget extends TargetControlledPermanent {
Set<CardType> cardTypes = getOpponentPermanentCardTypes(sourceId, sourceControllerId, game);
Set<UUID> possibleTargets = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
for (CardType type : permanent.getCardType()) {
if (cardTypes.contains(type)) {
@ -104,6 +101,7 @@ class GauntletsOfChaosFirstTarget extends TargetControlledPermanent {
}
}
}
}
return possibleTargets;
}
@ -114,9 +112,9 @@ class GauntletsOfChaosFirstTarget extends TargetControlledPermanent {
private EnumSet<CardType> getOpponentPermanentCardTypes(UUID sourceId, UUID sourceControllerId, Game game) {
Player controller = game.getPlayer(sourceControllerId);
EnumSet<CardType> cardTypes =EnumSet.noneOf(CardType.class);
EnumSet<CardType> cardTypes = EnumSet.noneOf(CardType.class);
if (controller != null) {
for (Permanent permanent: game.getBattlefield().getActivePermanents(sourceControllerId, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(sourceControllerId, game)) {
if (controller.hasOpponent(permanent.getControllerId(), game)) {
cardTypes.addAll(permanent.getCardType());
}
@ -161,6 +159,7 @@ class GauntletsOfChaosSecondTarget extends TargetPermanent {
Set<UUID> possibleTargets = new HashSet<>();
if (firstTarget != null) {
MageObject targetSource = game.getObject(sourceId);
if (targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
if (permanent.shareTypes(firstTarget)) {
@ -169,6 +168,7 @@ class GauntletsOfChaosSecondTarget extends TargetPermanent {
}
}
}
}
return possibleTargets;
}

View file

@ -117,11 +117,13 @@ class GlamerSpinnersEffect extends OneShotEffect {
}
// Check for protection
MageObject auraObject = game.getObject(auraId);
if(auraObject != null) {
if (permanentToAttachAuras.cantBeAttachedBy(auraObject, game)) {
passed = false;
}
}
}
}
if (passed) {
LinkedList<UUID> aurasToAttach = new LinkedList<>();
aurasToAttach.addAll(auras);

View file

@ -92,7 +92,7 @@ class GnarlrootTrapperManaCondition extends CreatureCastManaCondition {
public boolean apply(Game game, Ability source) {
if (super.apply(game, source)) {
MageObject object = game.getObject(source.getSourceId());
if (object.hasSubtype(SubType.ELF, game)
if (object != null && object.hasSubtype(SubType.ELF, game)
&& object.isCreature()) {
return true;
}

View file

@ -148,7 +148,7 @@ class GrenzoHavocRaiserEffect extends OneShotEffect {
MageObject sourceObject = game.getObject(source.getSourceId());
UUID exileId = CardUtil.getCardExileZoneId(game, source);
Card card = damagedPlayer.getLibrary().getFromTop(game);
if (card != null) {
if (card != null && sourceObject != null) {
// move card to exile
controller.moveCardToExileWithInfo(card, exileId, sourceObject.getIdName(), source.getSourceId(), game, Zone.LIBRARY, true);
// Add effects only if the card has a spellAbility (e.g. not for lands).

View file

@ -68,7 +68,7 @@ class GridMonitorEffect extends ContinuousRuleModifyingEffectImpl {
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.CAST_SPELL && event.getPlayerId().equals(source.getControllerId())) {
MageObject object = game.getObject(event.getSourceId());
if (object.isCreature()) {
if (object != null && object.isCreature()) {
return true;
}
}

View file

@ -132,7 +132,7 @@ class GrimReminderWatcher extends Watcher {
MageObject spell = game.getObject(event.getTargetId());
UUID playerId = event.getPlayerId();
if (playerId != null && spell != null) {
playersCastSpell.putIfAbsent(spell.getName(), new HashSet());
playersCastSpell.putIfAbsent(spell.getName(), new HashSet<>());
playersCastSpell.get(spell.getName()).add(playerId);
}
}
@ -144,7 +144,7 @@ class GrimReminderWatcher extends Watcher {
}
public Set<UUID> getPlayersCastSpell(String spellName) {
return playersCastSpell.getOrDefault(spellName, new HashSet());
return playersCastSpell.getOrDefault(spellName, new HashSet<>());
}
@Override

View file

@ -172,7 +172,7 @@ class GrimoireThiefCounterspellEffect extends OneShotEffect {
Cards cards = new CardsImpl();
MageObject sourceObject = game.getObject(source.getSourceId());
Set<UUID> exileZones = (Set<UUID>) game.getState().getValue(GrimoireThief.VALUE_PREFIX + source.getSourceId().toString());
if (exileZones != null) {
if (exileZones != null && sourceObject != null) {
for (ExileZone exileZone : game.getExile().getExileZones()) {
if (!exileZone.isEmpty()) {
cards.addAll(exileZone.getCards(game));

View file

@ -79,7 +79,7 @@ class GrinningTotemSearchAndExileEffect extends OneShotEffect {
Player you = game.getPlayer(source.getControllerId());
Player targetOpponent = game.getPlayer(source.getFirstTarget());
MageObject sourceObject = game.getObject(source.getSourceId());
if (you != null && targetOpponent != null) {
if (you != null && targetOpponent != null && sourceObject != null) {
if (targetOpponent.getLibrary().hasCards()) {
TargetCardInLibrary targetCard = new TargetCardInLibrary();
if (you.searchLibrary(targetCard, game, targetOpponent.getId())) {

View file

@ -72,7 +72,7 @@ class HandToHandEffect extends ContinuousRuleModifyingEffectImpl {
if (game.getPhase().getType() == TurnPhase.COMBAT) {
MageObject object = game.getObject(event.getSourceId());
if (event.getType() == GameEvent.EventType.CAST_SPELL) {
if (object.isInstant()) {
if (object != null && object.isInstant()) {
return true;
}
}

View file

@ -99,7 +99,7 @@ class HavenOfTheSpiritManaCondition extends CreatureCastManaCondition {
public boolean apply(Game game, Ability source, UUID manaProducer, Cost costToPay) {
if (super.apply(game, source)) {
MageObject object = game.getObject(source.getSourceId());
if (object.hasSubtype(SubType.DRAGON, game)
if (object != null && object.hasSubtype(SubType.DRAGON, game)
&& object.isCreature()) {
return true;
}

View file

@ -73,7 +73,7 @@ class HeraldsHornEffect extends OneShotEffect {
MageObject sourceObject = game.getObject(source.getSourceId());
// Look at the top card of your library.
if (controller != null && controller.getLibrary().hasCards()) {
if (controller != null && controller.getLibrary().hasCards() && sourceObject != null) {
Card card = controller.getLibrary().getFromTop(game);
Cards cards = new CardsImpl(card);
controller.lookAtCards(sourceObject.getIdName(), cards, game);

View file

@ -79,7 +79,7 @@ class JadeMonolithRedirectionEffect extends ReplacementEffectImpl {
Permanent targetCreature = game.getPermanent(source.getFirstTarget());
MageObject sourceObject = game.getObject(source.getSourceId());
DamageEvent damageEvent = (DamageEvent) event;
if (controller != null && targetCreature != null) {
if (controller != null && targetCreature != null && sourceObject != null) {
controller.damage(damageEvent.getAmount(), damageEvent.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), damageEvent.getAppliedEffects());
StringBuilder sb = new StringBuilder(sourceObject != null ? sourceObject.getLogName() : "");
sb.append(": ").append(damageEvent.getAmount()).append(" damage redirected from ").append(targetCreature.getLogName());

View file

@ -76,7 +76,7 @@ class JusticeTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
MageObject sourceObject = game.getObject(event.getSourceId());
if (sourceObject.getColor(game).isRed()) {
if (sourceObject != null && sourceObject.getColor(game).isRed()) {
if (sourceObject instanceof Permanent && sourceObject.isCreature()
|| sourceObject instanceof Spell) {
this.getEffects().get(0).setValue("damageAmount", event.getAmount());

View file

@ -84,7 +84,7 @@ class KeeperOfTheBeastsTarget extends TargetPlayer {
int count = 0;
MageObject targetSource = game.getObject(sourceId);
Player controller = game.getPlayer(sourceControllerId);
if (controller != null) {
if (controller != null && targetSource != null) {
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
Player player = game.getPlayer(playerId);
if (player != null

View file

@ -88,7 +88,7 @@ class KeeperOfTheLightTarget extends TargetPlayer {
int count = 0;
MageObject targetSource = game.getObject(sourceId);
Player controller = game.getPlayer(sourceControllerId);
if (controller != null) {
if (controller != null && targetSource != null) {
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
Player player = game.getPlayer(playerId);
if (player != null

View file

@ -80,8 +80,8 @@ class ChooseLetterEffect extends OneShotEffect {
ChoiceImpl choice = new ChoiceImpl(true);
choice.setMessage("Choose letter");
Set<String> choices = new HashSet<>();
for (Character letter = 'A'; letter <= 'Z'; letter++) {
choices.add(letter.toString());
for (char letter = 'A'; letter <= 'Z'; letter++) {
choices.add(Character.toString(letter));
}
choice.setChoices(choices);
@ -122,8 +122,8 @@ class MonkeyMonkeyMonkeyCount implements DynamicValue {
if (permanent != null && game.getState().getValue(mageObject.getId() + "_letter") != null) {
int letters = 0;
for (Permanent p : game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), sourceAbility.getControllerId(), sourceAbility.getSourceId(), game)) {
Character initial = Character.toUpperCase(p.getName().charAt(0));
if (initial.toString().equals(game.getState().getValue(mageObject.getId() + "_letter"))) {
char initial = Character.toUpperCase(p.getName().charAt(0));
if (Character.toString(initial).equals(game.getState().getValue(mageObject.getId() + "_letter"))) {
letters++;
}
}

View file

@ -62,7 +62,7 @@ class PatriarchsBiddingEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null) {
if (controller != null && sourceObject != null) {
Set<String> chosenTypes = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);

View file

@ -97,7 +97,7 @@ class PillarOfOriginsManaCondition extends CreatureCastManaCondition {
if (super.apply(game, source)) {
// check: ... of the chosen type
MageObject object = game.getObject(source.getSourceId());
if (creatureType != null && object.hasSubtype(creatureType, game)) {
if (creatureType != null && object != null && object.hasSubtype(creatureType, game)) {
return true;
}
}

View file

@ -80,13 +80,15 @@ class ETBSinceYourLastTurnTarget extends TargetCreaturePermanent {
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
MageObject targetSource = game.getObject(sourceId);
ETBSinceYourLastTurnWatcher watcher = (ETBSinceYourLastTurnWatcher) game.getState().getWatchers().get(ETBSinceYourLastTurnWatcher.class.getSimpleName());
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if(targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
if(watcher.enteredSinceLastTurn(sourceControllerId, new MageObjectReference(permanent.getId(), game))) {
if (watcher.enteredSinceLastTurn(sourceControllerId, new MageObjectReference(permanent.getId(), game))) {
return true;
}
}
}
}
return false;
}

View file

@ -73,11 +73,13 @@ class TargetControlledPermanentWithCMCGreaterOrLessThanOpponentPermanent extends
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
if(targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
}
}
return possibleTargets;
}
@ -121,6 +123,7 @@ class PucasMischiefSecondTarget extends TargetPermanent {
Set<UUID> possibleTargets = new HashSet<>();
if (firstTarget != null) {
MageObject targetSource = game.getObject(sourceId);
if (targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
if (firstTarget.getConvertedManaCost() >= permanent.getConvertedManaCost()) {
@ -129,6 +132,7 @@ class PucasMischiefSecondTarget extends TargetPermanent {
}
}
}
}
return possibleTargets;
}

View file

@ -82,6 +82,7 @@ class ReciprocateTarget extends TargetPermanent {
}
int count = 0;
MageObject targetSource = game.getObject(sourceId);
if(targetSource != null) {
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get(PlayerDamagedBySourceWatcher.class.getSimpleName(), sourceControllerId);
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)
@ -92,6 +93,7 @@ class ReciprocateTarget extends TargetPermanent {
}
}
}
}
return false;
}

View file

@ -119,6 +119,7 @@ class RemembranceEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if(mageObject != null) {
cardName = (String) game.getState().getValue(mageObject + "nameOfPermanent");
if (controller != null
&& cardName != null) {
@ -126,6 +127,7 @@ class RemembranceEffect extends OneShotEffect {
filterCard.add(new NamePredicate(cardName));
return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true).apply(game, source);
}
}
return false;
}
}

View file

@ -66,8 +66,9 @@ class RiptideChronologistEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (player != null && sourceObject != null) {
Choice typeChoice = new ChoiceCreatureType(sourceObject);
if (player != null && player.choose(outcome, typeChoice, game)) {
if (player.choose(outcome, typeChoice, game)) {
game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice());
FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent();
filterCreaturePermanent.add(new SubtypePredicate(SubType.byDescription(typeChoice.getChoice())));
@ -76,6 +77,7 @@ class RiptideChronologistEffect extends OneShotEffect {
}
return true;
}
}
return false;
}

View file

@ -69,7 +69,7 @@ class SamiteMinistrationEffect extends PreventionEffectImpl {
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionData = preventDamageAction(event, source, game);
MageObject sourceObject = game.getObject(event.getSourceId());
if (sourceObject.getColor(game).isBlack() || sourceObject.getColor(game).isRed()) {
if (sourceObject != null && (sourceObject.getColor(game).isBlack() || sourceObject.getColor(game).isRed())) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.gainLife(preventionData.getPreventedDamage(), game, source);

View file

@ -4,6 +4,7 @@ package mage.cards.s;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
@ -28,13 +29,12 @@ import mage.target.common.TargetCreaturePermanent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author LevelX2
*/
public final class SatyrFiredancer extends CardImpl {
public SatyrFiredancer(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT,CardType.CREATURE},"{1}{R}");
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT, CardType.CREATURE}, "{1}{R}");
this.subtype.add(SubType.SATYR);
this.power = new MageInt(1);
@ -100,12 +100,12 @@ class SatyrFiredancerTriggeredAbility extends TriggeredAbilityImpl {
if (damageSource != null) {
if (game.getOpponents(getControllerId()).contains(event.getTargetId())) {
MageObject object = game.getObject(event.getSourceId());
if (object.isInstant() || object.isSorcery()) {
if (object != null && (object.isInstant() || object.isSorcery())) {
if (!(damageSource instanceof StackObject) || !handledStackObjects.contains(damageSource.getId())) {
if (damageSource instanceof StackObject) {
handledStackObjects.add(damageSource.getId());
}
for (Effect effect: this.getEffects()) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId())); // used by adjust targets
effect.setValue("damage", event.getAmount());
}

View file

@ -72,9 +72,10 @@ class TargetPermanentsThatShareCardType extends TargetPermanent {
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
Set<CardType> cardTypes = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if(targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
for (CardType cardType :permanent.getCardType()) {
for (CardType cardType : permanent.getCardType()) {
if (cardTypes.contains(cardType)) {
return true;
}
@ -82,6 +83,7 @@ class TargetPermanentsThatShareCardType extends TargetPermanent {
cardTypes.addAll(permanent.getCardType());
}
}
}
return false;
}

View file

@ -103,7 +103,7 @@ class ShiningShoalRedirectDamageTargetEffect extends RedirectDamageFromSourceToT
return false;
}
// do the 2 objects match?
if (!sourceObject.getId().equals(chosenSourceObject.getId())) {
if (chosenSourceObject == null || !sourceObject.getId().equals(chosenSourceObject.getId())) {
return false;
}

View file

@ -78,11 +78,13 @@ class TargetControlledCreatureWithPowerGreaterOrLessThanOpponentPermanent extend
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
if(targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
}
}
return possibleTargets;
}
@ -126,6 +128,7 @@ class SpawnbrokerSecondTarget extends TargetPermanent {
Set<UUID> possibleTargets = new HashSet<>();
if (firstTarget != null) {
MageObject targetSource = game.getObject(sourceId);
if(targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
if (firstTarget.getPower().getValue() >= permanent.getPower().getValue()) {
@ -134,6 +137,7 @@ class SpawnbrokerSecondTarget extends TargetPermanent {
}
}
}
}
return possibleTargets;
}

View file

@ -111,7 +111,7 @@ class SphinxsDecreeCantCastEffect extends ContinuousRuleModifyingEffectImpl {
if (opponentId.equals(event.getPlayerId())) {
MageObject object = game.getObject(event.getSourceId());
if (event.getType() == GameEvent.EventType.CAST_SPELL) {
if (object.isInstant() || object.isSorcery()) {
if (object != null && (object.isInstant() || object.isSorcery())) {
return true;
}
}

View file

@ -129,7 +129,7 @@ class StaffOfTheLetterMagusEffect extends OneShotEffect {
int lifegainValue = 0;
String spellName = spell.getName();
for (int i = 0; i < spellName.length(); i++) {
Character letter = spellName.charAt(i);
char letter = spellName.charAt(i);
String chosenLetter = (String) game.getState().getValue(mageObject.getId() + "_letter");
if (Character.isLetter(letter) && Character.toUpperCase(letter) == chosenLetter.charAt(0)) {
lifegainValue++;

View file

@ -85,7 +85,7 @@ class StolenStrategyEffect extends OneShotEffect {
MageObject sourceObject = game.getObject(source.getSourceId());
UUID exileId = CardUtil.getCardExileZoneId(game, source);
Card card = damagedPlayer.getLibrary().getFromTop(game);
if (card != null) {
if (card != null && sourceObject != null) {
// move card to exile
controller.moveCardToExileWithInfo(card, exileId, sourceObject.getIdName(), source.getSourceId(), game, Zone.LIBRARY, true);
// Add effects only if the card has a spellAbility (e.g. not for lands).

View file

@ -85,14 +85,13 @@ class TariffEffect extends OneShotEffect {
Permanent creatureToPayFor = chooseOnePermanent(game, player, creatures);
if (creatureToPayFor != null) {
if (creatureToPayFor != null && sourceObject != null) {
ManaCosts manaCost = ManaCosts.removeVariableManaCost(creatureToPayFor.getManaCost());
String message = new StringBuilder("Pay ").append(manaCost.getText()).append(" (otherwise sacrifice ")
.append(creatureToPayFor.getName()).append(")?").toString();
String message = "Pay " + manaCost.getText() + " (otherwise sacrifice " +
creatureToPayFor.getName() + ")?";
if (player.chooseUse(Outcome.Benefit, message, source, game)) {
if (manaCost.pay(source, game, source.getSourceId(), player.getId(), false, null)) {
game.informPlayers(new StringBuilder(sourceObject != null ? sourceObject.getName() : "")
.append(": ").append(player.getLogName()).append(" has paid").toString());
game.informPlayers(sourceObject.getName() + ": " + player.getLogName() + " has paid");
return;
}
}

View file

@ -78,13 +78,15 @@ class TargetCreatureWithPowerLessThanNumberOfCardsInYourGraveyard extends Target
@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
MageObject targetSource = game.getObject(sourceId);
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if(targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
if(permanent.getPower().getValue() < game.getPlayer(sourceControllerId).getGraveyard().size()) {
if (permanent.getPower().getValue() < game.getPlayer(sourceControllerId).getGraveyard().size()) {
return true;
}
}
}
}
return false;
}

View file

@ -81,7 +81,7 @@ class TobiasBeckettEffect extends OneShotEffect {
MageObject sourceObject = game.getObject(source.getSourceId());
UUID exileId = CardUtil.getCardExileZoneId(game, source);
Card card = opponent.getLibrary().getFromTop(game);
if (card != null) {
if (card != null && sourceObject != null) {
// move card to exile
controller.moveCardToExileWithInfo(card, exileId, sourceObject.getIdName(), source.getSourceId(), game, Zone.LIBRARY, true);
// Add effects only if the card has a spellAbility (e.g. not for lands).

View file

@ -72,6 +72,9 @@ class ToppleTargetCreature extends TargetCreaturePermanent {
List<Permanent> activePermanents = game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game);
Set<UUID> possibleTargets = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
if(targetSource == null){
return possibleTargets;
}
for (Permanent permanent : activePermanents) {
if (permanent.getPower().getValue() > maxPower) {
maxPower = permanent.getPower().getValue();

View file

@ -107,6 +107,9 @@ class TriumphOfGerrardTargetCreature extends TargetControlledCreaturePermanent {
List<Permanent> activePermanents = game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game);
Set<UUID> possibleTargets = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
if(targetSource == null){
return possibleTargets;
}
for (Permanent permanent : activePermanents) {
if (permanent.getPower().getValue() > maxPower) {
maxPower = permanent.getPower().getValue();

View file

@ -64,6 +64,7 @@ class TsabosDecreeEffect extends OneShotEffect {
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
MageObject sourceObject = game.getObject(source.getSourceId());
if (player != null) {
if(sourceObject != null) {
Choice typeChoice = new ChoiceCreatureType(sourceObject);
if (!player.choose(outcome, typeChoice, game)) {
return false;
@ -90,6 +91,7 @@ class TsabosDecreeEffect extends OneShotEffect {
}
return true;
}
}
return false;
}

View file

@ -104,7 +104,7 @@ class UnclaimedTerritoryManaCondition extends CreatureCastManaCondition {
if (super.apply(game, source)) {
// check: ... of the chosen type
MageObject object = game.getObject(source.getSourceId());
if (creatureType != null && object.hasSubtype(creatureType, game)) {
if (creatureType != null && object != null && object.hasSubtype(creatureType, game)) {
return true;
}
}

View file

@ -72,13 +72,13 @@ class LookAtRandomCardEffect extends OneShotEffect {
Player you = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
MageObject sourceObject = game.getObject(source.getSourceId());
if (you != null && targetPlayer != null) {
if (you != null && targetPlayer != null && sourceObject != null) {
if(!targetPlayer.getHand().isEmpty())
{
Cards randomCard = new CardsImpl();
Card card = targetPlayer.getHand().getRandom(game);
randomCard.add(card);
you.lookAtCards(sourceObject != null ? sourceObject.getName() : null, randomCard, game);
you.lookAtCards(sourceObject.getName(), randomCard, game);
}
return true;
}

View file

@ -84,7 +84,7 @@ class VerdantSuccessionTriggeredAbility extends TriggeredAbilityImpl {
&& ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
MageObject mageObject = game.getObject(sourceId);
if (permanent != null
if (permanent != null && mageObject != null
&& filter.match(permanent, game)) {
game.getState().setValue("verdantSuccession" + mageObject, permanent);
return true;
@ -119,6 +119,7 @@ class VerdantSuccessionEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
MageObject mageObject = game.getObject(source.getSourceId());
if(mageObject != null) {
permanent = (Permanent) game.getState().getValue("verdantSuccession" + mageObject);
if (permanent != null) {
Player controller = game.getPlayer(permanent.getControllerId());
@ -137,6 +138,7 @@ class VerdantSuccessionEffect extends OneShotEffect {
}
}
}
}
return false;
}
}

View file

@ -65,7 +65,7 @@ class VillainousWealthEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null) {
if (controller != null && mageObject != null) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
FilterCard filter = new FilterNonlandCard();
filter.add(new ConvertedManaCostPredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));

View file

@ -2,6 +2,7 @@
package mage.cards.w;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
@ -22,7 +23,6 @@ import mage.game.Game;
import mage.players.Player;
/**
*
* @author fireshoes
*/
public final class WalkingDesecration extends CardImpl {
@ -64,8 +64,10 @@ class WalkingDesecrationEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (player != null) {
if (sourceObject != null) {
Choice typeChoice = new ChoiceCreatureType(sourceObject);
if (player != null && player.choose(outcome, typeChoice, game)) {
if (player.choose(outcome, typeChoice, game)) {
game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice());
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new SubtypePredicate(SubType.byDescription(typeChoice.getChoice())));
@ -73,6 +75,8 @@ class WalkingDesecrationEffect extends OneShotEffect {
game.addEffect(effect, source);
return true;
}
}
}
return false;
}