* Copy effects - fixed that it copy current P/T values (e.g. after effects applied) instead printed/selected values;

This commit is contained in:
Oleg Agafonov 2019-04-23 12:03:16 +04:00
parent d09e74861a
commit 33af8939af
5 changed files with 144 additions and 33 deletions

View file

@ -1,7 +1,5 @@
package mage.cards.e;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
@ -9,25 +7,22 @@ import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.CopyEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.constants.*;
import mage.game.Game;
import mage.game.events.EntersTheBattlefieldEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
*
* @author BetaSteward
*/
public final class EssenceOfTheWild extends CardImpl {
public EssenceOfTheWild(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{G}{G}{G}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{G}{G}{G}");
this.subtype.add(SubType.AVATAR);
this.power = new MageInt(6);
@ -73,11 +68,7 @@ class EssenceOfTheWildEffect extends ReplacementEffectImpl {
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourceObject != null) {
Permanent permanentReset = sourceObject.copy();
permanentReset.getCounters(game).clear();
permanentReset.getPower().resetToBaseValue();
permanentReset.getToughness().resetToBaseValue();
game.addEffect(new CopyEffect(Duration.Custom, permanentReset, event.getTargetId()), source);
game.addEffect(new CopyEffect(Duration.Custom, sourceObject, event.getTargetId()), source);
}
return false;
}

View file

@ -1,7 +1,5 @@
package mage.cards.i;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
@ -12,11 +10,7 @@ import mage.abilities.effects.common.CopyEffect;
import mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.constants.*;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.permanent.TokenPredicate;
@ -28,8 +22,9 @@ import mage.players.Player;
import mage.target.common.TargetCreaturePermanent;
import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
/**
*
* @author spjspj
*/
public final class IdentityThief extends CardImpl {
@ -114,11 +109,7 @@ class IdentityThiefEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && permanent != null && sourcePermanent != null) {
Permanent permanentReset = permanent.copy();
permanentReset.getCounters(game).clear();
permanentReset.getPower().resetToBaseValue();
permanentReset.getToughness().resetToBaseValue();
CopyEffect copyEffect = new CopyEffect(Duration.EndOfTurn, permanentReset, source.getSourceId());
CopyEffect copyEffect = new CopyEffect(Duration.EndOfTurn, permanent, source.getSourceId());
if (controller.moveCardToExileWithInfo(permanent, source.getSourceId(), sourcePermanent.getIdName(), source.getSourceId(), game, Zone.BATTLEFIELD, true)) {
// Copy exiled permanent
game.addEffect(copyEffect, source);

View file

@ -0,0 +1,125 @@
package org.mage.test.cards.copy;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* @author JayDi85
*/
public class EssenceOfTheWildTest extends CardTestPlayerBase {
// Essence of the Wild {3}{G}{G}{G}
// Creatures you control enter the battlefield as a copy of Essence of the Wild.
private Permanent findCopyPermanent(Game game, int num) {
int currentCopyNumber = 1;
for (Permanent perm : game.getBattlefield().getAllActivePermanents()) {
if (perm.isCopy()) {
if (currentCopyNumber == num) {
return perm;
}
currentCopyNumber++;
}
}
Assert.fail("copy " + num + " must exist");
return null;
}
private Permanent findOriginPermanent(Game game, String permName) {
for (Permanent perm : game.getBattlefield().getAllActivePermanents()) {
if (!perm.isCopy() && perm.getName().equals(permName)) {
return perm;
}
}
Assert.fail("can't find origin");
return null;
}
@Test
public void test_CopyCreature() {
// essence copy creature
addCard(Zone.BATTLEFIELD, playerA, "Essence of the Wild", 1);
//
addCard(Zone.BATTLEFIELD, playerA, "Plains", 2);
addCard(Zone.HAND, playerA, "Silvercoat Lion", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Silvercoat Lion");
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, "Silvercoat Lion", 0);
assertPermanentCount(playerA, "Essence of the Wild", 2);
Permanent copy = findCopyPermanent(currentGame, 1);
Assert.assertEquals("must have 6 p/t", 6, copy.getPower().getValue());
Assert.assertEquals("must have 6 p/t", 6, copy.getToughness().getValue());
}
@Test
public void test_CopyCreatureByCopied() {
// essence copy to creature 1 -> creature 1 copy to creature
addCard(Zone.BATTLEFIELD, playerA, "Essence of the Wild", 1);
//
addCard(Zone.BATTLEFIELD, playerA, "Plains", 4);
addCard(Zone.HAND, playerA, "Silvercoat Lion", 2);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Silvercoat Lion");
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Silvercoat Lion");
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, "Silvercoat Lion", 0);
assertPermanentCount(playerA, "Essence of the Wild", 3);
Permanent copy1 = findCopyPermanent(currentGame, 1);
Permanent copy2 = findCopyPermanent(currentGame, 2);
Assert.assertFalse("copy must be diffent", copy1.equals(copy2));
Assert.assertEquals("copy 1 must have 6 p/t", 6, copy1.getPower().getValue());
Assert.assertEquals("copy 1 must have 6 p/t", 6, copy1.getToughness().getValue());
Assert.assertEquals("copy 2 must have 6 p/t", 6, copy2.getPower().getValue());
Assert.assertEquals("copy 2 must have 6 p/t", 6, copy2.getToughness().getValue());
}
@Test
public void test_CopyCreatureWithContinuusEffect() {
// essence with -1/-1 must copy creature with normal p/t
addCard(Zone.BATTLEFIELD, playerA, "Essence of the Wild", 1);
//
addCard(Zone.BATTLEFIELD, playerA, "Liliana, Death Wielder", 1);
//
addCard(Zone.BATTLEFIELD, playerA, "Plains", 2);
addCard(Zone.HAND, playerA, "Silvercoat Lion", 1);
// apply -1/-1 effect (+2: Put a -1/-1 counter on up to one target creature.)
activateAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "+2:", "Essence of the Wild");
// copy
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Silvercoat Lion");
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, "Silvercoat Lion", 0);
assertPermanentCount(playerA, "Essence of the Wild", 2);
Permanent origin = findOriginPermanent(currentGame, "Essence of the Wild");
Permanent copy = findCopyPermanent(currentGame, 1);
Assert.assertEquals("origin must have 5 p/t", 6 - 1, origin.getPower().getValue());
Assert.assertEquals("origin must have 5 p/t", 6 - 1, origin.getToughness().getValue());
Assert.assertEquals("copy must have 6 p/t", 6, copy.getPower().getValue());
Assert.assertEquals("copy must have 6 p/t", 6, copy.getToughness().getValue());
}
}

