diff --git a/Mage/src/main/java/mage/abilities/AbilitiesImpl.java b/Mage/src/main/java/mage/abilities/AbilitiesImpl.java index 3cee96563b..f6dbe43a2d 100644 --- a/Mage/src/main/java/mage/abilities/AbilitiesImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilitiesImpl.java @@ -102,7 +102,7 @@ public class AbilitiesImpl extends ArrayList implements Ab rules.add(sbRule.toString()); } String rule = ability.getRule(); - if (rule.length() > 0) { + if (rule != null && rule.length() > 0) { rules.add(Character.toUpperCase(rule.charAt(0)) + rule.substring(1)); } } diff --git a/Mage/src/main/java/mage/abilities/common/DiesAttachedTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/DiesAttachedTriggeredAbility.java index 543b8b8e71..d5174481f4 100644 --- a/Mage/src/main/java/mage/abilities/common/DiesAttachedTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/DiesAttachedTriggeredAbility.java @@ -62,37 +62,40 @@ public class DiesAttachedTriggeredAbility extends TriggeredAbilityImpl { if (((ZoneChangeEvent) event).isDiesEvent()) { ZoneChangeEvent zEvent = (ZoneChangeEvent) event; boolean triggered = false; - 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.) - // So check here with the LKI of the enchantment - Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId()); - if (attachment != null - && zEvent.getTargetId() != null && attachment.getAttachedTo() != null - && zEvent.getTargetId().equals(attachment.getAttachedTo())) { - Permanent attachedTo = game.getPermanentOrLKIBattlefield(attachment.getAttachedTo()); - if (attachedTo != null - && attachment.getAttachedToZoneChangeCounter() == attachedTo.getZoneChangeCounter(game)) { // zoneChangeCounter is stored in Permanent - triggered = true; - } - } - } - if (triggered) { - for (Effect effect : getEffects()) { - effect.setValue("attachedTo", zEvent.getTarget()); - if (setTargetPointer.equals(SetTargetPointer.ATTACHED_TO_CONTROLLER)) { - Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId()); - if (attachment != null && attachment.getAttachedTo() != null) { - Permanent attachedTo = (Permanent) game.getLastKnownInformation(attachment.getAttachedTo(), Zone.BATTLEFIELD, attachment.getAttachedToZoneChangeCounter()); - if (attachedTo != null) { - effect.setTargetPointer(new FixedTarget(attachedTo.getControllerId())); - } + if (zEvent != null) { + if (zEvent.getTarget() != null && 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.) + // So check here with the LKI of the enchantment + Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId()); + if (attachment != null + && zEvent.getTargetId() != null && attachment.getAttachedTo() != null + && zEvent.getTargetId().equals(attachment.getAttachedTo())) { + Permanent attachedTo = game.getPermanentOrLKIBattlefield(attachment.getAttachedTo()); + if (attachedTo != null + && attachment.getAttachedToZoneChangeCounter() == attachedTo.getZoneChangeCounter(game)) { // zoneChangeCounter is stored in Permanent + triggered = true; } - } } - return true; + if (triggered) { + for (Effect effect : getEffects()) { + if (zEvent.getTarget() != null) { + effect.setValue("attachedTo", zEvent.getTarget()); + if (setTargetPointer.equals(SetTargetPointer.ATTACHED_TO_CONTROLLER)) { + Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId()); + if (attachment != null && attachment.getAttachedTo() != null) { + Permanent attachedTo = (Permanent) game.getLastKnownInformation(attachment.getAttachedTo(), Zone.BATTLEFIELD, attachment.getAttachedToZoneChangeCounter()); + if (attachedTo != null) { + effect.setTargetPointer(new FixedTarget(attachedTo.getControllerId())); + } + } + } + } + } + return true; + } } } return false; diff --git a/Mage/src/main/java/mage/abilities/keyword/AwakenAbility.java b/Mage/src/main/java/mage/abilities/keyword/AwakenAbility.java index 0fbd77b142..ff07f0d549 100644 --- a/Mage/src/main/java/mage/abilities/keyword/AwakenAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/AwakenAbility.java @@ -120,19 +120,21 @@ public class AwakenAbility extends SpellAbility { @Override public boolean apply(Game game, Ability source) { UUID targetId = null; - for (Target target : source.getTargets()) { - if (target.getFilter().getMessage().equals(filterMessage)) { - targetId = target.getFirstTarget(); + if (source != null && source.getTargets() != null) { + for (Target target : source.getTargets()) { + if (target.getFilter() != null && target.getFilter().getMessage().equals(filterMessage)) { + targetId = target.getFirstTarget(); + } + } + if (targetId != null) { + FixedTarget fixedTarget = new FixedTarget(targetId); + ContinuousEffect continuousEffect = new BecomesCreatureTargetEffect(new AwakenElementalToken(), false, true, Duration.Custom); + continuousEffect.setTargetPointer(fixedTarget); + game.addEffect(continuousEffect, source); + Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(awakenValue)); + effect.setTargetPointer(fixedTarget); + return effect.apply(game, source); } - } - if (targetId != null) { - FixedTarget fixedTarget = new FixedTarget(targetId); - ContinuousEffect continuousEffect = new BecomesCreatureTargetEffect(new AwakenElementalToken(), false, true, Duration.Custom); - continuousEffect.setTargetPointer(fixedTarget); - game.addEffect(continuousEffect, source); - Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(awakenValue)); - effect.setTargetPointer(fixedTarget); - return effect.apply(game, source); } return true; }