* Fixes to put token onto the battlefield that's a copy of creature on the battlefield effects that copy creatures that already copy other creatures.

This commit is contained in:
LevelX2 2014-10-21 16:01:00 +02:00
parent f84bab3c5b
commit 7dd873b1e6
13 changed files with 329 additions and 141 deletions

View file

@ -42,6 +42,7 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentCard;
import mage.game.permanent.PermanentToken;
import mage.util.functions.ApplyToPermanent;
/**
*
@ -55,7 +56,8 @@ public class CopyEffect extends ContinuousEffectImpl {
private MageObject target;
private UUID sourceId;
private int zoneChangeCounter;
private ApplyToPermanent applier;
public CopyEffect(MageObject target, UUID sourceId) {
this(Duration.Custom, target, sourceId);
}
@ -71,6 +73,7 @@ public class CopyEffect extends ContinuousEffectImpl {
this.target = effect.target.copy();
this.sourceId = effect.sourceId;
this.zoneChangeCounter = effect.zoneChangeCounter;
this.applier = effect.applier;
}
@Override
@ -155,4 +158,14 @@ public class CopyEffect extends ContinuousEffectImpl {
public UUID getSourceId() {
return sourceId;
}
public ApplyToPermanent getApplier() {
return applier;
}
public void setApplier(ApplyToPermanent applier) {
this.applier = applier;
}
}

View file

@ -30,6 +30,7 @@ package mage.abilities.effects.common;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.abilities.Ability;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
@ -41,6 +42,7 @@ import mage.game.permanent.token.Token;
import mage.players.Player;
import mage.target.Target;
import mage.target.TargetPermanent;
import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
@ -91,13 +93,11 @@ public class PopulateEffect extends OneShotEffect {
if (target.canChoose(source.getControllerId(), game)) {
player.choose(Outcome.Copy, target, source.getSourceId(), game);
Permanent tokenToCopy = game.getPermanent(target.getFirstTarget());
if (tokenToCopy != null && tokenToCopy instanceof PermanentToken) {
Token newToken = new Token("","");
CardUtil.copyTo(newToken).from(tokenToCopy);
if (newToken != null ) {
game.informPlayers("Token selected for populate: " + newToken.getName());
return newToken.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId());
}
if (tokenToCopy != null) {
game.informPlayers("Token selected for populate: " + tokenToCopy.getLogName());
Effect effect = new PutTokenOntoBattlefieldCopyTargetEffect();
effect.setTargetPointer(new FixedTarget(target.getFirstTarget()));
return effect.apply(game, source);
}
}
}

View file

@ -44,20 +44,20 @@ import mage.util.CardUtil;
* @author LevelX2
*/
public class PutCopySourceTokenOntoBattlefield extends OneShotEffect {
public class PutTokenOntoBattlefieldCopySource extends OneShotEffect {
public PutCopySourceTokenOntoBattlefield() {
public PutTokenOntoBattlefieldCopySource() {
super(Outcome.PutCreatureInPlay);
this.staticText = "put a token that's a copy of {this} onto the battlefield";
}
public PutCopySourceTokenOntoBattlefield(final PutCopySourceTokenOntoBattlefield effect) {
public PutTokenOntoBattlefieldCopySource(final PutTokenOntoBattlefieldCopySource effect) {
super(effect);
}
@Override
public PutCopySourceTokenOntoBattlefield copy() {
return new PutCopySourceTokenOntoBattlefield(this);
public PutTokenOntoBattlefieldCopySource copy() {
return new PutTokenOntoBattlefieldCopySource(this);
}
@Override

View file

@ -0,0 +1,147 @@
/*
* 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.abilities.effects.common;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.HasteAbility;
import mage.constants.CardType;
import mage.constants.Outcome;
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.EmptyApplyToPermanent;
/**
*
* @author LevelX2
*/
public class PutTokenOntoBattlefieldCopyTargetEffect extends OneShotEffect {
private final UUID playerId;
private final CardType additionalCardType;
private boolean gainsHaste;
private Permanent addedTokenPermanent;
public PutTokenOntoBattlefieldCopyTargetEffect() {
super(Outcome.PutCreatureInPlay);
this.playerId = null;
this.additionalCardType = null;
this.addedTokenPermanent = null;
}
public PutTokenOntoBattlefieldCopyTargetEffect(UUID playerId) {
this(playerId, null, false);
}
public PutTokenOntoBattlefieldCopyTargetEffect(UUID playerId, CardType additionalCardType, boolean gainsHaste) {
super(Outcome.PutCreatureInPlay);
this.playerId = playerId;
this.additionalCardType = additionalCardType;
this.gainsHaste = gainsHaste;
this.addedTokenPermanent = null;
}
public PutTokenOntoBattlefieldCopyTargetEffect(final PutTokenOntoBattlefieldCopyTargetEffect effect) {
super(effect);
this.playerId = effect.playerId;
this.additionalCardType = effect.additionalCardType;
this.gainsHaste = effect.gainsHaste;
this.addedTokenPermanent = effect.addedTokenPermanent;
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
if (permanent != null) {
// handle copies of copies
Permanent copyFromPermanent = permanent;
ApplyToPermanent applier = new EmptyApplyToPermanent();
for (Effect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) {
if (effect instanceof CopyEffect) {
CopyEffect copyEffect = (CopyEffect) effect;
// there is another copy effect that our targetPermanent copies stats from
if (copyEffect.getSourceId().equals(permanent.getId())) {
MageObject object = ((CopyEffect) effect).getTarget();
if (object instanceof Permanent) {
copyFromPermanent = (Permanent)object;
if (copyEffect.getApplier() != null) {
applier = copyEffect.getApplier();
}
}
}
}
}
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(copyFromPermanent); // needed so that entersBattlefied triggered abilities see the attributes (e.g. Master Biomancer)
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);
addedTokenPermanent = game.getPermanent(token.getLastAddedToken());
if (addedTokenPermanent != null) {
game.copyPermanent(copyFromPermanent, addedTokenPermanent, source, applier);
return true;
}
}
return false;
}
@Override
public PutTokenOntoBattlefieldCopyTargetEffect copy() {
return new PutTokenOntoBattlefieldCopyTargetEffect(this);
}
@Override
public String getText(Mode mode) {
StringBuilder sb = new StringBuilder();
sb.append("Put a token onto the battlefield that's a copy of ");
if (mode.getTargets() != null) {
sb.append(mode.getTargets().get(0).getTargetName());
}
return sb.toString();
}
public Permanent getAddedPermanent() {
return addedTokenPermanent;
}
}

View file

@ -1248,8 +1248,9 @@ public abstract class GameImpl implements Game, Serializable {
CopyEffect newEffect = new CopyEffect(duration, permanent, copyToPermanent.getId());
newEffect.newId();
newEffect.setTimestamp();
newEffect.setApplier(applier);
newEffect.init(newAbility, this);
// handle copies of copies
for (Effect effect : getState().getContinuousEffects().getLayeredEffects(this)) {
if (effect instanceof CopyEffect) {