mirror of
https://github.com/correl/mage.git
synced 2025-01-11 11:05:23 +00:00
Fixed that adjustTarget did not work correctly for Triggered abilities. Fixed that adjustTargets also works now for cards copied from graveyard (e.g.by Feldon of the Third Path).
This commit is contained in:
parent
0e3327621a
commit
96aafcd475
11 changed files with 211 additions and 8 deletions
|
@ -106,6 +106,7 @@ class FeldonOfTheThirdPathEffect extends OneShotEffect {
|
|||
Card card = game.getCard(getTargetPointer().getFirst(game, source));
|
||||
if (card != null) {
|
||||
EmptyToken token = new EmptyToken();
|
||||
// This fails if a card will be copied, that uses adjustTargets() method.
|
||||
CardUtil.copyTo(token).from(card);
|
||||
|
||||
token.addAbility(HasteAbility.getInstance());
|
||||
|
|
|
@ -102,7 +102,7 @@ public class NecroticPlague extends CardImpl {
|
|||
if (creatureController != null) {
|
||||
ability.setControllerId(creatureController.getId());
|
||||
ability.getTargets().clear();
|
||||
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
|
||||
TargetPermanent target = new TargetPermanent(filter);
|
||||
ability.getTargets().add(target);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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 org.mage.test.cards.abilities.enters;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class SepulchralPrimordialTest extends CardTestPlayerBase {
|
||||
|
||||
@Test
|
||||
public void testETB2Effect() {
|
||||
// When Sepulchral Primordial enters the battlefield, for each opponent, you may put up to one
|
||||
// target creature card from that player's graveyard onto the battlefield under your control.
|
||||
addCard(Zone.HAND, playerA, "Sepulchral Primordial", 1);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 7);
|
||||
|
||||
addCard(Zone.GRAVEYARD, playerB, "Silvercoat Lion", 1);
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Sepulchral Primordial");
|
||||
addTarget(playerA, "Silvercoat Lion"); // target for ETB Sepulchral Primordial
|
||||
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||
execute();
|
||||
|
||||
assertPermanentCount(playerA, "Sepulchral Primordial", 1);
|
||||
assertPermanentCount(playerA, "Silvercoat Lion", 1);
|
||||
|
||||
assertLife(playerA, 20);
|
||||
assertLife(playerB, 20);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
|
||||
/*
|
||||
* 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 org.mage.test.cards.copy;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
* Test the funtions of Feldon of the Third Path - {1}{R}{R} Legendary Creature
|
||||
* - Human Artificer 2/3 {2}{R}, {T} : Put a token onto the battlefield that's a
|
||||
* copy of target creature card in your graveyard, except it's an artifact in
|
||||
* addition to its other types. It gains haste. Sacrifice it at the beginning of
|
||||
* the next end step.
|
||||
*
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class FeldonOfTheThirdPathTest extends CardTestPlayerBase {
|
||||
|
||||
/**
|
||||
* Checking that enters the battlefield abilities of the copied creature
|
||||
* card works.
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testETBEffect() {
|
||||
// When Highway Robber enters the battlefield, target opponent loses 2 life and you gain 2 life.
|
||||
addCard(Zone.GRAVEYARD, playerA, "Highway Robber", 1);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Feldon of the Third Path", 1);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
|
||||
|
||||
activateAbility(2, PhaseStep.PRECOMBAT_MAIN, playerA,
|
||||
"{2}{R},{T}: Put a token onto the battlefield that's a copy of target creature card in your graveyard, except it's an artifact in addition to its other types. It gains haste. Sacrifice it at the beginning of the next end step.",
|
||||
"Highway Robber");
|
||||
setStopAt(2, PhaseStep.POSTCOMBAT_MAIN);
|
||||
execute();
|
||||
|
||||
assertPermanentCount(playerA, "Highway Robber", 1);
|
||||
assertPermanentCount(playerA, "Feldon of the Third Path", 1);
|
||||
|
||||
assertLife(playerA, 22); // +2 from Robber
|
||||
assertLife(playerB, 18); // -2 from Robber
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testETB2Effect() {
|
||||
// When Sepulchral Primordial enters the battlefield, for each opponent, you may put up to one
|
||||
// target creature card from that player's graveyard onto the battlefield under your control.
|
||||
addCard(Zone.GRAVEYARD, playerA, "Sepulchral Primordial", 1);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Feldon of the Third Path", 1);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
|
||||
|
||||
addCard(Zone.GRAVEYARD, playerB, "Silvercoat Lion", 1);
|
||||
|
||||
activateAbility(2, PhaseStep.PRECOMBAT_MAIN, playerA,
|
||||
"{2}{R},{T}: Put a token onto the battlefield that's a copy of target creature card in your graveyard, except it's an artifact in addition to its other types. It gains haste. Sacrifice it at the beginning of the next end step.",
|
||||
"Sepulchral Primordial");
|
||||
addTarget(playerA, "Silvercoat Lion"); // target for ETB Sepulchral Primordial
|
||||
setStopAt(2, PhaseStep.POSTCOMBAT_MAIN);
|
||||
execute();
|
||||
|
||||
assertPermanentCount(playerA, "Feldon of the Third Path", 1);
|
||||
assertPermanentCount(playerA, "Sepulchral Primordial", 1);
|
||||
assertPermanentCount(playerA, "Silvercoat Lion", 1);
|
||||
|
||||
assertLife(playerA, 20);
|
||||
assertLife(playerB, 20);
|
||||
|
||||
}
|
||||
}
|
|
@ -277,7 +277,7 @@ public abstract class AbilityImpl implements Ability {
|
|||
// and/or zones become the target of a spell trigger at this point; they'll wait to be put on
|
||||
// the stack until the spell has finished being cast.)
|
||||
|
||||
if (sourceObject != null) {
|
||||
if (sourceObject != null && !this.getAbilityType().equals(AbilityType.TRIGGERED)) { // triggered abilities check this already TriggeredAbilities.checkTriggers()
|
||||
sourceObject.adjustTargets(this, game);
|
||||
}
|
||||
if (getTargets().size() > 0 && getTargets().chooseTargets(getEffects().get(0).getOutcome(), this.controllerId, this, game) == false) {
|
||||
|
|
|
@ -44,7 +44,6 @@ import mage.game.events.GameEvent;
|
|||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -86,7 +85,7 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili
|
|||
ability.setControllerId(((Permanent) object).getControllerId());
|
||||
}
|
||||
ability.setSourceObject(object);
|
||||
if (ability.checkTrigger(event, game)) {
|
||||
if (ability.checkTrigger(event, game)) {
|
||||
UUID controllerId = ability.getControllerId();
|
||||
ability.trigger(game, controllerId);
|
||||
}
|
||||
|
|
|
@ -134,4 +134,24 @@ public class PermanentToken extends PermanentImpl {
|
|||
abilities.add(copyAbility);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void adjustTargets(Ability ability, Game game) {
|
||||
if (getToken().getCopySourceCard() != null) {
|
||||
getToken().getCopySourceCard().adjustTargets(ability, game);
|
||||
} else {
|
||||
super.adjustTargets(ability, game);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void adjustCosts(Ability ability, Game game) {
|
||||
if (getToken().getCopySourceCard() != null) {
|
||||
getToken().getCopySourceCard().adjustCosts(ability, game);
|
||||
} else {
|
||||
super.adjustCosts(ability, game);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -31,13 +31,13 @@ package mage.game.permanent.token;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Zone;
|
||||
import mage.MageObjectImpl;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Abilities;
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
|
@ -55,6 +55,7 @@ public class Token extends MageObjectImpl {
|
|||
private int tokenType;
|
||||
private int originalCardNumber;
|
||||
private String originalExpansionSetCode;
|
||||
private Card copySourceCard; // the card the Token is a copy from
|
||||
|
||||
public enum Type {
|
||||
FIRST(1),
|
||||
|
@ -96,6 +97,7 @@ public class Token extends MageObjectImpl {
|
|||
this.lastAddedTokenIds.addAll(token.lastAddedTokenIds);
|
||||
this.originalCardNumber = token.originalCardNumber;
|
||||
this.originalExpansionSetCode = token.originalExpansionSetCode;
|
||||
this.copySourceCard = token.copySourceCard; // will never be changed
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
|
@ -192,5 +194,16 @@ public class Token extends MageObjectImpl {
|
|||
public void setOriginalExpansionSetCode(String originalExpansionSetCode) {
|
||||
this.originalExpansionSetCode = originalExpansionSetCode;
|
||||
}
|
||||
|
||||
public Card getCopySourceCard() {
|
||||
return copySourceCard;
|
||||
}
|
||||
|
||||
public void setCopySourceCard(Card copySourceCard) {
|
||||
if (copySourceCard != null) {
|
||||
this.copySourceCard = copySourceCard.copy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1113,7 +1113,11 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
//20091005 - 603.3c, 603.3d
|
||||
int bookmark = game.bookmarkState();
|
||||
TriggeredAbility ability = source.copy();
|
||||
if (ability != null && ability.canChooseTarget(game)) {
|
||||
MageObject sourceObject = game.getObject(ability.getSourceId());
|
||||
if (sourceObject != null) {
|
||||
sourceObject.adjustTargets(ability, game);
|
||||
}
|
||||
if (ability.canChooseTarget(game)) {
|
||||
if (ability.isUsesStack()) {
|
||||
game.getStack().push(new StackAbility(ability, playerId));
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ public class CardUtil {
|
|||
for (AlternativeCost alternativeCost : ability.getAlternativeCosts()) {
|
||||
if (alternativeCost instanceof AlternativeCostImpl) {
|
||||
AlternativeCostImpl impl = (AlternativeCostImpl) alternativeCost;
|
||||
ManaCosts<ManaCost> adjustedCost = new ManaCostsImpl<ManaCost>();
|
||||
ManaCosts<ManaCost> adjustedCost = new ManaCostsImpl<>();
|
||||
boolean updated = false;
|
||||
Iterator it = impl.iterator();
|
||||
while (it.hasNext()) {
|
||||
|
|
|
@ -62,13 +62,18 @@ public class CopyTokenFunction implements Function<Token, Card> {
|
|||
// to show the source image, the original values have to be used
|
||||
target.setOriginalExpansionSetCode(((Token)sourceObj).getOriginalExpansionSetCode());
|
||||
target.setOriginalCardNumber(((Token)sourceObj).getOriginalCardNumber());
|
||||
target.setCopySourceCard(((PermanentToken)source).getToken().getCopySourceCard());
|
||||
} else if (source instanceof PermanentCard) {
|
||||
sourceObj = ((PermanentCard) source).getCard();
|
||||
target.setOriginalExpansionSetCode(source.getExpansionSetCode());
|
||||
target.setOriginalCardNumber(source.getCardNumber());
|
||||
target.setCopySourceCard((Card)sourceObj);
|
||||
} else {
|
||||
target.setOriginalExpansionSetCode(source.getExpansionSetCode());
|
||||
target.setOriginalCardNumber(source.getCardNumber());
|
||||
if (source instanceof Card) {
|
||||
target.setCopySourceCard((Card)source);
|
||||
}
|
||||
}
|
||||
|
||||
target.setName(sourceObj.getName());
|
||||
|
|
Loading…
Reference in a new issue