reworked auras which grant protection but don't remove themselves

This commit is contained in:
Evan Kranzler 2022-02-24 20:14:43 -05:00
parent 4024acdb28
commit eb4366013b
10 changed files with 125 additions and 231 deletions

View file

@ -5,6 +5,7 @@ import mage.abilities.Mode;
import mage.abilities.TriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.keyword.ProtectionAbility;
import mage.constants.*;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -19,6 +20,7 @@ public class GainAbilityAttachedEffect extends ContinuousEffectImpl {
protected AttachmentType attachmentType;
protected boolean independentEffect;
protected String targetObjectName;
protected boolean doesntRemoveItself = false;
public GainAbilityAttachedEffect(Ability ability, AttachmentType attachmentType) {
this(ability, attachmentType, Duration.WhileOnBattlefield);
@ -62,6 +64,7 @@ public class GainAbilityAttachedEffect extends ContinuousEffectImpl {
this.attachmentType = effect.attachmentType;
this.independentEffect = effect.independentEffect;
this.targetObjectName = effect.targetObjectName;
this.doesntRemoveItself = effect.doesntRemoveItself;
}
@Override
@ -82,7 +85,7 @@ public class GainAbilityAttachedEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = null;
Permanent permanent;
if (affectedObjectsSet) {
permanent = game.getPermanent(targetPointer.getFirst(game, source));
if (permanent == null) {
@ -93,9 +96,14 @@ public class GainAbilityAttachedEffect extends ContinuousEffectImpl {
Permanent equipment = game.getPermanent(source.getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) {
permanent = game.getPermanentOrLKIBattlefield(equipment.getAttachedTo());
} else {
permanent = null;
}
}
if (permanent != null) {
if (doesntRemoveItself && ability instanceof ProtectionAbility) {
((ProtectionAbility) ability).setAuraIdNotToBeRemoved(source.getSourceId());
}
permanent.addAbility(ability, source.getSourceId(), game);
afterGain(game, source, permanent, ability);
}
@ -114,6 +122,11 @@ public class GainAbilityAttachedEffect extends ContinuousEffectImpl {
//
}
public GainAbilityAttachedEffect setDoesntRemoveItself(boolean doesntRemoveItself) {
this.doesntRemoveItself = doesntRemoveItself;
return this;
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
@ -138,6 +151,9 @@ public class GainAbilityAttachedEffect extends ContinuousEffectImpl {
if (!duration.toString().isEmpty()) {
sb.append(' ').append(duration);
}
if (doesntRemoveItself) {
sb.append(" This effect doesn't remove {this}.");
}
return sb.toString();
}
}

View file

@ -15,7 +15,6 @@ import mage.game.stack.StackObject;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

View file

@ -1204,14 +1204,11 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override
public boolean cantBeAttachedBy(MageObject attachment, Ability source, Game game, boolean silentMode) {
for (ProtectionAbility ability : this.getAbilities(game).getProtectionAbilities()) {
if (!(attachment.hasSubtype(SubType.AURA, game)
&& !ability.removesAuras())
&& !(attachment.hasSubtype(SubType.EQUIPMENT, game)
&& !ability.removesEquipment())) {
if (!attachment.getId().equals(ability.getAuraIdNotToBeRemoved())
&& !ability.canTarget(attachment, game)) {
return !ability.getDoesntRemoveControlled() || isControlledBy(game.getControllerId(attachment.getId()));
}
if ((!attachment.hasSubtype(SubType.AURA, game) || ability.removesAuras())
&& (!attachment.hasSubtype(SubType.EQUIPMENT, game) || ability.removesEquipment())
&& !attachment.getId().equals(ability.getAuraIdNotToBeRemoved())
&& !ability.canTarget(attachment, game)) {
return !ability.getDoesntRemoveControlled() || isControlledBy(game.getControllerId(attachment.getId()));
}
}
return game.getContinuousEffects().preventedByRuleModification(new StayAttachedEvent(this.getId(), attachment.getId(), source), null, game, silentMode);