mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Implemented Crystalline Resonance
This commit is contained in:
parent
357d1873db
commit
2d11f69d0e
6 changed files with 186 additions and 88 deletions
|
|
@ -14,16 +14,24 @@ import mage.game.stack.StackObject;
|
|||
*/
|
||||
public class CycleControllerTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
private final boolean excludeSource;
|
||||
|
||||
public CycleControllerTriggeredAbility(Effect effect) {
|
||||
this(effect, false);
|
||||
}
|
||||
|
||||
public CycleControllerTriggeredAbility(Effect effect, boolean optional) {
|
||||
this(effect, optional, false);
|
||||
}
|
||||
|
||||
public CycleControllerTriggeredAbility(Effect effect, boolean optional, boolean excludeSource) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
this.excludeSource = excludeSource;
|
||||
}
|
||||
|
||||
private CycleControllerTriggeredAbility(final CycleControllerTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.excludeSource = ability.excludeSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -35,7 +43,7 @@ public class CycleControllerTriggeredAbility extends TriggeredAbilityImpl {
|
|||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (game.getState().getStack().isEmpty()
|
||||
|| !event.getPlayerId().equals(this.getControllerId())
|
||||
|| event.getSourceId().equals(this.getSourceId())) {
|
||||
|| (event.getSourceId().equals(this.getSourceId()) && excludeSource)) {
|
||||
return false;
|
||||
}
|
||||
StackObject item = game.getState().getStack().getFirst();
|
||||
|
|
@ -45,7 +53,7 @@ public class CycleControllerTriggeredAbility extends TriggeredAbilityImpl {
|
|||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever you cycle another card, " + super.getRule();
|
||||
return "Whenever you cycle " + (excludeSource ? "another" : "a") + " card, " + super.getRule();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ import mage.abilities.SpellAbility;
|
|||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.keyword.EnchantAbility;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
|
@ -26,13 +26,14 @@ import java.util.UUID;
|
|||
*/
|
||||
public class CopyPermanentEffect extends OneShotEffect {
|
||||
|
||||
private FilterPermanent filter;
|
||||
private ApplyToPermanent applier;
|
||||
private final FilterPermanent filter;
|
||||
private final ApplyToPermanent applier;
|
||||
private final boolean useTargetOfAbility;
|
||||
private Permanent bluePrintPermanent;
|
||||
private boolean useTargetOfAbility;
|
||||
private Duration duration = Duration.Custom;
|
||||
|
||||
public CopyPermanentEffect() {
|
||||
this(new FilterCreaturePermanent());
|
||||
this(StaticFilters.FILTER_PERMANENT_CREATURE);
|
||||
}
|
||||
|
||||
public CopyPermanentEffect(ApplyToPermanent applier) {
|
||||
|
|
@ -72,88 +73,95 @@ public class CopyPermanentEffect extends OneShotEffect {
|
|||
if (sourcePermanent == null) {
|
||||
sourcePermanent = game.getObject(source.getSourceId());
|
||||
}
|
||||
if (controller != null && sourcePermanent != null) {
|
||||
Permanent copyFromPermanent = null;
|
||||
if (useTargetOfAbility) {
|
||||
copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
} else {
|
||||
Target target = new TargetPermanent(filter);
|
||||
target.setNotTarget(true);
|
||||
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
|
||||
controller.choose(Outcome.Copy, target, source.getSourceId(), game);
|
||||
copyFromPermanent = game.getPermanent(target.getFirstTarget());
|
||||
}
|
||||
}
|
||||
if (copyFromPermanent != null) {
|
||||
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 again for new target
|
||||
if (bluePrintPermanent.hasSubtype(SubType.AURA, game)) {
|
||||
//copied from mage.cards.c.CopyEnchantment.java
|
||||
|
||||
// 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;
|
||||
Target auraTarget = null;
|
||||
|
||||
// attach - search effect in spell ability (example: cast Utopia Sprawl, cast Estrid's Invocation on it)
|
||||
for (Ability ability : bluePrintPermanent.getAbilities()) {
|
||||
if (ability instanceof SpellAbility) {
|
||||
auraOutcome = ability.getEffects().getOutcome(ability);
|
||||
for (Effect effect : ability.getEffects()) {
|
||||
if (effect instanceof AttachEffect) {
|
||||
if (bluePrintPermanent.getSpellAbility().getTargets().size() > 0) {
|
||||
auraTarget = bluePrintPermanent.getSpellAbility().getTargets().get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 (auraTarget == null) {
|
||||
for (Ability ability : bluePrintPermanent.getAbilities()) {
|
||||
if (ability instanceof EnchantAbility) {
|
||||
auraOutcome = ability.getEffects().getOutcome(ability);
|
||||
if (ability.getTargets().size() > 0) { // Animate Dead don't have targets
|
||||
auraTarget = ability.getTargets().get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (controller == null || sourcePermanent == null) {
|
||||
return false;
|
||||
}
|
||||
Permanent copyFromPermanent = null;
|
||||
if (useTargetOfAbility) {
|
||||
copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
} else {
|
||||
Target target = new TargetPermanent(filter);
|
||||
target.setNotTarget(true);
|
||||
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
|
||||
controller.choose(Outcome.Copy, target, source.getSourceId(), game);
|
||||
copyFromPermanent = game.getPermanent(target.getFirstTarget());
|
||||
}
|
||||
}
|
||||
if (copyFromPermanent == null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
bluePrintPermanent = game.copyPermanent(duration, copyFromPermanent, sourcePermanent.getId(), source, applier);
|
||||
if (bluePrintPermanent == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if object is a copy of an aura, it needs to attach again for new target
|
||||
if (!bluePrintPermanent.hasSubtype(SubType.AURA, game)) {
|
||||
return true;
|
||||
}
|
||||
//copied from mage.cards.c.CopyEnchantment.java
|
||||
|
||||
// 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;
|
||||
Target auraTarget = null;
|
||||
|
||||
// attach - search effect in spell ability (example: cast Utopia Sprawl, cast Estrid's Invocation on it)
|
||||
for (Ability ability : bluePrintPermanent.getAbilities()) {
|
||||
if (!(ability instanceof SpellAbility)) {
|
||||
continue;
|
||||
}
|
||||
auraOutcome = ability.getEffects().getOutcome(ability);
|
||||
for (Effect effect : ability.getEffects()) {
|
||||
if (!(effect instanceof AttachEffect)) {
|
||||
continue;
|
||||
}
|
||||
if (bluePrintPermanent.getSpellAbility().getTargets().size() > 0) {
|
||||
auraTarget = bluePrintPermanent.getSpellAbility().getTargets().get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 (auraTarget == null) {
|
||||
for (Ability ability : bluePrintPermanent.getAbilities()) {
|
||||
if (!(ability instanceof EnchantAbility)) {
|
||||
continue;
|
||||
}
|
||||
auraOutcome = ability.getEffects().getOutcome(ability);
|
||||
if (ability.getTargets().size() > 0) { // Animate Dead don't have targets
|
||||
auraTarget = ability.getTargets().get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* if this is a copy of a copy, the copy's target has been
|
||||
* copied and needs to be cleared
|
||||
*/
|
||||
if (auraTarget == null) {
|
||||
return true;
|
||||
}
|
||||
// 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)) {
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Permanent getBluePrintPermanent() {
|
||||
|
|
@ -164,4 +172,9 @@ public class CopyPermanentEffect extends OneShotEffect {
|
|||
public CopyPermanentEffect copy() {
|
||||
return new CopyPermanentEffect(this);
|
||||
}
|
||||
|
||||
public CopyPermanentEffect setDuration(Duration duration) {
|
||||
this.duration = duration;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue