mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
FirstSpellCastThisTurnWatcher refactored. Typo fix in Jace
This commit is contained in:
parent
e225bb2643
commit
44e125e604
3 changed files with 75 additions and 66 deletions
|
@ -27,8 +27,6 @@
|
||||||
*/
|
*/
|
||||||
package mage.sets.alarareborn;
|
package mage.sets.alarareborn;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
|
@ -41,15 +39,13 @@ import mage.constants.Layer;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.constants.Rarity;
|
import mage.constants.Rarity;
|
||||||
import mage.constants.SubLayer;
|
import mage.constants.SubLayer;
|
||||||
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.EventType;
|
|
||||||
import mage.game.stack.Spell;
|
import mage.game.stack.Spell;
|
||||||
import mage.game.stack.StackObject;
|
import mage.game.stack.StackObject;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.watchers.Watcher;
|
import mage.watchers.common.FirstSpellCastThisTurnWatcher;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -63,7 +59,6 @@ public class MaelstromNexus extends CardImpl {
|
||||||
|
|
||||||
// The first spell you cast each turn has cascade.
|
// The first spell you cast each turn has cascade.
|
||||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new MaelstromNexusGainCascadeFirstSpellEffect()), new FirstSpellCastThisTurnWatcher());
|
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new MaelstromNexusGainCascadeFirstSpellEffect()), new FirstSpellCastThisTurnWatcher());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MaelstromNexus(final MaelstromNexus card) {
|
public MaelstromNexus(final MaelstromNexus card) {
|
||||||
|
@ -112,55 +107,4 @@ class MaelstromNexusGainCascadeFirstSpellEffect extends ContinuousEffectImpl {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FirstSpellCastThisTurnWatcher extends Watcher {
|
|
||||||
|
|
||||||
Map<UUID, UUID> playerFirstSpellCast = new HashMap<>();
|
|
||||||
Map<UUID, UUID> playerFirstCastSpell = new HashMap<>();
|
|
||||||
|
|
||||||
public FirstSpellCastThisTurnWatcher() {
|
|
||||||
super("FirstSpellCastThisTurn", WatcherScope.GAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FirstSpellCastThisTurnWatcher(final FirstSpellCastThisTurnWatcher watcher) {
|
|
||||||
super(watcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void watch(GameEvent event, Game game) {
|
|
||||||
switch (event.getType()) {
|
|
||||||
case SPELL_CAST:
|
|
||||||
case CAST_SPELL:
|
|
||||||
Spell spell = (Spell) game.getObject(event.getTargetId());
|
|
||||||
if (spell != null && !playerFirstSpellCast.containsKey(spell.getControllerId())) {
|
|
||||||
if (event.getType().equals(EventType.SPELL_CAST)) {
|
|
||||||
playerFirstSpellCast.put(spell.getControllerId(), spell.getId());
|
|
||||||
} else if (event.getType().equals(EventType.CAST_SPELL)) {
|
|
||||||
playerFirstCastSpell.put(spell.getControllerId(), spell.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FirstSpellCastThisTurnWatcher copy() {
|
|
||||||
return new FirstSpellCastThisTurnWatcher(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reset() {
|
|
||||||
super.reset();
|
|
||||||
playerFirstSpellCast.clear();
|
|
||||||
playerFirstCastSpell.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getIdOfFirstCastSpell(UUID playerId) {
|
|
||||||
if (playerFirstSpellCast.get(playerId) == null) {
|
|
||||||
return playerFirstCastSpell.get(playerId);
|
|
||||||
} else {
|
|
||||||
return playerFirstSpellCast.get(playerId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -99,23 +99,23 @@ class JaceUnravelerOfSecretsEmblem extends Emblem {
|
||||||
this.setName("EMBLEM: Jace, Unraveler of Secrets");
|
this.setName("EMBLEM: Jace, Unraveler of Secrets");
|
||||||
Effect effect = new CounterTargetEffect();
|
Effect effect = new CounterTargetEffect();
|
||||||
effect.setText("counter that spell");
|
effect.setText("counter that spell");
|
||||||
this.getAbilities().add(new JaceUnravelerOfSecretsTriggertAbility(effect, false));
|
this.getAbilities().add(new JaceUnravelerOfSecretsTriggeredAbility(effect, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class JaceUnravelerOfSecretsTriggertAbility extends SpellCastOpponentTriggeredAbility {
|
class JaceUnravelerOfSecretsTriggeredAbility extends SpellCastOpponentTriggeredAbility {
|
||||||
|
|
||||||
public JaceUnravelerOfSecretsTriggertAbility(Effect effect, boolean optional) {
|
public JaceUnravelerOfSecretsTriggeredAbility(Effect effect, boolean optional) {
|
||||||
super(effect, optional);
|
super(effect, optional);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JaceUnravelerOfSecretsTriggertAbility(SpellCastOpponentTriggeredAbility ability) {
|
public JaceUnravelerOfSecretsTriggeredAbility(SpellCastOpponentTriggeredAbility ability) {
|
||||||
super(ability);
|
super(ability);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SpellCastOpponentTriggeredAbility copy() {
|
public SpellCastOpponentTriggeredAbility copy() {
|
||||||
return super.copy(); //To change body of generated methods, choose Tools | Templates.
|
return super.copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -137,5 +137,4 @@ class JaceUnravelerOfSecretsTriggertAbility extends SpellCastOpponentTriggeredAb
|
||||||
public String getRule() {
|
public String getRule() {
|
||||||
return "Whenever an opponent casts his or her first spell each turn, counter that spell.";
|
return "Whenever an opponent casts his or her first spell each turn, counter that spell.";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
package mage.watchers.common;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import mage.constants.WatcherScope;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.game.events.GameEvent;
|
||||||
|
import mage.game.events.GameEvent.EventType;
|
||||||
|
import static mage.game.events.GameEvent.EventType.CAST_SPELL;
|
||||||
|
import static mage.game.events.GameEvent.EventType.SPELL_CAST;
|
||||||
|
import mage.game.stack.Spell;
|
||||||
|
import mage.watchers.Watcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jeffwadsworth
|
||||||
|
**/
|
||||||
|
public class FirstSpellCastThisTurnWatcher extends Watcher {
|
||||||
|
|
||||||
|
private final Map<UUID, UUID> playerFirstSpellCast = new HashMap<>();
|
||||||
|
private final Map<UUID, UUID> playerFirstCastSpell = new HashMap<>();
|
||||||
|
|
||||||
|
public FirstSpellCastThisTurnWatcher() {
|
||||||
|
super("FirstSpellCastThisTurn", WatcherScope.GAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FirstSpellCastThisTurnWatcher(final FirstSpellCastThisTurnWatcher watcher) {
|
||||||
|
super(watcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void watch(GameEvent event, Game game) {
|
||||||
|
switch (event.getType()) {
|
||||||
|
case SPELL_CAST:
|
||||||
|
case CAST_SPELL:
|
||||||
|
Spell spell = (Spell) game.getObject(event.getTargetId());
|
||||||
|
if (spell != null && !playerFirstSpellCast.containsKey(spell.getControllerId())) {
|
||||||
|
if (event.getType().equals(EventType.SPELL_CAST)) {
|
||||||
|
playerFirstSpellCast.put(spell.getControllerId(), spell.getId());
|
||||||
|
} else if (event.getType().equals(EventType.CAST_SPELL)) {
|
||||||
|
playerFirstCastSpell.put(spell.getControllerId(), spell.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FirstSpellCastThisTurnWatcher copy() {
|
||||||
|
return new FirstSpellCastThisTurnWatcher(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
super.reset();
|
||||||
|
playerFirstSpellCast.clear();
|
||||||
|
playerFirstCastSpell.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getIdOfFirstCastSpell(UUID playerId) {
|
||||||
|
if (playerFirstSpellCast.get(playerId) == null) {
|
||||||
|
return playerFirstCastSpell.get(playerId);
|
||||||
|
} else {
|
||||||
|
return playerFirstSpellCast.get(playerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue