diff --git a/Mage/src/main/java/mage/abilities/keyword/MyriadAbility.java b/Mage/src/main/java/mage/abilities/keyword/MyriadAbility.java
index c75c130074f..01962f97879 100644
--- a/Mage/src/main/java/mage/abilities/keyword/MyriadAbility.java
+++ b/Mage/src/main/java/mage/abilities/keyword/MyriadAbility.java
@@ -27,9 +27,10 @@
*/
package mage.abilities.keyword;
+import java.util.ArrayList;
+import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
-import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.common.AttacksTriggeredAbility;
import mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
@@ -42,12 +43,15 @@ import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.targetpointer.FixedTarget;
import mage.target.targetpointer.FixedTargets;
+import org.apache.log4j.Logger;
public class MyriadAbility extends AttacksTriggeredAbility {
public MyriadAbility() {
super(new MyriadEffect(), false,
- "Myriad (Whenever this creature attacks, for each opponent other than the defending player, put a token that's a copy of this creature onto the battlefield tapped and attacking that player or a planeswalker he or she controls. Exile those tokens at the end of combat.)",
+ "Myriad (Whenever this creature attacks, for each opponent other than the defending player, "
+ + "put a token that's a copy of this creature onto the battlefield tapped and attacking "
+ + "that player or a planeswalker he or she controls. Exile those tokens at the end of combat.)",
SetTargetPointer.PLAYER
);
}
@@ -67,7 +71,10 @@ class MyriadEffect extends OneShotEffect {
public MyriadEffect() {
super(Outcome.Benefit);
- this.staticText = "for each opponent other than the defending player, you may put a token that's a copy of this creature onto the battlefield tapped and attacking that player or a planeswalker he or she controls. Exile the tokens at the end of combat";
+ this.staticText = "for each opponent other than the defending player, you may put a token "
+ + "that's a copy of this creature onto the battlefield tapped and attacking that "
+ + "player or a planeswalker he or she controls. "
+ + "Exile the tokens at the end of combat";
}
public MyriadEffect(final MyriadEffect effect) {
@@ -85,6 +92,11 @@ class MyriadEffect extends OneShotEffect {
Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourceObject != null) {
UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(source.getSourceId(), game);
+ if (defendingPlayerId == null) {
+ Logger.getLogger(MyriadEffect.class).error("defending player == null source: " + sourceObject.getName() + " attacking: " + (sourceObject.isAttacking() ? "Y" : "N"));
+ return false;
+ }
+ List tokens = new ArrayList<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (playerId != defendingPlayerId && controller.hasOpponent(playerId, game)) {
Player opponent = game.getPlayer(playerId);
@@ -93,13 +105,14 @@ class MyriadEffect extends OneShotEffect {
PutTokenOntoBattlefieldCopyTargetEffect effect = new PutTokenOntoBattlefieldCopyTargetEffect(controller.getId(), null, false, 1, true, true, playerId);
effect.setTargetPointer(new FixedTarget(sourceObject, game));
effect.apply(game, source);
- ExileTargetEffect exileEffect = new ExileTargetEffect();
- exileEffect.setTargetPointer(new FixedTargets(effect.getAddedPermanent(), game));
- DelayedTriggeredAbility delayedAbility = new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect);
- game.addDelayedTriggeredAbility(delayedAbility, source);
+ tokens.addAll(effect.getAddedPermanent());
}
}
-
+ }
+ if (!tokens.isEmpty()) {
+ ExileTargetEffect exileEffect = new ExileTargetEffect();
+ exileEffect.setTargetPointer(new FixedTargets(tokens, game));
+ game.addDelayedTriggeredAbility(new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect), source);
}
return true;
}
diff --git a/Mage/src/main/java/mage/game/combat/Combat.java b/Mage/src/main/java/mage/game/combat/Combat.java
index 6618cd85d7b..0428e403f6d 100644
--- a/Mage/src/main/java/mage/game/combat/Combat.java
+++ b/Mage/src/main/java/mage/game/combat/Combat.java
@@ -1286,13 +1286,21 @@ public class Combat implements Serializable, Copyable {
return defenderId;
}
+ /**
+ * Returns the playerId of the player that is attacked by given attacking
+ * creature
+ *
+ * @param attackingCreatureId
+ * @param game
+ * @return
+ */
public UUID getDefendingPlayerId(UUID attackingCreatureId, Game game) {
UUID defenderId = null;
for (CombatGroup group : groups) {
if (group.getAttackers().contains(attackingCreatureId)) {
defenderId = group.getDefenderId();
if (group.defenderIsPlaneswalker) {
- Permanent permanent = game.getPermanent(defenderId);
+ Permanent permanent = game.getPermanentOrLKIBattlefield(defenderId);
if (permanent != null) {
defenderId = permanent.getControllerId();
} else {