diff --git a/Mage.Sets/src/mage/cards/r/RazorfieldRipper.java b/Mage.Sets/src/mage/cards/r/RazorfieldRipper.java new file mode 100644 index 00000000000..db68c60d6dc --- /dev/null +++ b/Mage.Sets/src/mage/cards/r/RazorfieldRipper.java @@ -0,0 +1,105 @@ +package mage.cards.r; + +import java.util.UUID; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.costs.Cost; +import mage.abilities.costs.OrCost; +import mage.abilities.costs.common.PayEnergyCost; +import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.CountersControllerCount; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continuous.BoostTargetEffect; +import mage.abilities.effects.common.counter.GetEnergyCountersControllerEffect; +import mage.constants.*; +import mage.abilities.keyword.ReconfigureAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.targetpointer.FixedTarget; + +/** + * + * @author grimreap124 + */ +public final class RazorfieldRipper extends CardImpl { + + private static final DynamicValue xValue = new CountersControllerCount(CounterType.ENERGY); + + public RazorfieldRipper(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{2}{W}"); + + this.subtype.add(SubType.EQUIPMENT); + this.subtype.add(SubType.RHINO); + this.power = new MageInt(3); + this.toughness = new MageInt(3); + + // Whenever Razorfield Ripper or equipped creature attacks, you get {E}, then it gets +X/+X until end of turn, where X is the amount of {E} you have. + Ability ability = new RazorfieldRipperTriggeredAbility(new GetEnergyCountersControllerEffect(1)); + ability.addEffect(new BoostTargetEffect(xValue, xValue, Duration.EndOfTurn).setText("then it gets +X/+X until end of turn, where X is the amount of {E} you have.").concatBy(",")); + this.addAbility(ability); + + // Reconfigure--Pay {2} or {E}{E}{E}. + Cost cost = new OrCost("Pay {2} or {E}{E}{E}", new GenericManaCost(2), new PayEnergyCost(3)); + this.addAbility(new ReconfigureAbility(cost)); + + } + + private RazorfieldRipper(final RazorfieldRipper card) { + super(card); + } + + @Override + public RazorfieldRipper copy() { + return new RazorfieldRipper(this); + } +} + +class RazorfieldRipperTriggeredAbility extends TriggeredAbilityImpl { + + RazorfieldRipperTriggeredAbility(Effect effect) { + super(Zone.BATTLEFIELD, effect); + setTriggerPhrase("Whenever {this} or equipped creature attacks, "); + } + + private RazorfieldRipperTriggeredAbility(final RazorfieldRipperTriggeredAbility ability) { + super(ability); + } + + @Override + public RazorfieldRipperTriggeredAbility copy() { + return new RazorfieldRipperTriggeredAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DECLARED_ATTACKERS; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + UUID attacker; + if (!game.getCombat().getAttackers().contains(getSourceId())) { + Permanent permanent = getSourcePermanentOrLKI(game); + if (permanent != null && game.getCombat().getAttackers().contains(permanent.getAttachedTo())) { + attacker = permanent.getAttachedTo(); + } else { + attacker = null; + } + } else { + attacker = getSourceId(); + } + if (attacker == null) { + return false; + } + getEffects().setTargetPointer(new FixedTarget(attacker, game)); + return true; + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/ModernHorizons3Commander.java b/Mage.Sets/src/mage/sets/ModernHorizons3Commander.java index d096ce5d27e..83b908ef62d 100644 --- a/Mage.Sets/src/mage/sets/ModernHorizons3Commander.java +++ b/Mage.Sets/src/mage/sets/ModernHorizons3Commander.java @@ -211,6 +211,7 @@ public final class ModernHorizons3Commander extends ExpansionSet { cards.add(new SetCardInfo("Rampaging Baloths", 239, Rarity.MYTHIC, mage.cards.r.RampagingBaloths.class)); cards.add(new SetCardInfo("Rampant Growth", 240, Rarity.COMMON, mage.cards.r.RampantGrowth.class)); cards.add(new SetCardInfo("Ramunap Excavator", 241, Rarity.RARE, mage.cards.r.RamunapExcavator.class)); + cards.add(new SetCardInfo("Razorfield Ripper", 42, Rarity.RARE, mage.cards.r.RazorfieldRipper.class)); cards.add(new SetCardInfo("Reliquary Tower", 368, Rarity.UNCOMMON, mage.cards.r.ReliquaryTower.class)); cards.add(new SetCardInfo("Replication Technique", 192, Rarity.RARE, mage.cards.r.ReplicationTechnique.class)); cards.add(new SetCardInfo("Return of the Wildspeaker", 242, Rarity.RARE, mage.cards.r.ReturnOfTheWildspeaker.class)); diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/CountersControllerCount.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/CountersControllerCount.java new file mode 100644 index 00000000000..c6d6a86826b --- /dev/null +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/CountersControllerCount.java @@ -0,0 +1,53 @@ +package mage.abilities.dynamicvalue.common; + +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.effects.Effect; +import mage.counters.CounterType; +import mage.game.Game; +import mage.players.Player; + +import java.util.UUID; + +public class CountersControllerCount implements DynamicValue { + + private final CounterType counterType; + + /** + * Number of counters of the specified type on the Controller of the source + */ + public CountersControllerCount(CounterType counterType) { + this.counterType = counterType; + } + + protected CountersControllerCount(final CountersControllerCount countersCount) { + this.counterType = countersCount.counterType; + } + + @Override + public int calculate(Game game, Ability sourceAbility, Effect effect) { + UUID controllerId = sourceAbility.getControllerId(); + Player player = game.getPlayer(controllerId); + if (player == null) { + return 0; + } + return counterType != null + ? player.getCountersCount(counterType) + : 0; + } + + @Override + public CountersControllerCount copy() { + return new CountersControllerCount(this); + } + + @Override + public String toString() { + return "1"; + } + + @Override + public String getMessage() { + return (counterType != null ? counterType.toString() + ' ' : "") + "counter on {this}'s controller"; + } +} diff --git a/Mage/src/main/java/mage/abilities/keyword/ReconfigureAbility.java b/Mage/src/main/java/mage/abilities/keyword/ReconfigureAbility.java index 61d672923a8..a423bcd0792 100644 --- a/Mage/src/main/java/mage/abilities/keyword/ReconfigureAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/ReconfigureAbility.java @@ -3,6 +3,7 @@ package mage.abilities.keyword; import mage.abilities.Ability; import mage.abilities.ActivatedAbilityImpl; import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.costs.Cost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.OneShotEffect; @@ -17,14 +18,18 @@ import mage.target.common.TargetControlledCreaturePermanent; */ public class ReconfigureAbility extends ActivatedAbilityImpl { - private final String manaString; + private final Cost cost; public ReconfigureAbility(String manaString) { - super(Zone.BATTLEFIELD, new AttachEffect(Outcome.BoostCreature), new ManaCostsImpl<>(manaString)); - this.manaString = manaString; + this(new ManaCostsImpl<>(manaString)); + } + + public ReconfigureAbility(Cost cost) { + super(Zone.BATTLEFIELD, new AttachEffect(Outcome.BoostCreature), cost); + this.cost = cost; this.timing = TimingRule.SORCERY; this.addTarget(new TargetControlledCreaturePermanent()); - this.addSubAbility(new ReconfigureUnattachAbility(manaString)); + this.addSubAbility(new ReconfigureUnattachAbility(cost)); Ability ability = new SimpleStaticAbility(new ReconfigureTypeEffect()); ability.setRuleVisible(false); this.addSubAbility(ability); @@ -32,7 +37,7 @@ public class ReconfigureAbility extends ActivatedAbilityImpl { private ReconfigureAbility(final ReconfigureAbility ability) { super(ability); - this.manaString = ability.manaString; + this.cost = ability.cost; } @Override @@ -42,7 +47,7 @@ public class ReconfigureAbility extends ActivatedAbilityImpl { @Override public String getRule() { - return "Reconfigure " + manaString + " (" + manaString + return "Reconfigure " + cost.getText() + " (" + cost.getText() + ": Attach to target creature you control; " + "or unattach from a creature. Reconfigure only as a sorcery. " + "While attached, this isn't a creature.)"; @@ -51,8 +56,8 @@ public class ReconfigureAbility extends ActivatedAbilityImpl { class ReconfigureUnattachAbility extends ActivatedAbilityImpl { - protected ReconfigureUnattachAbility(String manaString) { - super(Zone.BATTLEFIELD, new ReconfigureUnattachEffect(), new ManaCostsImpl<>(manaString)); + protected ReconfigureUnattachAbility(Cost cost) { + super(Zone.BATTLEFIELD, new ReconfigureUnattachEffect(), cost); this.condition = ReconfigureUnattachAbility::checkForCreature; this.timing = TimingRule.SORCERY; this.setRuleVisible(false);