mirror of
https://github.com/correl/mage.git
synced 2024-12-26 11:09:27 +00:00
* Ethersworn Canonist - Code cleanup.
This commit is contained in:
parent
cfcefb3877
commit
da0080e2e1
1 changed files with 23 additions and 22 deletions
|
@ -27,10 +27,11 @@
|
||||||
*/
|
*/
|
||||||
package mage.sets.shardsofalara;
|
package mage.sets.shardsofalara;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
|
import mage.MageObject;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
|
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
|
||||||
|
@ -44,6 +45,7 @@ import mage.constants.WatcherScope;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
|
import mage.game.stack.Spell;
|
||||||
import mage.watchers.Watcher;
|
import mage.watchers.Watcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,29 +79,30 @@ public class EtherswornCanonist extends CardImpl {
|
||||||
|
|
||||||
class EtherswornCanonistWatcher extends Watcher {
|
class EtherswornCanonistWatcher extends Watcher {
|
||||||
|
|
||||||
private Map<UUID, Boolean> castNonartifactSpell = new HashMap<>();
|
private Set<UUID> castNonartifactSpell = new HashSet<>();
|
||||||
|
|
||||||
public EtherswornCanonistWatcher() {
|
public EtherswornCanonistWatcher() {
|
||||||
super("EtherswornCanonistWatcher", WatcherScope.GAME);
|
super(EtherswornCanonistWatcher.class.getName(), WatcherScope.GAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EtherswornCanonistWatcher(final EtherswornCanonistWatcher watcher) {
|
public EtherswornCanonistWatcher(final EtherswornCanonistWatcher watcher) {
|
||||||
super(watcher);
|
super(watcher);
|
||||||
for (Map.Entry<UUID, Boolean> entry: watcher.castNonartifactSpell.entrySet()) {
|
this.castNonartifactSpell.addAll(watcher.castNonartifactSpell);
|
||||||
castNonartifactSpell.put(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void watch(GameEvent event, Game game) {
|
public void watch(GameEvent event, Game game) {
|
||||||
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
|
if (event.getType() == GameEvent.EventType.SPELL_CAST && event.getPlayerId() != null) {
|
||||||
Card card = game.getCard(event.getSourceId());
|
Spell spell = game.getStack().getSpell(event.getTargetId());
|
||||||
if(card != null && !card.getCardType().contains(CardType.ARTIFACT)){
|
if (spell == null) {
|
||||||
UUID playerId = event.getPlayerId();
|
MageObject mageObject = game.getLastKnownInformation(event.getTargetId(), Zone.STACK);
|
||||||
if (playerId != null) {
|
if (mageObject instanceof Spell) {
|
||||||
castNonartifactSpell.put(playerId, true);
|
spell = (Spell) mageObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (spell != null && !spell.getCardType().contains(CardType.ARTIFACT)) {
|
||||||
|
castNonartifactSpell.add(event.getPlayerId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,12 +111,10 @@ class EtherswornCanonistWatcher extends Watcher {
|
||||||
castNonartifactSpell.clear();
|
castNonartifactSpell.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean castNonArtifactSpell(UUID player){
|
public boolean castNonArtifactSpell(UUID playerId) {
|
||||||
Boolean value = castNonartifactSpell.get(player);
|
return castNonartifactSpell.contains(playerId);
|
||||||
return value != null && value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EtherswornCanonistWatcher copy() {
|
public EtherswornCanonistWatcher copy() {
|
||||||
return new EtherswornCanonistWatcher(this);
|
return new EtherswornCanonistWatcher(this);
|
||||||
|
@ -144,7 +145,7 @@ class EtherswornCanonistReplacementEffect extends ContinuousRuleModifyingEffectI
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||||
EtherswornCanonistWatcher watcher = (EtherswornCanonistWatcher)game.getState().getWatchers().get("EtherswornCanonistWatcher");
|
EtherswornCanonistWatcher watcher = (EtherswornCanonistWatcher) game.getState().getWatchers().get(EtherswornCanonistWatcher.class.getName());
|
||||||
Card card = game.getCard(event.getSourceId());
|
Card card = game.getCard(event.getSourceId());
|
||||||
if (card != null && !card.getCardType().contains(CardType.ARTIFACT) && watcher.castNonArtifactSpell(event.getPlayerId())) {
|
if (card != null && !card.getCardType().contains(CardType.ARTIFACT) && watcher.castNonArtifactSpell(event.getPlayerId())) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue