From ceb0dfc10bf15334315fff89b6795dbfa5fe6086 Mon Sep 17 00:00:00 2001 From: Quercitron Date: Sun, 21 Feb 2016 17:51:02 +0300 Subject: [PATCH] Added Dueling Grounds --- .../commander2013/IllusionistsGambit.java | 2 +- .../mage/sets/fifthdawn/SilentArbiter.java | 2 +- .../mage/sets/invasion/DuelingGrounds.java | 146 ++++++++++++++++++ .../src/mage/sets/legions/GoblinGoon.java | 2 +- .../sets/newphyrexia/ChainedThroatseeker.java | 2 +- .../mage/sets/timeshifted/TeferisMoat.java | 4 +- .../abilities/effects/RestrictionEffect.java | 2 +- .../CantAttackControllerAttachedEffect.java | 2 +- ...CantAttackIfDefenderControlsPermanent.java | 2 +- ...ttackUnlessDefenderControllsPermanent.java | 2 +- .../common/combat/CantAttackYouAllEffect.java | 2 +- .../CantAttackYouOrPlaneswalkerAllEffect.java | 2 +- .../mage/game/permanent/PermanentImpl.java | 2 +- .../common/BlockedThisTurnWatcher.java | 79 ++++++++++ 14 files changed, 238 insertions(+), 13 deletions(-) create mode 100644 Mage.Sets/src/mage/sets/invasion/DuelingGrounds.java create mode 100644 Mage/src/main/java/mage/watchers/common/BlockedThisTurnWatcher.java diff --git a/Mage.Sets/src/mage/sets/commander2013/IllusionistsGambit.java b/Mage.Sets/src/mage/sets/commander2013/IllusionistsGambit.java index f3ab23dea4..3a3157d1b9 100644 --- a/Mage.Sets/src/mage/sets/commander2013/IllusionistsGambit.java +++ b/Mage.Sets/src/mage/sets/commander2013/IllusionistsGambit.java @@ -200,7 +200,7 @@ class IllusionistsGambitRestrictionEffect extends RestrictionEffect { } @Override - public boolean canAttack(UUID defenderId, Ability source, Game game) { + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { if (defenderId.equals(source.getControllerId())) { return false; } diff --git a/Mage.Sets/src/mage/sets/fifthdawn/SilentArbiter.java b/Mage.Sets/src/mage/sets/fifthdawn/SilentArbiter.java index e5ede523d6..43897a63de 100644 --- a/Mage.Sets/src/mage/sets/fifthdawn/SilentArbiter.java +++ b/Mage.Sets/src/mage/sets/fifthdawn/SilentArbiter.java @@ -92,7 +92,7 @@ class SilentArbiterAttackRestrictionEffect extends RestrictionEffect { } @Override - public boolean canAttack(UUID defenderId, Ability source, Game game) { + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { return game.getCombat().getAttackers().isEmpty(); } } diff --git a/Mage.Sets/src/mage/sets/invasion/DuelingGrounds.java b/Mage.Sets/src/mage/sets/invasion/DuelingGrounds.java new file mode 100644 index 0000000000..01b538c700 --- /dev/null +++ b/Mage.Sets/src/mage/sets/invasion/DuelingGrounds.java @@ -0,0 +1,146 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.sets.invasion; + +import java.util.Set; +import java.util.UUID; + +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.RestrictionEffect; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Rarity; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.watchers.common.AttackedThisTurnWatcher; +import mage.watchers.common.BlockedThisTurnWatcher; + +/** + * + * @author Quercitron + */ +public class DuelingGrounds extends CardImpl { + + public DuelingGrounds(UUID ownerId) { + super(ownerId, 245, "Dueling Grounds", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{1}{G}{W}"); + this.expansionSetCode = "INV"; + + // No more than one creature can attack each turn. + this.addAbility( + new SimpleStaticAbility(Zone.BATTLEFIELD, new NoMoreThanOneCreatureCanAttackEachTurnEffect()), + new AttackedThisTurnWatcher()); + + // No more than one creature can block each turn. + this.addAbility( + new SimpleStaticAbility(Zone.BATTLEFIELD, new NoMoreThanOneCreatureCanBlockEachTurnEffect()), + new BlockedThisTurnWatcher()); + } + + public DuelingGrounds(final DuelingGrounds card) { + super(card); + } + + @Override + public DuelingGrounds copy() { + return new DuelingGrounds(this); + } +} + +class NoMoreThanOneCreatureCanAttackEachTurnEffect extends RestrictionEffect { + + public NoMoreThanOneCreatureCanAttackEachTurnEffect() { + super(Duration.WhileOnBattlefield); + } + + public NoMoreThanOneCreatureCanAttackEachTurnEffect(final NoMoreThanOneCreatureCanAttackEachTurnEffect effect) { + super(effect); + this.staticText = "No more than one creature can attack each turn"; + } + + @Override + public ContinuousEffect copy() { + return new NoMoreThanOneCreatureCanAttackEachTurnEffect(this); + } + + @Override + public boolean applies(Permanent permanent, Ability source, Game game) { + return true; + } + + @Override + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (!game.getCombat().getAttackers().isEmpty()) { + return false; + } + AttackedThisTurnWatcher watcher = (AttackedThisTurnWatcher) game.getState().getWatchers().get("AttackedThisTurn"); + Set attackedThisTurnCreatures = watcher.getAttackedThisTurnCreatures(); + return attackedThisTurnCreatures.isEmpty() + || (attackedThisTurnCreatures.size() == 1 && attackedThisTurnCreatures.contains(attacker.getId())); + } + +} + +class NoMoreThanOneCreatureCanBlockEachTurnEffect extends RestrictionEffect { + + public NoMoreThanOneCreatureCanBlockEachTurnEffect() { + super(Duration.WhileOnBattlefield); + this.staticText = "No more than one creature can block each turn"; + } + + public NoMoreThanOneCreatureCanBlockEachTurnEffect(final NoMoreThanOneCreatureCanBlockEachTurnEffect effect) { + super(effect); + } + + @Override + public ContinuousEffect copy() { + return new NoMoreThanOneCreatureCanBlockEachTurnEffect(this); + } + + @Override + public boolean applies(Permanent permanent, Ability source, Game game) { + return true; + } + + @Override + public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) { + if (!game.getCombat().getBlockers().isEmpty()) { + return false; + } + BlockedThisTurnWatcher watcher = (BlockedThisTurnWatcher) game.getState().getWatchers().get("BlockedThisTurn"); + Set blockedThisTurnCreatures = watcher.getBlockedThisTurnCreatures(); + MageObjectReference blockerReference = new MageObjectReference(blocker.getId(), blocker.getZoneChangeCounter(game), game); + return blockedThisTurnCreatures.isEmpty() + || (blockedThisTurnCreatures.size() == 1 && blockedThisTurnCreatures.contains(blockerReference)); + } + +} diff --git a/Mage.Sets/src/mage/sets/legions/GoblinGoon.java b/Mage.Sets/src/mage/sets/legions/GoblinGoon.java index 452fd426db..d8c765e34d 100644 --- a/Mage.Sets/src/mage/sets/legions/GoblinGoon.java +++ b/Mage.Sets/src/mage/sets/legions/GoblinGoon.java @@ -90,7 +90,7 @@ class GoblinGoonCantAttackEffect extends RestrictionEffect { } @Override - public boolean canAttack(UUID defenderId, Ability source, Game game) { + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { UUID defendingPlayerId; Player defender = game.getPlayer(defenderId); if (defender == null) { diff --git a/Mage.Sets/src/mage/sets/newphyrexia/ChainedThroatseeker.java b/Mage.Sets/src/mage/sets/newphyrexia/ChainedThroatseeker.java index 20e397dfdc..afa9a1cc30 100644 --- a/Mage.Sets/src/mage/sets/newphyrexia/ChainedThroatseeker.java +++ b/Mage.Sets/src/mage/sets/newphyrexia/ChainedThroatseeker.java @@ -91,7 +91,7 @@ class ChainedThroatseekerCantAttackEffect extends RestrictionEffect { } @Override - public boolean canAttack(UUID defenderId, Ability source, Game game) { + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { Player targetPlayer = game.getPlayer(defenderId); if (targetPlayer != null) { if (targetPlayer.getCounters().containsKey(CounterType.POISON)) { diff --git a/Mage.Sets/src/mage/sets/timeshifted/TeferisMoat.java b/Mage.Sets/src/mage/sets/timeshifted/TeferisMoat.java index 6348e83d0d..5f4c0df4eb 100644 --- a/Mage.Sets/src/mage/sets/timeshifted/TeferisMoat.java +++ b/Mage.Sets/src/mage/sets/timeshifted/TeferisMoat.java @@ -92,7 +92,7 @@ class TeferisMoatRestrictionEffect extends RestrictionEffect { } @Override - public boolean canAttack(UUID defenderId, Ability source, Game game) { + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { return !defenderId.equals(source.getControllerId()); } @@ -100,4 +100,4 @@ class TeferisMoatRestrictionEffect extends RestrictionEffect { public TeferisMoatRestrictionEffect copy() { return new TeferisMoatRestrictionEffect(this); } -} +} diff --git a/Mage/src/main/java/mage/abilities/effects/RestrictionEffect.java b/Mage/src/main/java/mage/abilities/effects/RestrictionEffect.java index 2a87b1e4cf..596e8fa108 100644 --- a/Mage/src/main/java/mage/abilities/effects/RestrictionEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/RestrictionEffect.java @@ -65,7 +65,7 @@ public abstract class RestrictionEffect extends ContinuousEffectImpl { return true; } - public boolean canAttack(UUID defenderId, Ability source, Game game) { + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { return true; } diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackControllerAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackControllerAttachedEffect.java index 8c6f3c40fe..69c5101f3f 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackControllerAttachedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackControllerAttachedEffect.java @@ -63,7 +63,7 @@ public class CantAttackControllerAttachedEffect extends RestrictionEffect { } @Override - public boolean canAttack(UUID defenderId, Ability source, Game game) { + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { if (defenderId.equals(source.getControllerId())) { return false; } diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackIfDefenderControlsPermanent.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackIfDefenderControlsPermanent.java index f0fbf61e2d..5f0e23263f 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackIfDefenderControlsPermanent.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackIfDefenderControlsPermanent.java @@ -63,7 +63,7 @@ public class CantAttackIfDefenderControlsPermanent extends RestrictionEffect { } @Override - public boolean canAttack(UUID defenderId, Ability source, Game game) { + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { UUID defendingPlayerId; Player player = game.getPlayer(defenderId); if (player == null) { diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackUnlessDefenderControllsPermanent.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackUnlessDefenderControllsPermanent.java index 6c3b2e018c..fe22b6d289 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackUnlessDefenderControllsPermanent.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackUnlessDefenderControllsPermanent.java @@ -63,7 +63,7 @@ public class CantAttackUnlessDefenderControllsPermanent extends RestrictionEffec } @Override - public boolean canAttack(UUID defenderId, Ability source, Game game) { + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { UUID defendingPlayerId; Player player = game.getPlayer(defenderId); if (player == null) { diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouAllEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouAllEffect.java index 0ce92ebb15..d236dd2818 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouAllEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouAllEffect.java @@ -65,7 +65,7 @@ public class CantAttackYouAllEffect extends RestrictionEffect { } @Override - public boolean canAttack(UUID defenderId, Ability source, Game game) { + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { return !defenderId.equals(source.getControllerId()); } diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouOrPlaneswalkerAllEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouOrPlaneswalkerAllEffect.java index 96aa778fba..933928086e 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouOrPlaneswalkerAllEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouOrPlaneswalkerAllEffect.java @@ -65,7 +65,7 @@ public class CantAttackYouOrPlaneswalkerAllEffect extends RestrictionEffect { } @Override - public boolean canAttack(UUID defenderId, Ability source, Game game) { + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { if (defenderId.equals(source.getControllerId())) { return false; } diff --git a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java index c725fa67f9..c98db5750b 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java @@ -1108,7 +1108,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { return false; } for (Ability ability : effectEntry.getValue()) { - if (!effectEntry.getKey().canAttack(defenderId, ability, game)) { + if (!effectEntry.getKey().canAttack(this, defenderId, ability, game)) { return false; } } diff --git a/Mage/src/main/java/mage/watchers/common/BlockedThisTurnWatcher.java b/Mage/src/main/java/mage/watchers/common/BlockedThisTurnWatcher.java new file mode 100644 index 0000000000..fd7a1a2583 --- /dev/null +++ b/Mage/src/main/java/mage/watchers/common/BlockedThisTurnWatcher.java @@ -0,0 +1,79 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.watchers.common; + +import java.util.HashSet; +import java.util.Set; + +import mage.MageObjectReference; +import mage.constants.WatcherScope; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.watchers.Watcher; + +/** + * + * @author Quercitron + */ +public class BlockedThisTurnWatcher extends Watcher { + + private final Set blockedThisTurnCreatures; + + public BlockedThisTurnWatcher() { + super("BlockedThisTurn", WatcherScope.GAME); + blockedThisTurnCreatures = new HashSet<>(); + } + + public BlockedThisTurnWatcher(final BlockedThisTurnWatcher watcher) { + super(watcher); + blockedThisTurnCreatures = new HashSet<>(watcher.blockedThisTurnCreatures); + } + + @Override + public Watcher copy() { + return new BlockedThisTurnWatcher(this); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.BLOCKER_DECLARED) { + this.blockedThisTurnCreatures.add(new MageObjectReference(event.getSourceId(), game)); + } + } + + public Set getBlockedThisTurnCreatures() { + return this.blockedThisTurnCreatures; + } + + @Override + public void reset() { + super.reset(); + blockedThisTurnCreatures.clear(); + } + +}