Skip to content

Commit

Permalink
Added some exception handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
LevelX2 committed Aug 15, 2018
1 parent 2429425 commit b96d6e1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
8 changes: 5 additions & 3 deletions Mage.Sets/src/mage/cards/h/HaphazardBombardment.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ public boolean apply(Game game, Ability source) {
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;
}
Expand Down
12 changes: 7 additions & 5 deletions Mage.Sets/src/mage/cards/m/MetamorphicAlteration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mage.cards.m;

import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
Expand All @@ -18,8 +19,6 @@
import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent;

import java.util.UUID;

/**
*
* @author noahg
Expand All @@ -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
Expand Down Expand Up @@ -81,8 +80,11 @@ public boolean apply(Game game, Ability source) {
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;
}
Expand Down Expand Up @@ -150,4 +152,4 @@ public boolean apply(Game game, Ability source) {
public MetamorphicAlterationEffect copy() {
return new MetamorphicAlterationEffect(this);
}
}
}
4 changes: 2 additions & 2 deletions Mage/src/main/java/mage/abilities/keyword/KickerAbility.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 14 additions & 10 deletions Mage/src/main/java/mage/abilities/keyword/StormAbility.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package mage.abilities.keyword;

import mage.MageObjectReference;
Expand All @@ -14,6 +13,7 @@
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.watchers.common.CastSpellLastTurnWatcher;
import org.apache.log4j.Logger;

/**
*
Expand Down Expand Up @@ -75,17 +75,21 @@ public boolean apply(Game game, Ability source) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,12 @@ public String getTargetedName(Game game) {
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(' ');
}
}
}
}
Expand Down

0 comments on commit b96d6e1

Please sign in to comment.