Skip to content

Commit

Permalink
[MOC] Use utility functions for Rashmi and Ragavan.
Browse files Browse the repository at this point in the history
  • Loading branch information
Grath committed Apr 12, 2023
1 parent 1eae1c5 commit b4f368e
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions Mage.Sets/src/mage/cards/r/RashmiAndRagavan.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package mage.cards.r;

import mage.ApprovingObject;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SpellCastControllerTriggeredAbility;
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.CardsImpl;
import mage.constants.*;
import mage.filter.FilterCard;
import mage.filter.StaticFilters;
import mage.filter.predicate.mageobject.ManaValuePredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.token.TreasureToken;
import mage.game.stack.Spell;
import mage.players.Player;
import mage.target.common.TargetOpponent;
import mage.target.targetpointer.FixedTargets;
import mage.util.CardUtil;
import mage.watchers.common.SpellsCastWatcher;

Expand Down Expand Up @@ -49,9 +48,7 @@ public RashmiAndRagavan(UUID ownerId, CardSetInfo setInfo) {
// Then you may cast the exiled card without paying its mana cost if it’s a spell with mana value
// less than the number of artifacts you control.
// If you don’t cast it this way, you may cast it this turn.
Ability ability = new RashmiAndRagavanTriggeredAbility();
ability.addTarget(new TargetOpponent());
this.addAbility(ability, new SpellsCastWatcher());
this.addAbility(new RashmiAndRagavanTriggeredAbility());
}

private RashmiAndRagavan(final RashmiAndRagavan card) {
Expand All @@ -68,6 +65,8 @@ class RashmiAndRagavanTriggeredAbility extends SpellCastControllerTriggeredAbili

RashmiAndRagavanTriggeredAbility() {
super(new CreateTokenEffect(new TreasureToken()), false);
this.addTarget(new TargetOpponent());
this.addWatcher(new SpellsCastWatcher());
this.addEffect(new RashmiAndRagavanEffect());
}

Expand Down Expand Up @@ -125,7 +124,6 @@ public RashmiAndRagavanEffect copy() {

@Override
public boolean apply(Game game, Ability source) {
Boolean cardWasCast = false;
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller == null || player == null) {
Expand All @@ -149,17 +147,12 @@ public boolean apply(Game game, Ability source) {
int artifactCount = new PermanentsOnBattlefieldCount(
StaticFilters.FILTER_CONTROLLED_PERMANENT_ARTIFACT
).calculate(game, source, this);
if (!card.isLand() && card.getManaValue() < artifactCount && controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName()
+ " without paying its mana cost?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true),
game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
FilterCard filter = new FilterCard();
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, artifactCount));
Boolean cardWasCast = CardUtil.castSpellWithAttributesForFree(controller, source, game, new CardsImpl(card), filter);
if (!cardWasCast) {
ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, TargetController.YOU, Duration.EndOfTurn, false, true);
effect.setTargetPointer(new FixedTargets(cards, game));
game.addEffect(effect, source);
CardUtil.makeCardPlayable(game, source, card, Duration.EndOfTurn, false, controller.getId(), null);
}
return true;
}
Expand Down

0 comments on commit b4f368e

Please sign in to comment.