Test and fix for copying transformed creatures

This commit is contained in:
magenoxx 2012-06-11 19:36:56 +04:00
parent 263ff56244
commit 17dbe0ae57
10 changed files with 139 additions and 38 deletions

View file

@ -118,4 +118,29 @@ public class PhantasmalImageTest extends CardTestPlayerBase {
assertPermanentCount(playerA, "Illusionary Servant", 3);
}
/**
* Tests copying already transformed creature
* Makes sure it still has "When this creature becomes the target of a spell or ability, sacrifice it"
*/
@Test
public void testCopyAlreadyTransformed() {
addCard(Constants.Zone.BATTLEFIELD, playerB, "Island", 2);
addCard(Constants.Zone.BATTLEFIELD, playerB, "Forest", 2);
addCard(Constants.Zone.HAND, playerB, "Phantasmal Image");
addCard(Constants.Zone.HAND, playerB, "Titanic Growth");
addCard(Constants.Zone.BATTLEFIELD, playerA, "Huntmaster of the Fells");
castSpell(2, Constants.PhaseStep.PRECOMBAT_MAIN, playerB, "Phantasmal Image");
castSpell(2, Constants.PhaseStep.POSTCOMBAT_MAIN, playerB, "Titanic Growth", "Ravager of the Fells-M12");
setStopAt(2, Constants.PhaseStep.END_TURN);
execute();
// check opponent's creature wasn't chosen as a target for Titanic Growth
assertPowerToughness(playerA, "Ravager of the Fells", 4, 4);
// check playerA's creature was sacrificed
assertPermanentCount(playerB, "Ravager of the Fells", 0);
assertGraveyardCount(playerB, "Phantasmal Image", 1);
}
}

View file

@ -1,7 +1,5 @@
package mage;
import java.io.Serializable;
import java.util.List;
import mage.Constants.CardType;
import mage.abilities.Abilities;
import mage.abilities.Ability;
@ -9,6 +7,9 @@ import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.game.Game;
import java.io.Serializable;
import java.util.List;
public interface MageObject extends MageItem, Serializable {
public String getName();
@ -29,4 +30,16 @@ public interface MageObject extends MageItem, Serializable {
public void adjustCosts(Ability ability, Game game);
public MageObject copy();
/**
* Defines that MageObject is a copy of another object
* @param isCopy
*/
public void setCopy(boolean isCopy);
/**
* Checks if current MageObject is a copy of another object
* @return
*/
public boolean isCopy();
}

View file

@ -28,10 +28,6 @@
package mage;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.Constants.CardType;
import mage.abilities.Abilities;
import mage.abilities.AbilitiesImpl;
@ -42,6 +38,10 @@ import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.keyword.ChangelingAbility;
import mage.game.Game;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public abstract class MageObjectImpl<T extends MageObjectImpl<T>> implements MageObject {
protected UUID objectId;
@ -56,6 +56,7 @@ public abstract class MageObjectImpl<T extends MageObjectImpl<T>> implements Mag
protected String text;
protected MageInt power;
protected MageInt toughness;
protected boolean copy;
@Override
public abstract T copy();
@ -166,4 +167,13 @@ public abstract class MageObjectImpl<T extends MageObjectImpl<T>> implements Mag
}
}
@Override
public void setCopy(boolean isCopy) {
this.copy = isCopy;
}
@Override
public boolean isCopy() {
return copy;
}
}

View file

@ -67,7 +67,7 @@ public class CopyEffect extends ContinuousEffectImpl<CopyEffect> {
if (permanent == null) {
return false;
}
permanent.setName(target.getName());
permanent.getColor().setColor(target.getColor());
permanent.getManaCost().clear();
@ -94,6 +94,7 @@ public class CopyEffect extends ContinuousEffectImpl<CopyEffect> {
permanent.setTransformed(((Permanent)target).isTransformed());
permanent.setSecondCardFace(((Permanent) target).getSecondCardFace());
}
permanent.setCopy(true);
return true;
}

View file

@ -61,6 +61,37 @@ public class TransformAbility extends SimpleStaticAbility {
public String getRule() {
return "";
}
public static void transform(Permanent permanent, Card sourceCard, Game game) {
if (sourceCard == null) {
return;
}
permanent.setName(sourceCard.getName());
permanent.getColor().setColor(sourceCard.getColor());
permanent.getManaCost().clear();
permanent.getManaCost().add(sourceCard.getManaCost());
permanent.getCardType().clear();
for (Constants.CardType type : sourceCard.getCardType()) {
permanent.getCardType().add(type);
}
permanent.getSubtype().clear();
for (String type : sourceCard.getSubtype()) {
permanent.getSubtype().add(type);
}
permanent.getSupertype().clear();
for (String type : sourceCard.getSupertype()) {
permanent.getSupertype().add(type);
}
permanent.setExpansionSetCode(sourceCard.getExpansionSetCode());
permanent.getAbilities().clear();
for (Ability ability : sourceCard.getAbilities()) {
permanent.addAbility(ability, game);
}
permanent.getPower().setValue(sourceCard.getPower().getValue());
permanent.getToughness().setValue(sourceCard.getToughness().getValue());
}
}
class TransformEffect extends ContinuousEffectImpl<TransformEffect> {
@ -82,6 +113,10 @@ class TransformEffect extends ContinuousEffectImpl<TransformEffect> {
return false;
}
if (permanent.isCopy()) { // copies can't transform
return true;
}
if (!permanent.isTransformed()) {
// keep original card
return true;
@ -92,30 +127,8 @@ class TransformEffect extends ContinuousEffectImpl<TransformEffect> {
if (card == null) {
return false;
}
permanent.setName(card.getName());
permanent.getColor().setColor(card.getColor());
permanent.getManaCost().clear();
permanent.getManaCost().add(card.getManaCost());
permanent.getCardType().clear();
for (Constants.CardType type : card.getCardType()) {
permanent.getCardType().add(type);
}
permanent.getSubtype().clear();
for (String type : card.getSubtype()) {
permanent.getSubtype().add(type);
}
permanent.getSupertype().clear();
for (String type : card.getSupertype()) {
permanent.getSupertype().add(type);
}
permanent.setExpansionSetCode(card.getExpansionSetCode());
permanent.getAbilities().clear();
for (Ability ability : card.getAbilities()) {
permanent.addAbility(ability, game);
}
permanent.getPower().setValue(card.getPower().getValue());
permanent.getToughness().setValue(card.getToughness().getValue());
TransformAbility.transform(permanent, card, game);
return true;

View file

@ -40,6 +40,7 @@ import mage.abilities.effects.ContinuousEffects;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.CopyEffect;
import mage.abilities.keyword.LeylineAbility;
import mage.abilities.keyword.TransformAbility;
import mage.abilities.mana.TriggeredManaAbility;
import mage.actions.impl.MageAction;
import mage.cards.Card;
@ -746,6 +747,9 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
//getState().addCard(permanent);
permanent.reset(this);
permanent.assignNewId();
if (copyFromPermanent.isTransformed()) {
TransformAbility.transform(permanent, copyFromPermanent.getSecondCardFace(), this);
}
applier.apply(this, permanent);
Ability newAbility = source.copy();

View file

@ -27,9 +27,6 @@
*/
package mage.game.command;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.Constants;
import mage.MageInt;
import mage.ObjectColor;
@ -41,6 +38,10 @@ import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.game.Game;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* @author nantuko
*/
@ -147,6 +148,15 @@ public class Emblem implements CommandObject {
return this.id;
}
@Override
public void setCopy(boolean isCopy) {
}
@Override
public boolean isCopy() {
return false;
}
@Override
public Emblem copy() {
return new Emblem(this);

View file

@ -127,11 +127,17 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
this.minBlockedBy = permanent.minBlockedBy;
this.transformed = permanent.transformed;
this.pairedCard = permanent.pairedCard;
this.copy = permanent.copy;
}
@Override
public String toString() {
return this.name + "-" + this.expansionSetCode;
StringBuilder sb = new StringBuilder(this.name);
sb.append("-").append(this.expansionSetCode);
if (copy) {
sb.append(" [Copy]");
}
return sb.toString();
}
@Override
@ -144,6 +150,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
controllerChanged = false;
this.maxBlocks = 1;
this.minBlockedBy = 1;
this.copy = false;
}
@Override

View file

@ -79,6 +79,7 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
this.ability = spell.ability.copy();
this.controllerId = spell.controllerId;
this.fromZone = spell.fromZone;
this.copiedSpell = spell.copiedSpell;
}
@Override
@ -444,15 +445,23 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
public void setCopiedSpell(boolean isCopied) {
this.copiedSpell = isCopied;
}
public boolean isCopiedSpell ( ) {
public boolean isCopiedSpell() {
return this.copiedSpell;
}
public Zone getFromZone() {
return this.fromZone;
}
@Override
public void setCopy(boolean isCopy) {
setCopiedSpell(isCopy);
}
@Override
public boolean isCopy() {
return isCopiedSpell();
}
}

View file

@ -327,4 +327,13 @@ public class StackAbility implements StackObject, Ability {
public boolean isInUseableZone(Game game, boolean checkLKI) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCopy(boolean isCopy) {
}
@Override
public boolean isCopy() {
return false;
}
}