Fixed some possible exception bugs.

This commit is contained in:
LevelX2 2016-04-06 20:25:13 +02:00
parent ebac7426dc
commit 1ec61abb8e
5 changed files with 45 additions and 35 deletions

View file

@ -112,11 +112,13 @@ class ForkInTheRoadEffect extends OneShotEffect {
controller.moveCards(card, Zone.HAND, source, game);
revealed.remove(card);
}
card = revealed.getCards(game).iterator().next();
if (card != null) {
controller.moveCards(card, Zone.GRAVEYARD, source, game);
if (!revealed.isEmpty()) {
card = revealed.getCards(game).iterator().next();
if (card != null) {
controller.moveCards(card, Zone.GRAVEYARD, source, game);
}
}
} else if (target.getTargets().size() == 1) {
} else if (target.getTargets().size() == 1 && !revealed.isEmpty()) {
Card card = revealed.getCards(game).iterator().next();
if (card != null) {
controller.moveCards(card, Zone.HAND, source, game);

View file

@ -62,7 +62,7 @@ public class DiesAttachedTriggeredAbility extends TriggeredAbilityImpl {
if (((ZoneChangeEvent) event).isDiesEvent()) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
boolean triggered = false;
if (zEvent.getTarget().getAttachments().contains(this.getSourceId())) {
if (zEvent.getTarget().getAttachments() != null && zEvent.getTarget().getAttachments().contains(this.getSourceId())) {
triggered = true;
} else {
// If both (attachment and attached went to graveyard at the same time, the attachemnets can be already removed from the attached object.)

View file

@ -27,9 +27,10 @@
*/
package mage.abilities.condition.common;
import mage.constants.CardType;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.cards.Card;
import mage.constants.CardType;
import mage.game.Game;
import mage.players.Player;
@ -38,9 +39,9 @@ import mage.players.Player;
*/
public class TopLibraryCardTypeCondition implements Condition {
public static enum CheckType {CREATURE, LAND, SORCERY, INSTANT}
;
public static enum CheckType {
CREATURE, LAND, SORCERY, INSTANT
};
private TopLibraryCardTypeCondition.CheckType type;
@ -53,19 +54,22 @@ public class TopLibraryCardTypeCondition implements Condition {
boolean conditionApplies = false;
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && controller.getLibrary().size() > 0) {
switch (this.type) {
case CREATURE:
conditionApplies |= controller.getLibrary().getFromTop(game).getCardType().contains(CardType.CREATURE);
break;
case LAND:
conditionApplies |= controller.getLibrary().getFromTop(game).getCardType().contains(CardType.LAND);
break;
case SORCERY:
conditionApplies |= controller.getLibrary().getFromTop(game).getCardType().contains(CardType.SORCERY);
break;
case INSTANT:
conditionApplies |= controller.getLibrary().getFromTop(game).getCardType().contains(CardType.INSTANT);
break;
Card card = controller.getLibrary().getFromTop(game);
if (card != null) {
switch (this.type) {
case CREATURE:
conditionApplies |= card.getCardType().contains(CardType.CREATURE);
break;
case LAND:
conditionApplies |= card.getCardType().contains(CardType.LAND);
break;
case SORCERY:
conditionApplies |= card.getCardType().contains(CardType.SORCERY);
break;
case INSTANT:
conditionApplies |= card.getCardType().contains(CardType.INSTANT);
break;
}
}
}
return conditionApplies;

View file

@ -32,6 +32,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@ -182,7 +183,8 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
@Override
public Set<Card> getCards(Game game) {
Set<Card> cards = new LinkedHashSet<>();
for (UUID cardId : this) {
for (Iterator<UUID> it = this.iterator(); it.hasNext();) { // Changed to iterator becuase of ConcurrentModificationException
UUID cardId = it.next();
Card card = game.getCard(cardId);
if (card != null) { // this can happen during the cancelation (player concedes) of a game
cards.add(card);

View file

@ -364,19 +364,21 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
Map<UUID, Integer> assigned = new HashMap<>();
for (UUID attackerId : attackerOrder) {
Permanent attacker = game.getPermanent(attackerId);
int lethalDamage;
if (blocker.getAbilities().containsKey(DeathtouchAbility.getInstance().getId())) {
lethalDamage = 1;
} else {
lethalDamage = attacker.getToughness().getValue() - attacker.getDamage();
if (attacker != null) {
int lethalDamage;
if (blocker.getAbilities().containsKey(DeathtouchAbility.getInstance().getId())) {
lethalDamage = 1;
} else {
lethalDamage = attacker.getToughness().getValue() - attacker.getDamage();
}
if (lethalDamage >= damage) {
assigned.put(attackerId, damage);
break;
}
int damageAssigned = player.getAmount(lethalDamage, damage, "Assign damage to " + attacker.getName(), game);
assigned.put(attackerId, damageAssigned);
damage -= damageAssigned;
}
if (lethalDamage >= damage) {
assigned.put(attackerId, damage);
break;
}
int damageAssigned = player.getAmount(lethalDamage, damage, "Assign damage to " + attacker.getName(), game);
assigned.put(attackerId, damageAssigned);
damage -= damageAssigned;
}
for (Map.Entry<UUID, Integer> entry : assigned.entrySet()) {