From 3d078dce93f4b8bfaa2bf3852f7182679c3d862a Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Wed, 31 Mar 2021 08:15:38 -0400 Subject: [PATCH] [STX] Implemented Tanazir Quandrix --- .../src/mage/cards/g/GrunnTheLonelyKing.java | 3 +- .../src/mage/cards/o/OkaunEyeOfChaos.java | 3 +- .../src/mage/cards/t/TanazirQuandrix.java | 97 +++++++++++++++++++ .../mage/sets/StrixhavenSchoolOfMages.java | 1 + .../common/SourcePermanentPowerCount.java | 18 ++-- .../common/SourcePermanentToughnessValue.java | 28 +++--- 6 files changed, 118 insertions(+), 32 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/t/TanazirQuandrix.java diff --git a/Mage.Sets/src/mage/cards/g/GrunnTheLonelyKing.java b/Mage.Sets/src/mage/cards/g/GrunnTheLonelyKing.java index a46c3216f2..60ccea4421 100644 --- a/Mage.Sets/src/mage/cards/g/GrunnTheLonelyKing.java +++ b/Mage.Sets/src/mage/cards/g/GrunnTheLonelyKing.java @@ -40,8 +40,7 @@ public final class GrunnTheLonelyKing extends CardImpl { //Whenever Grunn attacks alone, double its power and toughness until end of turn. SourcePermanentPowerCount power = new SourcePermanentPowerCount(); - SourcePermanentToughnessValue toughness = new SourcePermanentToughnessValue(); - Effect effect = new BoostSourceEffect(power, toughness, Duration.EndOfTurn, true); + Effect effect = new BoostSourceEffect(power, SourcePermanentToughnessValue.getInstance(), Duration.EndOfTurn, true); effect.setText("double its power and toughness until end of turn"); this.addAbility(new AttacksAloneTriggeredAbility(effect)); } diff --git a/Mage.Sets/src/mage/cards/o/OkaunEyeOfChaos.java b/Mage.Sets/src/mage/cards/o/OkaunEyeOfChaos.java index b4c513c096..48dd0f65c3 100644 --- a/Mage.Sets/src/mage/cards/o/OkaunEyeOfChaos.java +++ b/Mage.Sets/src/mage/cards/o/OkaunEyeOfChaos.java @@ -22,7 +22,6 @@ import java.util.UUID; public final class OkaunEyeOfChaos extends CardImpl { private static final DynamicValue sourcePower = new SourcePermanentPowerCount(); - private static final DynamicValue sourceToughness = new SourcePermanentToughnessValue(); public OkaunEyeOfChaos(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{R}"); @@ -43,7 +42,7 @@ public final class OkaunEyeOfChaos extends CardImpl { this.addAbility(new WinsCoinFlipTriggeredAbility( new BoostSourceEffect( sourcePower, - sourceToughness, + SourcePermanentToughnessValue.getInstance(), Duration.EndOfTurn, true ).setText("double {this}'s power and toughness until end of turn") diff --git a/Mage.Sets/src/mage/cards/t/TanazirQuandrix.java b/Mage.Sets/src/mage/cards/t/TanazirQuandrix.java new file mode 100644 index 0000000000..88058f09ad --- /dev/null +++ b/Mage.Sets/src/mage/cards/t/TanazirQuandrix.java @@ -0,0 +1,97 @@ +package mage.cards.t; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.AttacksTriggeredAbility; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.SourcePermanentPowerCount; +import mage.abilities.dynamicvalue.common.SourcePermanentToughnessValue; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continuous.SetPowerToughnessAllEffect; +import mage.abilities.keyword.FlyingAbility; +import mage.abilities.keyword.TrampleAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.counters.CounterType; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.target.common.TargetControlledCreaturePermanent; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class TanazirQuandrix extends CardImpl { + + private static final DynamicValue xValue = new SourcePermanentPowerCount(true); + + public TanazirQuandrix(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{G}{U}"); + + this.addSuperType(SuperType.LEGENDARY); + this.subtype.add(SubType.ELDER); + this.subtype.add(SubType.DRAGON); + this.power = new MageInt(4); + this.toughness = new MageInt(4); + + // Flying + this.addAbility(FlyingAbility.getInstance()); + + // Trample + this.addAbility(TrampleAbility.getInstance()); + + // When Tanazir Quandrix enters the battlefield, double the number of +1/+1 counters on target creature you control. + Ability ability = new EntersBattlefieldTriggeredAbility(new TanazirQuandrixEffect()); + ability.addTarget(new TargetControlledCreaturePermanent()); + this.addAbility(ability); + + // Whenever Tanazir Quandrix attacks, you may have the base power and toughness of other creatures you control become equal to Tanazir Quandrix's power and toughness until end of turn. + this.addAbility(new AttacksTriggeredAbility(new SetPowerToughnessAllEffect( + xValue, SourcePermanentToughnessValue.getInstance(), Duration.EndOfTurn, + StaticFilters.FILTER_CONTROLLED_CREATURE, true + ).setText("have the base power and toughness of other creatures you control " + + "become equal to {this}'s power and toughness until end of turn"), true)); + } + + private TanazirQuandrix(final TanazirQuandrix card) { + super(card); + } + + @Override + public TanazirQuandrix copy() { + return new TanazirQuandrix(this); + } +} + +class TanazirQuandrixEffect extends OneShotEffect { + + TanazirQuandrixEffect() { + super(Outcome.Benefit); + staticText = "double the number of +1/+1 counters on target creature you control"; + } + + private TanazirQuandrixEffect(final TanazirQuandrixEffect effect) { + super(effect); + } + + @Override + public TanazirQuandrixEffect copy() { + return new TanazirQuandrixEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getFirstTarget()); + if (permanent == null) { + return false; + } + int counterCount = permanent.getCounters(game).getCount(CounterType.P1P1); + return counterCount > 0 && permanent.addCounters( + CounterType.P1P1.createInstance(counterCount), source.getControllerId(), source, game + ); + } +} diff --git a/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java b/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java index a7a1b449f2..7e65dd868c 100644 --- a/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java +++ b/Mage.Sets/src/mage/sets/StrixhavenSchoolOfMages.java @@ -103,6 +103,7 @@ public final class StrixhavenSchoolOfMages extends ExpansionSet { cards.add(new SetCardInfo("Study Break", 34, Rarity.COMMON, mage.cards.s.StudyBreak.class)); cards.add(new SetCardInfo("Sudden Breakthrough", 116, Rarity.COMMON, mage.cards.s.SuddenBreakthrough.class)); cards.add(new SetCardInfo("Swamp", 370, Rarity.LAND, mage.cards.basiclands.Swamp.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("Tanazir Quandrix", 240, Rarity.MYTHIC, mage.cards.t.TanazirQuandrix.class)); cards.add(new SetCardInfo("Thrilling Discovery", 243, Rarity.COMMON, mage.cards.t.ThrillingDiscovery.class)); cards.add(new SetCardInfo("Thunderous Orator", 35, Rarity.UNCOMMON, mage.cards.t.ThunderousOrator.class)); cards.add(new SetCardInfo("Torrent Sculptor", 159, Rarity.RARE, mage.cards.t.TorrentSculptor.class)); diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/SourcePermanentPowerCount.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/SourcePermanentPowerCount.java index c347fbc2c0..2c7042d72a 100644 --- a/Mage/src/main/java/mage/abilities/dynamicvalue/common/SourcePermanentPowerCount.java +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/SourcePermanentPowerCount.java @@ -3,7 +3,6 @@ package mage.abilities.dynamicvalue.common; import mage.abilities.Ability; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.Effect; -import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; @@ -12,7 +11,7 @@ import mage.game.permanent.Permanent; */ public class SourcePermanentPowerCount implements DynamicValue { - boolean allowNegativeValues; + private final boolean allowNegativeValues; public SourcePermanentPowerCount() { this(true); @@ -30,17 +29,12 @@ public class SourcePermanentPowerCount implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { - Permanent sourcePermanent = game.getPermanent(sourceAbility.getSourceId()); - if (sourcePermanent == null - || (sourceAbility.getSourceObjectZoneChangeCounter() > 0 - && sourcePermanent.getZoneChangeCounter(game) > sourceAbility.getSourceObjectZoneChangeCounter())) { - sourcePermanent = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD); + Permanent sourcePermanent = sourceAbility.getSourcePermanentOrLKI(game); + if (sourcePermanent == null) { + return 0; } - if (sourcePermanent != null - && (allowNegativeValues || sourcePermanent.getPower().getValue() >= 0)) { - return sourcePermanent.getPower().getValue(); - } - return 0; + int power = sourcePermanent.getPower().getValue(); + return allowNegativeValues ? power : Integer.max(power, 0); } @Override diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/SourcePermanentToughnessValue.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/SourcePermanentToughnessValue.java index 4b13eee1f6..d651268fae 100644 --- a/Mage/src/main/java/mage/abilities/dynamicvalue/common/SourcePermanentToughnessValue.java +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/SourcePermanentToughnessValue.java @@ -1,43 +1,39 @@ - - package mage.abilities.dynamicvalue.common; import mage.abilities.Ability; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.Effect; -import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; import java.io.ObjectStreamException; /** - * * @author LevelX2 */ public class SourcePermanentToughnessValue implements DynamicValue { - - private static final SourcePermanentToughnessValue instance = new SourcePermanentToughnessValue(); - + + private static final SourcePermanentToughnessValue instance = new SourcePermanentToughnessValue(); + private Object readResolve() throws ObjectStreamException { return instance; - } - + } + public static SourcePermanentToughnessValue getInstance() { return instance; } - + + private SourcePermanentToughnessValue() { + } + @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { - Permanent sourcePermanent = game.getPermanent(sourceAbility.getSourceId()); + Permanent sourcePermanent = sourceAbility.getSourcePermanentOrLKI(game); if (sourcePermanent == null) { - sourcePermanent = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD); + return 0; } - if (sourcePermanent != null) { - return sourcePermanent.getToughness().getValue(); - } - return 0; + return sourcePermanent.getToughness().getValue(); } @Override