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(new CounterPredicate(CounterType.AIM));
filter.add(Predicates.not(new AbilityPredicate(IndestructibleAbility.class))); filter.add(Predicates.not(new AbilityPredicate(IndestructibleAbility.class)));
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game); List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
Permanent permanent = permanents.get(RandomUtil.nextInt(permanents.size())); if (!permanents.isEmpty()) {
if (permanent != null) { Permanent permanent = permanents.get(RandomUtil.nextInt(permanents.size()));
permanent.destroy(source.getSourceId(), game, false); if (permanent != null) {
permanent.destroy(source.getSourceId(), game, false);
}
} }
return true; return true;
} }

View file

@ -1,5 +1,6 @@
package mage.cards.m; package mage.cards.m;
import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.AsEntersBattlefieldAbility;
@ -18,8 +19,6 @@ import mage.target.Target;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/** /**
* *
* @author noahg * @author noahg
@ -81,8 +80,11 @@ class ChooseACreature extends OneShotEffect {
if (target.canChoose(source.getSourceId(), controller.getId(), game)) { if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.choose(Outcome.Copy, target, source.getSourceId(), game); controller.choose(Outcome.Copy, target, source.getSourceId(), game);
Permanent chosenPermanent = game.getPermanent(target.getFirstTarget()); 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; return false;
} }

View file

@ -1,7 +1,7 @@
package mage.abilities.keyword; package mage.abilities.keyword;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.SpellAbility; import mage.abilities.SpellAbility;
import mage.abilities.StaticAbility; 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_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 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 keywordText;
protected String reminderText; protected String reminderText;

View file

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

View file

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