From da3c8613448e710f9641f19e86b9f4e59c447d4e Mon Sep 17 00:00:00 2001 From: Ingmar Goudt Date: Mon, 31 Dec 2018 16:03:36 +0100 Subject: [PATCH] add nullchecks for game.getObject --- Mage.Sets/src/mage/cards/a/Abeyance.java | 3 + .../src/mage/cards/a/AcolytesReward.java | 6 +- .../src/mage/cards/a/AdviceFromTheFae.java | 2 +- .../src/mage/cards/a/AllianceOfArms.java | 2 +- .../src/mage/cards/a/AvenMimeomancer.java | 4 +- Mage.Sets/src/mage/cards/a/AvenShrine.java | 30 ++++--- Mage.Sets/src/mage/cards/b/BalaGedThief.java | 2 +- .../src/mage/cards/b/BaneAlleyBroker.java | 2 +- Mage.Sets/src/mage/cards/b/BlazeCommando.java | 2 +- Mage.Sets/src/mage/cards/b/BlazingHope.java | 16 ++-- .../src/mage/cards/b/BloodlineShaman.java | 2 +- Mage.Sets/src/mage/cards/b/BombSquad.java | 2 +- .../src/mage/cards/b/BraceForImpact.java | 2 +- .../src/mage/cards/b/BrandedBrawlers.java | 2 +- Mage.Sets/src/mage/cards/c/CabalShrine.java | 30 ++++--- Mage.Sets/src/mage/cards/c/CandlesGlow.java | 4 +- .../src/mage/cards/c/CarpetOfFlowers.java | 3 +- Mage.Sets/src/mage/cards/c/CavernOfSouls.java | 2 +- .../src/mage/cards/c/CephalidShrine.java | 52 +++++------ .../src/mage/cards/c/CharmbreakerDevils.java | 2 +- .../src/mage/cards/c/CollectiveVoyage.java | 2 +- Mage.Sets/src/mage/cards/c/ColossalWhale.java | 2 +- .../src/mage/cards/c/CrownOfTheAges.java | 4 +- .../src/mage/cards/c/CrushUnderfoot.java | 2 +- Mage.Sets/src/mage/cards/c/CurseOfChaos.java | 2 +- Mage.Sets/src/mage/cards/d/DaringThief.java | 68 +++++++------- .../src/mage/cards/d/DaxosOfMeletis.java | 2 +- .../src/mage/cards/d/DeadbridgeChant.java | 2 +- Mage.Sets/src/mage/cards/d/DeathDenied.java | 2 +- Mage.Sets/src/mage/cards/d/DecayingSoil.java | 2 +- .../src/mage/cards/d/DiscipleOfDeceit.java | 2 +- Mage.Sets/src/mage/cards/d/DropOfHoney.java | 4 +- Mage.Sets/src/mage/cards/d/DustOfMoments.java | 16 ++-- Mage.Sets/src/mage/cards/d/DwarvenShrine.java | 30 ++++--- .../mage/cards/e/ElbrusTheBindingBlade.java | 2 +- .../src/mage/cards/e/ElvishSoultiller.java | 26 +++--- .../src/mage/cards/e/ExecutionersSwing.java | 2 +- Mage.Sets/src/mage/cards/e/Extinction.java | 19 ++-- .../src/mage/cards/g/GauntletsOfChaos.java | 88 +++++++++---------- .../src/mage/cards/g/GlamerSpinners.java | 6 +- .../src/mage/cards/g/GnarlrootTrapper.java | 2 +- .../src/mage/cards/g/GrenzoHavocRaiser.java | 2 +- Mage.Sets/src/mage/cards/g/GridMonitor.java | 2 +- Mage.Sets/src/mage/cards/g/GrimReminder.java | 4 +- Mage.Sets/src/mage/cards/g/GrimoireThief.java | 2 +- Mage.Sets/src/mage/cards/g/GrinningTotem.java | 2 +- Mage.Sets/src/mage/cards/h/HandToHand.java | 2 +- .../mage/cards/h/HavenOfTheSpiritDragon.java | 2 +- Mage.Sets/src/mage/cards/h/HeraldsHorn.java | 2 +- Mage.Sets/src/mage/cards/j/JadeMonolith.java | 2 +- Mage.Sets/src/mage/cards/j/Justice.java | 2 +- .../src/mage/cards/k/KeeperOfTheBeasts.java | 2 +- .../src/mage/cards/k/KeeperOfTheLight.java | 2 +- .../src/mage/cards/m/MonkeyMonkeyMonkey.java | 8 +- .../src/mage/cards/p/PatriarchsBidding.java | 2 +- .../src/mage/cards/p/PillarOfOrigins.java | 2 +- .../src/mage/cards/p/PrematureBurial.java | 10 ++- Mage.Sets/src/mage/cards/p/PucasMischief.java | 18 ++-- Mage.Sets/src/mage/cards/r/Reciprocate.java | 16 ++-- Mage.Sets/src/mage/cards/r/Remembrance.java | 14 +-- .../src/mage/cards/r/RiptideChronologist.java | 18 ++-- .../src/mage/cards/s/SamiteMinistration.java | 2 +- .../src/mage/cards/s/SatyrFiredancer.java | 16 ++-- .../src/mage/cards/s/ShiftingLoyalties.java | 14 +-- Mage.Sets/src/mage/cards/s/ShiningShoal.java | 2 +- Mage.Sets/src/mage/cards/s/Spawnbroker.java | 18 ++-- Mage.Sets/src/mage/cards/s/SphinxsDecree.java | 2 +- .../mage/cards/s/StaffOfTheLetterMagus.java | 2 +- .../src/mage/cards/s/StolenStrategy.java | 2 +- Mage.Sets/src/mage/cards/t/Tariff.java | 9 +- .../src/mage/cards/t/TemporaryInsanity.java | 10 ++- Mage.Sets/src/mage/cards/t/TobiasBeckett.java | 2 +- Mage.Sets/src/mage/cards/t/Topple.java | 3 + .../src/mage/cards/t/TriumphOfGerrard.java | 3 + Mage.Sets/src/mage/cards/t/TsabosDecree.java | 46 +++++----- .../src/mage/cards/u/UnclaimedTerritory.java | 2 +- Mage.Sets/src/mage/cards/u/UrzasBauble.java | 4 +- .../src/mage/cards/v/VerdantSuccession.java | 32 +++---- .../src/mage/cards/v/VillainousWealth.java | 2 +- .../src/mage/cards/w/WalkingDesecration.java | 22 +++-- 80 files changed, 408 insertions(+), 354 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/Abeyance.java b/Mage.Sets/src/mage/cards/a/Abeyance.java index d2692d74fd..dd9714b9d3 100644 --- a/Mage.Sets/src/mage/cards/a/Abeyance.java +++ b/Mage.Sets/src/mage/cards/a/Abeyance.java @@ -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; diff --git a/Mage.Sets/src/mage/cards/a/AcolytesReward.java b/Mage.Sets/src/mage/cards/a/AcolytesReward.java index 012d5e1cc1..7f48be367e 100644 --- a/Mage.Sets/src/mage/cards/a/AcolytesReward.java +++ b/Mage.Sets/src/mage/cards/a/AcolytesReward.java @@ -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()); } } } diff --git a/Mage.Sets/src/mage/cards/a/AdviceFromTheFae.java b/Mage.Sets/src/mage/cards/a/AdviceFromTheFae.java index 49876ba87a..fcf6697af8 100644 --- a/Mage.Sets/src/mage/cards/a/AdviceFromTheFae.java +++ b/Mage.Sets/src/mage/cards/a/AdviceFromTheFae.java @@ -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 topCards = controller.getLibrary().getTopCards(game, 5); Cards cardsFromLibrary = new CardsImpl(); for (Card card : topCards) { diff --git a/Mage.Sets/src/mage/cards/a/AllianceOfArms.java b/Mage.Sets/src/mage/cards/a/AllianceOfArms.java index 30533ffff2..3dcf8431e5 100644 --- a/Mage.Sets/src/mage/cards/a/AllianceOfArms.java +++ b/Mage.Sets/src/mage/cards/a/AllianceOfArms.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/a/AvenMimeomancer.java b/Mage.Sets/src/mage/cards/a/AvenMimeomancer.java index 64ccbf893f..dcb30c301d 100644 --- a/Mage.Sets/src/mage/cards/a/AvenMimeomancer.java +++ b/Mage.Sets/src/mage/cards/a/AvenMimeomancer.java @@ -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"; } } diff --git a/Mage.Sets/src/mage/cards/a/AvenShrine.java b/Mage.Sets/src/mage/cards/a/AvenShrine.java index d949acb21f..7bf7b50760 100644 --- a/Mage.Sets/src/mage/cards/a/AvenShrine.java +++ b/Mage.Sets/src/mage/cards/a/AvenShrine.java @@ -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,21 +91,23 @@ class AvenShrineEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { int count = 0; MageObject mageObject = game.getObject(source.getSourceId()); - Spell spell = (Spell) game.getState().getValue("avenShrine" + mageObject); - if (spell != null) { - Player controller = game.getPlayer(spell.getControllerId()); - if (controller != null) { - String name = spell.getName(); - FilterCard filterCardName = new FilterCard(); - filterCardName.add(new NamePredicate(name)); - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - count += player.getGraveyard().count(filterCardName, game); + if(mageObject != null) { + Spell spell = (Spell) game.getState().getValue("avenShrine" + mageObject); + if (spell != null) { + Player controller = game.getPlayer(spell.getControllerId()); + if (controller != null) { + String name = spell.getName(); + FilterCard filterCardName = new FilterCard(); + filterCardName.add(new NamePredicate(name)); + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + Player player = game.getPlayer(playerId); + if (player != null) { + count += player.getGraveyard().count(filterCardName, game); + } } + controller.gainLife(count, game, source); + return true; } - controller.gainLife(count, game, source); - return true; } } return false; diff --git a/Mage.Sets/src/mage/cards/b/BalaGedThief.java b/Mage.Sets/src/mage/cards/b/BalaGedThief.java index 50f18dede1..1ab4059d2c 100644 --- a/Mage.Sets/src/mage/cards/b/BalaGedThief.java +++ b/Mage.Sets/src/mage/cards/b/BalaGedThief.java @@ -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; diff --git a/Mage.Sets/src/mage/cards/b/BaneAlleyBroker.java b/Mage.Sets/src/mage/cards/b/BaneAlleyBroker.java index 4527e5460a..6c7e3f8b9b 100644 --- a/Mage.Sets/src/mage/cards/b/BaneAlleyBroker.java +++ b/Mage.Sets/src/mage/cards/b/BaneAlleyBroker.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/b/BlazeCommando.java b/Mage.Sets/src/mage/cards/b/BlazeCommando.java index 07376a338c..64d8c84bf5 100644 --- a/Mage.Sets/src/mage/cards/b/BlazeCommando.java +++ b/Mage.Sets/src/mage/cards/b/BlazeCommando.java @@ -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(); } } diff --git a/Mage.Sets/src/mage/cards/b/BlazingHope.java b/Mage.Sets/src/mage/cards/b/BlazingHope.java index 4708a0241e..3ca5a50c30 100644 --- a/Mage.Sets/src/mage/cards/b/BlazingHope.java +++ b/Mage.Sets/src/mage/cards/b/BlazingHope.java @@ -75,13 +75,15 @@ class BlazingHopeTarget extends TargetCreaturePermanent { int count = 0; Player controller = game.getPlayer(sourceControllerId); MageObject targetSource = game.getObject(sourceId); - for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { - if (!targets.containsKey(permanent.getId())) { - if (notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { - if (controller != null && permanent.getPower().getValue() >= controller.getLife()) { - count++; - if (count >= remainingTargets) { - return true; + 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)) { + if (controller != null && permanent.getPower().getValue() >= controller.getLife()) { + count++; + if (count >= remainingTargets) { + return true; + } } } } diff --git a/Mage.Sets/src/mage/cards/b/BloodlineShaman.java b/Mage.Sets/src/mage/cards/b/BloodlineShaman.java index d658ab2bbf..9cae143784 100644 --- a/Mage.Sets/src/mage/cards/b/BloodlineShaman.java +++ b/Mage.Sets/src/mage/cards/b/BloodlineShaman.java @@ -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()))); diff --git a/Mage.Sets/src/mage/cards/b/BombSquad.java b/Mage.Sets/src/mage/cards/b/BombSquad.java index b0cd273ca4..fdfb32772f 100644 --- a/Mage.Sets/src/mage/cards/b/BombSquad.java +++ b/Mage.Sets/src/mage/cards/b/BombSquad.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/b/BraceForImpact.java b/Mage.Sets/src/mage/cards/b/BraceForImpact.java index 9d45dbaedd..28f17918e2 100644 --- a/Mage.Sets/src/mage/cards/b/BraceForImpact.java +++ b/Mage.Sets/src/mage/cards/b/BraceForImpact.java @@ -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()); } } diff --git a/Mage.Sets/src/mage/cards/b/BrandedBrawlers.java b/Mage.Sets/src/mage/cards/b/BrandedBrawlers.java index dd1acafed7..b7bff9ce2e 100644 --- a/Mage.Sets/src/mage/cards/b/BrandedBrawlers.java +++ b/Mage.Sets/src/mage/cards/b/BrandedBrawlers.java @@ -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) { diff --git a/Mage.Sets/src/mage/cards/c/CabalShrine.java b/Mage.Sets/src/mage/cards/c/CabalShrine.java index e58672dbfe..fe994ad773 100644 --- a/Mage.Sets/src/mage/cards/c/CabalShrine.java +++ b/Mage.Sets/src/mage/cards/c/CabalShrine.java @@ -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,21 +91,23 @@ class CabalShrineEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { int count = 0; MageObject mageObject = game.getObject(source.getSourceId()); - Spell spell = (Spell) game.getState().getValue("cabalShrine" + mageObject); - if (spell != null) { - Player controller = game.getPlayer(spell.getControllerId()); - if (controller != null) { - String name = spell.getName(); - FilterCard filterCardName = new FilterCard(); - filterCardName.add(new NamePredicate(name)); - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - count += player.getGraveyard().count(filterCardName, game); + if(mageObject != null) { + Spell spell = (Spell) game.getState().getValue("cabalShrine" + mageObject); + if (spell != null) { + Player controller = game.getPlayer(spell.getControllerId()); + if (controller != null) { + String name = spell.getName(); + FilterCard filterCardName = new FilterCard(); + filterCardName.add(new NamePredicate(name)); + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + Player player = game.getPlayer(playerId); + if (player != null) { + count += player.getGraveyard().count(filterCardName, game); + } } + controller.discard(count, false, source, game); + return true; } - controller.discard(count, false, source, game); - return true; } } return false; diff --git a/Mage.Sets/src/mage/cards/c/CandlesGlow.java b/Mage.Sets/src/mage/cards/c/CandlesGlow.java index 158da85435..7bf8e711e2 100644 --- a/Mage.Sets/src/mage/cards/c/CandlesGlow.java +++ b/Mage.Sets/src/mage/cards/c/CandlesGlow.java @@ -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"); } } } diff --git a/Mage.Sets/src/mage/cards/c/CarpetOfFlowers.java b/Mage.Sets/src/mage/cards/c/CarpetOfFlowers.java index 64f3dc27f9..947525af65 100644 --- a/Mage.Sets/src/mage/cards/c/CarpetOfFlowers.java +++ b/Mage.Sets/src/mage/cards/c/CarpetOfFlowers.java @@ -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(); } } diff --git a/Mage.Sets/src/mage/cards/c/CavernOfSouls.java b/Mage.Sets/src/mage/cards/c/CavernOfSouls.java index e1a5f5a2a1..87e9f839eb 100644 --- a/Mage.Sets/src/mage/cards/c/CavernOfSouls.java +++ b/Mage.Sets/src/mage/cards/c/CavernOfSouls.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/c/CephalidShrine.java b/Mage.Sets/src/mage/cards/c/CephalidShrine.java index b8cc075cc5..4bd752a840 100644 --- a/Mage.Sets/src/mage/cards/c/CephalidShrine.java +++ b/Mage.Sets/src/mage/cards/c/CephalidShrine.java @@ -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,31 +93,33 @@ class CephalidShrineEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { int count = 0; MageObject mageObject = game.getObject(source.getSourceId()); - Spell spell = (Spell) game.getState().getValue("cephalidShrine" + mageObject); - if (spell != null) { - Player controller = game.getPlayer(spell.getControllerId()); - if (controller != null) { - String name = spell.getName(); - FilterCard filterCardName = new FilterCard(); - filterCardName.add(new NamePredicate(name)); - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - count += player.getGraveyard().count(filterCardName, game); + if(mageObject != null) { + Spell spell = (Spell) game.getState().getValue("cephalidShrine" + mageObject); + if (spell != null) { + Player controller = game.getPlayer(spell.getControllerId()); + if (controller != null) { + String name = spell.getName(); + FilterCard filterCardName = new FilterCard(); + filterCardName.add(new NamePredicate(name)); + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + Player player = game.getPlayer(playerId); + if (player != null) { + count += player.getGraveyard().count(filterCardName, game); + } + } + // even if the cost is 0, we still offer + Cost cost = new GenericManaCost(count); + if (game.getStack().contains((StackObject) spell) + && cost.canPay(source, source.getSourceId(), controller.getId(), game) + && controller.chooseUse(outcome, "Pay " + cost.getText() + " to prevent countering " + spell.getName() + "?", source, game) + && cost.pay(source, game, source.getSourceId(), controller.getId(), false) + && cost.isPaid()) { + return false; + } else { + spell.counter(source.getId(), game); + game.informPlayers(spell.getName() + " has been countered due to " + controller.getName() + " not paying " + cost.getText()); + return true; } - } - // even if the cost is 0, we still offer - Cost cost = new GenericManaCost(count); - if (game.getStack().contains((StackObject) spell) - && cost.canPay(source, source.getSourceId(), controller.getId(), game) - && controller.chooseUse(outcome, "Pay " + cost.getText() + " to prevent countering " + spell.getName() + "?", source, game) - && cost.pay(source, game, source.getSourceId(), controller.getId(), false) - && cost.isPaid()) { - return false; - } else { - spell.counter(source.getId(), game); - game.informPlayers(spell.getName() + " has been countered due to " + controller.getName() + " not paying " + cost.getText()); - return true; } } } diff --git a/Mage.Sets/src/mage/cards/c/CharmbreakerDevils.java b/Mage.Sets/src/mage/cards/c/CharmbreakerDevils.java index 2d4f308185..2158bd95f8 100644 --- a/Mage.Sets/src/mage/cards/c/CharmbreakerDevils.java +++ b/Mage.Sets/src/mage/cards/c/CharmbreakerDevils.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/c/CollectiveVoyage.java b/Mage.Sets/src/mage/cards/c/CollectiveVoyage.java index bcdcda9492..11a0f6ddc9 100644 --- a/Mage.Sets/src/mage/cards/c/CollectiveVoyage.java +++ b/Mage.Sets/src/mage/cards/c/CollectiveVoyage.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/c/ColossalWhale.java b/Mage.Sets/src/mage/cards/c/ColossalWhale.java index b1d47d77ed..8a4ac9a8d2 100644 --- a/Mage.Sets/src/mage/cards/c/ColossalWhale.java +++ b/Mage.Sets/src/mage/cards/c/ColossalWhale.java @@ -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 diff --git a/Mage.Sets/src/mage/cards/c/CrownOfTheAges.java b/Mage.Sets/src/mage/cards/c/CrownOfTheAges.java index 29fb1beecf..1fbe8b43e2 100644 --- a/Mage.Sets/src/mage/cards/c/CrownOfTheAges.java +++ b/Mage.Sets/src/mage/cards/c/CrownOfTheAges.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/c/CrushUnderfoot.java b/Mage.Sets/src/mage/cards/c/CrushUnderfoot.java index 623d5007af..692f43ca97 100644 --- a/Mage.Sets/src/mage/cards/c/CrushUnderfoot.java +++ b/Mage.Sets/src/mage/cards/c/CrushUnderfoot.java @@ -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); diff --git a/Mage.Sets/src/mage/cards/c/CurseOfChaos.java b/Mage.Sets/src/mage/cards/c/CurseOfChaos.java index 4b5e917876..e30c0a860e 100644 --- a/Mage.Sets/src/mage/cards/c/CurseOfChaos.java +++ b/Mage.Sets/src/mage/cards/c/CurseOfChaos.java @@ -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 diff --git a/Mage.Sets/src/mage/cards/d/DaringThief.java b/Mage.Sets/src/mage/cards/d/DaringThief.java index 6c78419114..f61519a5df 100644 --- a/Mage.Sets/src/mage/cards/d/DaringThief.java +++ b/Mage.Sets/src/mage/cards/d/DaringThief.java @@ -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); @@ -41,7 +41,7 @@ public final class DaringThief extends CardImpl { this.toughness = new MageInt(3); // Inspired - Whenever Daring Thief becomes untapped, you may exchange control of target nonland permanent you control and target permanent an opponent controls that shares a card type with it. - Ability ability = new InspiredAbility(new ExchangeControlTargetEffect(Duration.EndOfGame, + Ability ability = new InspiredAbility(new ExchangeControlTargetEffect(Duration.EndOfGame, "you may exchange control of target nonland permanent you control and target permanent an opponent controls that shares a card type with it", false, true), true); ability.addTarget(new TargetControlledPermanentSharingOpponentPermanentCardType()); ability.addTarget(new DaringThiefSecondTarget()); @@ -59,23 +59,23 @@ public final class DaringThief extends CardImpl { } class TargetControlledPermanentSharingOpponentPermanentCardType extends TargetControlledPermanent { - + public TargetControlledPermanentSharingOpponentPermanentCardType() { super(); this.filter = this.filter.copy(); filter.add(Predicates.not(new CardTypePredicate(CardType.LAND))); setTargetName("nonland permanent you control"); - } - + } + public TargetControlledPermanentSharingOpponentPermanentCardType(final TargetControlledPermanentSharingOpponentPermanentCardType target) { super(target); } - + @Override public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { if (super.canTarget(controllerId, id, source, game)) { Set cardTypes = getOpponentPermanentCardTypes(source.getSourceId(), controllerId, game); - Permanent permanent = game.getPermanent(id); + Permanent permanent = game.getPermanent(id); for (CardType type : permanent.getCardType()) { if (cardTypes.contains(type)) { return true; @@ -84,36 +84,38 @@ class TargetControlledPermanentSharingOpponentPermanentCardType extends TargetCo } return false; } - + @Override public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { // get all cardtypes from opponents permanents Set cardTypes = getOpponentPermanentCardTypes(sourceId, sourceControllerId, game); Set possibleTargets = new HashSet<>(); MageObject targetSource = game.getObject(sourceId); - 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)) { - possibleTargets.add(permanent.getId()); - break; - } + 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)) { + possibleTargets.add(permanent.getId()); + break; + } + } } } } - return possibleTargets; + return possibleTargets; } - + @Override public TargetControlledPermanentSharingOpponentPermanentCardType copy() { return new TargetControlledPermanentSharingOpponentPermanentCardType(this); } - + private EnumSet getOpponentPermanentCardTypes(UUID sourceId, UUID sourceControllerId, Game game) { Player controller = game.getPlayer(sourceControllerId); - EnumSet cardTypes =EnumSet.noneOf(CardType.class); + EnumSet 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()); } @@ -127,20 +129,20 @@ class TargetControlledPermanentSharingOpponentPermanentCardType extends TargetCo class DaringThiefSecondTarget extends TargetPermanent { private Permanent firstTarget = null; - + public DaringThiefSecondTarget() { super(); this.filter = this.filter.copy(); filter.add(new ControllerPredicate(TargetController.OPPONENT)); setTargetName("permanent an opponent controls that shares a card type with it"); - } + } public DaringThiefSecondTarget(final DaringThiefSecondTarget target) { super(target); this.firstTarget = target.firstTarget; } - + @Override public boolean canTarget(UUID id, Ability source, Game game) { if (super.canTarget(id, source, game)) { @@ -152,29 +154,31 @@ class DaringThiefSecondTarget extends TargetPermanent { } return false; } - + @Override public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { Set possibleTargets = new HashSet<>(); if (firstTarget != null) { MageObject targetSource = game.getObject(sourceId); - for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { - if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { - if (permanent.shareTypes(firstTarget)) { - possibleTargets.add(permanent.getId()); + 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)) { + possibleTargets.add(permanent.getId()); + } } } } } return possibleTargets; } - + @Override public boolean chooseTarget(Outcome outcome, UUID playerId, Ability source, Game game) { firstTarget = game.getPermanent(source.getFirstTarget()); return super.chooseTarget(Outcome.Damage, playerId, source, game); - } - + } + @Override public DaringThiefSecondTarget copy() { return new DaringThiefSecondTarget(this); diff --git a/Mage.Sets/src/mage/cards/d/DaxosOfMeletis.java b/Mage.Sets/src/mage/cards/d/DaxosOfMeletis.java index 87131ba9ba..46d31f47e4 100644 --- a/Mage.Sets/src/mage/cards/d/DaxosOfMeletis.java +++ b/Mage.Sets/src/mage/cards/d/DaxosOfMeletis.java @@ -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 diff --git a/Mage.Sets/src/mage/cards/d/DeadbridgeChant.java b/Mage.Sets/src/mage/cards/d/DeadbridgeChant.java index 9857b7b602..3437bb03a0 100644 --- a/Mage.Sets/src/mage/cards/d/DeadbridgeChant.java +++ b/Mage.Sets/src/mage/cards/d/DeadbridgeChant.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/d/DeathDenied.java b/Mage.Sets/src/mage/cards/d/DeathDenied.java index 0fe70f8a59..e54bf6697e 100644 --- a/Mage.Sets/src/mage/cards/d/DeathDenied.java +++ b/Mage.Sets/src/mage/cards/d/DeathDenied.java @@ -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); } } diff --git a/Mage.Sets/src/mage/cards/d/DecayingSoil.java b/Mage.Sets/src/mage/cards/d/DecayingSoil.java index d32aa25a43..dec74944c5 100644 --- a/Mage.Sets/src/mage/cards/d/DecayingSoil.java +++ b/Mage.Sets/src/mage/cards/d/DecayingSoil.java @@ -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(); } } diff --git a/Mage.Sets/src/mage/cards/d/DiscipleOfDeceit.java b/Mage.Sets/src/mage/cards/d/DiscipleOfDeceit.java index 5bd24e3e10..51f1c84f64 100644 --- a/Mage.Sets/src/mage/cards/d/DiscipleOfDeceit.java +++ b/Mage.Sets/src/mage/cards/d/DiscipleOfDeceit.java @@ -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); diff --git a/Mage.Sets/src/mage/cards/d/DropOfHoney.java b/Mage.Sets/src/mage/cards/d/DropOfHoney.java index b9c619b819..8f69d77020 100644 --- a/Mage.Sets/src/mage/cards/d/DropOfHoney.java +++ b/Mage.Sets/src/mage/cards/d/DropOfHoney.java @@ -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(); } } \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/d/DustOfMoments.java b/Mage.Sets/src/mage/cards/d/DustOfMoments.java index de75c254c0..742418813e 100644 --- a/Mage.Sets/src/mage/cards/d/DustOfMoments.java +++ b/Mage.Sets/src/mage/cards/d/DustOfMoments.java @@ -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()); } } } diff --git a/Mage.Sets/src/mage/cards/d/DwarvenShrine.java b/Mage.Sets/src/mage/cards/d/DwarvenShrine.java index 0c37d8c951..8aa1f05f06 100644 --- a/Mage.Sets/src/mage/cards/d/DwarvenShrine.java +++ b/Mage.Sets/src/mage/cards/d/DwarvenShrine.java @@ -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,21 +90,23 @@ class DwarvenShrineEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { int count = 0; MageObject mageObject = game.getObject(source.getSourceId()); - Spell spell = (Spell) game.getState().getValue("dwarvenShrine" + mageObject); - if (spell != null) { - Player controller = game.getPlayer(spell.getControllerId()); - if (controller != null) { - String name = spell.getName(); - FilterCard filterCardName = new FilterCard(); - filterCardName.add(new NamePredicate(name)); - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - count += player.getGraveyard().count(filterCardName, game); + if(mageObject != null) { + Spell spell = (Spell) game.getState().getValue("dwarvenShrine" + mageObject); + if (spell != null) { + Player controller = game.getPlayer(spell.getControllerId()); + if (controller != null) { + String name = spell.getName(); + FilterCard filterCardName = new FilterCard(); + filterCardName.add(new NamePredicate(name)); + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + Player player = game.getPlayer(playerId); + if (player != null) { + count += player.getGraveyard().count(filterCardName, game); + } } + controller.damage(count * 2, mageObject.getId(), game, false, true); + return true; } - controller.damage(count * 2, mageObject.getId(), game, false, true); - return true; } } return false; diff --git a/Mage.Sets/src/mage/cards/e/ElbrusTheBindingBlade.java b/Mage.Sets/src/mage/cards/e/ElbrusTheBindingBlade.java index d949dd182a..7c88a09f72 100644 --- a/Mage.Sets/src/mage/cards/e/ElbrusTheBindingBlade.java +++ b/Mage.Sets/src/mage/cards/e/ElbrusTheBindingBlade.java @@ -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()); } } diff --git a/Mage.Sets/src/mage/cards/e/ElvishSoultiller.java b/Mage.Sets/src/mage/cards/e/ElvishSoultiller.java index 34ec6693f8..e5bbd37e20 100644 --- a/Mage.Sets/src/mage/cards/e/ElvishSoultiller.java +++ b/Mage.Sets/src/mage/cards/e/ElvishSoultiller.java @@ -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,18 +69,20 @@ class ElvishSoultillerEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); MageObject mageObject = game.getObject(source.getSourceId()); - Choice typeChoice = new ChoiceCreatureType(mageObject); - if (controller != null && mageObject != null && controller.choose(outcome, typeChoice, game)) { - if (!game.isSimulation()) { - game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice()); + if (controller != null && mageObject != null) { + Choice typeChoice = new ChoiceCreatureType(mageObject); + if (controller.choose(outcome, typeChoice, game)) { + if (!game.isSimulation()) { + game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice()); + } + Cards cardsToLibrary = new CardsImpl(); + FilterCreatureCard filter = new FilterCreatureCard(); + filter.add(new SubtypePredicate(SubType.byDescription(typeChoice.getChoice()))); + cardsToLibrary.addAll(controller.getGraveyard().getCards(filter, source.getSourceId(), source.getControllerId(), game)); + controller.putCardsOnTopOfLibrary(cardsToLibrary, game, source, false); + controller.shuffleLibrary(source, game); + return true; } - Cards cardsToLibrary = new CardsImpl(); - FilterCreatureCard filter = new FilterCreatureCard(); - filter.add(new SubtypePredicate(SubType.byDescription(typeChoice.getChoice()))); - cardsToLibrary.addAll(controller.getGraveyard().getCards(filter, source.getSourceId(), source.getControllerId(), game)); - controller.putCardsOnTopOfLibrary(cardsToLibrary, game, source, false); - controller.shuffleLibrary(source, game); - return true; } return false; } diff --git a/Mage.Sets/src/mage/cards/e/ExecutionersSwing.java b/Mage.Sets/src/mage/cards/e/ExecutionersSwing.java index 40dae7bd51..668225ef53 100644 --- a/Mage.Sets/src/mage/cards/e/ExecutionersSwing.java +++ b/Mage.Sets/src/mage/cards/e/ExecutionersSwing.java @@ -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)) { diff --git a/Mage.Sets/src/mage/cards/e/Extinction.java b/Mage.Sets/src/mage/cards/e/Extinction.java index 5bb472dacc..e77c192cb2 100644 --- a/Mage.Sets/src/mage/cards/e/Extinction.java +++ b/Mage.Sets/src/mage/cards/e/Extinction.java @@ -56,15 +56,18 @@ class ExtinctionEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); MageObject sourceObject = game.getObject(source.getSourceId()); - Choice typeChoice = new ChoiceCreatureType(sourceObject); - if (player != null && 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()))); - for (Permanent creature : game.getBattlefield().getActivePermanents(filterCreaturePermanent, source.getSourceId(), game)) { - creature.destroy(source.getSourceId(), game, true); + if (player != null && sourceObject != null) { + Choice typeChoice = new ChoiceCreatureType(sourceObject); + + 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()))); + for (Permanent creature : game.getBattlefield().getActivePermanents(filterCreaturePermanent, source.getSourceId(), game)) { + creature.destroy(source.getSourceId(), game, true); + } + return true; } - return true; } return false; } diff --git a/Mage.Sets/src/mage/cards/g/GauntletsOfChaos.java b/Mage.Sets/src/mage/cards/g/GauntletsOfChaos.java index 76865d61d0..a466ce4acd 100644 --- a/Mage.Sets/src/mage/cards/g/GauntletsOfChaos.java +++ b/Mage.Sets/src/mage/cards/g/GauntletsOfChaos.java @@ -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,20 +19,24 @@ 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, - "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", false, true, true), - new ManaCostsImpl("{5}") + Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ExchangeControlTargetEffect(Duration.EndOfGame, + "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", false, true, true), + new ManaCostsImpl("{5}") ); ability.addCost(new SacrificeSourceCost()); ability.addTarget(new GauntletsOfChaosFirstTarget()); @@ -59,7 +55,7 @@ public final class GauntletsOfChaos extends CardImpl { } class GauntletsOfChaosFirstTarget extends TargetControlledPermanent { - + public GauntletsOfChaosFirstTarget() { super(); this.filter = this.filter.copy(); @@ -68,17 +64,17 @@ class GauntletsOfChaosFirstTarget extends TargetControlledPermanent { new CardTypePredicate(CardType.CREATURE), new CardTypePredicate(CardType.LAND))); setTargetName("artifact, creature, or land you control"); - } - + } + public GauntletsOfChaosFirstTarget(final GauntletsOfChaosFirstTarget target) { super(target); } - + @Override public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { if (super.canTarget(controllerId, id, source, game)) { Set cardTypes = getOpponentPermanentCardTypes(source.getSourceId(), controllerId, game); - Permanent permanent = game.getPermanent(id); + Permanent permanent = game.getPermanent(id); for (CardType type : permanent.getCardType()) { if (cardTypes.contains(type)) { return true; @@ -87,36 +83,38 @@ class GauntletsOfChaosFirstTarget extends TargetControlledPermanent { } return false; } - + @Override public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { // get all cardtypes from opponents permanents Set cardTypes = getOpponentPermanentCardTypes(sourceId, sourceControllerId, game); Set possibleTargets = new HashSet<>(); MageObject targetSource = game.getObject(sourceId); - 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)) { - possibleTargets.add(permanent.getId()); - break; - } + 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)) { + possibleTargets.add(permanent.getId()); + break; + } + } } } } - return possibleTargets; + return possibleTargets; } - + @Override public GauntletsOfChaosFirstTarget copy() { return new GauntletsOfChaosFirstTarget(this); } - + private EnumSet getOpponentPermanentCardTypes(UUID sourceId, UUID sourceControllerId, Game game) { Player controller = game.getPlayer(sourceControllerId); - EnumSet cardTypes =EnumSet.noneOf(CardType.class); + EnumSet 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()); } @@ -130,20 +128,20 @@ class GauntletsOfChaosFirstTarget extends TargetControlledPermanent { class GauntletsOfChaosSecondTarget extends TargetPermanent { private Permanent firstTarget = null; - + public GauntletsOfChaosSecondTarget() { super(); this.filter = this.filter.copy(); filter.add(new ControllerPredicate(TargetController.OPPONENT)); setTargetName("permanent an opponent controls that shares one of those types with it"); - } + } public GauntletsOfChaosSecondTarget(final GauntletsOfChaosSecondTarget target) { super(target); this.firstTarget = target.firstTarget; } - + @Override public boolean canTarget(UUID id, Ability source, Game game) { if (super.canTarget(id, source, game)) { @@ -155,29 +153,31 @@ class GauntletsOfChaosSecondTarget extends TargetPermanent { } return false; } - + @Override public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { Set possibleTargets = new HashSet<>(); if (firstTarget != null) { MageObject targetSource = game.getObject(sourceId); - for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { - if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { - if (permanent.shareTypes(firstTarget)) { - possibleTargets.add(permanent.getId()); + 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)) { + possibleTargets.add(permanent.getId()); + } } } } } return possibleTargets; } - + @Override public boolean chooseTarget(Outcome outcome, UUID playerId, Ability source, Game game) { firstTarget = game.getPermanent(source.getFirstTarget()); return super.chooseTarget(Outcome.Damage, playerId, source, game); - } - + } + @Override public GauntletsOfChaosSecondTarget copy() { return new GauntletsOfChaosSecondTarget(this); diff --git a/Mage.Sets/src/mage/cards/g/GlamerSpinners.java b/Mage.Sets/src/mage/cards/g/GlamerSpinners.java index 0ff769a8b1..7723affb53 100644 --- a/Mage.Sets/src/mage/cards/g/GlamerSpinners.java +++ b/Mage.Sets/src/mage/cards/g/GlamerSpinners.java @@ -117,8 +117,10 @@ class GlamerSpinnersEffect extends OneShotEffect { } // Check for protection MageObject auraObject = game.getObject(auraId); - if (permanentToAttachAuras.cantBeAttachedBy(auraObject, game)) { - passed = false; + if(auraObject != null) { + if (permanentToAttachAuras.cantBeAttachedBy(auraObject, game)) { + passed = false; + } } } } diff --git a/Mage.Sets/src/mage/cards/g/GnarlrootTrapper.java b/Mage.Sets/src/mage/cards/g/GnarlrootTrapper.java index 896252385a..69e6f81b23 100644 --- a/Mage.Sets/src/mage/cards/g/GnarlrootTrapper.java +++ b/Mage.Sets/src/mage/cards/g/GnarlrootTrapper.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/g/GrenzoHavocRaiser.java b/Mage.Sets/src/mage/cards/g/GrenzoHavocRaiser.java index f416760744..693c82d082 100644 --- a/Mage.Sets/src/mage/cards/g/GrenzoHavocRaiser.java +++ b/Mage.Sets/src/mage/cards/g/GrenzoHavocRaiser.java @@ -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). diff --git a/Mage.Sets/src/mage/cards/g/GridMonitor.java b/Mage.Sets/src/mage/cards/g/GridMonitor.java index f14efbff1a..5462f1b8f3 100644 --- a/Mage.Sets/src/mage/cards/g/GridMonitor.java +++ b/Mage.Sets/src/mage/cards/g/GridMonitor.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/g/GrimReminder.java b/Mage.Sets/src/mage/cards/g/GrimReminder.java index 3b1e8bf30c..6ad9da49df 100644 --- a/Mage.Sets/src/mage/cards/g/GrimReminder.java +++ b/Mage.Sets/src/mage/cards/g/GrimReminder.java @@ -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 getPlayersCastSpell(String spellName) { - return playersCastSpell.getOrDefault(spellName, new HashSet()); + return playersCastSpell.getOrDefault(spellName, new HashSet<>()); } @Override diff --git a/Mage.Sets/src/mage/cards/g/GrimoireThief.java b/Mage.Sets/src/mage/cards/g/GrimoireThief.java index 9205d05f15..fb6e18edde 100644 --- a/Mage.Sets/src/mage/cards/g/GrimoireThief.java +++ b/Mage.Sets/src/mage/cards/g/GrimoireThief.java @@ -172,7 +172,7 @@ class GrimoireThiefCounterspellEffect extends OneShotEffect { Cards cards = new CardsImpl(); MageObject sourceObject = game.getObject(source.getSourceId()); Set exileZones = (Set) 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)); diff --git a/Mage.Sets/src/mage/cards/g/GrinningTotem.java b/Mage.Sets/src/mage/cards/g/GrinningTotem.java index b2fa96eebf..fef1f9047d 100644 --- a/Mage.Sets/src/mage/cards/g/GrinningTotem.java +++ b/Mage.Sets/src/mage/cards/g/GrinningTotem.java @@ -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())) { diff --git a/Mage.Sets/src/mage/cards/h/HandToHand.java b/Mage.Sets/src/mage/cards/h/HandToHand.java index 0804212ce3..001df4208c 100644 --- a/Mage.Sets/src/mage/cards/h/HandToHand.java +++ b/Mage.Sets/src/mage/cards/h/HandToHand.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/h/HavenOfTheSpiritDragon.java b/Mage.Sets/src/mage/cards/h/HavenOfTheSpiritDragon.java index 8233253bd2..5259cb2d73 100644 --- a/Mage.Sets/src/mage/cards/h/HavenOfTheSpiritDragon.java +++ b/Mage.Sets/src/mage/cards/h/HavenOfTheSpiritDragon.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/h/HeraldsHorn.java b/Mage.Sets/src/mage/cards/h/HeraldsHorn.java index c57b4d8139..2224de65e8 100644 --- a/Mage.Sets/src/mage/cards/h/HeraldsHorn.java +++ b/Mage.Sets/src/mage/cards/h/HeraldsHorn.java @@ -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); diff --git a/Mage.Sets/src/mage/cards/j/JadeMonolith.java b/Mage.Sets/src/mage/cards/j/JadeMonolith.java index ba66a726d2..3202fe33ec 100644 --- a/Mage.Sets/src/mage/cards/j/JadeMonolith.java +++ b/Mage.Sets/src/mage/cards/j/JadeMonolith.java @@ -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()); diff --git a/Mage.Sets/src/mage/cards/j/Justice.java b/Mage.Sets/src/mage/cards/j/Justice.java index 311609dfbd..9828d5340b 100644 --- a/Mage.Sets/src/mage/cards/j/Justice.java +++ b/Mage.Sets/src/mage/cards/j/Justice.java @@ -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()); diff --git a/Mage.Sets/src/mage/cards/k/KeeperOfTheBeasts.java b/Mage.Sets/src/mage/cards/k/KeeperOfTheBeasts.java index cc4ccc8fcd..6c3e7c0a38 100644 --- a/Mage.Sets/src/mage/cards/k/KeeperOfTheBeasts.java +++ b/Mage.Sets/src/mage/cards/k/KeeperOfTheBeasts.java @@ -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 diff --git a/Mage.Sets/src/mage/cards/k/KeeperOfTheLight.java b/Mage.Sets/src/mage/cards/k/KeeperOfTheLight.java index 080bdc1360..538cd5c2f7 100644 --- a/Mage.Sets/src/mage/cards/k/KeeperOfTheLight.java +++ b/Mage.Sets/src/mage/cards/k/KeeperOfTheLight.java @@ -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 diff --git a/Mage.Sets/src/mage/cards/m/MonkeyMonkeyMonkey.java b/Mage.Sets/src/mage/cards/m/MonkeyMonkeyMonkey.java index 4d3f500902..e508cc19b7 100644 --- a/Mage.Sets/src/mage/cards/m/MonkeyMonkeyMonkey.java +++ b/Mage.Sets/src/mage/cards/m/MonkeyMonkeyMonkey.java @@ -80,8 +80,8 @@ class ChooseLetterEffect extends OneShotEffect { ChoiceImpl choice = new ChoiceImpl(true); choice.setMessage("Choose letter"); Set 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++; } } diff --git a/Mage.Sets/src/mage/cards/p/PatriarchsBidding.java b/Mage.Sets/src/mage/cards/p/PatriarchsBidding.java index 24eae2bf48..bf61c7675f 100644 --- a/Mage.Sets/src/mage/cards/p/PatriarchsBidding.java +++ b/Mage.Sets/src/mage/cards/p/PatriarchsBidding.java @@ -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 chosenTypes = new HashSet<>(); for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); diff --git a/Mage.Sets/src/mage/cards/p/PillarOfOrigins.java b/Mage.Sets/src/mage/cards/p/PillarOfOrigins.java index 80b830551c..f238821e39 100644 --- a/Mage.Sets/src/mage/cards/p/PillarOfOrigins.java +++ b/Mage.Sets/src/mage/cards/p/PillarOfOrigins.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/p/PrematureBurial.java b/Mage.Sets/src/mage/cards/p/PrematureBurial.java index 9f35bb5888..3f8ac248ae 100644 --- a/Mage.Sets/src/mage/cards/p/PrematureBurial.java +++ b/Mage.Sets/src/mage/cards/p/PrematureBurial.java @@ -80,10 +80,12 @@ 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 (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { - if(watcher.enteredSinceLastTurn(sourceControllerId, new MageObjectReference(permanent.getId(), game))) { - return true; + 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))) { + return true; + } } } } diff --git a/Mage.Sets/src/mage/cards/p/PucasMischief.java b/Mage.Sets/src/mage/cards/p/PucasMischief.java index fb18899101..cb5f3d419e 100644 --- a/Mage.Sets/src/mage/cards/p/PucasMischief.java +++ b/Mage.Sets/src/mage/cards/p/PucasMischief.java @@ -73,9 +73,11 @@ class TargetControlledPermanentWithCMCGreaterOrLessThanOpponentPermanent extends public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { Set possibleTargets = new HashSet<>(); MageObject targetSource = game.getObject(sourceId); - for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { - if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { - possibleTargets.add(permanent.getId()); + 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,10 +123,12 @@ class PucasMischiefSecondTarget extends TargetPermanent { Set possibleTargets = new HashSet<>(); if (firstTarget != null) { MageObject targetSource = game.getObject(sourceId); - 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()) { - possibleTargets.add(permanent.getId()); + 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()) { + possibleTargets.add(permanent.getId()); + } } } } diff --git a/Mage.Sets/src/mage/cards/r/Reciprocate.java b/Mage.Sets/src/mage/cards/r/Reciprocate.java index 1a4073f1c5..90bcb754d0 100644 --- a/Mage.Sets/src/mage/cards/r/Reciprocate.java +++ b/Mage.Sets/src/mage/cards/r/Reciprocate.java @@ -82,13 +82,15 @@ class ReciprocateTarget extends TargetPermanent { } int count = 0; MageObject targetSource = game.getObject(sourceId); - 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) - && watcher != null && watcher.hasSourceDoneDamage(permanent.getId(), game)) { - count++; - if (count >= remainingTargets) { - return true; + 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) + && watcher != null && watcher.hasSourceDoneDamage(permanent.getId(), game)) { + count++; + if (count >= remainingTargets) { + return true; + } } } } diff --git a/Mage.Sets/src/mage/cards/r/Remembrance.java b/Mage.Sets/src/mage/cards/r/Remembrance.java index 237553bc60..135d49484c 100644 --- a/Mage.Sets/src/mage/cards/r/Remembrance.java +++ b/Mage.Sets/src/mage/cards/r/Remembrance.java @@ -119,12 +119,14 @@ class RemembranceEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); MageObject mageObject = game.getObject(source.getSourceId()); - cardName = (String) game.getState().getValue(mageObject + "nameOfPermanent"); - if (controller != null - && cardName != null) { - FilterCard filterCard = new FilterCard("card named " + cardName); - filterCard.add(new NamePredicate(cardName)); - return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true).apply(game, source); + if(mageObject != null) { + cardName = (String) game.getState().getValue(mageObject + "nameOfPermanent"); + if (controller != null + && cardName != null) { + FilterCard filterCard = new FilterCard("card named " + cardName); + filterCard.add(new NamePredicate(cardName)); + return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true).apply(game, source); + } } return false; } diff --git a/Mage.Sets/src/mage/cards/r/RiptideChronologist.java b/Mage.Sets/src/mage/cards/r/RiptideChronologist.java index 71ee115eed..6149c2b7bd 100644 --- a/Mage.Sets/src/mage/cards/r/RiptideChronologist.java +++ b/Mage.Sets/src/mage/cards/r/RiptideChronologist.java @@ -66,15 +66,17 @@ class RiptideChronologistEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); MageObject sourceObject = game.getObject(source.getSourceId()); - Choice typeChoice = new ChoiceCreatureType(sourceObject); - if (player != null && 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()))); - for (Permanent creature : game.getBattlefield().getActivePermanents(filterCreaturePermanent, source.getSourceId(), game)) { - creature.untap(game); + if (player != null && sourceObject != null) { + Choice typeChoice = new ChoiceCreatureType(sourceObject); + 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()))); + for (Permanent creature : game.getBattlefield().getActivePermanents(filterCreaturePermanent, source.getSourceId(), game)) { + creature.untap(game); + } + return true; } - return true; } return false; } diff --git a/Mage.Sets/src/mage/cards/s/SamiteMinistration.java b/Mage.Sets/src/mage/cards/s/SamiteMinistration.java index 5035bafdaa..3f2fbe5abd 100644 --- a/Mage.Sets/src/mage/cards/s/SamiteMinistration.java +++ b/Mage.Sets/src/mage/cards/s/SamiteMinistration.java @@ -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); diff --git a/Mage.Sets/src/mage/cards/s/SatyrFiredancer.java b/Mage.Sets/src/mage/cards/s/SatyrFiredancer.java index fafe925705..3db3ccfc6d 100644 --- a/Mage.Sets/src/mage/cards/s/SatyrFiredancer.java +++ b/Mage.Sets/src/mage/cards/s/SatyrFiredancer.java @@ -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); @@ -47,7 +47,7 @@ public final class SatyrFiredancer extends CardImpl { public SatyrFiredancer(final SatyrFiredancer card) { super(card); } - + @Override public void adjustTargets(Ability ability, Game game) { if (ability instanceof SatyrFiredancerTriggeredAbility) { @@ -59,7 +59,7 @@ public final class SatyrFiredancer extends CardImpl { } } } - + @Override public SatyrFiredancer copy() { return new SatyrFiredancer(this); @@ -97,15 +97,15 @@ class SatyrFiredancerTriggeredAbility extends TriggeredAbilityImpl { public boolean checkTrigger(GameEvent event, Game game) { if (isControlledBy(game.getControllerId(event.getSourceId()))) { MageObject damageSource = game.getObject(event.getSourceId()); - if (damageSource != null) { + 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()); } @@ -147,7 +147,7 @@ class SatyrFiredancerDamageEffect extends OneShotEffect { if (targetCreature != null && controller != null) { int damage = (Integer) this.getValue("damage"); if (damage > 0) { - targetCreature.damage(damage, source.getSourceId(), game, false, true); + targetCreature.damage(damage, source.getSourceId(), game, false, true); } return true; } diff --git a/Mage.Sets/src/mage/cards/s/ShiftingLoyalties.java b/Mage.Sets/src/mage/cards/s/ShiftingLoyalties.java index af8b412ecf..7cd05fd423 100644 --- a/Mage.Sets/src/mage/cards/s/ShiftingLoyalties.java +++ b/Mage.Sets/src/mage/cards/s/ShiftingLoyalties.java @@ -72,14 +72,16 @@ class TargetPermanentsThatShareCardType extends TargetPermanent { public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { Set cardTypes = new HashSet<>(); MageObject targetSource = game.getObject(sourceId); - for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { - if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { - for (CardType cardType :permanent.getCardType()) { - if (cardTypes.contains(cardType)) { - return true; + if(targetSource != null) { + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { + if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { + for (CardType cardType : permanent.getCardType()) { + if (cardTypes.contains(cardType)) { + return true; + } } + cardTypes.addAll(permanent.getCardType()); } - cardTypes.addAll(permanent.getCardType()); } } return false; diff --git a/Mage.Sets/src/mage/cards/s/ShiningShoal.java b/Mage.Sets/src/mage/cards/s/ShiningShoal.java index 5733872da8..79ad6ea8bf 100644 --- a/Mage.Sets/src/mage/cards/s/ShiningShoal.java +++ b/Mage.Sets/src/mage/cards/s/ShiningShoal.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/s/Spawnbroker.java b/Mage.Sets/src/mage/cards/s/Spawnbroker.java index 822f3cafbe..2e291383a3 100644 --- a/Mage.Sets/src/mage/cards/s/Spawnbroker.java +++ b/Mage.Sets/src/mage/cards/s/Spawnbroker.java @@ -78,9 +78,11 @@ class TargetControlledCreatureWithPowerGreaterOrLessThanOpponentPermanent extend public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { Set possibleTargets = new HashSet<>(); MageObject targetSource = game.getObject(sourceId); - for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { - if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { - possibleTargets.add(permanent.getId()); + 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,10 +128,12 @@ class SpawnbrokerSecondTarget extends TargetPermanent { Set possibleTargets = new HashSet<>(); if (firstTarget != null) { MageObject targetSource = game.getObject(sourceId); - 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()) { - possibleTargets.add(permanent.getId()); + 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()) { + possibleTargets.add(permanent.getId()); + } } } } diff --git a/Mage.Sets/src/mage/cards/s/SphinxsDecree.java b/Mage.Sets/src/mage/cards/s/SphinxsDecree.java index 2b841942ca..eba89ba355 100644 --- a/Mage.Sets/src/mage/cards/s/SphinxsDecree.java +++ b/Mage.Sets/src/mage/cards/s/SphinxsDecree.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/s/StaffOfTheLetterMagus.java b/Mage.Sets/src/mage/cards/s/StaffOfTheLetterMagus.java index b31f034cc6..8251a67122 100644 --- a/Mage.Sets/src/mage/cards/s/StaffOfTheLetterMagus.java +++ b/Mage.Sets/src/mage/cards/s/StaffOfTheLetterMagus.java @@ -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++; diff --git a/Mage.Sets/src/mage/cards/s/StolenStrategy.java b/Mage.Sets/src/mage/cards/s/StolenStrategy.java index 18e0108846..d1bb562666 100644 --- a/Mage.Sets/src/mage/cards/s/StolenStrategy.java +++ b/Mage.Sets/src/mage/cards/s/StolenStrategy.java @@ -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). diff --git a/Mage.Sets/src/mage/cards/t/Tariff.java b/Mage.Sets/src/mage/cards/t/Tariff.java index d2e42f109c..2f2d3b5a2d 100644 --- a/Mage.Sets/src/mage/cards/t/Tariff.java +++ b/Mage.Sets/src/mage/cards/t/Tariff.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/t/TemporaryInsanity.java b/Mage.Sets/src/mage/cards/t/TemporaryInsanity.java index 4cec552117..2560ddfc08 100644 --- a/Mage.Sets/src/mage/cards/t/TemporaryInsanity.java +++ b/Mage.Sets/src/mage/cards/t/TemporaryInsanity.java @@ -78,10 +78,12 @@ 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 (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { - if(permanent.getPower().getValue() < game.getPlayer(sourceControllerId).getGraveyard().size()) { - return true; + 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()) { + return true; + } } } } diff --git a/Mage.Sets/src/mage/cards/t/TobiasBeckett.java b/Mage.Sets/src/mage/cards/t/TobiasBeckett.java index 041b8a6e1f..7dde7e7ae9 100644 --- a/Mage.Sets/src/mage/cards/t/TobiasBeckett.java +++ b/Mage.Sets/src/mage/cards/t/TobiasBeckett.java @@ -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). diff --git a/Mage.Sets/src/mage/cards/t/Topple.java b/Mage.Sets/src/mage/cards/t/Topple.java index 9c888e6de3..40ea412678 100644 --- a/Mage.Sets/src/mage/cards/t/Topple.java +++ b/Mage.Sets/src/mage/cards/t/Topple.java @@ -72,6 +72,9 @@ class ToppleTargetCreature extends TargetCreaturePermanent { List activePermanents = game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game); Set 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(); diff --git a/Mage.Sets/src/mage/cards/t/TriumphOfGerrard.java b/Mage.Sets/src/mage/cards/t/TriumphOfGerrard.java index f9c97e72b3..91364091eb 100644 --- a/Mage.Sets/src/mage/cards/t/TriumphOfGerrard.java +++ b/Mage.Sets/src/mage/cards/t/TriumphOfGerrard.java @@ -107,6 +107,9 @@ class TriumphOfGerrardTargetCreature extends TargetControlledCreaturePermanent { List activePermanents = game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game); Set 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(); diff --git a/Mage.Sets/src/mage/cards/t/TsabosDecree.java b/Mage.Sets/src/mage/cards/t/TsabosDecree.java index 422d34b075..45a9835c66 100644 --- a/Mage.Sets/src/mage/cards/t/TsabosDecree.java +++ b/Mage.Sets/src/mage/cards/t/TsabosDecree.java @@ -64,31 +64,33 @@ class TsabosDecreeEffect extends OneShotEffect { Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source)); MageObject sourceObject = game.getObject(source.getSourceId()); if (player != null) { - Choice typeChoice = new ChoiceCreatureType(sourceObject); - if (!player.choose(outcome, typeChoice, game)) { - return false; - } - game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice()); - targetPlayer.revealCards("hand of " + targetPlayer.getName(), targetPlayer.getHand(), game); - FilterCard filterCard = new FilterCard(); - filterCard.add(new SubtypePredicate(SubType.byDescription(typeChoice.getChoice()))); - List toDiscard = new ArrayList<>(); - for (Card card : targetPlayer.getHand().getCards(game)) { - if (filterCard.match(card, game)) { - toDiscard.add(card); + if(sourceObject != null) { + Choice typeChoice = new ChoiceCreatureType(sourceObject); + if (!player.choose(outcome, typeChoice, game)) { + return false; } - } - for (Card card : toDiscard) { - targetPlayer.discard(card, source, game); - } - FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent(); - filterCreaturePermanent.add(new SubtypePredicate(SubType.byDescription(typeChoice.getChoice()))); - for (Permanent creature : game.getBattlefield().getActivePermanents(filterCreaturePermanent, source.getSourceId(), game)) { - if (creature.isControlledBy(targetPlayer.getId())) { - creature.destroy(source.getSourceId(), game, true); + game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice()); + targetPlayer.revealCards("hand of " + targetPlayer.getName(), targetPlayer.getHand(), game); + FilterCard filterCard = new FilterCard(); + filterCard.add(new SubtypePredicate(SubType.byDescription(typeChoice.getChoice()))); + List toDiscard = new ArrayList<>(); + for (Card card : targetPlayer.getHand().getCards(game)) { + if (filterCard.match(card, game)) { + toDiscard.add(card); + } } + for (Card card : toDiscard) { + targetPlayer.discard(card, source, game); + } + FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent(); + filterCreaturePermanent.add(new SubtypePredicate(SubType.byDescription(typeChoice.getChoice()))); + for (Permanent creature : game.getBattlefield().getActivePermanents(filterCreaturePermanent, source.getSourceId(), game)) { + if (creature.isControlledBy(targetPlayer.getId())) { + creature.destroy(source.getSourceId(), game, true); + } + } + return true; } - return true; } return false; } diff --git a/Mage.Sets/src/mage/cards/u/UnclaimedTerritory.java b/Mage.Sets/src/mage/cards/u/UnclaimedTerritory.java index 9b3cd9cc20..393374047a 100644 --- a/Mage.Sets/src/mage/cards/u/UnclaimedTerritory.java +++ b/Mage.Sets/src/mage/cards/u/UnclaimedTerritory.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/u/UrzasBauble.java b/Mage.Sets/src/mage/cards/u/UrzasBauble.java index 4975d5af23..31f43a7691 100644 --- a/Mage.Sets/src/mage/cards/u/UrzasBauble.java +++ b/Mage.Sets/src/mage/cards/u/UrzasBauble.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/v/VerdantSuccession.java b/Mage.Sets/src/mage/cards/v/VerdantSuccession.java index 94ca35d03a..d46a2412fc 100644 --- a/Mage.Sets/src/mage/cards/v/VerdantSuccession.java +++ b/Mage.Sets/src/mage/cards/v/VerdantSuccession.java @@ -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,21 +119,23 @@ class VerdantSuccessionEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { MageObject mageObject = game.getObject(source.getSourceId()); - permanent = (Permanent) game.getState().getValue("verdantSuccession" + mageObject); - if (permanent != null) { - Player controller = game.getPlayer(permanent.getControllerId()); - if (controller != null) { - FilterCard filterCard = new FilterCard("Card named " + permanent.getName()); - filterCard.add(new NamePredicate(permanent.getName())); - TargetCardInLibrary target = new TargetCardInLibrary(filterCard); - controller.searchLibrary(target, game); - if (!target.getTargets().isEmpty()) { - Card card = game.getCard(target.getFirstTarget()); - if (card != null - && controller.moveCards(card, Zone.BATTLEFIELD, source, game)) { - controller.shuffleLibrary(source, game); + if(mageObject != null) { + permanent = (Permanent) game.getState().getValue("verdantSuccession" + mageObject); + if (permanent != null) { + Player controller = game.getPlayer(permanent.getControllerId()); + if (controller != null) { + FilterCard filterCard = new FilterCard("Card named " + permanent.getName()); + filterCard.add(new NamePredicate(permanent.getName())); + TargetCardInLibrary target = new TargetCardInLibrary(filterCard); + controller.searchLibrary(target, game); + if (!target.getTargets().isEmpty()) { + Card card = game.getCard(target.getFirstTarget()); + if (card != null + && controller.moveCards(card, Zone.BATTLEFIELD, source, game)) { + controller.shuffleLibrary(source, game); + } + return true; } - return true; } } } diff --git a/Mage.Sets/src/mage/cards/v/VillainousWealth.java b/Mage.Sets/src/mage/cards/v/VillainousWealth.java index 2945165687..e45e4eded9 100644 --- a/Mage.Sets/src/mage/cards/v/VillainousWealth.java +++ b/Mage.Sets/src/mage/cards/v/VillainousWealth.java @@ -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)); diff --git a/Mage.Sets/src/mage/cards/w/WalkingDesecration.java b/Mage.Sets/src/mage/cards/w/WalkingDesecration.java index 59dea99b8c..3993a5594d 100644 --- a/Mage.Sets/src/mage/cards/w/WalkingDesecration.java +++ b/Mage.Sets/src/mage/cards/w/WalkingDesecration.java @@ -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,14 +64,18 @@ class WalkingDesecrationEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); MageObject sourceObject = game.getObject(source.getSourceId()); - Choice typeChoice = new ChoiceCreatureType(sourceObject); - if (player != null && 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()))); - RequirementEffect effect = new AttacksIfAbleAllEffect(filter, Duration.EndOfTurn); - game.addEffect(effect, source); - return true; + if (player != null) { + if (sourceObject != null) { + Choice typeChoice = new ChoiceCreatureType(sourceObject); + 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()))); + RequirementEffect effect = new AttacksIfAbleAllEffect(filter, Duration.EndOfTurn); + game.addEffect(effect, source); + return true; + } + } } return false; }