diff --git a/forge-game/src/main/java/forge/game/card/Card.java b/forge-game/src/main/java/forge/game/card/Card.java index 5249b18cd2aa..326f3f2706da 100644 --- a/forge-game/src/main/java/forge/game/card/Card.java +++ b/forge-game/src/main/java/forge/game/card/Card.java @@ -3377,7 +3377,7 @@ public final int getMaxManaProduced() { } public final SpellAbility getFirstSpellAbility() { - return Iterables.getFirst(currentState.getNonManaAbilities(), null); + return currentState.getFirstSpellAbility(); } public final SpellPermanent getSpellPermanent() { diff --git a/forge-game/src/main/java/forge/game/card/CardState.java b/forge-game/src/main/java/forge/game/card/CardState.java index 58f519285316..873d89378cb0 100644 --- a/forge-game/src/main/java/forge/game/card/CardState.java +++ b/forge-game/src/main/java/forge/game/card/CardState.java @@ -456,49 +456,33 @@ public final boolean removeIntrinsicKeyword(final Keyword k) { } public final FCollectionView getSpellAbilities() { - FCollection newCol = new FCollection<>(); - updateSpellAbilities(newCol); - newCol.addAll(abilities); - card.updateSpellAbilities(newCol, this); - return newCol; + FCollection result = new FCollection<>(abilities); + if (getStateName().equals(CardStateName.Original)) { + if (getCard().hasState(CardStateName.LeftSplit)) + result.addAll(getCard().getState(CardStateName.LeftSplit).abilities); + if (getCard().hasState(CardStateName.RightSplit)) + result.addAll(getCard().getState(CardStateName.RightSplit).abilities); + } + card.updateSpellAbilities(result, this); + return result; } public final FCollectionView getManaAbilities() { - FCollection newCol = new FCollection<>(); - updateSpellAbilities(newCol); - newCol.addAll(abilities); - card.updateSpellAbilities(newCol, this); - newCol.removeIf(Predicate.not(SpellAbility::isManaAbility)); - return newCol; + FCollectionView result = getSpellAbilities(); + result.removeIf(Predicate.not(SpellAbility::isManaAbility)); + return result; } public final FCollectionView getNonManaAbilities() { - FCollection newCol = new FCollection<>(); - updateSpellAbilities(newCol); - newCol.addAll(abilities); - card.updateSpellAbilities(newCol, this); - newCol.removeIf(SpellAbility::isManaAbility); - return newCol; + FCollectionView result = getSpellAbilities(); + result.removeIf(SpellAbility::isManaAbility); + return result; } - protected final void updateSpellAbilities(FCollection newCol) { - // add Split to Original - if (getStateName().equals(CardStateName.Original)) { - if (getCard().hasState(CardStateName.LeftSplit)) { - CardState leftState = getCard().getState(CardStateName.LeftSplit); - newCol.addAll(leftState.abilities); - leftState.updateSpellAbilities(newCol); - } - if (getCard().hasState(CardStateName.RightSplit)) { - CardState rightState = getCard().getState(CardStateName.RightSplit); - newCol.addAll(rightState.abilities); - rightState.updateSpellAbilities(newCol); - } - } - + protected final SpellAbility getIntrinsicSpell() { // SpellPermanent only for Original State switch(getStateName()) { case Backside: if (!getCard().isModal()) { - return; + return null; } break; case Original: @@ -511,32 +495,65 @@ protected final void updateSpellAbilities(FCollection newCol) { case SpecializeW: break; default: - return; - } - // if card has left or right split, disable intrinsic Spell for original - if (getStateName().equals(CardStateName.Original) && (getCard().hasState(CardStateName.LeftSplit) || getCard().hasState(CardStateName.RightSplit))) { - return; + return null; } CardTypeView type = getTypeWithChanges(); + if (!type.isPermanent()) { + return null; + } + if (type.isLand()) { if (landAbility == null) { landAbility = new LandAbility(card, this); } - newCol.add(landAbility); + return landAbility; } else if (type.isAura()) { - newCol.add(getAuraSpell()); - } else if (type.isPermanent()) { + return getAuraSpell(); + } else { if (abilities.anyMatch(s -> ( s.isBasicSpell() && s.getSubAbility() == null && (ApiType.PermanentCreature.equals(s.getApi()) || ApiType.PermanentNoncreature.equals(s.getApi()))) )) { - return; + return null; } if (permanentAbility == null) { permanentAbility = new SpellPermanent(card, this); } - newCol.add(permanentAbility); + return permanentAbility; + } + } + + protected final void updateSpellAbilities(List newCol) { + // add Split to Original + if (getStateName().equals(CardStateName.Original) && + (getCard().hasState(CardStateName.LeftSplit) || getCard().hasState(CardStateName.RightSplit))) { + boolean skip = false; + // insert right first, so left can be added before + if (getCard().hasState(CardStateName.RightSplit)) { + skip = true; + SpellAbility spRight = getCard().getState(CardStateName.RightSplit).getIntrinsicSpell(); + if (spRight != null) { + newCol.add(0, spRight); + } + } + if (getCard().hasState(CardStateName.LeftSplit)) { + skip = true; + SpellAbility spLeft = getCard().getState(CardStateName.LeftSplit).getIntrinsicSpell(); + if (spLeft != null) { + newCol.add(0, spLeft); + } + } + + // if card has left or right split, disable intrinsic Spell for original + if (skip) { + return; + } + } + + SpellAbility sp = getIntrinsicSpell(); + if (sp != null) { + newCol.add(0, sp); } } @@ -559,9 +576,7 @@ public List applySpellAbility(List list) { list.clear(); } CardTypeView type = state.getTypeWithChanges(); - if (!type.isLand()) { - return list; - } + state.updateSpellAbilities(list); for (MagicColor.Color c : MagicColor.Color.values()) { if (c.getBasicLandType() == null) { continue; @@ -620,7 +635,7 @@ public final SpellAbility getFirstSpellAbility() { if (this.card.getCastSA() != null) { return this.card.getCastSA(); } - return Iterables.getFirst(getNonManaAbilities(), null); + return getNonManaAbilities().stream().filter(SpellAbility::isSpell).findFirst().orElse(null); } public final SpellAbility getFirstSpellAbilityWithFallback() { diff --git a/forge-game/src/main/java/forge/game/keyword/KeywordCollection.java b/forge-game/src/main/java/forge/game/keyword/KeywordCollection.java index 542abdb3d707..993469625568 100644 --- a/forge-game/src/main/java/forge/game/keyword/KeywordCollection.java +++ b/forge-game/src/main/java/forge/game/keyword/KeywordCollection.java @@ -24,6 +24,9 @@ public class KeywordCollection implements ICardTraitChanges, Iterable