From aefcd3c6974f330e224dcd17e29fcb55dda4d311 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 13 Apr 2013 23:34:33 +0200 Subject: [PATCH] Fixed NPE of HasCounterCondition. --- .../condition/common/HasCounterCondition.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Mage/src/mage/abilities/condition/common/HasCounterCondition.java b/Mage/src/mage/abilities/condition/common/HasCounterCondition.java index 2e17487c52..e6a2733b93 100644 --- a/Mage/src/mage/abilities/condition/common/HasCounterCondition.java +++ b/Mage/src/mage/abilities/condition/common/HasCounterCondition.java @@ -29,8 +29,10 @@ package mage.abilities.condition.common; import mage.abilities.Ability; import mage.abilities.condition.Condition; +import mage.cards.Card; import mage.counters.CounterType; import mage.game.Game; +import mage.game.permanent.Permanent; /** * @@ -60,14 +62,31 @@ public class HasCounterCondition implements Condition { @Override public boolean apply(Game game, Ability source) { + Card card = null; + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent == null) { + card = game.getCard(source.getSourceId()); + if (card == null) { + return false; + } + } if (from != -1) { //range compare - int count = game.getPermanent(source.getSourceId()).getCounters().getCount(counterType); + int count; + if (card != null) { + count = card.getCounters().getCount(counterType); + } else { + count = permanent.getCounters().getCount(counterType); + } if (to == Integer.MAX_VALUE) { return count >= from; } return count >= from && count <= to; } else { // single compare (lte) - return game.getPermanent(source.getSourceId()).getCounters().getCount(counterType) >= amount; + if (card != null) { + return card.getCounters().getCount(counterType) >= amount; + } else { + return permanent.getCounters().getCount(counterType) >= amount; + } } } }