fixed some NPEs

This commit is contained in:
BetaSteward 2011-03-31 23:36:58 -04:00
parent def31fef83
commit 6f87867788
7 changed files with 42 additions and 34 deletions

View file

@ -98,7 +98,7 @@ public class ProteanHydra extends CardImpl<ProteanHydra> {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) { if (permanent != null && source.getManaCostsToPay().getVariableCosts().size() > 0) {
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
permanent.addCounters(new PlusOneCounter(amount)); permanent.addCounters(new PlusOneCounter(amount));
} }

View file

@ -28,6 +28,7 @@
package mage.sets.magic2011; package mage.sets.magic2011;
import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
import mage.Constants.CardType; import mage.Constants.CardType;
import mage.Constants.Duration; import mage.Constants.Duration;
@ -102,9 +103,10 @@ class GargoyleSentinelEffect extends ContinuousEffectImpl<GargoyleSentinelEffect
switch (layer) { switch (layer) {
case AbilityAddingRemovingEffects_6: case AbilityAddingRemovingEffects_6:
if (sublayer == SubLayer.NA) { if (sublayer == SubLayer.NA) {
for (Ability ability: permanent.getAbilities()) { for (Iterator<Ability> i = permanent.getAbilities().iterator(); i.hasNext();) {
if (ability.getId().equals(DefenderAbility.getInstance().getId())) Ability entry = i.next();
permanent.getAbilities().remove(ability); if (entry.getId().equals(DefenderAbility.getInstance().getId()))
i.remove();
} }
permanent.getAbilities().add(FlyingAbility.getInstance()); permanent.getAbilities().add(FlyingAbility.getInstance());
} }

View file

@ -71,7 +71,7 @@ public abstract class RedirectionEffect<T extends RedirectionEffect<T>> extends
DamageEvent damageEvent = (DamageEvent)event; DamageEvent damageEvent = (DamageEvent)event;
Permanent permanent = game.getPermanent(redirectTarget.getFirstTarget()); Permanent permanent = game.getPermanent(redirectTarget.getFirstTarget());
Ability damageSource = getSource(damageEvent.getSourceId(), game); Ability damageSource = getSource(damageEvent.getSourceId(), game);
if (permanent != null) { if (permanent != null && damageSource != null) {
permanent.damage(damageEvent.getAmount(), damageSource.getId(), game, damageEvent.isPreventable(), damageEvent.isCombatDamage()); permanent.damage(damageEvent.getAmount(), damageSource.getId(), game, damageEvent.isPreventable(), damageEvent.isCombatDamage());
return true; return true;
} }

View file

@ -67,13 +67,15 @@ public class DestroyTargetEffect extends OneShotEffect<DestroyTargetEffect> {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
int affectedTargets = 0; int affectedTargets = 0;
for (UUID permanentId : source.getTargets().get(0).getTargets()) { if (source.getTargets().size() > 0) {
Permanent permanent = game.getPermanent(permanentId); for (UUID permanentId : source.getTargets().get(0).getTargets()) {
if (permanent != null) { Permanent permanent = game.getPermanent(permanentId);
permanent.destroy(source.getId(), game, noRegen); if (permanent != null) {
affectedTargets++; permanent.destroy(source.getId(), game, noRegen);
} affectedTargets++;
} }
}
}
return affectedTargets > 0; return affectedTargets > 0;
} }

View file

@ -58,19 +58,21 @@ public class ReturnToHandTargetEffect extends OneShotEffect<ReturnToHandTargetEf
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
switch (source.getTargets().get(0).getZone()) { if (source.getTargets().size() > 0) {
case BATTLEFIELD: switch (source.getTargets().get(0).getZone()) {
Permanent permanent = game.getPermanent(source.getFirstTarget()); case BATTLEFIELD:
if (permanent != null) { Permanent permanent = game.getPermanent(source.getFirstTarget());
return permanent.moveToZone(Zone.HAND, source.getId(), game, false); if (permanent != null) {
} return permanent.moveToZone(Zone.HAND, source.getId(), game, false);
break; }
case GRAVEYARD: break;
Card card = game.getCard(source.getFirstTarget()); case GRAVEYARD:
if (card != null) { Card card = game.getCard(source.getFirstTarget());
return card.moveToZone(Zone.HAND, source.getId(), game, true); if (card != null) {
} return card.moveToZone(Zone.HAND, source.getId(), game, true);
break; }
break;
}
} }
return false; return false;
} }

View file

@ -63,14 +63,16 @@ public class BoostPowerXSourceEffect extends ContinuousEffectImpl<BoostPowerXSou
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount(); if (source.getManaCostsToPay().getVariableCosts().size() > 0) {
if (amount == 0) { int amountX = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
return false; if (amountX == 0) {
} return false;
Permanent target = (Permanent) game.getPermanent(source.getSourceId()); }
if (target != null) { Permanent target = (Permanent) game.getPermanent(source.getSourceId());
target.addPower(amount); if (target != null) {
return true; target.addPower(amountX);
return true;
}
} }
return false; return false;
} }

View file

@ -318,7 +318,7 @@ public class GameState implements Serializable, Copyable<GameState> {
//TODO: this is awkward - improve //TODO: this is awkward - improve
if (event.getType() == EventType.ZONE_CHANGE) { if (event.getType() == EventType.ZONE_CHANGE) {
ZoneChangeEvent zEvent = (ZoneChangeEvent)event; ZoneChangeEvent zEvent = (ZoneChangeEvent)event;
if (zEvent.getFromZone() == Zone.BATTLEFIELD) { if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getTarget() != null) {
if (zEvent.getTarget() instanceof PermanentCard) { if (zEvent.getTarget() instanceof PermanentCard) {
((PermanentCard)zEvent.getTarget()).checkPermanentOnlyTriggers(zEvent, game); ((PermanentCard)zEvent.getTarget()).checkPermanentOnlyTriggers(zEvent, game);
} }