Merge origin/master

This commit is contained in:
Jeff 2018-11-14 17:19:21 -06:00
commit 23a0d97807

View file

@ -1,12 +1,12 @@
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.SpellAbility;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.EnchantAbility;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubType; import mage.constants.SubType;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
@ -20,8 +20,9 @@ import mage.target.TargetPermanent;
import mage.util.functions.ApplyToPermanent; import mage.util.functions.ApplyToPermanent;
import mage.util.functions.EmptyApplyToPermanent; import mage.util.functions.EmptyApplyToPermanent;
import java.util.UUID;
/** /**
*
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class CopyPermanentEffect extends OneShotEffect { public class CopyPermanentEffect extends OneShotEffect {
@ -59,7 +60,9 @@ public class CopyPermanentEffect extends OneShotEffect {
super(effect); super(effect);
this.filter = effect.filter.copy(); this.filter = effect.filter.copy();
this.applier = effect.applier; this.applier = effect.applier;
this.bluePrintPermanent = effect.bluePrintPermanent; if (effect.bluePrintPermanent != null) {
this.bluePrintPermanent = effect.bluePrintPermanent.copy();
}
this.useTargetOfAbility = effect.useTargetOfAbility; this.useTargetOfAbility = effect.useTargetOfAbility;
} }
@ -84,42 +87,70 @@ public class CopyPermanentEffect extends OneShotEffect {
} }
if (copyFromPermanent != null) { if (copyFromPermanent != null) {
bluePrintPermanent = game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, applier); bluePrintPermanent = game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, applier);
if (bluePrintPermanent == null) {
return false;
}
//if object is a copy of an aura, it needs to attach // if object is a copy of an aura, it needs to attach again for new target
if (bluePrintPermanent.hasSubtype(SubType.AURA, game)){ if (bluePrintPermanent.hasSubtype(SubType.AURA, game)) {
//copied from mage.cards.c.CopyEnchantment.java //copied from mage.cards.c.CopyEnchantment.java
Target target = bluePrintPermanent.getSpellAbility().getTargets().get(0);
// permanent can be attached (Estrid's Mask) or enchant (Utopia Sprawl)
// TODO: fix Animate Dead -- it's can't be copied (can't retarget)
Outcome auraOutcome = Outcome.BoostCreature; Outcome auraOutcome = Outcome.BoostCreature;
Target auraTarget = null;
// attach - search effect in spell ability (example: cast Utopia Sprawl, cast Estrid's Invocation on it)
for (Ability ability : bluePrintPermanent.getAbilities()) { for (Ability ability : bluePrintPermanent.getAbilities()) {
if (ability instanceof SpellAbility) { if (ability instanceof SpellAbility) {
for (Effect effect : ability.getEffects()) { for (Effect effect : ability.getEffects()) {
if (effect instanceof AttachEffect) { if (effect instanceof AttachEffect) {
auraOutcome = effect.getOutcome(); if (bluePrintPermanent.getSpellAbility().getTargets().size() > 0) {
auraTarget = bluePrintPermanent.getSpellAbility().getTargets().get(0);
auraOutcome = effect.getOutcome();
}
} }
} }
} }
} }
/*if this is a copy of a copy, the copy's target has been // enchant - search in all abilities (example: cast Estrid's Invocation on enchanted creature by Estrid, the Masked second ability, cast Estrid's Invocation on it)
*copied and needs to be cleared if (auraTarget == null) {
*/ for (Ability ability : bluePrintPermanent.getAbilities()) {
{ if (ability instanceof EnchantAbility) {
UUID targetId = target.getFirstTarget(); if (ability.getTargets().size() > 0) { // Animate Dead don't have targets
if(targetId != null) auraTarget = ability.getTargets().get(0);
target.remove(targetId); for (Effect effect : ability.getEffects()) {
// first outcome
auraOutcome = effect.getOutcome();
}
}
}
}
} }
target.setNotTarget(true); /* if this is a copy of a copy, the copy's target has been
if (controller.choose(auraOutcome, target, source.getSourceId(), game)) { * copied and needs to be cleared
UUID targetId = target.getFirstTarget(); */
Permanent targetPermanent = game.getPermanent(targetId); if (auraTarget != null) {
Player targetPlayer = game.getPlayer(targetId); // clear selected target
if (targetPermanent != null) { if (auraTarget.getFirstTarget() != null) {
targetPermanent.addAttachment(sourcePermanent.getId(), game); auraTarget.remove(auraTarget.getFirstTarget());
} else if (targetPlayer != null) { }
targetPlayer.addAttachment(sourcePermanent.getId(), game);
} else { // select new target
return false; auraTarget.setNotTarget(true);
if (controller.choose(auraOutcome, auraTarget, source.getSourceId(), game)) {
UUID targetId = auraTarget.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;
}
} }
} }
} }