From b8473bfb9d0ba76fbd49bda59202cf4acb4fbf27 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Fri, 30 Sep 2022 09:33:32 -0400 Subject: [PATCH] [BRO] Implemented Surge Engine --- Mage.Sets/src/mage/cards/s/SurgeEngine.java | 139 ++++++++++++++++++++ Mage.Sets/src/mage/sets/TheBrothersWar.java | 1 + 2 files changed, 140 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/s/SurgeEngine.java diff --git a/Mage.Sets/src/mage/cards/s/SurgeEngine.java b/Mage.Sets/src/mage/cards/s/SurgeEngine.java new file mode 100644 index 0000000000..ee1671266a --- /dev/null +++ b/Mage.Sets/src/mage/cards/s/SurgeEngine.java @@ -0,0 +1,139 @@ +package mage.cards.s; + +import mage.MageInt; +import mage.ObjectColor; +import mage.abilities.Ability; +import mage.abilities.ActivatedAbilityImpl; +import mage.abilities.common.ActivateIfConditionActivatedAbility; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.condition.Condition; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.effects.common.continuous.BecomesColorSourceEffect; +import mage.abilities.effects.common.continuous.GainAbilitySourceEffect; +import mage.abilities.effects.common.continuous.LoseAbilitySourceEffect; +import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect; +import mage.abilities.keyword.CantBeBlockedSourceAbility; +import mage.abilities.keyword.DefenderAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.game.Game; +import mage.util.CardUtil; + +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class SurgeEngine extends CardImpl { + + public SurgeEngine(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{2}"); + + this.subtype.add(SubType.CONSTRUCT); + this.power = new MageInt(3); + this.toughness = new MageInt(2); + + // Defender + this.addAbility(DefenderAbility.getInstance()); + + // {U}: Surge Engine loses defender and gains "This creature can't be blocked." + Ability ability = new SimpleActivatedAbility(new LoseAbilitySourceEffect( + DefenderAbility.getInstance(), Duration.Custom + ), new ManaCostsImpl<>("{U}")); + ability.addEffect(new GainAbilitySourceEffect( + new CantBeBlockedSourceAbility(), Duration.Custom + ).setText("and gains \"This creature can't be blocked.\"")); + this.addAbility(ability); + + // {2}{U}: Surge Engine becomes blue and has base power and toughness 5/4. Activate only if Surge Engine doesn't have defender. + ability = new ActivateIfConditionActivatedAbility( + Zone.BATTLEFIELD, new BecomesColorSourceEffect(ObjectColor.BLUE, Duration.Custom), + new ManaCostsImpl<>("{2}{U}"), SurgeEngineCondition.instance + ); + ability.addEffect(new SetBasePowerToughnessSourceEffect( + 5, 4, Duration.Custom, SubLayer.SetPT_7b + ).setText("and has base power and toughness 5/4")); + this.addAbility(ability); + + // {4}{U}{U}: Draw three cards. Activate only if Surge Engine is blue and only once. + this.addAbility(new SurgeEngineAbility()); + } + + private SurgeEngine(final SurgeEngine card) { + super(card); + } + + @Override + public SurgeEngine copy() { + return new SurgeEngine(this); + } +} + +enum SurgeEngineCondition implements Condition { + instance; + + @Override + public boolean apply(Game game, Ability source) { + return Optional + .ofNullable(source.getSourcePermanentIfItStillExists(game)) + .filter(Objects::nonNull) + .map(permanent -> permanent.hasAbility(DefenderAbility.getInstance(), game)) + .orElse(false); + } + + @Override + public String toString() { + return "if {this} doesn't have defender"; + } +} + +class SurgeEngineAbility extends ActivatedAbilityImpl { + + private static final Condition staticCondition = (game, source) -> Optional + .ofNullable(source.getSourcePermanentIfItStillExists(game)) + .filter(Objects::nonNull) + .map(permanent -> permanent.getColor(game)) + .map(ObjectColor::isBlue) + .orElse(false); + + SurgeEngineAbility() { + super(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(3), new ManaCostsImpl<>("{4}{U}{U}")); + this.condition = staticCondition; + } + + private SurgeEngineAbility(final SurgeEngineAbility ability) { + super(ability); + } + + @Override + public SurgeEngineAbility copy() { + return new SurgeEngineAbility(this); + } + + @Override + public boolean activate(Game game, boolean noMana) { + if (!super.activate(game, noMana)) { + return false; + } + game.getState().setValue(CardUtil.getCardZoneString("activationsAny" + originalId, sourceId, game), true); + return true; + } + + @Override + protected boolean hasMoreActivationsThisTurn(Game game) { + if (!super.hasMoreActivationsThisTurn(game)) { + return false; + } + Object value = game.getState().getValue(CardUtil.getCardZoneString("activationsAny" + originalId, sourceId, game)); + return value == null || ((Boolean) value) == false; + } + + @Override + public String getRule() { + return "{4}{U}{U}: Draw three cards. Activate only if {this} is blue and only once."; + } +} diff --git a/Mage.Sets/src/mage/sets/TheBrothersWar.java b/Mage.Sets/src/mage/sets/TheBrothersWar.java index a85646a2cb..293adba674 100644 --- a/Mage.Sets/src/mage/sets/TheBrothersWar.java +++ b/Mage.Sets/src/mage/sets/TheBrothersWar.java @@ -26,6 +26,7 @@ public final class TheBrothersWar extends ExpansionSet { cards.add(new SetCardInfo("Mountain", 284, Rarity.LAND, mage.cards.basiclands.Mountain.class, FULL_ART_BFZ_VARIOUS)); cards.add(new SetCardInfo("Plains", 278, Rarity.LAND, mage.cards.basiclands.Plains.class, FULL_ART_BFZ_VARIOUS)); cards.add(new SetCardInfo("Recruitment Officer", 23, Rarity.UNCOMMON, mage.cards.r.RecruitmentOfficer.class)); + cards.add(new SetCardInfo("Surge Engine", 81, Rarity.MYTHIC, mage.cards.s.SurgeEngine.class)); cards.add(new SetCardInfo("Swamp", 282, Rarity.LAND, mage.cards.basiclands.Swamp.class, FULL_ART_BFZ_VARIOUS)); cards.add(new SetCardInfo("The Mightstone and Weakstone", 238, Rarity.RARE, mage.cards.t.TheMightstoneAndWeakstone.class)); }