* Fixed some problems with creation of tokens of target permanents (fixes #1244).

This commit is contained in:
LevelX2 2015-09-08 18:13:32 +02:00
parent 39cfbec82f
commit e37c9a6472
24 changed files with 383 additions and 130 deletions

View file

@ -40,12 +40,9 @@ import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.EmptyToken;
import mage.game.permanent.token.Token;
import mage.players.Player;
import mage.players.PlayerList;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.util.CardUtil;
/**
*
@ -57,7 +54,6 @@ public class TemptWithReflections extends CardImpl {
super(ownerId, 60, "Tempt with Reflections", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{3}{U}");
this.expansionSetCode = "C13";
// Tempting offer - Choose target creature you control. Put a token onto the battlefield that's a copy of that creature. Each opponent may put a token onto the battlefield that's a copy of that creature. For each opponent who does, put a token onto the battlefield that's a copy of that creature.
this.getSpellAbility().addEffect(new TemptWithReflectionsEffect());
this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent());
@ -115,16 +111,16 @@ class TemptWithReflectionsEffect extends OneShotEffect {
player = playerList.getNext(game);
} while (!player.getId().equals(game.getActivePlayerId()));
for (UUID playerId: playersSaidYes) {
for (UUID playerId : playersSaidYes) {
effect = new PutTokenOntoBattlefieldCopyTargetEffect(playerId);
effect.setTargetPointer(getTargetPointer());
effect.apply(game, source);
effect.apply(game, source);
}
if (playersSaidYes.size() > 0) {
effect = new PutTokenOntoBattlefieldCopyTargetEffect();
effect.setTargetPointer(getTargetPointer());
effect.apply(game, source);
effect.apply(game, source);
}
return true;
}

View file

@ -53,7 +53,7 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.EmptyToken;
import mage.util.CardUtil;
import mage.util.functions.ApplyToPermanent;
import mage.util.functions.AbilityApplier;
/**
*
@ -61,6 +61,12 @@ import mage.util.functions.ApplyToPermanent;
*/
public class ProgenitorMimic extends CardImpl {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("no Token");
static {
filter.add(Predicates.not(new TokenPredicate()));
}
public ProgenitorMimic(UUID ownerId) {
super(ownerId, 92, "Progenitor Mimic", Rarity.MYTHIC, new CardType[]{CardType.CREATURE}, "{4}{G}{U}");
this.expansionSetCode = "DGM";
@ -72,11 +78,17 @@ public class ProgenitorMimic extends CardImpl {
// You may have Progenitor Mimic enter the battlefield as a copy of any creature on the battlefield
// except it gains "At the beginning of your upkeep, if this creature isn't a token,
// put a token onto the battlefield that's a copy of this creature."
AbilityApplier applier = new AbilityApplier(
new ConditionalTriggeredAbility(
new BeginningOfUpkeepTriggeredAbility(new ProgenitorMimicCopyEffect(), TargetController.YOU, false),
new SourceMatchesFilterCondition(filter),
"At the beginning of your upkeep, if this creature isn't a token, put a token onto the battlefield that's a copy of this creature.")
);
this.addAbility(new SimpleStaticAbility(
Zone.BATTLEFIELD,
new EntersBattlefieldEffect(new CopyPermanentEffect(new ProgenitorMimicApplyToPermanent()),
"You may have {this} enter the battlefield as a copy of any creature on the battlefield except it gains \"At the beginning of your upkeep, if this creature isn't a token, put a token onto the battlefield that's a copy of this creature.\"",
true)));
new EntersBattlefieldEffect(new CopyPermanentEffect(applier),
"You may have {this} enter the battlefield as a copy of any creature on the battlefield except it gains \"At the beginning of your upkeep, if this creature isn't a token, put a token onto the battlefield that's a copy of this creature.\"",
true)));
}
public ProgenitorMimic(final ProgenitorMimic card) {
@ -89,24 +101,6 @@ public class ProgenitorMimic extends CardImpl {
}
}
class ProgenitorMimicApplyToPermanent extends ApplyToPermanent {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("no Token");
static {
filter.add(Predicates.not(new TokenPredicate()));
}
@Override
public Boolean apply(Game game, Permanent permanent) {
Ability ability = new ConditionalTriggeredAbility(
new BeginningOfUpkeepTriggeredAbility(new ProgenitorMimicCopyEffect(), TargetController.YOU, false),
new SourceMatchesFilterCondition(filter),
"At the beginning of your upkeep, if this creature isn't a token, put a token onto the battlefield that's a copy of this creature.");
permanent.addAbility(ability, game);
return true;
}
}
class ProgenitorMimicCopyEffect extends OneShotEffect {
public ProgenitorMimicCopyEffect() {
@ -144,14 +138,14 @@ class ProgenitorMimicCopyEffect extends OneShotEffect {
// if it was no copy of copy take the target itself
copyFromPermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
if (copyFromPermanent != null) {
EmptyToken token = new EmptyToken();
if (copyFromPermanent != null) {
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(copyFromPermanent); // needed so that entersBattlefied triggered abilities see the attributes (e.g. Master Biomancer)
token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId());
Permanent newPermanentToken = game.getPermanent(token.getLastAddedToken());
if (newPermanentToken != null) {
game.copyPermanent(copyFromPermanent, newPermanentToken, source, null);
game.copyPermanent(copyFromPermanent, newPermanentToken, source, null);
return true;
}
}

View file

@ -28,10 +28,8 @@
package mage.sets.innistrad;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility;
@ -41,6 +39,9 @@ import mage.abilities.effects.EntersBattlefieldEffect;
import mage.abilities.effects.common.CopyPermanentEffect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
@ -55,8 +56,6 @@ import mage.util.functions.ApplyToPermanent;
*/
public class EvilTwin extends CardImpl {
public EvilTwin(UUID ownerId) {
super(ownerId, 212, "Evil Twin", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{2}{U}{B}");
this.expansionSetCode = "ISD";
@ -69,8 +68,8 @@ public class EvilTwin extends CardImpl {
this.addAbility(new SimpleStaticAbility(
Zone.BATTLEFIELD,
new EntersBattlefieldEffect(new CopyPermanentEffect(new EvilTwinApplyToPermanent()),
"You may have {this} enter the battlefield as a copy of any creature on the battlefield except it gains \"{U}{B}, {T}: Destroy target creature with the same name as this creature\"",
true)));
"You may have {this} enter the battlefield as a copy of any creature on the battlefield except it gains \"{U}{B}, {T}: Destroy target creature with the same name as this creature\"",
true)));
}
public EvilTwin(final EvilTwin card) {
@ -99,6 +98,16 @@ class EvilTwinApplyToPermanent extends ApplyToPermanent {
permanent.addAbility(ability, game);
return true;
}
@Override
public Boolean apply(Game game, MageObject mageObject) {
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new DestroyTargetEffect(), new ManaCostsImpl("{U}{B}"));
ability.addCost(new TapSourceCost());
ability.addTarget(new TargetCreaturePermanent(filter));
mageObject.getAbilities().add(ability);
return true;
}
}
class EvilTwinPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Permanent>> {

View file

@ -28,7 +28,7 @@
package mage.sets.limitedalpha;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.EntersBattlefieldEffect;
@ -50,7 +50,7 @@ import mage.util.functions.ApplyToPermanent;
/**
*
* @author KholdFuzion
*
*/
public class CopyArtifact extends CardImpl {
@ -58,7 +58,6 @@ public class CopyArtifact extends CardImpl {
super(ownerId, 54, "Copy Artifact", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{1}{U}");
this.expansionSetCode = "LEA";
// You may have Copy Artifact enter the battlefield as a copy of any artifact on the battlefield, except it's an enchantment in addition to its other types.
Ability ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new EntersBattlefieldEffect(
new CopyArtifactEffect(),
@ -79,6 +78,25 @@ public class CopyArtifact extends CardImpl {
class CopyArtifactEffect extends OneShotEffect {
ApplyToPermanent applier = new ApplyToPermanent() {
@Override
public Boolean apply(Game game, Permanent permanent) {
if (!permanent.getCardType().contains(CardType.ENCHANTMENT)) {
permanent.getCardType().add(CardType.ENCHANTMENT);
}
return true;
}
@Override
public Boolean apply(Game game, MageObject mageObject) {
if (!mageObject.getCardType().contains(CardType.ENCHANTMENT)) {
mageObject.getCardType().add(CardType.ENCHANTMENT);
}
return true;
}
};
private static final FilterPermanent filter = new FilterPermanent("artifact");
static {
@ -104,16 +122,7 @@ class CopyArtifactEffect extends OneShotEffect {
player.choose(Outcome.Copy, target, source.getSourceId(), game);
Permanent copyFromPermanent = game.getPermanent(target.getFirstTarget());
if (copyFromPermanent != null) {
game.copyPermanent(copyFromPermanent, sourcePermanent, source, new ApplyToPermanent() {
@Override
public Boolean apply(Game game, Permanent permanent) {
if (!permanent.getCardType().contains(CardType.ENCHANTMENT)) {
permanent.getCardType().add(CardType.ENCHANTMENT);
}
return true;
}
});
game.copyPermanent(copyFromPermanent, sourcePermanent, source, applier);
return true;
}
}

View file

@ -29,6 +29,7 @@ package mage.sets.magic2012;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.BecomesTargetTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
@ -115,6 +116,18 @@ class PhantasmalImageCopyEffect extends OneShotEffect {
//permanent.addAbility(new BecomesTargetTriggeredAbility(new SacrificeSourceEffect()), game);
return true;
}
@Override
public Boolean apply(Game game, MageObject mageObject) {
if (!mageObject.getSubtype().contains("Illusion")) {
mageObject.getSubtype().add("Illusion");
}
// Add directly because the created permanent is only used to copy from, so there is no need to add the ability to e.g. TriggeredAbilities
mageObject.getAbilities().add(new BecomesTargetTriggeredAbility(new SacrificeSourceEffect()));
//permanent.addAbility(new BecomesTargetTriggeredAbility(new SacrificeSourceEffect()), game);
return true;
}
});
return true;

View file

@ -47,7 +47,7 @@ import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.Target;
import mage.target.TargetPermanent;
import mage.util.functions.ApplyToPermanent;
import mage.util.functions.AbilityApplier;
/**
*
@ -82,6 +82,7 @@ public class MercurialPretender extends CardImpl {
return new MercurialPretender(this);
}
}
class MercurialPretenderCopyEffect extends OneShotEffect {
public MercurialPretenderCopyEffect() {
@ -103,16 +104,10 @@ class MercurialPretenderCopyEffect extends OneShotEffect {
player.choose(Outcome.Copy, target, source.getSourceId(), game);
Permanent copyFromPermanent = game.getPermanent(target.getFirstTarget());
if (copyFromPermanent != null) {
game.copyPermanent(copyFromPermanent, sourcePermanent, source, new ApplyToPermanent() {
@Override
public Boolean apply(Game game, Permanent permanent) {
game.copyPermanent(copyFromPermanent, sourcePermanent, source,
// {2}{U}{U}: Return this creature to its owner's hand.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ReturnToHandSourceEffect(true), new ManaCostsImpl("{2}{U}{U}"));
permanent.addAbility(ability, game);
return true;
}
});
new AbilityApplier(new SimpleActivatedAbility(Zone.BATTLEFIELD, new ReturnToHandSourceEffect(true), new ManaCostsImpl("{2}{U}{U}")))
);
return true;
}
}

View file

@ -29,6 +29,7 @@ package mage.sets.mirrodinbesieged;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
@ -110,6 +111,15 @@ class CryptoplasmEffect extends OneShotEffect {
permanent.addAbility(upkeepAbility, source.getSourceId(), game);
return true;
}
@Override
public Boolean apply(Game game, MageObject mageObject) {
Ability upkeepAbility = new BeginningOfUpkeepTriggeredAbility(new CryptoplasmEffect(), TargetController.YOU, true);
upkeepAbility.addTarget(new TargetCreaturePermanent());
mageObject.getAbilities().add(upkeepAbility);
return true;
}
});
game.addEffect(effect, source);

View file

@ -25,20 +25,20 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.sets.newphyrexia;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.EntersBattlefieldEffect;
import mage.abilities.effects.common.CopyPermanentEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
@ -51,7 +51,7 @@ import mage.util.functions.ApplyToPermanent;
* @author Loki
*/
public class PhyrexianMetamorph extends CardImpl {
private static final FilterPermanent filter = new FilterPermanent("artifact or creature");
static {
@ -59,8 +59,8 @@ public class PhyrexianMetamorph extends CardImpl {
new CardTypePredicate(CardType.ARTIFACT),
new CardTypePredicate(CardType.CREATURE)));
}
public PhyrexianMetamorph (UUID ownerId) {
public PhyrexianMetamorph(UUID ownerId) {
super(ownerId, 42, "Phyrexian Metamorph", Rarity.RARE, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{3}{UP}");
this.expansionSetCode = "NPH";
this.subtype.add("Shapeshifter");
@ -71,13 +71,19 @@ public class PhyrexianMetamorph extends CardImpl {
ApplyToPermanent phyrexianMetamorphApplier = new ApplyToPermanent() {
@Override
public Boolean apply(Game game, Permanent permanent) {
if (!permanent.getCardType().contains(CardType.ARTIFACT)) {
permanent.getCardType().add(CardType.ARTIFACT);
return apply(game, (MageObject) permanent);
}
@Override
public Boolean apply(Game game, MageObject mageObject) {
if (!mageObject.getCardType().contains(CardType.ARTIFACT)) {
mageObject.getCardType().add(CardType.ARTIFACT);
}
return true;
}
};
// {UP} ( can be paid with either {U} or 2 life.)
// You may have Phyrexian Metamorph enter the battlefield as a copy of any artifact or creature on the battlefield, except it's an artifact in addition to its other types.
Effect effect = new CopyPermanentEffect(filter, phyrexianMetamorphApplier);
@ -86,7 +92,7 @@ public class PhyrexianMetamorph extends CardImpl {
this.addAbility(ability);
}
public PhyrexianMetamorph (final PhyrexianMetamorph card) {
public PhyrexianMetamorph(final PhyrexianMetamorph card) {
super(card);
}

View file

@ -28,16 +28,17 @@
package mage.sets.planechase2012;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.EntersBattlefieldEffect;
import mage.abilities.effects.common.CopyPermanentEffect;
import mage.abilities.keyword.NinjutsuAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.util.functions.ApplyToPermanent;
@ -60,7 +61,7 @@ public class SakashimasStudent extends CardImpl {
// Ninjutsu {1}{U}
this.addAbility(new NinjutsuAbility(new ManaCostsImpl("{1}{U}")));
// You may have Sakashima's Student enter the battlefield as a copy of any creature on the battlefield, except it's still a Ninja in addition to its other creature types.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD,new EntersBattlefieldEffect(
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new EntersBattlefieldEffect(
new CopyPermanentEffect(new SakashimasStudentApplyToPermanent()),
"You may have {this} enter the battlefield as a copy of any creature on the battlefield, except it's still a Ninja in addition to its other creature types",
true)));
@ -86,4 +87,13 @@ class SakashimasStudentApplyToPermanent extends ApplyToPermanent {
}
return true;
}
@Override
public Boolean apply(Game game, MageObject mageObject) {
if (!mageObject.getSubtype().contains("Ninja")) {
mageObject.getSubtype().add("Ninja");
}
return true;
}
}

View file

@ -29,6 +29,7 @@ package mage.sets.saviorsofkamigawa;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility;
@ -119,6 +120,21 @@ class SakashimaTheImpostorCopyEffect extends OneShotEffect {
), game);
return true;
}
@Override
public Boolean apply(Game game, MageObject mageObject) {
if (!mageObject.getSupertype().contains("Legendary")) {
mageObject.getSubtype().add("Legendary");
}
mageObject.setName("Sakashima the Impostor");
// {2}{U}{U}: Return Sakashima the Impostor to its owner's hand at the beginning of the next end step
mageObject.getAbilities().add(new SimpleActivatedAbility(Zone.BATTLEFIELD,
new CreateDelayedTriggeredAbilityEffect(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnToHandSourceEffect(true)), false),
new ManaCostsImpl("{2}{U}{U}")
));
return true;
}
});
return true;

View file

@ -29,6 +29,7 @@ package mage.sets.theros;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.CopyPermanentEffect;
@ -77,6 +78,14 @@ public class ArtisanOfForms extends CardImpl {
class ArtisanOfFormsApplyToPermanent extends ApplyToPermanent {
@Override
public Boolean apply(Game game, MageObject mageObject) {
Effect effect = new CopyPermanentEffect(new ArtisanOfFormsApplyToPermanent());
effect.setText("have {this} become a copy of target creature and gain this ability");
mageObject.getAbilities().add(new HeroicAbility(effect, true));
return true;
}
@Override
public Boolean apply(Game game, Permanent permanent) {
Effect effect = new CopyPermanentEffect(new ArtisanOfFormsApplyToPermanent());
@ -84,4 +93,5 @@ class ArtisanOfFormsApplyToPermanent extends ApplyToPermanent {
permanent.addAbility(new HeroicAbility(effect, true), game);
return true;
}
}

View file

@ -29,6 +29,7 @@ package mage.sets.unlimitededition;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
@ -115,6 +116,15 @@ class VesuvanDoppelgangerCopyEffect extends OneShotEffect {
new VesuvanDoppelgangerCopyEffect(), TargetController.YOU, true, false, rule2));
return true;
}
@Override
public Boolean apply(Game game, MageObject mageObject) {
mageObject.getColor(game).setColor(sourcePermanent.getColor(game));
mageObject.getAbilities().add(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD,
new VesuvanDoppelgangerCopyEffect(), TargetController.YOU, true, false, rule2));
return true;
}
});
return true;
}
@ -127,4 +137,4 @@ class VesuvanDoppelgangerCopyEffect extends OneShotEffect {
public VesuvanDoppelgangerCopyEffect copy() {
return new VesuvanDoppelgangerCopyEffect(this);
}
}
}

View file

@ -29,6 +29,7 @@ package mage.sets.vintagemasters;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.EntersBattlefieldEffect;
import mage.abilities.effects.common.CopyPermanentEffect;
@ -86,4 +87,12 @@ class DacksDuplicateApplyToPermanent extends ApplyToPermanent {
permanent.addAbility(HasteAbility.getInstance(), game);
return true;
}
@Override
public Boolean apply(Game game, MageObject mageObject) {
mageObject.getAbilities().add(new DethroneAbility());
mageObject.getAbilities().add(HasteAbility.getInstance());
return true;
}
}

View file

@ -38,28 +38,28 @@ import org.mage.test.serverside.base.CardTestPlayerBase;
*
* @author LevelX2
*/
public class ArtisanOfFormsTest extends CardTestPlayerBase {
/**
* Targeting a Artisan of Forms triggers it Heroic ability. So it can copy a target creature.
* If Cackling Counterpart later resolves, it should copy the creature that Artisan of Forms copies, not
* the Artisan itself.
* Targeting a Artisan of Forms triggers it Heroic ability. So it can copy a
* target creature. If Cackling Counterpart later resolves, it should copy
* the creature that Artisan of Forms copies, not the Artisan itself.
*/
@Test
public void testCopyTriggeredByCracklingCounterpart() {
// Heroic - Whenever you cast a spell that targets Artisan of Forms, you may have Artisan of Forms become a copy of target creature and gain this ability.
addCard(Zone.BATTLEFIELD, playerA, "Artisan of Forms");
addCard(Zone.HAND, playerA, "Artisan of Forms"); // {1}{U}
// {1}{U}{U} Put a token onto the battlefield that's a copy of target creature you control.
addCard(Zone.HAND, playerA, "Cackling Counterpart");
addCard(Zone.BATTLEFIELD, playerA, "Island",3);
addCard(Zone.BATTLEFIELD, playerA, "Island", 5);
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cackling Counterpart", "Artisan of Forms");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Artisan of Forms");
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Cackling Counterpart", "Artisan of Forms");
addTarget(playerA, "Silvercoat Lion");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertLife(playerA, 20);
@ -70,18 +70,18 @@ public class ArtisanOfFormsTest extends CardTestPlayerBase {
assertPermanentCount(playerB, "Silvercoat Lion", 1);
// 1 + 2 Silvercoat Lion at the end
assertPermanentCount(playerA, "Silvercoat Lion", 2);
for (Permanent permanent :currentGame.getBattlefield().getAllActivePermanents(playerA.getId())) {
for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents(playerA.getId())) {
if (permanent.getName().equals("Silvercoat Lion")) {
Assert.assertEquals("Creature has to have Cast + Heroic ability", 2, permanent.getAbilities().size());
}
}
}
/**
* Targeting a Artisan of Forms triggers it Heroic ability. So it can copy a target creature.
* If populate spell later resolves, it should copy the creature that Artisan of Forms copies, not
* the Artisan itself.
/**
* Targeting a Artisan of Forms triggers it Heroic ability. So it can copy a
* target creature. If populate spell later resolves, it should copy the
* creature that Artisan of Forms copies, not the Artisan itself.
*/
@Test
public void testCopyTriggeredByPopulate() {
@ -90,17 +90,17 @@ public class ArtisanOfFormsTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerA, "Artisan of Forms");
// {1}{U}{U} Put a token onto the battlefield that's a copy of target creature you control.
addCard(Zone.HAND, playerA, "Cackling Counterpart");
addCard(Zone.BATTLEFIELD, playerA, "Island",3);
addCard(Zone.BATTLEFIELD, playerA, "Island", 3);
addCard(Zone.HAND, playerA, "Eyes in the Skies");
addCard(Zone.BATTLEFIELD, playerA, "Plains",4);
addCard(Zone.BATTLEFIELD, playerA, "Plains", 4);
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cackling Counterpart", "Artisan of Forms");
addTarget(playerA, "Silvercoat Lion");
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Eyes in the Skies");
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Eyes in the Skies");
addTarget(playerA, "Silvercoat Lion");
setStopAt(1, PhaseStep.END_TURN);
execute();
@ -113,12 +113,12 @@ public class ArtisanOfFormsTest extends CardTestPlayerBase {
assertPermanentCount(playerA, "Bird", 1);
// 3 Silvercoat Lion at the end
assertPermanentCount(playerA, "Silvercoat Lion", 3);
for (Permanent permanent :currentGame.getBattlefield().getAllActivePermanents(playerA.getId())) {
for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents(playerA.getId())) {
if (permanent.getName().equals("Silvercoat Lion")) {
Assert.assertEquals("Creature has to have Cast + Heroic ability", 2, permanent.getAbilities().size());
}
}
}
}
}

