mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
Foxed some EntersBattlefieldTriggeredAbilities with Intervening-If-Clause not handled correctly.
This commit is contained in:
parent
b19b43c4c8
commit
570a6d92dc
9 changed files with 93 additions and 99 deletions
|
|
@ -6,7 +6,7 @@ import mage.constants.Zone;
|
|||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.watchers.Watcher;
|
||||
import mage.watchers.common.CastFromHandWatcher;
|
||||
|
||||
/**
|
||||
* Warning: CastFromHandWatcher must be installed to card for proper working.
|
||||
|
|
@ -31,9 +31,8 @@ public class CastFromHandCondition implements Condition {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
// Probably watcher is no longer needed
|
||||
Watcher watcher = game.getState().getWatchers().get("CastFromHand", source.getSourceId());
|
||||
if (watcher != null && watcher.conditionMet()) {
|
||||
CastFromHandWatcher watcher = (CastFromHandWatcher) game.getState().getWatchers().get(CastFromHandWatcher.class.getName(), source.getSourceId());
|
||||
if (watcher != null && watcher.spellWasCastFromHand(source.getSourceId()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,23 @@
|
|||
package mage.watchers.common;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.game.turn.Step;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
public class CastFromHandWatcher extends Watcher {
|
||||
|
||||
private final Set<UUID> spellsCastFromHand = new HashSet<>();
|
||||
private Step step;
|
||||
|
||||
public CastFromHandWatcher() {
|
||||
super("CastFromHand", WatcherScope.CARD);
|
||||
super(CastFromHandWatcher.class.getName(), WatcherScope.GAME);
|
||||
}
|
||||
|
||||
public CastFromHandWatcher(final CastFromHandWatcher watcher) {
|
||||
|
|
@ -18,14 +26,35 @@ public class CastFromHandWatcher extends Watcher {
|
|||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.SPELL_CAST && event.getZone() == Zone.HAND) {
|
||||
/**
|
||||
* This does still not handle if a spell is cast from hand and comes to
|
||||
* play from other zones during the same step. But at least the state is
|
||||
* reset if the game comes to a new step
|
||||
*/
|
||||
|
||||
if (step != null && game.getTurn().getStep() != step) {
|
||||
spellsCastFromHand.clear();
|
||||
step = null;
|
||||
}
|
||||
if (event.getType() == GameEvent.EventType.SPELL_CAST && event.getZone().equals(Zone.HAND)) {
|
||||
step = game.getTurn().getStep();
|
||||
Spell spell = (Spell) game.getObject(event.getTargetId());
|
||||
if (this.getSourceId().equals(spell.getSourceId())) {
|
||||
condition = true;
|
||||
condition = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean spellWasCastFromHand(UUID sourceId) {
|
||||
return spellsCastFromHand.contains(sourceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
spellsCastFromHand.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CastFromHandWatcher copy() {
|
||||
return new CastFromHandWatcher(this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue