mirror of
https://github.com/magefree/mage.git
synced 2026-01-09 20:32:06 -08:00
Fix Sanctuary Blade ability causing a trigger (#11682)
* Fix Sanctuary Blade ability causing a trigger * Remove unnecessary logic and correct test * Re-add strict choose mode --------- Co-authored-by: Matthew Wilson <matthew_w@vaadin.com>
This commit is contained in:
parent
dfa6019c3e
commit
784a5fb1e4
4 changed files with 197 additions and 3 deletions
|
|
@ -0,0 +1,52 @@
|
|||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.StaticAbility;
|
||||
import mage.abilities.effects.BecomesAttachedToCreatureSourceEffect;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.Zone;
|
||||
|
||||
/**
|
||||
* Based on {@link mage.abilities.common.AsEntersBattlefieldAbility}.
|
||||
* This allows rule wording such as "as {this} becomes attached to a creature..."
|
||||
* For this, there should not be a trigger, as in the case of the wording "when..."
|
||||
* As per rule 603.6d, this should be a static ability.
|
||||
* See [[Sanctuary Blade]].
|
||||
*
|
||||
* @author DominionSpy
|
||||
*/
|
||||
public class AsBecomesAttachedToCreatureSourceAbility extends StaticAbility {
|
||||
|
||||
public AsBecomesAttachedToCreatureSourceAbility(Effect effect) {
|
||||
this(effect, null);
|
||||
}
|
||||
|
||||
public AsBecomesAttachedToCreatureSourceAbility(Effect effect, String text) {
|
||||
super(Zone.BATTLEFIELD, new BecomesAttachedToCreatureSourceEffect(effect, null, text));
|
||||
}
|
||||
|
||||
protected AsBecomesAttachedToCreatureSourceAbility(final AsBecomesAttachedToCreatureSourceAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsBecomesAttachedToCreatureSourceAbility copy() {
|
||||
return new AsBecomesAttachedToCreatureSourceAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEffect(Effect effect) {
|
||||
if (!getEffects().isEmpty()) {
|
||||
Effect attachEffect = this.getEffects().get(0);
|
||||
if (attachEffect instanceof BecomesAttachedToCreatureSourceEffect) {
|
||||
((BecomesAttachedToCreatureSourceEffect) attachEffect).addEffect(effect);
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.addEffect(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "As {this} becomes attached to a creature, " + super.getRule();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
package mage.abilities.effects;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.constants.Duration;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
||||
/**
|
||||
* Based on {@link EntersBattlefieldEffect}.
|
||||
* This allows rule wording such as "as {this} becomes attached to a creature..."
|
||||
* For this, there should not be a trigger, as in the case of the wording "when..."
|
||||
* As per rule 614.1c, this should be a replacement effect.
|
||||
* See [[Sanctuary Blade]].
|
||||
*
|
||||
* @author DominionSpy
|
||||
*/
|
||||
public class BecomesAttachedToCreatureSourceEffect extends ReplacementEffectImpl {
|
||||
|
||||
protected Effects baseEffects = new Effects();
|
||||
protected String text;
|
||||
protected Condition condition;
|
||||
|
||||
public BecomesAttachedToCreatureSourceEffect(Effect baseEffect) {
|
||||
this(baseEffect, "");
|
||||
}
|
||||
|
||||
public BecomesAttachedToCreatureSourceEffect(Effect baseEffect, String text) {
|
||||
this(baseEffect, null, text);
|
||||
}
|
||||
|
||||
public BecomesAttachedToCreatureSourceEffect(Effect baseEffect, Condition condition, String text) {
|
||||
super(Duration.WhileOnBattlefield, baseEffect.getOutcome(), false);
|
||||
this.baseEffects.add(baseEffect);
|
||||
this.text = text;
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
protected BecomesAttachedToCreatureSourceEffect(final BecomesAttachedToCreatureSourceEffect effect) {
|
||||
super(effect);
|
||||
this.baseEffects = effect.baseEffects.copy();
|
||||
this.text = effect.text;
|
||||
this.condition = effect.condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BecomesAttachedToCreatureSourceEffect copy() {
|
||||
return new BecomesAttachedToCreatureSourceEffect(this);
|
||||
}
|
||||
|
||||
public void addEffect(Effect effect) {
|
||||
baseEffects.add(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checksEventType(GameEvent event, Game game) {
|
||||
return GameEvent.EventType.ATTACH == event.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (event.getSourceId().equals(source.getSourceId())) {
|
||||
return condition == null || condition.apply(game, source);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
for (Effect effect : baseEffects) {
|
||||
if (effect instanceof ContinuousEffect) {
|
||||
game.addEffect((ContinuousEffect) effect, source);
|
||||
} else {
|
||||
effect.setValue("appliedEffects", event.getAppliedEffects());
|
||||
effect.apply(game, source);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
return (text == null || text.isEmpty()) ? baseEffects.getText(mode) : text;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue