From 74e0f76b1abb8146376cb91d8eec21a0eda9374c Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 27 Oct 2014 20:28:14 +0100 Subject: [PATCH] * Angelic Arbiter - Fixed handling of the restriction effects. --- .../mage/sets/magic2011/AngelicArbiter.java | 76 +++++++++---------- .../common/AttackedThisTurnWatcher.java | 7 +- .../common/CastSpellLastTurnWatcher.java | 8 +- 3 files changed, 43 insertions(+), 48 deletions(-) diff --git a/Mage.Sets/src/mage/sets/magic2011/AngelicArbiter.java b/Mage.Sets/src/mage/sets/magic2011/AngelicArbiter.java index efff118418..96690bbdbb 100644 --- a/Mage.Sets/src/mage/sets/magic2011/AngelicArbiter.java +++ b/Mage.Sets/src/mage/sets/magic2011/AngelicArbiter.java @@ -28,13 +28,9 @@ package mage.sets.magic2011; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.Rarity; -import mage.constants.WatcherScope; -import mage.constants.Zone; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; @@ -42,11 +38,18 @@ import mage.abilities.effects.ContinuousRuleModifiyingEffectImpl; import mage.abilities.effects.RestrictionEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.WatcherScope; +import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.watchers.Watcher; +import mage.watchers.common.CastSpellLastTurnWatcher; /** * @@ -67,7 +70,7 @@ public class AngelicArbiter extends CardImpl { // Each opponent who cast a spell this turn can't attack with creatures. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AngelicArbiterCantAttackTargetEffect(Duration.WhileOnBattlefield))); - this.addWatcher(new AngelicArbiterWatcher1()); + // Each opponent who attacked with a creature this turn can't cast spells. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AngelicArbiterEffect2())); this.addWatcher(new AngelicArbiterWatcher2()); @@ -84,41 +87,17 @@ public class AngelicArbiter extends CardImpl { } -class AngelicArbiterWatcher1 extends Watcher { - - public AngelicArbiterWatcher1() { - super("OpponentCastSpell", WatcherScope.PLAYER); - } - - public AngelicArbiterWatcher1(final AngelicArbiterWatcher1 watcher) { - super(watcher); - } - - @Override - public AngelicArbiterWatcher1 copy() { - return new AngelicArbiterWatcher1(this); - } - - @Override - public void watch(GameEvent event, Game game) { - if (condition == true) { //no need to check - condition has already occured - return; - } - if (event.getType() == EventType.SPELL_CAST && game.getActivePlayerId().equals(event.getPlayerId()) && game.getOpponents(controllerId).contains(event.getPlayerId())) { - condition = true; - } - } - -} - class AngelicArbiterWatcher2 extends Watcher { + private final Set playersThatAttackedThisTurn = new HashSet<>(); + public AngelicArbiterWatcher2() { - super("OpponentAttacked", WatcherScope.PLAYER); + super("PlayerAttacked", WatcherScope.GAME); } public AngelicArbiterWatcher2(final AngelicArbiterWatcher2 watcher) { super(watcher); + this.playersThatAttackedThisTurn.addAll(watcher.playersThatAttackedThisTurn); } @Override @@ -128,10 +107,25 @@ class AngelicArbiterWatcher2 extends Watcher { @Override public void watch(GameEvent event, Game game) { - if (event.getType() == EventType.DECLARED_ATTACKERS && game.getActivePlayerId().equals(event.getPlayerId()) && game.getOpponents(controllerId).contains(event.getPlayerId())) { - condition = true; + if (event.getType() == EventType.DECLARED_ATTACKERS + && game.getActivePlayerId().equals(event.getPlayerId()) + && game.getOpponents(controllerId).contains(event.getPlayerId()) + && game.getCombat().getAttackerId().equals(event.getPlayerId()) + && game.getCombat().getAttackers().size() > 0) { + playersThatAttackedThisTurn.add(event.getPlayerId()); } } + + @Override + public void reset() { + super.reset(); + playersThatAttackedThisTurn.clear(); + } + + + public boolean hasPlayerAttackedThisTurn(UUID playerId) { + return playersThatAttackedThisTurn.contains(playerId); + } } class AngelicArbiterCantAttackTargetEffect extends RestrictionEffect { @@ -148,8 +142,8 @@ class AngelicArbiterCantAttackTargetEffect extends RestrictionEffect { @Override public boolean applies(Permanent permanent, Ability source, Game game) { if (game.getActivePlayerId().equals(permanent.getControllerId()) && game.getOpponents(source.getControllerId()).contains(permanent.getControllerId())) { - Watcher watcher = game.getState().getWatchers().get("OpponentCastSpell", source.getControllerId()); - if (watcher != null && watcher.conditionMet()) { + CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher"); + if (watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(permanent.getControllerId()) > 0) { return true; } } @@ -191,8 +185,8 @@ class AngelicArbiterEffect2 extends ContinuousRuleModifiyingEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { if (event.getType() == EventType.CAST_SPELL && game.getActivePlayerId().equals(event.getPlayerId()) && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { - Watcher watcher = game.getState().getWatchers().get("OpponentAttacked", source.getControllerId()); - if (watcher != null && watcher.conditionMet()) { + AngelicArbiterWatcher2 watcher = (AngelicArbiterWatcher2) game.getState().getWatchers().get("PlayerAttacked"); + if (watcher != null && watcher.hasPlayerAttackedThisTurn(event.getPlayerId())) { return true; } } diff --git a/Mage/src/mage/watchers/common/AttackedThisTurnWatcher.java b/Mage/src/mage/watchers/common/AttackedThisTurnWatcher.java index 5a92bb5155..be9dac0356 100644 --- a/Mage/src/mage/watchers/common/AttackedThisTurnWatcher.java +++ b/Mage/src/mage/watchers/common/AttackedThisTurnWatcher.java @@ -27,15 +27,14 @@ */ package mage.watchers.common; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; import mage.constants.WatcherScope; import mage.game.Game; import mage.game.events.GameEvent; import mage.watchers.Watcher; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - /** * @author magenoxx_at_gmail.com */ diff --git a/Mage/src/mage/watchers/common/CastSpellLastTurnWatcher.java b/Mage/src/mage/watchers/common/CastSpellLastTurnWatcher.java index d5800980ea..bb2d579a30 100644 --- a/Mage/src/mage/watchers/common/CastSpellLastTurnWatcher.java +++ b/Mage/src/mage/watchers/common/CastSpellLastTurnWatcher.java @@ -28,16 +28,18 @@ package mage.watchers.common; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.UUID; import mage.constants.WatcherScope; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.stack.Spell; import mage.watchers.Watcher; - - /** * * @author nantuko, BetaSteward_at_googlemail.com