mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
* Angelic Arbiter - Fixed handling of the restriction effects.
This commit is contained in:
parent
aff9eb4c33
commit
74e0f76b1a
3 changed files with 43 additions and 48 deletions
|
@ -28,13 +28,9 @@
|
||||||
|
|
||||||
package mage.sets.magic2011;
|
package mage.sets.magic2011;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
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.MageInt;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
|
@ -42,11 +38,18 @@ import mage.abilities.effects.ContinuousRuleModifiyingEffectImpl;
|
||||||
import mage.abilities.effects.RestrictionEffect;
|
import mage.abilities.effects.RestrictionEffect;
|
||||||
import mage.abilities.keyword.FlyingAbility;
|
import mage.abilities.keyword.FlyingAbility;
|
||||||
import mage.cards.CardImpl;
|
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.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.events.GameEvent.EventType;
|
import mage.game.events.GameEvent.EventType;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.watchers.Watcher;
|
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.
|
// Each opponent who cast a spell this turn can't attack with creatures.
|
||||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AngelicArbiterCantAttackTargetEffect(Duration.WhileOnBattlefield)));
|
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.
|
// Each opponent who attacked with a creature this turn can't cast spells.
|
||||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AngelicArbiterEffect2()));
|
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AngelicArbiterEffect2()));
|
||||||
this.addWatcher(new AngelicArbiterWatcher2());
|
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 {
|
class AngelicArbiterWatcher2 extends Watcher {
|
||||||
|
|
||||||
|
private final Set<UUID> playersThatAttackedThisTurn = new HashSet<>();
|
||||||
|
|
||||||
public AngelicArbiterWatcher2() {
|
public AngelicArbiterWatcher2() {
|
||||||
super("OpponentAttacked", WatcherScope.PLAYER);
|
super("PlayerAttacked", WatcherScope.GAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AngelicArbiterWatcher2(final AngelicArbiterWatcher2 watcher) {
|
public AngelicArbiterWatcher2(final AngelicArbiterWatcher2 watcher) {
|
||||||
super(watcher);
|
super(watcher);
|
||||||
|
this.playersThatAttackedThisTurn.addAll(watcher.playersThatAttackedThisTurn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -128,10 +107,25 @@ class AngelicArbiterWatcher2 extends Watcher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void watch(GameEvent event, Game game) {
|
public void watch(GameEvent event, Game game) {
|
||||||
if (event.getType() == EventType.DECLARED_ATTACKERS && game.getActivePlayerId().equals(event.getPlayerId()) && game.getOpponents(controllerId).contains(event.getPlayerId())) {
|
if (event.getType() == EventType.DECLARED_ATTACKERS
|
||||||
condition = true;
|
&& 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 {
|
class AngelicArbiterCantAttackTargetEffect extends RestrictionEffect {
|
||||||
|
@ -148,8 +142,8 @@ class AngelicArbiterCantAttackTargetEffect extends RestrictionEffect {
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(Permanent permanent, Ability source, Game game) {
|
public boolean applies(Permanent permanent, Ability source, Game game) {
|
||||||
if (game.getActivePlayerId().equals(permanent.getControllerId()) && game.getOpponents(source.getControllerId()).contains(permanent.getControllerId())) {
|
if (game.getActivePlayerId().equals(permanent.getControllerId()) && game.getOpponents(source.getControllerId()).contains(permanent.getControllerId())) {
|
||||||
Watcher watcher = game.getState().getWatchers().get("OpponentCastSpell", source.getControllerId());
|
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
|
||||||
if (watcher != null && watcher.conditionMet()) {
|
if (watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(permanent.getControllerId()) > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,8 +185,8 @@ class AngelicArbiterEffect2 extends ContinuousRuleModifiyingEffectImpl {
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
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())) {
|
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());
|
AngelicArbiterWatcher2 watcher = (AngelicArbiterWatcher2) game.getState().getWatchers().get("PlayerAttacked");
|
||||||
if (watcher != null && watcher.conditionMet()) {
|
if (watcher != null && watcher.hasPlayerAttackedThisTurn(event.getPlayerId())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,15 +27,14 @@
|
||||||
*/
|
*/
|
||||||
package mage.watchers.common;
|
package mage.watchers.common;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import mage.constants.WatcherScope;
|
import mage.constants.WatcherScope;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.watchers.Watcher;
|
import mage.watchers.Watcher;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author magenoxx_at_gmail.com
|
* @author magenoxx_at_gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -28,16 +28,18 @@
|
||||||
|
|
||||||
package mage.watchers.common;
|
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.Map.Entry;
|
||||||
|
import java.util.UUID;
|
||||||
import mage.constants.WatcherScope;
|
import mage.constants.WatcherScope;
|
||||||
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.game.stack.Spell;
|
||||||
import mage.watchers.Watcher;
|
import mage.watchers.Watcher;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author nantuko, BetaSteward_at_googlemail.com
|
* @author nantuko, BetaSteward_at_googlemail.com
|
||||||
|
|
Loading…
Reference in a new issue