mirror of
https://github.com/correl/mage.git
synced 2024-12-25 19:25:41 +00:00
fixed some NPEs
This commit is contained in:
parent
def31fef83
commit
6f87867788
7 changed files with 42 additions and 34 deletions
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,7 @@ 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;
|
||||||
|
if (source.getTargets().size() > 0) {
|
||||||
for (UUID permanentId : source.getTargets().get(0).getTargets()) {
|
for (UUID permanentId : source.getTargets().get(0).getTargets()) {
|
||||||
Permanent permanent = game.getPermanent(permanentId);
|
Permanent permanent = game.getPermanent(permanentId);
|
||||||
if (permanent != null) {
|
if (permanent != null) {
|
||||||
|
@ -74,6 +75,7 @@ public class DestroyTargetEffect extends OneShotEffect<DestroyTargetEffect> {
|
||||||
affectedTargets++;
|
affectedTargets++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return affectedTargets > 0;
|
return affectedTargets > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,7 @@ public class ReturnToHandTargetEffect extends OneShotEffect<ReturnToHandTargetEf
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
|
if (source.getTargets().size() > 0) {
|
||||||
switch (source.getTargets().get(0).getZone()) {
|
switch (source.getTargets().get(0).getZone()) {
|
||||||
case BATTLEFIELD:
|
case BATTLEFIELD:
|
||||||
Permanent permanent = game.getPermanent(source.getFirstTarget());
|
Permanent permanent = game.getPermanent(source.getFirstTarget());
|
||||||
|
@ -72,6 +73,7 @@ public class ReturnToHandTargetEffect extends OneShotEffect<ReturnToHandTargetEf
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,15 +63,17 @@ 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();
|
||||||
|
if (amountX == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Permanent target = (Permanent) game.getPermanent(source.getSourceId());
|
Permanent target = (Permanent) game.getPermanent(source.getSourceId());
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
target.addPower(amount);
|
target.addPower(amountX);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue