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,34 +87,61 @@ 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) {
if (bluePrintPermanent.getSpellAbility().getTargets().size() > 0) {
auraTarget = bluePrintPermanent.getSpellAbility().getTargets().get(0);
auraOutcome = effect.getOutcome(); 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); // 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)
if (controller.choose(auraOutcome, target, source.getSourceId(), game)) { if (auraTarget == null) {
UUID targetId = target.getFirstTarget(); for (Ability ability : bluePrintPermanent.getAbilities()) {
if (ability instanceof EnchantAbility) {
if (ability.getTargets().size() > 0) { // Animate Dead don't have targets
auraTarget = ability.getTargets().get(0);
for (Effect effect : ability.getEffects()) {
// first outcome
auraOutcome = effect.getOutcome();
}
}
}
}
}
/* if this is a copy of a copy, the copy's target has been
* copied and needs to be cleared
*/
if (auraTarget != null) {
// clear selected target
if (auraTarget.getFirstTarget() != null) {
auraTarget.remove(auraTarget.getFirstTarget());
}
// select new target
auraTarget.setNotTarget(true);
if (controller.choose(auraOutcome, auraTarget, source.getSourceId(), game)) {
UUID targetId = auraTarget.getFirstTarget();
Permanent targetPermanent = game.getPermanent(targetId); Permanent targetPermanent = game.getPermanent(targetId);
Player targetPlayer = game.getPlayer(targetId); Player targetPlayer = game.getPlayer(targetId);
if (targetPermanent != null) { if (targetPermanent != null) {
@ -124,6 +154,7 @@ public class CopyPermanentEffect extends OneShotEffect {
} }
} }
} }
}
return true; return true;
} }
return false; return false;