cleanup BecomesColorTargetEffect

add option to retain color
This commit is contained in:
xenohedron 2024-02-04 20:34:20 -05:00
parent cbb56c2248
commit 4968f0b18c
4 changed files with 28 additions and 27 deletions

View file

@ -1,4 +1,3 @@
package mage.cards.e;
import java.util.UUID;
@ -17,7 +16,6 @@ import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.SuperType;
import mage.constants.Zone;
import mage.target.Target;
import mage.target.common.TargetControlledPermanent;
import mage.target.common.TargetSpellOrPermanent;
@ -38,14 +36,12 @@ public final class EightAndAHalfTails extends CardImpl {
// {1}{W}: Target permanent you control gains protection from white until end of turn.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new GainAbilityTargetEffect(ProtectionAbility.from(ObjectColor.WHITE), Duration.EndOfTurn), new ManaCostsImpl<>("{1}{W}"));
Target target = new TargetControlledPermanent();
ability.addTarget(target);
ability.addTarget(new TargetControlledPermanent());
this.addAbility(ability);
// {1}: Target spell or permanent becomes white until end of turn.
ability = new SimpleActivatedAbility(Zone.BATTLEFIELD,
new BecomesColorTargetEffect(ObjectColor.WHITE, Duration.EndOfTurn, "Target spell or permanent becomes white until end of turn"), new ManaCostsImpl<>("{1}"));
target = new TargetSpellOrPermanent();
ability.addTarget(target);
ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BecomesColorTargetEffect(ObjectColor.WHITE, Duration.EndOfTurn)
.setText("Target spell or permanent becomes white until end of turn"), new ManaCostsImpl<>("{1}"));
ability.addTarget(new TargetSpellOrPermanent());
this.addAbility(ability);
}

View file

@ -1,5 +1,3 @@
package mage.cards.i;
import java.util.UUID;
@ -24,7 +22,7 @@ public final class Incite extends CardImpl {
// Target creature becomes red until end of turn and attacks this turn if able.
this.getSpellAbility().addTarget(new TargetCreaturePermanent());
this.getSpellAbility().addEffect(new BecomesColorTargetEffect(ObjectColor.RED, Duration.EndOfTurn, "Target creature becomes red until end of turn"));
this.getSpellAbility().addEffect(new BecomesColorTargetEffect(ObjectColor.RED, Duration.EndOfTurn));
this.getSpellAbility().addEffect(new AttacksIfAbleTargetEffect(Duration.EndOfTurn).setText("and attacks this turn if able"));
}

View file

@ -6,7 +6,6 @@ import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.RestrictionEffect;
import mage.abilities.effects.common.continuous.AddCardTypeTargetEffect;
import mage.abilities.effects.common.continuous.BecomesColorTargetEffect;
@ -43,16 +42,17 @@ public final class XathridGorgon extends CardImpl {
this.addAbility(DeathtouchAbility.getInstance());
// {2}{B}, {tap}: Put a petrification counter on target creature. It gains defender and becomes a colorless artifact in addition to its other types. Its activated abilities can't be activated.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new AddCountersTargetEffect(CounterType.PETRIFICATION.createInstance()), new ManaCostsImpl<>("{2}{B}"));
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD,
new AddCountersTargetEffect(CounterType.PETRIFICATION.createInstance()),
new ManaCostsImpl<>("{2}{B}"));
ability.addCost(new TapSourceCost());
ability.addTarget(new TargetCreaturePermanent());
Effect effect = new GainAbilityTargetEffect(DefenderAbility.getInstance(), Duration.Custom);
effect.setText("It gains defender");
ability.addEffect(effect);
effect = new AddCardTypeTargetEffect(Duration.Custom, CardType.ARTIFACT);
effect.setText("and becomes a colorless");
ability.addEffect(effect);
ability.addEffect(new BecomesColorTargetEffect(ObjectColor.COLORLESS, Duration.Custom, " artifact in addition to its other types"));
ability.addEffect(new GainAbilityTargetEffect(DefenderAbility.getInstance(), Duration.Custom)
.setText("It gains defender"));
ability.addEffect(new AddCardTypeTargetEffect(Duration.Custom, CardType.ARTIFACT)
.setText("and becomes a colorless"));
ability.addEffect(new BecomesColorTargetEffect(ObjectColor.COLORLESS, Duration.Custom)
.setText(" artifact in addition to its other types"));
ability.addEffect(new XathridGorgonCantActivateEffect());
this.addAbility(ability);

View file

@ -23,29 +23,29 @@ import mage.players.Player;
public class BecomesColorTargetEffect extends ContinuousEffectImpl {
private ObjectColor setColor;
private final boolean retainColor;
/**
* Set the color of a spell or permanent
*
* @param duration
*/
public BecomesColorTargetEffect(Duration duration) {
this(null, duration, null);
this(null, duration);
}
public BecomesColorTargetEffect(ObjectColor setColor, Duration duration) {
this(setColor, duration, null);
this(setColor, false, duration);
}
public BecomesColorTargetEffect(ObjectColor setColor, Duration duration, String text) {
public BecomesColorTargetEffect(ObjectColor setColor, boolean retainColor, Duration duration) {
super(duration, Layer.ColorChangingEffects_5, SubLayer.NA, Outcome.Benefit);
this.setColor = setColor;
staticText = text;
this.retainColor = retainColor;
}
protected BecomesColorTargetEffect(final BecomesColorTargetEffect effect) {
super(effect);
this.setColor = effect.setColor;
this.retainColor = effect.retainColor;
}
@Override
@ -82,7 +82,11 @@ public class BecomesColorTargetEffect extends ContinuousEffectImpl {
if (targetObject != null) {
if (targetObject instanceof Spell || targetObject instanceof Permanent) {
objectFound = true;
targetObject.getColor(game).setColor(setColor);
if (retainColor) {
targetObject.getColor(game).addColor(setColor);
} else {
targetObject.getColor(game).setColor(setColor);
}
} else {
objectFound = false;
}
@ -114,6 +118,9 @@ public class BecomesColorTargetEffect extends ContinuousEffectImpl {
} else {
sb.append(setColor.getDescription());
}
if (retainColor) {
sb.append(" in addition to its other colors");
}
if (!duration.toString().isEmpty()) {
sb.append(' ').append(duration.toString());
}