View file

@ -94,4 +94,35 @@ public class FelhideSpiritbinderTest extends CardTestPlayerBase {
assertLife(playerB, 20);
}
@Test
public void testCopyATokenCreature() {
addCard(Zone.BATTLEFIELD, playerA, "Forest", 3);
addCard(Zone.HAND, playerA, "Call of the Herd", 1);
// Inspired - Whenever Felhide Spiritbinder becomes untapped, you may pay {1}{R}.
// If you do, put a token onto the battlefield that's a copy of another target creature
// except it's an enchantment in addition to its other types. It gains haste. Exile it at the beginning of the next end step.
addCard(Zone.BATTLEFIELD, playerB, "Felhide Spiritbinder", 1);
addCard(Zone.BATTLEFIELD, playerB, "Mountain", 2);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Call of the Herd");
attack(2, playerB, "Felhide Spiritbinder");
setStopAt(4, PhaseStep.PRECOMBAT_MAIN);
execute();
assertPermanentCount(playerA, "Elephant", 1);
assertPermanentCount(playerB, "Elephant", 1);
assertAbility(playerB, "Elephant", HasteAbility.getInstance(), true);
Permanent copiedTokenElephant = getPermanent("Elephant", playerB);
Assert.assertEquals("Elephant has Enchantment card type", true, copiedTokenElephant.getCardType().contains(CardType.ENCHANTMENT));
assertLife(playerA, 17);
assertLife(playerB, 20);
}
}

View file

@ -82,28 +82,27 @@ public class FlameshadowConjuringTest extends CardTestPlayerBase {
// Whenever a nontoken creature enters the battlefield under your control, you may pay {R}. If you do, put a token onto the battlefield that's a copy of that creature.
// That token gains haste. Exile it at the beginning of the next end step.
addCard(Zone.BATTLEFIELD, playerA, "Flameshadow Conjuring", 1);
// Sacrifice a creature: Nantuko Husk gets +2/+2 until end of turn.
addCard(Zone.BATTLEFIELD, playerA, "Nantuko Husk", 1);
// Deathtouch, lifelink
// When Wurmcoil Engine dies, put a 3/3 colorless Wurm artifact creature token with deathtouch and a 3/3 colorless Wurm artifact creature token with lifelink onto the battlefield.
addCard(Zone.HAND, playerA, "Wurmcoil Engine", 1); // 6/6 - {6}
addCard(Zone.BATTLEFIELD, playerB, "Plains", 3);
// Destroy target attacking creature.
addCard(Zone.HAND, playerB, "Kill Shot", 1); // {2}{U}
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Wurmcoil Engine");
setChoice(playerA, "Yes");
attack(1, playerA, "Wurmcoil Engine");
attack(1, playerA, "Nantuko Husk");
activateAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Sacrifice a creature");
// addTarget(playerA, "Wurmcoil Engine[only copy]");
setChoice(playerA, "Wurmcoil Engine[only copy]");
castSpell(1, PhaseStep.END_COMBAT, playerB, "Kill Shot", "Wurmcoil Engine");
setStopAt(1, PhaseStep.END_TURN);
execute();
assertGraveyardCount(playerB, "Kill Shot", 1);
assertPermanentCount(playerA, "Wurmcoil Engine", 1);
assertPowerToughness(playerA, "Nantuko Husk", 4, 4);
assertLife(playerB, 12);
assertLife(playerB, 14);
assertLife(playerA, 26);
assertPermanentCount(playerA, "Wurm", 2);

View file

@ -33,19 +33,14 @@ import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.AddCardTypeTargetEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.keyword.HasteAbility;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.EmptyToken;
import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
import mage.util.functions.ApplyToPermanent;
import mage.util.functions.EmptyApplyToPermanent;
@ -72,6 +67,13 @@ public class PutTokenOntoBattlefieldCopyTargetEffect extends OneShotEffect {
this(playerId, null, false);
}
/**
*
* @param playerId null the token is controlled/owned by the controller of
* the source ability
* @param additionalCardType the token gains tis card types in addition
* @param gainsHaste the token gains haste
*/
public PutTokenOntoBattlefieldCopyTargetEffect(UUID playerId, CardType additionalCardType, boolean gainsHaste) {
super(Outcome.PutCreatureInPlay);
this.playerId = playerId;
@ -113,28 +115,19 @@ public class PutTokenOntoBattlefieldCopyTargetEffect extends OneShotEffect {
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(copyFromPermanent); // needed so that entersBattlefied triggered abilities see the attributes (e.g. Master Biomancer)
applier.apply(game, token);
if (additionalCardType != null && !token.getCardType().contains(additionalCardType)) {
token.getCardType().add(additionalCardType);
}
if (gainsHaste) {
token.addAbility(HasteAbility.getInstance());
}
token.putOntoBattlefield(1, game, source.getSourceId(), playerId == null ? source.getControllerId() : playerId);
for (UUID tokenId : token.getLastAddedTokenIds()) { // by cards like Doubling Season multiple tokens can be added to the battlefield
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
addedTokenPermanents.add(tokenPermanent);
game.copyPermanent(copyFromPermanent, tokenPermanent, source, applier);
if (additionalCardType != null) {
ContinuousEffect effect = new AddCardTypeTargetEffect(additionalCardType, Duration.Custom);
effect.setTargetPointer(new FixedTarget(tokenPermanent, game));
game.addEffect(effect, source);
}
if (gainsHaste) {
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
effect.setTargetPointer(new FixedTarget(tokenPermanent, game));
game.addEffect(effect, source);
}
}
}
return true;

View file

@ -137,7 +137,7 @@ public class Token extends MageObjectImpl {
return false;
}
lastAddedTokenIds.clear();
// TODO: Check this setCode handling because it makes no sens if token put into play with e.g. "Feldon of the third Path"
// TODO: Check this setCode handling because it makes no sense if token put into play with e.g. "Feldon of the third Path"
Card source = game.getCard(sourceId);
String setCode;
if (this.getOriginalExpansionSetCode() != null && !this.getOriginalExpansionSetCode().isEmpty()) {

View file

@ -0,0 +1,59 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.util.functions;
import mage.MageObject;
import mage.abilities.Ability;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class AbilityApplier extends ApplyToPermanent {
private final Ability ability;
public AbilityApplier(Ability ability) {
this.ability = ability;
}
@Override
public Boolean apply(Game game, Permanent permanent) {
permanent.addAbility(ability, game);
return true;
}
@Override
public Boolean apply(Game game, MageObject mageObject) {
mageObject.getAbilities().add(ability);
return true;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.util.functions;
import mage.MageObject;
import mage.game.Game;
/**
*
* @author LevelX2
*/
public abstract class ApplyToMageObject {
public abstract Boolean apply(Game game, MageObject mageObject);
}

View file

@ -7,7 +7,7 @@ import mage.game.permanent.Permanent;
/**
* @author noxx
*/
public abstract class ApplyToPermanent implements Serializable {
public abstract class ApplyToPermanent extends ApplyToMageObject implements Serializable {
public abstract Boolean apply(Game game, Permanent permanent);
}

View file

@ -0,0 +1,36 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.util.functions;
/**
*
* @author LevelX2
*/
public class CardTypeApplier {
}

View file

@ -78,7 +78,7 @@ public class CopyTokenFunction implements Function<Token, Card> {
target.setOriginalExpansionSetCode(source.getExpansionSetCode());
target.setOriginalCardNumber(source.getCardNumber());
if (source instanceof Card) {
target.setCopySourceCard((Card) source);
target.setCopySourceCard(source);
}
}

View file

@ -1,5 +1,6 @@
package mage.util.functions;
import mage.MageObject;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -8,8 +9,15 @@ import mage.game.permanent.Permanent;
*/
public class EmptyApplyToPermanent extends ApplyToPermanent {
@Override
public Boolean apply(Game game, Permanent permanent) {
// do nothing
return true;
}
@Override
public Boolean apply(Game game, MageObject mageObject) {
return true;
}
}