Added some exception handling.

This commit is contained in:
LevelX2 2018-08-15 11:28:13 +02:00
parent 2429425fd2
commit b96d6e12af
5 changed files with 34 additions and 24 deletions

View file

@ -131,9 +131,11 @@ class HaphazardBombardmentEndOfTurnEffect extends OneShotEffect {
filter.add(new CounterPredicate(CounterType.AIM));
filter.add(Predicates.not(new AbilityPredicate(IndestructibleAbility.class)));
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
Permanent permanent = permanents.get(RandomUtil.nextInt(permanents.size()));
if (permanent != null) {
permanent.destroy(source.getSourceId(), game, false);
if (!permanents.isEmpty()) {
Permanent permanent = permanents.get(RandomUtil.nextInt(permanents.size()));
if (permanent != null) {
permanent.destroy(source.getSourceId(), game, false);
}
}
return true;
}

View file

@ -1,5 +1,6 @@
package mage.cards.m;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
@ -18,8 +19,6 @@ import mage.target.Target;
import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
*
* @author noahg
@ -28,7 +27,7 @@ public final class MetamorphicAlteration extends CardImpl {
public MetamorphicAlteration(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{U}");
this.subtype.add(SubType.AURA);
// Enchant creature
@ -81,8 +80,11 @@ class ChooseACreature extends OneShotEffect {
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.choose(Outcome.Copy, target, source.getSourceId(), game);
Permanent chosenPermanent = game.getPermanent(target.getFirstTarget());
game.getState().setValue(source.getSourceId().toString() + INFO_KEY, chosenPermanent.copy());
if (chosenPermanent != null) {
game.getState().setValue(source.getSourceId().toString() + INFO_KEY, chosenPermanent.copy());
}
}
return true;
}
return false;
}
@ -150,4 +152,4 @@ class MetamorphicAlterationEffect extends ContinuousEffectImpl {
public MetamorphicAlterationEffect copy() {
return new MetamorphicAlterationEffect(this);
}
}
}

View file

@ -1,7 +1,7 @@
package mage.abilities.keyword;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.StaticAbility;
@ -52,7 +52,7 @@ public class KickerAbility extends StaticAbility implements OptionalAdditionalSo
protected static final String KICKER_REMINDER_MANA = "You may pay an additional {cost} as you cast this spell.";
protected static final String KICKER_REMINDER_COST = "You may {cost} in addition to any other costs as you cast this spell.";
protected Map<String, Integer> activations = new HashMap<>(); // zoneChangeCounter, activations
protected Map<String, Integer> activations = new ConcurrentHashMap<>(); // zoneChangeCounter, activations
protected String keywordText;
protected String reminderText;

View file

@ -1,4 +1,3 @@
package mage.abilities.keyword;
import mage.MageObjectReference;
@ -14,6 +13,7 @@ import mage.game.events.GameEvent.EventType;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.watchers.common.CastSpellLastTurnWatcher;
import org.apache.log4j.Logger;
/**
*
@ -75,17 +75,21 @@ class StormEffect extends OneShotEffect {
MageObjectReference spellRef = (MageObjectReference) this.getValue("StormSpellRef");
if (spellRef != null) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
int stormCount = watcher.getSpellOrder(spellRef, game) - 1;
if (stormCount > 0) {
Spell spell = (Spell) this.getValue("StormSpell");
if (spell != null) {
if (!game.isSimulation()) {
game.informPlayers("Storm: " + spell.getLogName() + " will be copied " + stormCount + " time" + (stormCount > 1 ? "s" : ""));
}
for (int i = 0; i < stormCount; i++) {
spell.createCopyOnStack(game, source, source.getControllerId(), true);
if (watcher != null) {
int stormCount = watcher.getSpellOrder(spellRef, game) - 1;
if (stormCount > 0) {
Spell spell = (Spell) this.getValue("StormSpell");
if (spell != null) {
if (!game.isSimulation()) {
game.informPlayers("Storm: " + spell.getLogName() + " will be copied " + stormCount + " time" + (stormCount > 1 ? "s" : ""));
}
for (int i = 0; i < stormCount; i++) {
spell.createCopyOnStack(game, source, source.getControllerId(), true);
}
}
}
} else {
Logger.getLogger(StormEffect.class).fatal("CastSpellLastTurnWatcher not found. game = " + game == null ? "NULL" : game.getGameType().toString());
}
return true;
}

View file

@ -248,10 +248,12 @@ public class TargetSpellOrPermanent extends TargetImpl {
sb.append(permanent.getLogName()).append(' ');
} else {
Spell spell = game.getStack().getSpell(targetId);
if (spell.isFaceDown(game)) {
sb.append(GameLog.getNeutralColoredText("face down spell"));
} else {
sb.append(spell.getLogName()).append(' ');
if (spell != null) {
if (spell.isFaceDown(game)) {
sb.append(GameLog.getNeutralColoredText("face down spell"));
} else {
sb.append(spell.getLogName()).append(' ');
}
}
}
}