From ef13a84d43d1f4e326e70f7ca7be80483be65b0c Mon Sep 17 00:00:00 2001 From: Lyu Zong-Hong Date: Thu, 11 Feb 2021 14:32:49 +0900 Subject: [PATCH] Fix crash when getting triggered controler for merged permanent --- .../java/forge/game/ability/AbilityUtils.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java index 68d68535008..a4179f8ba29 100644 --- a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java +++ b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java @@ -395,7 +395,7 @@ public class AbilityUtils { *

* calculateAmount. *

- * + * * @param card * a {@link forge.game.card.Card} object. * @param amount @@ -792,7 +792,7 @@ public class AbilityUtils { *

* getDefinedObjects. *

- * + * * @param card * a {@link forge.game.card.Card} object. * @param def @@ -822,7 +822,7 @@ public class AbilityUtils { /** * Filter list by type. - * + * * @param list * a CardList * @param type @@ -951,7 +951,7 @@ public class AbilityUtils { *

* getDefinedPlayers. *

- * + * * @param card * a {@link forge.game.card.Card} object. * @param def @@ -1054,6 +1054,10 @@ public class AbilityUtils { if (c instanceof SpellAbility) { o = ((SpellAbility) c).getActivatingPlayer(); } + // For merged permanent + if (c instanceof CardCollection) { + o = ((CardCollection) c).get(0).getController(); + } } else if (defParsed.endsWith("Opponent")) { String triggeringType = defParsed.substring(9); @@ -1065,6 +1069,10 @@ public class AbilityUtils { if (c instanceof SpellAbility) { o = ((SpellAbility) c).getActivatingPlayer().getOpponents(); } + // For merged permanent + if (c instanceof CardCollection) { + o = ((CardCollection) c).get(0).getController().getOpponents();; + } } else if (defParsed.endsWith("Owner")) { String triggeringType = defParsed.substring(9); @@ -1073,6 +1081,10 @@ public class AbilityUtils { if (c instanceof Card) { o = ((Card) c).getOwner(); } + // For merged permanent + if (c instanceof CardCollection) { + o = ((CardCollection) c).get(0).getOwner(); + } } else { final String triggeringType = defParsed.substring(9); @@ -1225,7 +1237,7 @@ public class AbilityUtils { *

* getDefinedSpellAbilities. *

- * + * * @param card * a {@link forge.game.card.Card} object. * @param def @@ -1489,7 +1501,7 @@ public class AbilityUtils { *

* handleRemembering. *

- * + * * @param sa * a SpellAbility object. */ @@ -1554,7 +1566,7 @@ public class AbilityUtils { *

* Parse non-mana X variables. *

- * + * * @param c * a {@link forge.game.card.Card} object. * @param s @@ -1716,7 +1728,7 @@ public class AbilityUtils { final String payingMana = StringUtils.join(sa.getRootAbility().getPayingMana()); final int num = sq[0].length() > 7 ? Integer.parseInt(sq[0].split("_")[1]) : 3; final boolean adamant = StringUtils.countMatches(payingMana, MagicColor.toShortString(sq[1])) >= num; - return CardFactoryUtil.doXMath(Integer.parseInt(sq[adamant ? 2 : 3]), expr, c); + return CardFactoryUtil.doXMath(Integer.parseInt(sq[adamant ? 2 : 3]), expr, c); } if (l[0].startsWith("LastStateBattlefield")) { @@ -1969,7 +1981,7 @@ public class AbilityUtils { } return cause; } - + public static SpellAbility addSpliceEffects(final SpellAbility sa) { final Card source = sa.getHostCard(); @@ -2029,7 +2041,7 @@ public class AbilityUtils { if (spliceCost == null) return; - + SpellAbility firstSpell = c.getFirstSpellAbility(); Map params = Maps.newHashMap(firstSpell.getMapParams()); ApiType api = AbilityRecordType.getRecordType(params).getApiTypeOf(params);