diff --git a/Mage.Sets/src/mage/cards/a/AscendantSpirit.java b/Mage.Sets/src/mage/cards/a/AscendantSpirit.java new file mode 100644 index 0000000000..c05070ef1a --- /dev/null +++ b/Mage.Sets/src/mage/cards/a/AscendantSpirit.java @@ -0,0 +1,128 @@ +package mage.cards.a; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.effects.common.continuous.AddCardSubTypeSourceEffect; +import mage.abilities.effects.common.continuous.GainAbilitySourceEffect; +import mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.permanent.Permanent; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class AscendantSpirit extends CardImpl { + + public AscendantSpirit(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{U}"); + + this.addSuperType(SuperType.SNOW); + this.subtype.add(SubType.SPIRIT); + this.power = new MageInt(1); + this.toughness = new MageInt(1); + + // {S}{S}: Ascendant Spirit becomes a Spirit Warrior with base power and toughness 2/3. + Ability ability = new SimpleActivatedAbility(new AddCardSubTypeSourceEffect( + Duration.Custom, SubType.SPIRIT, SubType.WARRIOR + ).setText("{this} becomes a Spirit Warrior"), new ManaCostsImpl("{S}{S}")); + ability.addEffect(new SetPowerToughnessSourceEffect( + 2, 3, Duration.Custom, SubLayer.SetPT_7b + ).setText("with base power and toughness 2/3")); + this.addAbility(ability); + + // {S}{S}{S}: If Ascendant Spirit is a Warrior, put a flying counter on it and it becomes a Spirit Warrior Angel with base power and toughness 4/4. + this.addAbility(new SimpleActivatedAbility( + new AscendantSpiritWarriorEffect(), new ManaCostsImpl("{S}{S}{S}") + )); + + // {S}{S}{S}{S}: If Ascendant Spirit is an Angel, put two +1/+1 counters on it and it gains "Whenever this creature deals damage to a player, draw a card." + this.addAbility(new SimpleActivatedAbility( + new AscendantSpiritAngelEffect(), new ManaCostsImpl("{S}{S}{S}{S}") + )); + } + + private AscendantSpirit(final AscendantSpirit card) { + super(card); + } + + @Override + public AscendantSpirit copy() { + return new AscendantSpirit(this); + } +} + +class AscendantSpiritWarriorEffect extends OneShotEffect { + + AscendantSpiritWarriorEffect() { + super(Outcome.Benefit); + staticText = "if {this} is a Warrior, put a flying counter on it " + + "and it becomes a Spirit Warrior Angel with base power and toughness 4/4"; + } + + private AscendantSpiritWarriorEffect(final AscendantSpiritWarriorEffect effect) { + super(effect); + } + + @Override + public AscendantSpiritWarriorEffect copy() { + return new AscendantSpiritWarriorEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = source.getSourcePermanentIfItStillExists(game); + if (permanent == null || !permanent.hasSubtype(SubType.WARRIOR, game)) { + return false; + } + permanent.addCounters(CounterType.FLYING.createInstance(), source, game); + game.addEffect(new AddCardSubTypeSourceEffect( + Duration.Custom, SubType.SPIRIT, SubType.WARRIOR, SubType.ANGEL + ), source); + game.addEffect(new SetPowerToughnessSourceEffect( + 4, 4, Duration.Custom, SubLayer.SetPT_7b + ), source); + return true; + } +} + +class AscendantSpiritAngelEffect extends OneShotEffect { + + AscendantSpiritAngelEffect() { + super(Outcome.Benefit); + staticText = "if {this} is an Angel, put two +1/+1 counters on it and it gains " + + "\"Whenever this creature deals damage to a player, draw a card.\""; + } + + private AscendantSpiritAngelEffect(final AscendantSpiritAngelEffect effect) { + super(effect); + } + + @Override + public AscendantSpiritAngelEffect copy() { + return new AscendantSpiritAngelEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = source.getSourcePermanentIfItStillExists(game); + if (permanent == null || !permanent.hasSubtype(SubType.ANGEL, game)) { + return false; + } + permanent.addCounters(CounterType.P1P1.createInstance(2), source, game); + game.addEffect(new GainAbilitySourceEffect(new DealsCombatDamageToAPlayerTriggeredAbility( + new DrawCardSourceControllerEffect(1), false + ), Duration.Custom), source); + return true; + } +} diff --git a/Mage.Sets/src/mage/cards/f/FigureOfDestiny.java b/Mage.Sets/src/mage/cards/f/FigureOfDestiny.java index b707de0208..1b03d4810c 100644 --- a/Mage.Sets/src/mage/cards/f/FigureOfDestiny.java +++ b/Mage.Sets/src/mage/cards/f/FigureOfDestiny.java @@ -1,71 +1,56 @@ - package mage.cards.f; -import java.util.UUID; import mage.MageInt; +import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; -import mage.abilities.condition.LockedInCondition; -import mage.abilities.condition.common.SourceMatchesFilterCondition; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.decorator.ConditionalContinuousEffect; -import mage.abilities.effects.common.continuous.BecomesCreatureSourceEffect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continuous.AddCardSubTypeSourceEffect; +import mage.abilities.effects.common.continuous.GainAbilitySourceEffect; +import mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect; import mage.abilities.keyword.FirstStrikeAbility; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.SubType; -import mage.constants.Zone; -import mage.filter.common.FilterCreaturePermanent; -import mage.game.permanent.token.TokenImpl; +import mage.constants.*; +import mage.game.Game; +import mage.game.permanent.Permanent; + +import java.util.UUID; /** - * - * @author LevelX2 + * @author TheElk801 */ public final class FigureOfDestiny extends CardImpl { - private static final FilterCreaturePermanent filter2 = new FilterCreaturePermanent(); - private static final FilterCreaturePermanent filter3 = new FilterCreaturePermanent(); - static { - filter2.add(SubType.SPIRIT.getPredicate()); - filter3.add(SubType.WARRIOR.getPredicate()); - } - public FigureOfDestiny(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{R/W}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{R/W}"); this.subtype.add(SubType.KITHKIN); this.power = new MageInt(1); this.toughness = new MageInt(1); // {RW}: Figure of Destiny becomes a Kithkin Spirit with base power and toughness 2/2. - this.addAbility(new SimpleActivatedAbility( - Zone.BATTLEFIELD, - new BecomesCreatureSourceEffect(new FigureOfDestiny.FigureOfDestinyToken1(), "", Duration.Custom), - new ManaCostsImpl("{R/W}"))); + Ability ability = new SimpleActivatedAbility(new AddCardSubTypeSourceEffect( + Duration.Custom, SubType.KITHKIN, SubType.SPIRIT + ).setText("{this} becomes a Kithkin Spirit"), new ManaCostsImpl("{R/W}")); + ability.addEffect(new SetPowerToughnessSourceEffect( + 2, 2, Duration.Custom, SubLayer.SetPT_7b + ).setText("with base power and toughness 2/2")); + this.addAbility(ability); + // {RW}{RW}{RW}: If Figure of Destiny is a Spirit, it becomes a Kithkin Spirit Warrior with base power and toughness 4/4. this.addAbility(new SimpleActivatedAbility( - Zone.BATTLEFIELD, - new ConditionalContinuousEffect( - new BecomesCreatureSourceEffect(new FigureOfDestiny.FigureOfDestinyToken2(), "", Duration.Custom), - new LockedInCondition(new SourceMatchesFilterCondition(filter2)), - "If {this} is a Spirit, it becomes a Kithkin Spirit Warrior with base power and toughness 4/4"), - new ManaCostsImpl("{R/W}{R/W}{R/W}") - )); + new FigureOfDestinySpiritEffect(), new ManaCostsImpl("{R/W}{R/W}{R/W}") + )); + // {RW}{RW}{RW}{RW}{RW}{RW}: If Figure of Destiny is a Warrior, it becomes a Kithkin Spirit Warrior Avatar with base power and toughness 8/8, flying, and first strike. this.addAbility(new SimpleActivatedAbility( - Zone.BATTLEFIELD, - new ConditionalContinuousEffect( - new BecomesCreatureSourceEffect(new FigureOfDestiny.FigureOfDestinyToken3(), "", Duration.Custom), - new LockedInCondition(new SourceMatchesFilterCondition(filter3)), - "If {this} is a Warrior, it becomes a Kithkin Spirit Warrior Avatar with base power and toughness 8/8, flying, and first strike"), - new ManaCostsImpl("{R/W}{R/W}{R/W}{R/W}{R/W}{R/W}") - )); + new FigureOfDestinyWarriorEffect(), new ManaCostsImpl("{R/W}{R/W}{R/W}{R/W}{R/W}{R/W}") + )); } - public FigureOfDestiny(final FigureOfDestiny card) { + private FigureOfDestiny(final FigureOfDestiny card) { super(card); } @@ -73,78 +58,75 @@ public final class FigureOfDestiny extends CardImpl { public FigureOfDestiny copy() { return new FigureOfDestiny(this); } +} - private class FigureOfDestinyToken1 extends TokenImpl { +class FigureOfDestinySpiritEffect extends OneShotEffect { - public FigureOfDestinyToken1() { - super("Figure of Destiny", "Kithkin Spirit with base power and toughness 2/2"); - this.cardType.add(CardType.CREATURE); - this.subtype.add(SubType.KITHKIN); - this.subtype.add(SubType.SPIRIT); - - this.color.setRed(true); - this.color.setWhite(true); - this.power = new MageInt(2); - this.toughness = new MageInt(2); - } - - public FigureOfDestinyToken1(final FigureOfDestinyToken1 token) { - super(token); - } - - public FigureOfDestinyToken1 copy() { - return new FigureOfDestinyToken1(this); - } + FigureOfDestinySpiritEffect() { + super(Outcome.Benefit); + staticText = "if {this} is a Spirit, it becomes a Kithkin Spirit Warrior with base power and toughness 4/4"; } - private class FigureOfDestinyToken2 extends TokenImpl { - - public FigureOfDestinyToken2() { - super("Figure of Destiny", "Kithkin Spirit Warrior with base power and toughness 4/4"); - this.cardType.add(CardType.CREATURE); - this.subtype.add(SubType.KITHKIN); - this.subtype.add(SubType.SPIRIT); - this.subtype.add(SubType.WARRIOR); - - this.color.setRed(true); - this.color.setWhite(true); - this.power = new MageInt(4); - this.toughness = new MageInt(4); - } - public FigureOfDestinyToken2(final FigureOfDestinyToken2 token) { - super(token); - } - - public FigureOfDestinyToken2 copy() { - return new FigureOfDestinyToken2(this); - } - + private FigureOfDestinySpiritEffect(final FigureOfDestinySpiritEffect effect) { + super(effect); } - private class FigureOfDestinyToken3 extends TokenImpl { + @Override + public FigureOfDestinySpiritEffect copy() { + return new FigureOfDestinySpiritEffect(this); + } - public FigureOfDestinyToken3() { - super("Figure of Destiny", "Kithkin Spirit Warrior Avatar with base power and toughness 8/8, flying, and first strike"); - this.cardType.add(CardType.CREATURE); - this.subtype.add(SubType.KITHKIN); - this.subtype.add(SubType.SPIRIT); - this.subtype.add(SubType.WARRIOR); - this.subtype.add(SubType.AVATAR); - - this.color.setRed(true); - this.color.setWhite(true); - this.power = new MageInt(8); - this.toughness = new MageInt(8); - this.addAbility(FlyingAbility.getInstance()); - this.addAbility(FirstStrikeAbility.getInstance()); - } - - public FigureOfDestinyToken3(final FigureOfDestinyToken3 token) { - super(token); - } - - public FigureOfDestinyToken3 copy() { - return new FigureOfDestinyToken3(this); + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = source.getSourcePermanentIfItStillExists(game); + if (permanent == null || !permanent.hasSubtype(SubType.SPIRIT, game)) { + return false; } + game.addEffect(new AddCardSubTypeSourceEffect( + Duration.Custom, SubType.KITHKIN, SubType.SPIRIT, SubType.WARRIOR + ), source); + game.addEffect(new SetPowerToughnessSourceEffect( + 4, 4, Duration.Custom, SubLayer.SetPT_7b + ), source); + return true; + } +} + +class FigureOfDestinyWarriorEffect extends OneShotEffect { + + FigureOfDestinyWarriorEffect() { + super(Outcome.Benefit); + staticText = "if {this} is a Warrior, it becomes a Kithkin Spirit Warrior Avatar " + + "with base power and toughness 8/8, flying, and first strike"; + } + + private FigureOfDestinyWarriorEffect(final FigureOfDestinyWarriorEffect effect) { + super(effect); + } + + @Override + public FigureOfDestinyWarriorEffect copy() { + return new FigureOfDestinyWarriorEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = source.getSourcePermanentIfItStillExists(game); + if (permanent == null || !permanent.hasSubtype(SubType.WARRIOR, game)) { + return false; + } + game.addEffect(new AddCardSubTypeSourceEffect( + Duration.Custom, SubType.KITHKIN, SubType.SPIRIT, SubType.WARRIOR, SubType.AVATAR + ), source); + game.addEffect(new SetPowerToughnessSourceEffect( + 8, 8, Duration.Custom, SubLayer.SetPT_7b + ), source); + game.addEffect(new GainAbilitySourceEffect( + FlyingAbility.getInstance(), Duration.Custom + ), source); + game.addEffect(new GainAbilitySourceEffect( + FirstStrikeAbility.getInstance(), Duration.Custom + ), source); + return true; } } diff --git a/Mage.Sets/src/mage/cards/w/WardenOfTheFirstTree.java b/Mage.Sets/src/mage/cards/w/WardenOfTheFirstTree.java index 5c3a6624bc..d88bc23d6a 100644 --- a/Mage.Sets/src/mage/cards/w/WardenOfTheFirstTree.java +++ b/Mage.Sets/src/mage/cards/w/WardenOfTheFirstTree.java @@ -1,76 +1,67 @@ - package mage.cards.w; -import java.util.UUID; import mage.MageInt; +import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; -import mage.abilities.condition.LockedInCondition; +import mage.abilities.condition.Condition; import mage.abilities.condition.common.SourceMatchesFilterCondition; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.decorator.ConditionalContinuousEffect; import mage.abilities.decorator.ConditionalOneShotEffect; -import mage.abilities.effects.common.continuous.BecomesCreatureSourceEffect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continuous.AddCardSubTypeSourceEffect; +import mage.abilities.effects.common.continuous.GainAbilitySourceEffect; +import mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.keyword.LifelinkAbility; import mage.abilities.keyword.TrampleAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.SubType; -import mage.constants.Zone; +import mage.constants.*; import mage.counters.CounterType; -import mage.filter.common.FilterCreaturePermanent; -import mage.game.permanent.token.TokenImpl; +import mage.filter.FilterPermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; + +import java.util.UUID; /** - * - * @author LevelX2 + * @author TheElk801 */ public final class WardenOfTheFirstTree extends CardImpl { - private static final FilterCreaturePermanent FILTER = new FilterCreaturePermanent(); - private static final FilterCreaturePermanent FILTER2 = new FilterCreaturePermanent(); - - static { - FILTER.add(SubType.WARRIOR.getPredicate()); - FILTER2.add(SubType.SPIRIT.getPredicate()); - } + private static final FilterPermanent filter = new FilterPermanent(SubType.SPIRIT, ""); + private static final Condition condition = new SourceMatchesFilterCondition(filter); public WardenOfTheFirstTree(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{G}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{G}"); this.subtype.add(SubType.HUMAN); this.power = new MageInt(1); this.toughness = new MageInt(1); // {1}{W/B}: Warden of the First Tree becomes a Human Warrior with base power and toughness 3/3. - this.addAbility(new SimpleActivatedAbility( - Zone.BATTLEFIELD, - new BecomesCreatureSourceEffect(new WardenOfTheFirstTree1(), "", Duration.Custom), - new ManaCostsImpl("{1}{W/B}"))); + Ability ability = new SimpleActivatedAbility(new AddCardSubTypeSourceEffect( + Duration.Custom, SubType.HUMAN, SubType.WARRIOR + ).setText("{this} becomes a Human Warrior"), new ManaCostsImpl("{1}{W/B}")); + ability.addEffect(new SetPowerToughnessSourceEffect( + 3, 3, Duration.Custom, SubLayer.SetPT_7b + ).setText("with base power and toughness 3/3")); + this.addAbility(ability); // {2}{W/B}{W/B}: If Warden of the First Tree is a Warrior, it becomes a Human Spirit Warrior with trample and lifelink. this.addAbility(new SimpleActivatedAbility( - Zone.BATTLEFIELD, - new ConditionalContinuousEffect( - new BecomesCreatureSourceEffect(new WardenOfTheFirstTree2(), "", Duration.Custom), - new LockedInCondition(new SourceMatchesFilterCondition(FILTER)), - "If {this} is a Warrior, it becomes a Human Spirit Warrior with trample and lifelink"), - new ManaCostsImpl("{2}{W/B}{W/B}") + new WardenOfTheFirstTreeEffect(), new ManaCostsImpl("{2}{W/B}{W/B}") )); // {3}{W/B}{W/B}{W/B}: If Warden of the First Tree is a Spirit, put five +1/+1 counters on it. this.addAbility(new SimpleActivatedAbility( - Zone.BATTLEFIELD, new ConditionalOneShotEffect( new AddCountersSourceEffect(CounterType.P1P1.createInstance(5)), - new SourceMatchesFilterCondition(FILTER2), - "If {this} is a Spirit, put five +1/+1 counters on it"), - new ManaCostsImpl("{3}{W/B}{W/B}{W/B}") + condition, "If {this} is a Spirit, put five +1/+1 counters on it" + ), new ManaCostsImpl("{3}{W/B}{W/B}{W/B}") )); } - public WardenOfTheFirstTree(final WardenOfTheFirstTree card) { + private WardenOfTheFirstTree(final WardenOfTheFirstTree card) { super(card); } @@ -80,46 +71,37 @@ public final class WardenOfTheFirstTree extends CardImpl { } } -class WardenOfTheFirstTree1 extends TokenImpl { +class WardenOfTheFirstTreeEffect extends OneShotEffect { - public WardenOfTheFirstTree1() { - super("Warden of the First Tree", "Human Warrior with base power and toughness 3/3"); - this.cardType.add(CardType.CREATURE); - this.subtype.add(SubType.HUMAN); - this.subtype.add(SubType.WARRIOR); - - this.power = new MageInt(3); - this.toughness = new MageInt(3); - } - public WardenOfTheFirstTree1(final WardenOfTheFirstTree1 token) { - super(token); + WardenOfTheFirstTreeEffect() { + super(Outcome.Benefit); + staticText = "if {this} is a Warrior, it becomes a Human Spirit Warrior with trample and lifelink"; } - public WardenOfTheFirstTree1 copy() { - return new WardenOfTheFirstTree1(this); - } -} - -class WardenOfTheFirstTree2 extends TokenImpl { - - public WardenOfTheFirstTree2() { - super("Warden of the First Tree", "Human Spirit Warrior with trample and lifelink"); - this.cardType.add(CardType.CREATURE); - this.subtype.add(SubType.HUMAN); - this.subtype.add(SubType.SPIRIT); - this.subtype.add(SubType.WARRIOR); - - this.power = new MageInt(3); - this.toughness = new MageInt(3); - - this.addAbility(TrampleAbility.getInstance()); - this.addAbility(LifelinkAbility.getInstance()); - } - public WardenOfTheFirstTree2(final WardenOfTheFirstTree2 token) { - super(token); - } - - public WardenOfTheFirstTree2 copy() { - return new WardenOfTheFirstTree2(this); + private WardenOfTheFirstTreeEffect(final WardenOfTheFirstTreeEffect effect) { + super(effect); + } + + @Override + public WardenOfTheFirstTreeEffect copy() { + return new WardenOfTheFirstTreeEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = source.getSourcePermanentIfItStillExists(game); + if (permanent == null || !permanent.hasSubtype(SubType.WARRIOR, game)) { + return false; + } + game.addEffect(new AddCardSubTypeSourceEffect( + Duration.Custom, SubType.HUMAN, SubType.SPIRIT, SubType.WARRIOR + ), source); + game.addEffect(new GainAbilitySourceEffect( + TrampleAbility.getInstance(), Duration.Custom + ), source); + game.addEffect(new GainAbilitySourceEffect( + LifelinkAbility.getInstance(), Duration.Custom + ), source); + return true; } } diff --git a/Mage.Sets/src/mage/sets/Kaldheim.java b/Mage.Sets/src/mage/sets/Kaldheim.java index f94748c4e7..e6bab81eb9 100644 --- a/Mage.Sets/src/mage/sets/Kaldheim.java +++ b/Mage.Sets/src/mage/sets/Kaldheim.java @@ -71,6 +71,7 @@ public final class Kaldheim extends ExpansionSet { cards.add(new SetCardInfo("Arctic Treeline", 249, Rarity.COMMON, mage.cards.a.ArcticTreeline.class)); cards.add(new SetCardInfo("Armed and Armored", 379, Rarity.UNCOMMON, mage.cards.a.ArmedAndArmored.class)); cards.add(new SetCardInfo("Arni Slays the Troll", 201, Rarity.UNCOMMON, mage.cards.a.ArniSlaysTheTroll.class)); + cards.add(new SetCardInfo("Ascendant Spirit", 43, Rarity.RARE, mage.cards.a.AscendantSpirit.class)); cards.add(new SetCardInfo("Augury Raven", 44, Rarity.COMMON, mage.cards.a.AuguryRaven.class)); cards.add(new SetCardInfo("Avalanche Caller", 45, Rarity.UNCOMMON, mage.cards.a.AvalancheCaller.class)); cards.add(new SetCardInfo("Axgard Armory", 250, Rarity.UNCOMMON, mage.cards.a.AxgardArmory.class)); diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/AddCardSubTypeSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/AddCardSubTypeSourceEffect.java new file mode 100644 index 0000000000..81dd21641b --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/AddCardSubTypeSourceEffect.java @@ -0,0 +1,81 @@ +package mage.abilities.effects.common.continuous; + +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.Mode; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.constants.*; +import mage.game.Game; +import mage.game.permanent.Permanent; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +/** + * @author TheElk801 + */ +public class AddCardSubTypeSourceEffect extends ContinuousEffectImpl { + + private final List addedSubTypes = new ArrayList<>(); + + public AddCardSubTypeSourceEffect(Duration duration, SubType... addedSubType) { + super(duration, Layer.TypeChangingEffects_4, SubLayer.NA, Outcome.Benefit); + for (SubType cardType : addedSubType) { + this.addedSubTypes.add(cardType); + } + } + + private AddCardSubTypeSourceEffect(final AddCardSubTypeSourceEffect effect) { + super(effect); + this.addedSubTypes.addAll(effect.addedSubTypes); + } + + @Override + public void init(Ability source, Game game) { + super.init(source, game); + affectedObjectList.add(new MageObjectReference(source.getSourceId(), game)); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent != null && affectedObjectList.contains(new MageObjectReference(permanent, game))) { + for (SubType cardType : addedSubTypes) { + permanent.addSubType(game, cardType); + } + return true; + } else if (this.getDuration() == Duration.Custom) { + this.discard(); + } + return false; + } + + @Override + public AddCardSubTypeSourceEffect copy() { + return new AddCardSubTypeSourceEffect(this); + } + + @Override + public String getText(Mode mode) { + if (staticText != null && !staticText.isEmpty()) { + return staticText; + } + StringBuilder sb = new StringBuilder(); + sb.append("{this} becomes "); + boolean article = false; + for (SubType subType : addedSubTypes) { + if (!article) { + if (subType.toString().startsWith("A") || subType.toString().startsWith("E")) { + sb.append("an "); + } else { + sb.append("a "); + } + article = true; + } + sb.append(subType.toString().toLowerCase(Locale.ENGLISH)).append(" "); + } + sb.append(" in addition to its other types ").append(this.getDuration().toString()); + return sb.toString(); + } +}