Merge pull request #5261 from magefree/FixEstridsInvocation5234

Copy effects
This commit is contained in:
Oleg Agafonov 2018-08-25 04:35:11 +04:00 committed by GitHub
commit e22d9c3072
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 10 deletions

View file

@ -14,7 +14,7 @@ import mage.constants.CardType;
import mage.constants.SubType; import mage.constants.SubType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterEnchantmentPermanent; import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
@ -31,7 +31,8 @@ public final class CopyEnchantment extends CardImpl {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{U}"); super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{U}");
// You may have Copy Enchantment enter the battlefield as a copy of any enchantment on the battlefield. // You may have Copy Enchantment enter the battlefield as a copy of any enchantment on the battlefield.
this.addAbility(new EntersBattlefieldAbility(new CopyEnchantmentEffect(new FilterEnchantmentPermanent("any enchantment")), true)); //this.addAbility(new EntersBattlefieldAbility(new CopyEnchantmentEffect(new FilterEnchantmentPermanent("any enchantment")), true));
this.addAbility(new EntersBattlefieldAbility(new CopyPermanentEffect(StaticFilters.FILTER_ENCHANTMENT_PERMANENT), true));
} }
public CopyEnchantment(final CopyEnchantment card) { public CopyEnchantment(final CopyEnchantment card) {

View file

@ -1,10 +1,14 @@
package mage.abilities.effects.common; package mage.abilities.effects.common;
import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubType;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.StaticFilters; import mage.filter.StaticFilters;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
@ -61,25 +65,64 @@ public class CopyPermanentEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getPermanentEntering(source.getSourceId()); MageObject sourcePermanent = game.getPermanentEntering(source.getSourceId());
if (sourceObject == null) { if (sourcePermanent == null) {
sourceObject = game.getObject(source.getSourceId()); sourcePermanent = game.getObject(source.getSourceId());
} }
if (player != null && sourceObject != null) { if (controller != null && sourcePermanent != null) {
Permanent copyFromPermanent = null; Permanent copyFromPermanent = null;
if (useTargetOfAbility) { if (useTargetOfAbility) {
copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source)); copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
} else { } else {
Target target = new TargetPermanent(filter); Target target = new TargetPermanent(filter);
target.setNotTarget(true); target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) { if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
player.choose(Outcome.Copy, target, source.getSourceId(), game); controller.choose(Outcome.Copy, target, source.getSourceId(), game);
copyFromPermanent = game.getPermanent(target.getFirstTarget()); copyFromPermanent = game.getPermanent(target.getFirstTarget());
} }
} }
if (copyFromPermanent != null) { if (copyFromPermanent != null) {
bluePrintPermanent = game.copyPermanent(copyFromPermanent, sourceObject.getId(), source, applier); bluePrintPermanent = game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, applier);
//if object is a copy of an aura, it needs to attach
if (bluePrintPermanent.hasSubtype(SubType.AURA, game)){
//copied from mage.cards.c.CopyEnchantment.java
Target target = bluePrintPermanent.getSpellAbility().getTargets().get(0);
Outcome auraOutcome = Outcome.BoostCreature;
for (Ability ability : bluePrintPermanent.getAbilities()) {
if (ability instanceof SpellAbility) {
for (Effect effect : ability.getEffects()) {
if (effect instanceof AttachEffect) {
auraOutcome = effect.getOutcome();
}
}
}
}
/*if this is a copy of a copy, the copy's target has been
*copied and needs to be cleared
*/
{
UUID targetId = target.getFirstTarget();
if(targetId != null)
target.remove(targetId);
}
target.setNotTarget(true);
if (controller.choose(auraOutcome, target, source.getSourceId(), game)) {
UUID targetId = target.getFirstTarget();
Permanent targetPermanent = game.getPermanent(targetId);
Player targetPlayer = game.getPlayer(targetId);
if (targetPermanent != null) {
targetPermanent.addAttachment(sourcePermanent.getId(), game);
} else if (targetPlayer != null) {
targetPlayer.addAttachment(sourcePermanent.getId(), game);
} else {
return false;
}
}
}
} }
return true; return true;
} }