From c1fa3422fd7ea373baf352b42c8b670f717f271e Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 2 Jun 2015 23:37:15 +0200 Subject: [PATCH] * Mycosynth Golem - Fixed not working second ability. --- .../mage/sets/fifthdawn/MycosynthGolem.java | 89 ++++++++++--------- .../mage/sets/magic2015/ChiefEngineer.java | 3 - .../abilities/other/MycosynthGolemTest.java | 17 +++- Mage/src/mage/abilities/AbilityImpl.java | 16 +++- .../keyword/AffinityForArtifactsAbility.java | 2 +- 5 files changed, 74 insertions(+), 53 deletions(-) diff --git a/Mage.Sets/src/mage/sets/fifthdawn/MycosynthGolem.java b/Mage.Sets/src/mage/sets/fifthdawn/MycosynthGolem.java index acd7225b6b0..084fbf7fc3e 100644 --- a/Mage.Sets/src/mage/sets/fifthdawn/MycosynthGolem.java +++ b/Mage.Sets/src/mage/sets/fifthdawn/MycosynthGolem.java @@ -29,27 +29,39 @@ package mage.sets.fifthdawn; import java.util.UUID; import mage.MageInt; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.keyword.AffinityForArtifactsAbility; -import mage.cards.Card; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; +import mage.constants.Layer; import mage.constants.Outcome; import mage.constants.Rarity; +import mage.constants.SubLayer; import mage.constants.Zone; +import mage.filter.FilterSpell; +import mage.filter.predicate.mageobject.CardTypePredicate; import mage.game.Game; -import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.game.stack.Spell; +import mage.game.stack.StackObject; +import mage.players.Player; /** * * @author jeffwadsworth */ public class MycosynthGolem extends CardImpl { + + private static final FilterSpell filter = new FilterSpell("Artifact creature spells you cast"); + static { + filter.add(new CardTypePredicate(CardType.ARTIFACT)); + filter.add(new CardTypePredicate(CardType.CREATURE)); + } + public MycosynthGolem(UUID ownerId) { super(ownerId, 137, "Mycosynth Golem", Rarity.RARE, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{11}"); this.expansionSetCode = "5DN"; @@ -62,7 +74,8 @@ public class MycosynthGolem extends CardImpl { this.addAbility(new AffinityForArtifactsAbility()); // Artifact creature spells you cast have affinity for artifacts. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new MycosynthGolemEffect())); + this.addAbility(new SimpleStaticAbility( + Zone.BATTLEFIELD, new MycosynthGolemGainAbilitySpellsEffect(new AffinityForArtifactsAbility(), filter))); } @@ -76,56 +89,46 @@ public class MycosynthGolem extends CardImpl { } } -class MycosynthGolemEffect extends ReplacementEffectImpl { +class MycosynthGolemGainAbilitySpellsEffect extends ContinuousEffectImpl { - public MycosynthGolemEffect() { - super(Duration.WhileOnBattlefield, Outcome.Benefit); - staticText = "Artifact creature spells you cast have affinity for artifacts"; + private final Ability ability; + private final FilterSpell filter; + + public MycosynthGolemGainAbilitySpellsEffect(Ability ability, FilterSpell filter) { + super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); + this.ability = ability; + this.filter = filter; + staticText = filter.getMessage() + " have " + ability.getRule(); } - public MycosynthGolemEffect(final MycosynthGolemEffect effect) { + public MycosynthGolemGainAbilitySpellsEffect(final MycosynthGolemGainAbilitySpellsEffect effect) { super(effect); + this.ability = effect.ability; + this.filter = effect.filter; } @Override - public MycosynthGolemEffect copy() { - return new MycosynthGolemEffect(this); + public MycosynthGolemGainAbilitySpellsEffect copy() { + return new MycosynthGolemGainAbilitySpellsEffect(this); } @Override public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - MageObject object = game.getObject(event.getSourceId()); - if (object != null) { - Card card = (Card) object; - Ability ability = new AffinityForArtifactsAbility(); - game.getState().addOtherAbility(card, ability); - ability.setControllerId(source.getControllerId()); - ability.setSourceId(card.getId()); - game.getState().addAbility(ability, source.getSourceId(), card); - } - return false; - } - - @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.CAST_SPELL; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if ((event.getType() == GameEvent.EventType.CAST_SPELL) - && event.getPlayerId() == source.getControllerId()) { - MageObject spellObject = game.getObject(event.getSourceId()); - if (spellObject != null - && spellObject.getCardType().contains(CardType.CREATURE) - && spellObject.getCardType().contains(CardType.ARTIFACT)) { - return true; + Player player = game.getPlayer(source.getControllerId()); + Permanent permanent = game.getPermanent(source.getSourceId()); + if (player != null && permanent != null) { + for (StackObject stackObject : game.getStack()) { + // only spells cast, so no copies of spells + if ((stackObject instanceof Spell) && !stackObject.isCopy() && stackObject.getControllerId().equals(source.getControllerId())) { + Spell spell = (Spell) stackObject; + if (filter.match(spell, game)) { + if (!spell.getAbilities().contains(ability)) { + game.getState().addOtherAbility(spell.getCard(), ability); + } + } + } } + return true; } return false; } diff --git a/Mage.Sets/src/mage/sets/magic2015/ChiefEngineer.java b/Mage.Sets/src/mage/sets/magic2015/ChiefEngineer.java index 32f86d943ac..516de3d0fd9 100644 --- a/Mage.Sets/src/mage/sets/magic2015/ChiefEngineer.java +++ b/Mage.Sets/src/mage/sets/magic2015/ChiefEngineer.java @@ -27,14 +27,12 @@ */ package mage.sets.magic2015; -import java.util.Iterator; import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.keyword.ConvokeAbility; -import mage.cards.Card; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; @@ -43,7 +41,6 @@ import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.SubLayer; import mage.constants.Zone; -import mage.filter.FilterCard; import mage.filter.FilterSpell; import mage.filter.predicate.mageobject.CardTypePredicate; import mage.game.Game; diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/other/MycosynthGolemTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/other/MycosynthGolemTest.java index 69cefe72618..0de986e4214 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/other/MycosynthGolemTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/other/MycosynthGolemTest.java @@ -30,7 +30,8 @@ package org.mage.test.cards.abilities.other; import mage.constants.PhaseStep; import mage.constants.Zone; -import org.junit.Ignore; +import mage.game.permanent.Permanent; +import org.junit.Assert; import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBase; @@ -50,10 +51,11 @@ public class MycosynthGolemTest extends CardTestPlayerBase { * */ - @Ignore // at this time player.getPlayable() does not account for spells that gain abilities + // @Ignore // at this time player.getPlayable() does not account for spells that gain abilities @Test public void testSpellsAffinity() { addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1); + addCard(Zone.BATTLEFIELD, playerA, "Forest", 1); addCard(Zone.BATTLEFIELD, playerA, "Mycosynth Golem"); addCard(Zone.HAND, playerA, "Alpha Myr"); @@ -64,6 +66,17 @@ public class MycosynthGolemTest extends CardTestPlayerBase { assertPermanentCount(playerA, "Alpha Myr", 1); assertHandCount(playerA, "Alpha Myr", 0); + + Permanent mountain = getPermanent("Mountain", playerA); + Permanent forest = getPermanent("Forest", playerA); + int tappedLands = 0; + if (mountain.isTapped()) { + tappedLands++; + } + if (forest.isTapped()) { + tappedLands++; + } + Assert.assertEquals("only one land may be tapped because the cost reduction", 1, tappedLands); } diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java index 844e6de7c48..f9847aa8b7e 100644 --- a/Mage/src/mage/abilities/AbilityImpl.java +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -352,10 +352,18 @@ public abstract class AbilityImpl implements Ability { //20100716 - 601.2e if (sourceObject != null) { sourceObject.adjustCosts(this, game); - for (Ability ability : sourceObject.getAbilities()) { - if (ability instanceof AdjustingSourceCosts) { - ((AdjustingSourceCosts)ability).adjustCosts(this, game); - } + if (sourceObject instanceof Card) { + for (Ability ability : ((Card)sourceObject).getAbilities(game)) { + if (ability instanceof AdjustingSourceCosts) { + ((AdjustingSourceCosts)ability).adjustCosts(this, game); + } + } + } else { + for (Ability ability : sourceObject.getAbilities()) { + if (ability instanceof AdjustingSourceCosts) { + ((AdjustingSourceCosts)ability).adjustCosts(this, game); + } + } } } diff --git a/Mage/src/mage/abilities/keyword/AffinityForArtifactsAbility.java b/Mage/src/mage/abilities/keyword/AffinityForArtifactsAbility.java index 6bb24081cb3..2f2a1729280 100644 --- a/Mage/src/mage/abilities/keyword/AffinityForArtifactsAbility.java +++ b/Mage/src/mage/abilities/keyword/AffinityForArtifactsAbility.java @@ -65,7 +65,7 @@ public class AffinityForArtifactsAbility extends SimpleStaticAbility implements @Override public String getRule() { - return "Affinity for artifacts"; + return "affinity for artifacts (This spell costs {1} less to cast for each artifact you control.)"; } @Override