* Mycosynth Golem - Fixed not working second ability.

This commit is contained in:
LevelX2 2015-06-02 23:37:15 +02:00
parent bb28394f71
commit c1fa3422fd
5 changed files with 74 additions and 53 deletions

View file

@ -29,20 +29,25 @@ package mage.sets.fifthdawn;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.keyword.AffinityForArtifactsAbility; import mage.abilities.keyword.AffinityForArtifactsAbility;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.SubLayer;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterSpell;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.game.Game; 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;
/** /**
* *
@ -50,6 +55,13 @@ import mage.game.events.GameEvent;
*/ */
public class MycosynthGolem extends CardImpl { 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) { public MycosynthGolem(UUID ownerId) {
super(ownerId, 137, "Mycosynth Golem", Rarity.RARE, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{11}"); super(ownerId, 137, "Mycosynth Golem", Rarity.RARE, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{11}");
this.expansionSetCode = "5DN"; this.expansionSetCode = "5DN";
@ -62,7 +74,8 @@ public class MycosynthGolem extends CardImpl {
this.addAbility(new AffinityForArtifactsAbility()); this.addAbility(new AffinityForArtifactsAbility());
// Artifact creature spells you cast have affinity for artifacts. // 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() { private final Ability ability;
super(Duration.WhileOnBattlefield, Outcome.Benefit); private final FilterSpell filter;
staticText = "Artifact creature spells you cast have affinity for artifacts";
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); super(effect);
this.ability = effect.ability;
this.filter = effect.filter;
} }
@Override @Override
public MycosynthGolemEffect copy() { public MycosynthGolemGainAbilitySpellsEffect copy() {
return new MycosynthGolemEffect(this); return new MycosynthGolemGainAbilitySpellsEffect(this);
} }
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return true; Player player = game.getPlayer(source.getControllerId());
} Permanent permanent = game.getPermanent(source.getSourceId());
if (player != null && permanent != null) {
@Override for (StackObject stackObject : game.getStack()) {
public boolean replaceEvent(GameEvent event, Ability source, Game game) { // only spells cast, so no copies of spells
MageObject object = game.getObject(event.getSourceId()); if ((stackObject instanceof Spell) && !stackObject.isCopy() && stackObject.getControllerId().equals(source.getControllerId())) {
if (object != null) { Spell spell = (Spell) stackObject;
Card card = (Card) object; if (filter.match(spell, game)) {
Ability ability = new AffinityForArtifactsAbility(); if (!spell.getAbilities().contains(ability)) {
game.getState().addOtherAbility(card, ability); game.getState().addOtherAbility(spell.getCard(), 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;
} }
return true;
} }
return false; return false;
} }

View file

@ -27,14 +27,12 @@
*/ */
package mage.sets.magic2015; package mage.sets.magic2015;
import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.keyword.ConvokeAbility; import mage.abilities.keyword.ConvokeAbility;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
@ -43,7 +41,6 @@ import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.SubLayer; import mage.constants.SubLayer;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.FilterSpell; import mage.filter.FilterSpell;
import mage.filter.predicate.mageobject.CardTypePredicate; import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.game.Game; import mage.game.Game;

View file

@ -30,7 +30,8 @@ package org.mage.test.cards.abilities.other;
import mage.constants.PhaseStep; import mage.constants.PhaseStep;
import mage.constants.Zone; import mage.constants.Zone;
import org.junit.Ignore; import mage.game.permanent.Permanent;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase; 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 @Test
public void testSpellsAffinity() { public void testSpellsAffinity() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1); addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 1);
addCard(Zone.BATTLEFIELD, playerA, "Mycosynth Golem"); addCard(Zone.BATTLEFIELD, playerA, "Mycosynth Golem");
addCard(Zone.HAND, playerA, "Alpha Myr"); addCard(Zone.HAND, playerA, "Alpha Myr");
@ -65,6 +67,17 @@ public class MycosynthGolemTest extends CardTestPlayerBase {
assertPermanentCount(playerA, "Alpha Myr", 1); assertPermanentCount(playerA, "Alpha Myr", 1);
assertHandCount(playerA, "Alpha Myr", 0); 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);
} }
} }

View file

@ -352,9 +352,17 @@ public abstract class AbilityImpl implements Ability {
//20100716 - 601.2e //20100716 - 601.2e
if (sourceObject != null) { if (sourceObject != null) {
sourceObject.adjustCosts(this, game); sourceObject.adjustCosts(this, game);
for (Ability ability : sourceObject.getAbilities()) { if (sourceObject instanceof Card) {
if (ability instanceof AdjustingSourceCosts) { for (Ability ability : ((Card)sourceObject).getAbilities(game)) {
((AdjustingSourceCosts)ability).adjustCosts(this, 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);
}
} }
} }
} }

View file

@ -65,7 +65,7 @@ public class AffinityForArtifactsAbility extends SimpleStaticAbility implements
@Override @Override
public String getRule() { public String getRule() {
return "Affinity for artifacts"; return "affinity for artifacts <i>(This spell costs {1} less to cast for each artifact you control.)</i>";
} }
@Override @Override