refactor: removed spell usage in watcher and cost (related to #11572, #11575);

This commit is contained in:
Oleg Agafonov 2024-01-13 12:05:33 +04:00
parent 95481cd736
commit de21d0ee02
2 changed files with 20 additions and 22 deletions

View file

@ -1,7 +1,7 @@
package mage.cards.m; package mage.cards.m;
import mage.MageObject; import mage.MageObject;
import mage.ObjectColor;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.SpellAbility; import mage.abilities.SpellAbility;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
@ -18,7 +18,6 @@ import mage.watchers.Watcher;
import java.util.UUID; import java.util.UUID;
/** /**
*
* @author jeffwadsworth * @author jeffwadsworth
*/ */
public final class ManaMaze extends CardImpl { public final class ManaMaze extends CardImpl {
@ -65,8 +64,8 @@ class ManaMazeEffect extends ContinuousRuleModifyingEffectImpl {
Card card = spellAbility.getCharacteristics(game); Card card = spellAbility.getCharacteristics(game);
if (card != null) { if (card != null) {
LastSpellCastWatcher watcher = game.getState().getWatcher(LastSpellCastWatcher.class); LastSpellCastWatcher watcher = game.getState().getWatcher(LastSpellCastWatcher.class);
if (watcher != null && watcher.getLastSpellCast() != null) { if (watcher != null && watcher.getLastSpellColor() != null) {
return !card.getColor(game).intersection(watcher.getLastSpellCast().getColor(game)).isColorless(); return !card.getColor(game).intersection(watcher.getLastSpellColor()).isColorless();
} }
} }
return false; return false;
@ -80,7 +79,7 @@ class ManaMazeEffect extends ContinuousRuleModifyingEffectImpl {
class LastSpellCastWatcher extends Watcher { class LastSpellCastWatcher extends Watcher {
private Spell lastSpellCast = null; private ObjectColor lastSpellColor = null;
public LastSpellCastWatcher() { public LastSpellCastWatcher() {
super(WatcherScope.GAME); super(WatcherScope.GAME);
@ -97,7 +96,7 @@ class LastSpellCastWatcher extends Watcher {
} }
} }
if (spell != null) { if (spell != null) {
lastSpellCast = spell; this.lastSpellColor = spell.getColor(game);
} }
} }
} }
@ -105,10 +104,10 @@ class LastSpellCastWatcher extends Watcher {
@Override @Override
public void reset() { public void reset() {
super.reset(); super.reset();
lastSpellCast = null; this.lastSpellColor = null;
} }
public Spell getLastSpellCast() { public ObjectColor getLastSpellColor() {
return lastSpellCast; return this.lastSpellColor;
} }
} }

View file

@ -58,7 +58,7 @@ class SynthesisPodCost extends CostImpl {
filter.add(TargetController.YOU.getControllerPredicate()); filter.add(TargetController.YOU.getControllerPredicate());
} }
private Spell exiledSpell = null; private Integer exiledSpellManaValue = null;
SynthesisPodCost() { SynthesisPodCost() {
super(); super();
@ -84,11 +84,11 @@ class SynthesisPodCost extends CostImpl {
return false; return false;
} }
String spellName = spell.getName(); String spellName = spell.getName();
exiledSpell = spell; this.exiledSpellManaValue = spell.getManaValue();
player.moveCards(spell.getCard(), Zone.EXILED, source, game); player.moveCards(spell.getCard(), Zone.EXILED, source, game);
paid = true; this.paid = true;
game.informPlayers(player.getLogName() + " exiles " + spellName + " (as costs)"); game.informPlayers(player.getLogName() + " exiles " + spellName + " (as costs)");
return paid; return this.paid;
} }
@Override @Override
@ -101,8 +101,8 @@ class SynthesisPodCost extends CostImpl {
return new SynthesisPodCost(this); return new SynthesisPodCost(this);
} }
Spell getExiledSpell() { public Integer getExiledSpellManaValue() {
return exiledSpell; return this.exiledSpellManaValue;
} }
} }
@ -128,17 +128,16 @@ class SynthesisPodEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source)); Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
Spell spell = CardUtil Integer exiledSpellManaValue = CardUtil
.castStream(source.getCosts(), SynthesisPodCost.class) .castStream(source.getCosts(), SynthesisPodCost.class)
.map(SynthesisPodCost::getExiledSpell) .map(SynthesisPodCost::getExiledSpellManaValue)
.findFirst() .findFirst()
.orElse(null); .orElse(null);
if (controller == null || opponent == null || spell == null) { if (controller == null || opponent == null || exiledSpellManaValue == null) {
return false; return false;
} }
int mv = spell.getManaValue();
Cards cards = new CardsImpl(); Cards cards = new CardsImpl();
Card card = getCard(mv, opponent, cards, game); Card card = getCard(exiledSpellManaValue, opponent, cards, game);
opponent.revealCards(source, cards, game); opponent.revealCards(source, cards, game);
if (card != null) { if (card != null) {
controller.moveCards(card, Zone.EXILED, source, game); controller.moveCards(card, Zone.EXILED, source, game);
@ -150,10 +149,10 @@ class SynthesisPodEffect extends OneShotEffect {
return true; return true;
} }
private static Card getCard(int mv, Player opponent, Cards cards, Game game) { private static Card getCard(int exiledSpellManaValue, Player opponent, Cards cards, Game game) {
for (Card card : opponent.getLibrary().getCards(game)) { for (Card card : opponent.getLibrary().getCards(game)) {
cards.add(card); cards.add(card);
if (card.getManaValue() == mv + 1) { if (card.getManaValue() == exiledSpellManaValue + 1) {
return card; return card;
} }
} }