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

View file

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