Fixed handling and initialization of Fixedtarget object. Fixing a problem of ReturnToBattlefieldUnderYourControlTargetEffect that caused objects to return taht already left the zone they should be moved from.

This commit is contained in:
LevelX2 2015-06-29 18:34:53 +02:00
parent 148fd0e6ae
commit f45c5cedeb
16 changed files with 398 additions and 209 deletions

View file

@ -58,12 +58,12 @@ public class SpitefulShadows extends CardImpl {
this.expansionSetCode = "DKA";
this.subtype.add("Aura");
// Enchant creature
TargetPermanent auraTarget = new TargetCreaturePermanent();
this.getSpellAbility().addTarget(auraTarget);
this.getSpellAbility().addEffect(new AttachEffect(Outcome.UnboostCreature));
this.addAbility(new EnchantAbility(auraTarget.getTargetName()));
// Whenever enchanted creature is dealt damage, it deals that much damage to its controller.
this.addAbility(new SpitefulShadowsTriggeredAbility());
}
@ -135,16 +135,16 @@ class SpitefulShadowsEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Integer damageAmount = (Integer) this.getValue("damageAmount");
UUID targetId = this.targetPointer.getFirst(game, source);
if (damageAmount != null && targetId != null) {
Permanent permanent = game.getPermanent(targetId);
if (damageAmount != null) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent == null) {
permanent = (Permanent) game.getLastKnownInformation(targetId, Zone.BATTLEFIELD);
FixedTarget fixedTarget = (FixedTarget) getTargetPointer();
permanent = (Permanent) game.getLastKnownInformation(fixedTarget.getTarget(), Zone.BATTLEFIELD, fixedTarget.getZoneChangeCounter());
}
if (permanent != null) {
Player player = game.getPlayer(permanent.getControllerId());
if (player != null) {
player.damage(damageAmount, targetId, game, false, true);
player.damage(damageAmount, permanent.getId(), game, false, true);
return true;
}
}

View file

@ -59,7 +59,7 @@ public class Necroskitter extends CardImpl {
this.power = new MageInt(1);
this.toughness = new MageInt(4);
// Wither
// Wither (This deals damage to creatures in the form of -1/-1 counters.)
this.addAbility(WitherAbility.getInstance());
// Whenever a creature an opponent controls with a -1/-1 counter on it dies, you may return that card to the battlefield under your control.

View file

@ -1,16 +1,16 @@
/*
* 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
@ -20,23 +20,22 @@
* 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.sets.magic2011;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.common.ReturnSourceFromGraveyardToBattlefieldEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
/**
*
@ -53,6 +52,7 @@ public class ReassemblingSkeleton extends CardImpl {
this.power = new MageInt(1);
this.toughness = new MageInt(1);
// {1}{B}: Return Reassembling Skeleton from your graveyard to the battlefield tapped.
this.addAbility(new SimpleActivatedAbility(Zone.GRAVEYARD, new ReturnSourceFromGraveyardToBattlefieldEffect(true), new ManaCostsImpl("{1}{B}")));
}

View file

@ -89,9 +89,6 @@ class ScytheOfTheWretchedTriggeredAbility extends TriggeredAbilityImpl {
public ScytheOfTheWretchedTriggeredAbility() {
super(Zone.ALL, new ScytheOfTheWretchedReanimateEffect(), false);
Effect effect = new AttachEffect(Outcome.AddAbility);
effect.setText("Attach {this} to that creature.");
addEffect(effect);
}
public ScytheOfTheWretchedTriggeredAbility(final ScytheOfTheWretchedTriggeredAbility ability) {
@ -115,7 +112,7 @@ class ScytheOfTheWretchedTriggeredAbility extends TriggeredAbilityImpl {
Permanent equippedCreature = getEquippedCreature(game);
for (MageObjectReference mor : zoneChange.getTarget().getDealtDamageByThisTurn()) {
Permanent permanent = (Permanent) game.getLastKnownInformation(mor.getSourceId(), Zone.BATTLEFIELD);
if((equippedCreature != null && mor.refersTo(equippedCreature, game))
if ((equippedCreature != null && mor.refersTo(equippedCreature, game))
|| (permanent != null && permanent.getAttachments().contains(getSourceId()))) {
setTarget(new FixedTarget(event.getTargetId()));
return true;
@ -149,7 +146,7 @@ class ScytheOfTheWretchedReanimateEffect extends OneShotEffect {
public ScytheOfTheWretchedReanimateEffect() {
super(Outcome.PutCreatureInPlay);
this.staticText = "return that card to the battlefield under your control";
this.staticText = "return that card to the battlefield under your control. Attach {this} to that creature";
}
public ScytheOfTheWretchedReanimateEffect(final ScytheOfTheWretchedReanimateEffect effect) {
@ -163,6 +160,9 @@ class ScytheOfTheWretchedReanimateEffect extends OneShotEffect {
if (card != null && controller != null) {
Zone currentZone = game.getState().getZone(card.getId());
controller.putOntoBattlefieldWithInfo(card, game, currentZone, source.getSourceId());
Effect effect = new AttachEffect(Outcome.AddAbility);
effect.setTargetPointer(new FixedTarget(card.getId()));
effect.apply(game, source);
return true;
}

View file

@ -37,7 +37,6 @@ import mage.abilities.LoyaltyAbility;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
import mage.abilities.effects.common.continuous.BoostTargetEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.Card;
@ -65,7 +64,6 @@ import mage.target.common.TargetOpponent;
import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
/**
*
*
@ -78,11 +76,10 @@ public class JaceArchitectOfThought extends CardImpl {
this.expansionSetCode = "RTR";
this.subtype.add("Jace");
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.LOYALTY.createInstance(4)), false));
// +1: Until your next turn, whenever a creature an opponent controls attacks, it gets -1/-0 until end of turn.
this.addAbility(new LoyaltyAbility(new CreateDelayedTriggeredAbilityEffect(new JaceArchitectOfThoughtDelayedTriggeredAbility()),1));
this.addAbility(new LoyaltyAbility(new JaceArchitectOfThoughtStartEffect1(), 1));
// -2: Reveal the top three cards of your library. An opponent separates those cards into two piles. Put one pile into your hand and the other on the bottom of your library in any order.
this.addAbility(new LoyaltyAbility(new JaceArchitectOfThoughtEffect2(), -2));
@ -102,16 +99,45 @@ public class JaceArchitectOfThought extends CardImpl {
}
}
class JaceArchitectOfThoughtStartEffect1 extends OneShotEffect {
public JaceArchitectOfThoughtStartEffect1() {
super(Outcome.UnboostCreature);
this.staticText = "Until your next turn, whenever a creature an opponent controls attacks, it gets -1/-0 until end of turn";
}
public JaceArchitectOfThoughtStartEffect1(final JaceArchitectOfThoughtStartEffect1 effect) {
super(effect);
}
@Override
public JaceArchitectOfThoughtStartEffect1 copy() {
return new JaceArchitectOfThoughtStartEffect1(this);
}
@Override
public boolean apply(Game game, Ability source) {
DelayedTriggeredAbility delayedAbility = new JaceArchitectOfThoughtDelayedTriggeredAbility(game.getTurnNum());
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
game.addDelayedTriggeredAbility(delayedAbility);
return true;
}
}
class JaceArchitectOfThoughtDelayedTriggeredAbility extends DelayedTriggeredAbility {
private int startingTurn;
public JaceArchitectOfThoughtDelayedTriggeredAbility() {
super(new BoostTargetEffect(-1,0, Duration.EndOfTurn), Duration.Custom, false);
public JaceArchitectOfThoughtDelayedTriggeredAbility(int startingTurn) {
super(new BoostTargetEffect(-1, 0, Duration.EndOfTurn), Duration.Custom, false);
this.startingTurn = startingTurn;
}
public JaceArchitectOfThoughtDelayedTriggeredAbility(JaceArchitectOfThoughtDelayedTriggeredAbility ability) {
public JaceArchitectOfThoughtDelayedTriggeredAbility(final JaceArchitectOfThoughtDelayedTriggeredAbility ability) {
super(ability);
this.startingTurn = ability.startingTurn;
}
@Override
@ -135,12 +161,6 @@ class JaceArchitectOfThoughtDelayedTriggeredAbility extends DelayedTriggeredAbil
return new JaceArchitectOfThoughtDelayedTriggeredAbility(this);
}
@Override
public void init(Game game) {
startingTurn = game.getTurnNum();
}
@Override
public boolean isInactive(Game game) {
return game.getActivePlayerId().equals(getControllerId()) && game.getTurnNum() != startingTurn;
@ -195,10 +215,10 @@ class JaceArchitectOfThoughtEffect2 extends OneShotEffect {
opponent = game.getPlayer(targetOpponent.getFirstTarget());
}
}
if (opponent == null) {
if (opponent == null) {
opponent = game.getPlayer(opponents.iterator().next());
}
TargetCard target = new TargetCard(0, cards.size(), Zone.PICK, new FilterCard("cards to put in the first pile"));
target.setRequired(false);
Cards pile1 = new CardsImpl();
@ -213,27 +233,27 @@ class JaceArchitectOfThoughtEffect2 extends OneShotEffect {
}
player.revealCards("Pile 1 (Jace, Architect of Thought)", pile1, game);
player.revealCards("Pile 2 (Jace, Architect of Thought)", cards, game);
postPileToLog("Pile 1", pile1.getCards(game), game);
postPileToLog("Pile 2", cards.getCards(game), game);
Cards cardsToHand = cards;
Cards cardsToLibrary = pile1;
List<Card> cardPile1 = new ArrayList<>();
List<Card> cardPile2 = new ArrayList<>();
for (UUID cardId: pile1) {
for (UUID cardId : pile1) {
cardPile1.add(game.getCard(cardId));
}
for (UUID cardId: cards) {
for (UUID cardId : cards) {
cardPile2.add(game.getCard(cardId));
}
boolean pileChoice = player.choosePile(Outcome.Neutral, "Choose a pile to to put into your hand.", cardPile1, cardPile2, game);
if (pileChoice){
if (pileChoice) {
cardsToHand = pile1;
cardsToLibrary = cards;
}
game.informPlayers(player.getLogName() +" chose pile" + (pileChoice?"1":"2"));
game.informPlayers(player.getLogName() + " chose pile" + (pileChoice ? "1" : "2"));
for (UUID cardUuid : cardsToHand) {
Card card = cardsToHand.get(cardUuid, game);
@ -260,11 +280,11 @@ class JaceArchitectOfThoughtEffect2 extends OneShotEffect {
}
return false;
}
private void postPileToLog(String pileName, Set<Card> cards, Game game) {
StringBuilder message = new StringBuilder(pileName).append(": ");
for (Card card : cards) {
message.append(card.getName()).append(" ");
message.append(card.getName()).append(" ");
}
if (cards.isEmpty()) {
message.append(" (empty)");
@ -320,15 +340,14 @@ class JaceArchitectOfThoughtEffect3 extends OneShotEffect {
FilterCard filter = new FilterCard("card to cast without mana costs");
TargetCardInExile target = new TargetCardInExile(filter, source.getSourceId());
while (jaceExileZone.count(filter, game) > 0 && controller.choose(Outcome.PlayForFree, jaceExileZone, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
if (controller.cast(card.getSpellAbility(), game, true))
{
game.getExile().removeCard(card, game);
}
if (controller.cast(card.getSpellAbility(), game, true)) {
game.getExile().removeCard(card, game);
}
target.clearChosen();
}
target.clearChosen();
}
return true;

View file

@ -73,7 +73,7 @@ public class MarchesaTheBlackRose extends CardImpl {
// Dethrone
this.addAbility(new DethroneAbility());
// Other creatures you control have dethrone.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD,
new GainAbilityControlledEffect(new DethroneAbility(), Duration.WhileOnBattlefield, new FilterCreaturePermanent(), true)));
@ -118,11 +118,11 @@ class MarchesaTheBlackRoseTriggeredAbility extends TriggeredAbilityImpl {
if (((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD
&& ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
if (permanent != null &&
permanent.getControllerId().equals(this.getControllerId())
if (permanent != null
&& permanent.getControllerId().equals(this.getControllerId())
&& permanent.getCardType().contains(CardType.CREATURE)
&& permanent.getCounters().getCount(CounterType.P1P1) > 0) {
for (Effect effect: this.getEffects()) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(permanent.getId()));
}
return true;
@ -155,7 +155,7 @@ class MarchesaTheBlackRoseEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(this.getTargetPointer().getFirst(game, source));
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (card != null) {
Effect effect = new ReturnToBattlefieldUnderYourControlTargetEffect();
effect.setText("return that card to the battlefield under your control at the beginning of the next end step");
@ -163,7 +163,7 @@ class MarchesaTheBlackRoseEffect extends OneShotEffect {
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
delayedAbility.getEffects().get(0).setTargetPointer(new FixedTarget(card.getId()));
delayedAbility.getEffects().get(0).setTargetPointer(getTargetPointer());
game.addDelayedTriggeredAbility(delayedAbility);
return true;
}