mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 11:32:00 -08:00
fix RippleEffect so that it still triggers even when original spell is exiled or countered
This commit is contained in:
parent
9621959922
commit
50b1085ebb
1 changed files with 21 additions and 32 deletions
|
|
@ -16,8 +16,6 @@ import mage.players.Player;
|
||||||
import mage.target.TargetCard;
|
import mage.target.TargetCard;
|
||||||
import mage.util.CardUtil;
|
import mage.util.CardUtil;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author klayhamn
|
* @author klayhamn
|
||||||
*/
|
*/
|
||||||
|
|
@ -37,39 +35,42 @@ public class RippleEffect extends OneShotEffect {
|
||||||
this.setText();
|
this.setText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RippleEffect(final RippleEffect effect) {
|
||||||
|
super(effect);
|
||||||
|
this.rippleNumber = effect.rippleNumber;
|
||||||
|
this.isTargetSelf = effect.isTargetSelf;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RippleEffect copy() {
|
||||||
|
return new RippleEffect(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player player = game.getPlayer(source.getControllerId());
|
Player player = game.getPlayer(source.getControllerId());
|
||||||
MageObject sourceObject = game.getObject(source.getSourceId());
|
MageObject sourceObject = game.getObject(source.getSourceId());
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
if (!player.chooseUse(Outcome.Neutral, "Reveal " + rippleNumber + " cards from the top of your library?", source, game)){
|
if (!player.chooseUse(Outcome.Neutral, "Reveal " + rippleNumber + " cards from the top of your library?", source, game)){
|
||||||
return false; //fizzle
|
return true; //fizzle
|
||||||
}
|
}
|
||||||
|
|
||||||
Cards cards = new CardsImpl();
|
Cards cards = new CardsImpl();
|
||||||
int count = Math.min(rippleNumber, player.getLibrary().size());
|
cards.addAll(player.getLibrary().getTopCards(game, rippleNumber)); // pull top cards
|
||||||
if (count == 0) {
|
player.revealCards(sourceObject.getIdName(), cards, game); // reveal the cards
|
||||||
return true;
|
|
||||||
}
|
|
||||||
player.revealCards(sourceObject.getIdName(), cards, game);
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
Card card = player.getLibrary().removeFromTop(game);
|
|
||||||
cards.add(card);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select cards with the same name as the spell on which the ripple effect applies
|
// Find out which card should be rippled
|
||||||
// FIXME: I'm not sure the "isTargetSelf" flag is the most elegant solution
|
// FIXME: I'm not sure the "isTargetSelf" flag is the most elegant solution
|
||||||
String cardNameToRipple;
|
String cardNameToRipple;
|
||||||
if (isTargetSelf) { // if the ripple applies to the same card that triggered it
|
if (isTargetSelf) { // if the ripple applies to the same card that triggered it
|
||||||
cardNameToRipple = sourceObject.getName();
|
cardNameToRipple = sourceObject.getName();
|
||||||
} else { // if the ripple is caused by something else (e.g. Thrumming Stone)
|
} else { // if the ripple is caused by something else (e.g. Thrumming Stone)
|
||||||
if (targetPointer == null) {
|
Spell spellOnStack = game.getStack().getSpell(targetPointer.getFirst(game, source));
|
||||||
return true; // this might be possible if the "rememberSource" param wasn't used (which would constitute a bug)
|
if (spellOnStack == null) { // if the ripple target got countered or exiled
|
||||||
|
spellOnStack = (Spell) game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.STACK);
|
||||||
}
|
}
|
||||||
UUID triggeringSpellID = targetPointer.getFirst(game, source);
|
|
||||||
Spell spellOnStack = game.getStack().getSpell(triggeringSpellID);
|
|
||||||
if (spellOnStack == null) {
|
if (spellOnStack == null) {
|
||||||
return true; // spell was countered or exiled, effect should fizzle
|
return true; // should not happen?
|
||||||
}
|
}
|
||||||
cardNameToRipple = spellOnStack.getName();
|
cardNameToRipple = spellOnStack.getName();
|
||||||
}
|
}
|
||||||
|
|
@ -90,24 +91,12 @@ public class RippleEffect extends OneShotEffect {
|
||||||
}
|
}
|
||||||
// move cards that weren't cast to the bottom of the library
|
// move cards that weren't cast to the bottom of the library
|
||||||
player.putCardsOnBottomOfLibrary(cards, game, source, true);
|
player.putCardsOnBottomOfLibrary(cards, game, source, true);
|
||||||
// do we need to fire an event here? there is nothing that listens to ripple so far...
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RippleEffect(final RippleEffect effect) {
|
|
||||||
super(effect);
|
|
||||||
this.rippleNumber = effect.rippleNumber;
|
|
||||||
this.isTargetSelf = effect.isTargetSelf;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RippleEffect copy() {
|
|
||||||
return new RippleEffect(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setText() {
|
private void setText() {
|
||||||
StringBuilder sb = new StringBuilder("Ripple ").append(rippleNumber);
|
StringBuilder sb = new StringBuilder("Ripple ").append(rippleNumber);
|
||||||
sb.append(". <i>(You may reveal the top ");
|
sb.append(". <i>(You may reveal the top ");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue