mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
* Mycosynth Golem - Fixed not working second ability.
This commit is contained in:
parent
bb28394f71
commit
c1fa3422fd
5 changed files with 74 additions and 53 deletions
|
|
@ -29,20 +29,25 @@ 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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -50,6 +55,13 @@ import mage.game.events.GameEvent;
|
|||
*/
|
||||
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,57 +89,47 @@ 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) {
|
||||
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;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
||||
|
|
@ -65,6 +67,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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -352,12 +352,20 @@ public abstract class AbilityImpl implements Ability {
|
|||
//20100716 - 601.2e
|
||||
if (sourceObject != null) {
|
||||
sourceObject.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this is a hack to prevent mana abilities with mana costs from causing endless loops - pay other costs first
|
||||
if (this instanceof ManaAbility && !costs.pay(this, game, sourceId, controllerId, noMana)) {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class AffinityForArtifactsAbility extends SimpleStaticAbility implements
|
|||
|
||||
@Override
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue