mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
Fix River Song's Diary logic to work with MDFC and split cards
This commit is contained in:
parent
90ec56812d
commit
15dd149c67
1 changed files with 18 additions and 24 deletions
|
|
@ -3,7 +3,6 @@ package mage.cards.r;
|
||||||
import mage.MageObjectReference;
|
import mage.MageObjectReference;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.condition.Condition;
|
import mage.abilities.condition.Condition;
|
||||||
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
|
|
||||||
import mage.abilities.dynamicvalue.DynamicValue;
|
import mage.abilities.dynamicvalue.DynamicValue;
|
||||||
import mage.abilities.effects.Effect;
|
import mage.abilities.effects.Effect;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
|
|
@ -24,7 +23,6 @@ import mage.game.events.ZoneChangeEvent;
|
||||||
import mage.game.ExileZone;
|
import mage.game.ExileZone;
|
||||||
import mage.game.stack.Spell;
|
import mage.game.stack.Spell;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.target.targetpointer.FixedTarget;
|
|
||||||
import mage.util.CardUtil;
|
import mage.util.CardUtil;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
@ -42,15 +40,12 @@ public final class RiverSongsDiary extends CardImpl {
|
||||||
this.addAbility(new RiverSongsDiaryImprintAbility().setAbilityWord(AbilityWord.IMPRINT));
|
this.addAbility(new RiverSongsDiaryImprintAbility().setAbilityWord(AbilityWord.IMPRINT));
|
||||||
|
|
||||||
// At the beginning of your upkeep, if there are four or more cards exiled with River Song's Diary, choose one of them at random. You may cast it without paying its mana cost.
|
// At the beginning of your upkeep, if there are four or more cards exiled with River Song's Diary, choose one of them at random. You may cast it without paying its mana cost.
|
||||||
this.addAbility(new ConditionalInterveningIfTriggeredAbility(
|
this.addAbility(new BeginningOfUpkeepTriggeredAbility(
|
||||||
new BeginningOfUpkeepTriggeredAbility(
|
new RiverSongsDiaryCastEffect()
|
||||||
new RiverSongsDiaryCastEffect()
|
.setText("choose one of them at random. You may cast it without paying its mana cost.")
|
||||||
), RiverSongsDiaryCondition.instance,
|
).withInterveningIf(RiverSongsDiaryCondition.instance)
|
||||||
"At the beginning of your upkeep, if there are four or more cards exiled with " +
|
.addHint(RiverSongsDiaryExiledSpellsCount.getHint())
|
||||||
" {this}, choose one of them at random. You may cast it without paying its mana cost."
|
);
|
||||||
).addHint(RiverSongsDiaryExiledSpellsCount.getHint()));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private RiverSongsDiary(final RiverSongsDiary card) {
|
private RiverSongsDiary(final RiverSongsDiary card) {
|
||||||
|
|
@ -76,7 +71,6 @@ enum RiverSongsDiaryCondition implements Condition {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "there are four or more cards exiled with {this}";
|
return "there are four or more cards exiled with {this}";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum RiverSongsDiaryExiledSpellsCount implements DynamicValue {
|
enum RiverSongsDiaryExiledSpellsCount implements DynamicValue {
|
||||||
|
|
@ -152,22 +146,26 @@ class RiverSongsDiaryImprintAbility extends TriggeredAbilityImpl {
|
||||||
|
|
||||||
class RiverSongsDiaryExileEffect extends ReplacementEffectImpl {
|
class RiverSongsDiaryExileEffect extends ReplacementEffectImpl {
|
||||||
|
|
||||||
private final MageObjectReference mor;
|
// we store both Spell and Card to work properly on split cards
|
||||||
|
private final MageObjectReference morSpell;
|
||||||
|
private final MageObjectReference morCard;
|
||||||
|
|
||||||
RiverSongsDiaryExileEffect(Spell spell, Game game) {
|
RiverSongsDiaryExileEffect(Spell spell, Game game) {
|
||||||
super(Duration.OneUse, Outcome.Benefit);
|
super(Duration.OneUse, Outcome.Benefit);
|
||||||
this.mor = new MageObjectReference(spell.getCard(), game);
|
this.morSpell = new MageObjectReference(spell.getCard(), game);
|
||||||
|
this.morCard = new MageObjectReference(spell.getMainCard(), game);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RiverSongsDiaryExileEffect(final RiverSongsDiaryExileEffect effect) {
|
private RiverSongsDiaryExileEffect(final RiverSongsDiaryExileEffect effect) {
|
||||||
super(effect);
|
super(effect);
|
||||||
this.mor = effect.mor;
|
this.morSpell = effect.morSpell;
|
||||||
|
this.morCard = effect.morCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||||
Player player = game.getPlayer(source.getControllerId());
|
Player player = game.getPlayer(source.getControllerId());
|
||||||
Spell sourceSpell = game.getStack().getSpell(event.getTargetId());
|
Spell sourceSpell = morSpell.getSpell(game);
|
||||||
if (player == null || sourceSpell == null || sourceSpell.isCopy()) {
|
if (player == null || sourceSpell == null || sourceSpell.isCopy()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -187,14 +185,10 @@ class RiverSongsDiaryExileEffect extends ReplacementEffectImpl {
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||||
ZoneChangeEvent zEvent = ((ZoneChangeEvent) event);
|
ZoneChangeEvent zEvent = ((ZoneChangeEvent) event);
|
||||||
if (zEvent.getFromZone() != Zone.STACK
|
return Zone.STACK.equals(zEvent.getFromZone())
|
||||||
|| zEvent.getToZone() != Zone.GRAVEYARD
|
&& Zone.GRAVEYARD.equals(zEvent.getToZone())
|
||||||
|| event.getSourceId() == null
|
&& morSpell.refersTo(event.getSourceId(), game) // this is how we check that the spell resolved properly (and was not countered or the like)
|
||||||
|| !event.getSourceId().equals(event.getTargetId())
|
&& morCard.refersTo(event.getTargetId(), game); // this is how we check that the card being moved is the one we want.
|
||||||
|| !mor.equals(new MageObjectReference(event.getTargetId(), game))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue