* Haldan, Avid Arcanist - fixed rollback error on usage without partner;

This commit is contained in:
Oleg Agafonov 2021-02-22 08:03:27 +04:00
parent 65ad97ced5
commit 4f7631f0f0
2 changed files with 37 additions and 33 deletions

View file

@ -38,7 +38,7 @@ public final class HaldanAvidArcanist extends CardImpl {
// exiled them, and you may spend mana as though it were mana of any color to cast those spells.
Ability ability = new SimpleStaticAbility(new HaldanAvidArcanistCastFromExileEffect());
ability.addEffect(new HaldanAvidArcanistSpendAnyManaEffect());
this.addAbility(ability);
this.addAbility(ability, PakoArcaneRetriever.createWatcher());
}
private HaldanAvidArcanist(final HaldanAvidArcanist card) {
@ -48,7 +48,7 @@ public final class HaldanAvidArcanist extends CardImpl {
@Override
public HaldanAvidArcanist copy() {
return new HaldanAvidArcanist(this);
}
}
}
class HaldanAvidArcanistCastFromExileEffect extends AsThoughEffectImpl {
@ -74,13 +74,13 @@ class HaldanAvidArcanistCastFromExileEffect extends AsThoughEffectImpl {
@Override
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
Card card = game.getCard(sourceId);
if (card == null || !source.isControlledBy(affectedControllerId)
|| game.getState().getZone(sourceId) != Zone.EXILED
|| !PakoArcaneRetriever.checkWatcher(affectedControllerId, card, game)) {
return false;
}
return !card.isCreature() && card.getCounters(game).containsKey(CounterType.FETCH);
Card card = game.getCard(sourceId);
if (card == null || !source.isControlledBy(affectedControllerId)
|| game.getState().getZone(sourceId) != Zone.EXILED
|| !PakoArcaneRetriever.checkWatcher(affectedControllerId, card, game)) {
return false;
}
return !card.isCreature() && card.getCounters(game).containsKey(CounterType.FETCH);
}
}
@ -107,17 +107,17 @@ class HaldanAvidArcanistSpendAnyManaEffect extends AsThoughEffectImpl implements
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
// The card may be on the stack, in which case it will not have a fetch counter
// on it. In this case, we will have to rely on the watcher to tell us whether
// or not it is a valid card to apply the effect to.
Zone zone;
Card card = game.getCard(objectId);
if (card == null || !source.isControlledBy(affectedControllerId)
|| (zone = game.getState().getZone(objectId)) != Zone.EXILED && zone != Zone.STACK
|| !PakoArcaneRetriever.checkWatcher(affectedControllerId, card, game)) {
return false;
}
return !card.isCreature() && (card.getCounters(game).containsKey(CounterType.FETCH) || zone == Zone.STACK);
// The card may be on the stack, in which case it will not have a fetch counter
// on it. In this case, we will have to rely on the watcher to tell us whether
// or not it is a valid card to apply the effect to.
Zone zone;
Card card = game.getCard(objectId);
if (card == null || !source.isControlledBy(affectedControllerId)
|| (zone = game.getState().getZone(objectId)) != Zone.EXILED && zone != Zone.STACK
|| !PakoArcaneRetriever.checkWatcher(affectedControllerId, card, game)) {
return false;
}
return !card.isCreature() && (card.getCounters(game).containsKey(CounterType.FETCH) || zone == Zone.STACK);
}
@Override

View file

@ -58,6 +58,10 @@ public final class PakoArcaneRetriever extends CardImpl {
PakoArcaneRetrieverWatcher watcher = game.getState().getWatcher(PakoArcaneRetrieverWatcher.class);
return watcher != null && watcher.checkCard(playerId, card, game);
}
public static Watcher createWatcher() {
return new PakoArcaneRetrieverWatcher();
}
}
class PakoArcaneRetrieverEffect extends OneShotEffect {
@ -124,23 +128,23 @@ class PakoArcaneRetrieverWatcher extends Watcher {
}
void addCard(UUID playerId, Card card, Game game) {
playerMap.computeIfAbsent(playerId, u -> new HashSet<MageObjectReference>())
.add(new MageObjectReference(card, game));
playerMap.computeIfAbsent(playerId, u -> new HashSet<MageObjectReference>())
.add(new MageObjectReference(card, game));
}
boolean checkCard(UUID playerId, Card card, Game game) {
if (card == null)
return false;
if (card == null)
return false;
// If the card has been moved onto the stack (e.g. by attempting to cast), the
// number of zone change counters will be 1 more than when the pako effect
// exiled it and the watcher took a reference.
// https://github.com/magefree/mage/issues/7585
final int zoneChangeDifference = game.getState().getZone(card.getId()) == Zone.STACK ? 1 : 0;
return playerMap.computeIfAbsent(playerId, u -> new HashSet<MageObjectReference>())
// If the card has been moved onto the stack (e.g. by attempting to cast), the
// number of zone change counters will be 1 more than when the pako effect
// exiled it and the watcher took a reference.
// https://github.com/magefree/mage/issues/7585
final int zoneChangeDifference = game.getState().getZone(card.getId()) == Zone.STACK ? 1 : 0;
return playerMap.computeIfAbsent(playerId, u -> new HashSet<MageObjectReference>())
.stream()
.anyMatch(ref -> ref.getSourceId().equals(card.getId())
&& ref.getZoneChangeCounter() == (game.getState().getZoneChangeCounter(card.getId())
- zoneChangeDifference));
.anyMatch(ref -> ref.getSourceId().equals(card.getId())
&& ref.getZoneChangeCounter() == (game.getState().getZoneChangeCounter(card.getId())
- zoneChangeDifference));
}
}