View file

@ -1051,11 +1051,8 @@ public class TestPlayer implements Player {
}
Player itemPlayer = game.getPlayer(objectId);
if (itemPlayer != null) {
return itemPlayer;
}
return itemPlayer;
return null;
}
private void assertAliasZone(PlayerAction action, Game game, TestPlayer player, String aliasName, Zone needZone, boolean mustHave) {
@ -1344,6 +1341,9 @@ public class TestPlayer implements Player {
@Override
public int chooseReplacementEffect(Map<String, String> rEffects, Game game) {
if (rEffects.size() <= 1) {
return 0;
}
if (!choices.isEmpty()) {
for (String choice : choices) {
for (int index = 0; index < rEffects.size(); index++) {

View file

@ -122,8 +122,12 @@ public class CopyEffect extends ContinuousEffectImpl {
permanent.addAbility(ability, getSourceId(), game, false); // no new Id so consumed replacement effects are known while new continuousEffects.apply happen.
}
}
permanent.getPower().setValue(copyFromObject.getPower().getValue());
permanent.getToughness().setValue(copyFromObject.getToughness().getValue());
// Primal Clay example:
// If a creature thats already on the battlefield becomes a copy of this creature, it copies the power, toughness,
// and abilities that were chosen for this creature as it entered the battlefield. (2018-03-16)
permanent.getPower().setValue(copyFromObject.getPower().getBaseValueModified());
permanent.getToughness().setValue(copyFromObject.getToughness().getBaseValueModified());
if (copyFromObject instanceof Permanent) {
Permanent targetPermanent = (Permanent) copyFromObject;
permanent.setTransformed(targetPermanent.isTransformed());