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,10 +131,12 @@ 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);
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
@ -81,9 +80,12 @@ 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());
if (chosenPermanent != null) {
game.getState().setValue(source.getSourceId().toString() + INFO_KEY, chosenPermanent.copy());
}
}
return true;
}
return false;
}

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,6 +75,7 @@ class StormEffect extends OneShotEffect {
MageObjectReference spellRef = (MageObjectReference) this.getValue("StormSpellRef");
if (spellRef != null) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
if (watcher != null) {
int stormCount = watcher.getSpellOrder(spellRef, game) - 1;
if (stormCount > 0) {
Spell spell = (Spell) this.getValue("StormSpell");
@ -87,6 +88,9 @@ class StormEffect extends OneShotEffect {
}
}
}
} else {
Logger.getLogger(StormEffect.class).fatal("CastSpellLastTurnWatcher not found. game = " + game == null ? "NULL" : game.getGameType().toString());
}
return true;
}
return false;

View file

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