diff --git a/Mage.Sets/src/mage/cards/c/CapitalPunishment.java b/Mage.Sets/src/mage/cards/c/CapitalPunishment.java index 9d3352938b0..7ad2bd77d1c 100644 --- a/Mage.Sets/src/mage/cards/c/CapitalPunishment.java +++ b/Mage.Sets/src/mage/cards/c/CapitalPunishment.java @@ -27,12 +27,10 @@ */ package mage.cards.c; -import java.util.UUID; - import mage.abilities.Ability; import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.Effect; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CouncilsDilemmaVoteEffect; import mage.abilities.effects.common.SacrificeOpponentsEffect; import mage.abilities.effects.common.discard.DiscardEachPlayerEffect; import mage.cards.CardImpl; @@ -44,6 +42,8 @@ import mage.filter.common.FilterControlledCreaturePermanent; import mage.game.Game; import mage.players.Player; +import java.util.UUID; + /** * * @author JRHerlehy @@ -68,7 +68,7 @@ public class CapitalPunishment extends CardImpl { } } -class CapitalPunishmentDilemmaEffect extends OneShotEffect { +class CapitalPunishmentDilemmaEffect extends CouncilsDilemmaVoteEffect { public CapitalPunishmentDilemmaEffect() { super(Outcome.Detriment); @@ -86,28 +86,17 @@ class CapitalPunishmentDilemmaEffect extends OneShotEffect { //If no controller, exit out here and do not vote. if (controller == null) return false; - int deathCount = 0, taxesCount = 0; + this.vote("death", "taxes", controller, game, source); - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - if (player.chooseUse(Outcome.Detriment, "Choose death?", source, game)) { - deathCount++; - game.informPlayers(player.getName() + " has voted for death"); - } else { - taxesCount++; - game.informPlayers(player.getName() + " has voted for taxes"); - } - } + //Death Votes + if (voteOneCount > 0) { + Effect sacrificeEffect = new SacrificeOpponentsEffect(voteOneCount, new FilterControlledCreaturePermanent()); + sacrificeEffect.apply(game, source); } - if (deathCount > 0) { - Effect sacraficeEffect = new SacrificeOpponentsEffect(deathCount, new FilterControlledCreaturePermanent()); - sacraficeEffect.apply(game, source); - } - - if (taxesCount > 0) { - Effect discardEffect = new DiscardEachPlayerEffect(new StaticValue(taxesCount), false, TargetController.OPPONENT); + //Taxes Votes + if (voteTwoCount > 0) { + Effect discardEffect = new DiscardEachPlayerEffect(new StaticValue(voteTwoCount), false, TargetController.OPPONENT); discardEffect.apply(game, source); } diff --git a/Mage.Sets/src/mage/cards/e/Expropriate.java b/Mage.Sets/src/mage/cards/e/Expropriate.java index fefd82a3c53..7c17bd8d09d 100644 --- a/Mage.Sets/src/mage/cards/e/Expropriate.java +++ b/Mage.Sets/src/mage/cards/e/Expropriate.java @@ -31,7 +31,7 @@ package mage.cards.e; import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.ContinuousEffectImpl; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CouncilsDilemmaVoteEffect; import mage.abilities.effects.common.ExileSpellEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -74,7 +74,9 @@ public class Expropriate extends CardImpl { } } -class ExpropriateDilemmaEffect extends OneShotEffect { +class ExpropriateDilemmaEffect extends CouncilsDilemmaVoteEffect { + + private Players moneyVoters = new Players(); public ExpropriateDilemmaEffect() { super(Outcome.Benefit); @@ -96,62 +98,74 @@ class ExpropriateDilemmaEffect extends OneShotEffect { //If not controller, exit out here and do not vote. if (controller == null) return false; - int timeCount = 0, moneyCount = 0; - Players moneyVoters = new Players(); + this.vote("time", "money", controller, game, source); + //Time Votes + if (voteOneCount > 0) { + this.turnsForTimeVote(voteOneCount, controller, game, source); + } + + //Money Votes + if (voteTwoCount > 0) { + this.controlForMoneyVote(controller, game, source); + } + + return true; + } + + private void turnsForTimeVote(int timeCount, Player controller, Game game, Ability source) { + if (timeCount == 1) { + game.informPlayers(controller.getName() + " will take an extra turn"); + } else { + game.informPlayers(controller.getName() + " will take " + timeCount + " extra turns"); + } + + do { + game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false)); + timeCount--; + } while (timeCount > 0); + } + + private void controlForMoneyVote(Player controller, Game game, Ability source) { + List chosenCards = new ArrayList<>(); + + for (UUID playerId : moneyVoters.keySet()) { + FilterPermanent filter = new FilterPermanent("permanent owned by " + game.getPlayer(playerId).getName()); + filter.add(new OwnerIdPredicate(playerId)); + + Target target = new TargetPermanent(filter); + target.setNotTarget(true); + + if (controller.choose(Outcome.GainControl, target, source.getSourceId(), game)) { + Permanent targetPermanent = game.getPermanent(target.getFirstTarget()); + + if (targetPermanent != null) chosenCards.add(targetPermanent); + } + } + + for (Permanent permanent : chosenCards) { + ContinuousEffect effect = new ExpropriateControlEffect(controller.getId()); + effect.setTargetPointer(new FixedTarget(permanent.getId())); + game.addEffect(effect, source); + game.informPlayers(controller.getName() + " gained control of " + permanent.getName() + " owned by " + game.getPlayer(permanent.getOwnerId()).getName()); + } + } + + @Override + protected void vote(String choiceOne, String choiceTwo, Player controller, Game game, Ability source) { for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { - if (player.chooseUse(Outcome.Benefit, "Choose time?", source, game)) { - timeCount++; - game.informPlayers(player.getName() + " has voted for time"); + if (player.chooseUse(Outcome.Vote, "Choose " + choiceOne + "?", source, game)) { + voteOneCount++; + game.informPlayers(player.getName() + " has voted for " + choiceOne); } else { - moneyCount++; moneyVoters.addPlayer(player); - game.informPlayers(player.getName() + " has voted for money"); + voteTwoCount++; + game.informPlayers(player.getName() + " has voted for " + choiceTwo); } } } - - if (timeCount > 0) { - if (timeCount == 1) { - game.informPlayers(controller.getName() + " will take an extra turn"); - } else { - game.informPlayers(controller.getName() + " will take " + timeCount + " extra turns"); - } - - do { - game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false)); - timeCount--; - } while (timeCount > 0); - } - - if (moneyCount > 0) { - List chosenCards = new ArrayList<>(); - - for (UUID playerId : moneyVoters.keySet()) { - FilterPermanent filter = new FilterPermanent("permanent owned by " + game.getPlayer(playerId).getName()); - filter.add(new OwnerIdPredicate(playerId)); - - Target target = new TargetPermanent(filter); - target.setNotTarget(true); - - if (controller.choose(Outcome.GainControl, target, source.getSourceId(), game)) { - Permanent targetPermanent = game.getPermanent(target.getFirstTarget()); - - if (targetPermanent != null) chosenCards.add(targetPermanent); - } - } - - for (Permanent permanent : chosenCards) { - ContinuousEffect effect = new ExpropriateControlEffect(controller.getId()); - effect.setTargetPointer(new FixedTarget(permanent.getId())); - game.addEffect(effect, source); - game.informPlayers(controller.getName() + " gained control of " + permanent.getName() + " owned by " + game.getPlayer(permanent.getOwnerId()).getName()); - } - } //End moneyCount if statement - - return true; } @Override @@ -183,9 +197,7 @@ class ExpropriateControlEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source)); - if (permanent != null && controllerId != null) { - return permanent.changeControllerId(controllerId, game); - } - return false; + return permanent != null && controllerId != null && + permanent.changeControllerId(controllerId, game); } } diff --git a/Mage.Sets/src/mage/cards/l/LieutenantsOfTheGuard.java b/Mage.Sets/src/mage/cards/l/LieutenantsOfTheGuard.java index 9290e927f14..9f48fb32916 100644 --- a/Mage.Sets/src/mage/cards/l/LieutenantsOfTheGuard.java +++ b/Mage.Sets/src/mage/cards/l/LieutenantsOfTheGuard.java @@ -31,7 +31,7 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.effects.Effect; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CouncilsDilemmaVoteEffect; import mage.abilities.effects.common.CreateTokenEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -73,7 +73,7 @@ public class LieutenantsOfTheGuard extends CardImpl { } } -class LieutenantsOfTheGuardDilemmaEffect extends OneShotEffect { +class LieutenantsOfTheGuardDilemmaEffect extends CouncilsDilemmaVoteEffect { public LieutenantsOfTheGuardDilemmaEffect() { super(Outcome.Benefit); this.staticText = "starting with you, each player votes for strength or numbers. Put a +1/+1 counter on {this} for each strength vote and put a 1/1 white Soldier creature token onto the battlefield for each numbers vote."; @@ -90,29 +90,18 @@ class LieutenantsOfTheGuardDilemmaEffect extends OneShotEffect { //If no controller, exit out here and do not vote. if (controller == null) return false; - int strengthCount = 0, numbersCount = 0; - - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - if (player.chooseUse(Outcome.BoostCreature, "Choose strength?", source, game)) { - strengthCount++; - game.informPlayers(player.getName() + " has voted for strength"); - } else { - numbersCount++; - game.informPlayers(player.getName() + " has voted for numbers"); - } - } - } + this.vote("strength", "numbers", controller, game, source); Permanent permanent = game.getPermanent(source.getSourceId()); + //Strength Votes //If strength received zero votes or the permanent is no longer on the battlefield, do not attempt to put P1P1 counters on it. - if (strengthCount > 0 && permanent != null) permanent.addCounters(CounterType.P1P1.createInstance(strengthCount), game); + if (voteOneCount > 0 && permanent != null) + permanent.addCounters(CounterType.P1P1.createInstance(voteOneCount), game); - //Create the appropriate number of tokens for the controller. - if (numbersCount > 0) { - Effect tokenEffect = new CreateTokenEffect(new SoldierToken(), numbersCount); + //Numbers Votes + if (voteTwoCount > 0) { + Effect tokenEffect = new CreateTokenEffect(new SoldierToken(), voteTwoCount); tokenEffect.apply(game, source); } diff --git a/Mage.Sets/src/mage/cards/m/MessengerJays.java b/Mage.Sets/src/mage/cards/m/MessengerJays.java index 3cc5174e3d8..936c5845aea 100644 --- a/Mage.Sets/src/mage/cards/m/MessengerJays.java +++ b/Mage.Sets/src/mage/cards/m/MessengerJays.java @@ -31,7 +31,7 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.effects.Effect; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CouncilsDilemmaVoteEffect; import mage.abilities.effects.common.DrawDiscardControllerEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; @@ -74,7 +74,7 @@ public class MessengerJays extends CardImpl { } } -class MessengerJaysDilemmaEffect extends OneShotEffect { +class MessengerJaysDilemmaEffect extends CouncilsDilemmaVoteEffect { public MessengerJaysDilemmaEffect() { super(Outcome.Benefit); @@ -92,29 +92,19 @@ class MessengerJaysDilemmaEffect extends OneShotEffect { //If no controller, exit out here and do not vote. if (controller == null) return false; - int featherCount = 0, quillCount = 0; - - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - if (player.chooseUse(Outcome.BoostCreature, "Choose feather?", source, game)) { - featherCount++; - game.informPlayers(player.getName() + " has voted for feather"); - } else { - quillCount++; - game.informPlayers(player.getName() + " has voted for quill"); - } - } - } + this.vote("feather", "quill", controller, game, source); Permanent permanent = game.getPermanent(source.getSourceId()); + //Feathers Votes //If feathers received zero votes or the permanent is no longer on the battlefield, do not attempt to put P1P1 counter on it. - if (featherCount > 0 && permanent != null) permanent.addCounters(CounterType.P1P1.createInstance(featherCount), game); + if (voteOneCount > 0 && permanent != null) + permanent.addCounters(CounterType.P1P1.createInstance(voteOneCount), game); + //Quill Votes //Only let the controller loot the appropriate amount of cards if it was voted for. - if (quillCount > 0) { - Effect lootCardsEffect = new DrawDiscardControllerEffect(quillCount, quillCount); + if (voteTwoCount > 0) { + Effect lootCardsEffect = new DrawDiscardControllerEffect(voteTwoCount, voteTwoCount); lootCardsEffect.apply(game, source); } diff --git a/Mage.Sets/src/mage/cards/o/OrchardElemental.java b/Mage.Sets/src/mage/cards/o/OrchardElemental.java index 2a4c3e4bc80..b53fc6c72b2 100644 --- a/Mage.Sets/src/mage/cards/o/OrchardElemental.java +++ b/Mage.Sets/src/mage/cards/o/OrchardElemental.java @@ -27,12 +27,11 @@ */ package mage.cards.o; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.effects.Effect; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CouncilsDilemmaVoteEffect; import mage.abilities.effects.common.GainLifeEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -43,6 +42,8 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; +import java.util.UUID; + /** * * @author JRHerlehy @@ -70,7 +71,7 @@ public class OrchardElemental extends CardImpl { } } -class OrchardElementalDilemmaEffect extends OneShotEffect { +class OrchardElementalDilemmaEffect extends CouncilsDilemmaVoteEffect { public OrchardElementalDilemmaEffect() { super(Outcome.Benefit); @@ -87,27 +88,18 @@ class OrchardElementalDilemmaEffect extends OneShotEffect { if (controller == null) return false; - int sproutCount = 0, harvestCount = 0; - - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - if (player.chooseUse(Outcome.BoostCreature, "Choose sprout?", source, game)) { - sproutCount++; - game.informPlayers(player.getName() + " has voted for sprout"); - } else { - harvestCount++; - game.informPlayers(player.getName() + " has voted for harvest"); - } - } - } + this.vote("sprout", "harvest", controller, game, source); Permanent permanent = game.getPermanent(source.getSourceId()); - if (sproutCount > 0 && permanent != null) permanent.addCounters(CounterType.P1P1.createInstance(sproutCount * 2), game); + //Sprout Votes + //If sprout received zero votes or the permanent is no longer on the battlefield, do not attempt to put P1P1 counter on it. + if (voteOneCount > 0 && permanent != null) + permanent.addCounters(CounterType.P1P1.createInstance(voteOneCount * 2), game); - if (harvestCount > 0) { - Effect gainLifeEffect = new GainLifeEffect(harvestCount * 3); + //Harvest Votes + if (voteTwoCount > 0) { + Effect gainLifeEffect = new GainLifeEffect(voteTwoCount * 3); gainLifeEffect.apply(game, source); } diff --git a/Mage.Sets/src/mage/cards/s/SelvalasStampede.java b/Mage.Sets/src/mage/cards/s/SelvalasStampede.java index f8a86470d97..c7150f9252c 100644 --- a/Mage.Sets/src/mage/cards/s/SelvalasStampede.java +++ b/Mage.Sets/src/mage/cards/s/SelvalasStampede.java @@ -27,11 +27,8 @@ */ package mage.cards.s; -import java.util.UUID; - import mage.abilities.Ability; -import mage.abilities.effects.Effect; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CouncilsDilemmaVoteEffect; import mage.cards.*; import mage.constants.CardType; import mage.constants.Outcome; @@ -41,6 +38,8 @@ import mage.game.Game; import mage.players.Player; import mage.target.common.TargetCardInHand; +import java.util.UUID; + /** * * @author JRHerlehy @@ -65,7 +64,7 @@ public class SelvalasStampede extends CardImpl { } } -class SelvalasStampedeDilemmaEffect extends OneShotEffect { +class SelvalasStampedeDilemmaEffect extends CouncilsDilemmaVoteEffect { public SelvalasStampedeDilemmaEffect() { super(Outcome.Benefit); @@ -83,29 +82,18 @@ class SelvalasStampedeDilemmaEffect extends OneShotEffect { //If no controller, exit here and do not vote. if (controller == null) return false; - int wildCount = 0, freeCount = 0; + this.vote("wild", "free", controller, game, source); - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - if (player.chooseUse(Outcome.Benefit, "Choose wild?", source, game)) { - wildCount++; - game.informPlayers(player.getName() + " has voted for wild"); - } else { - freeCount++; - game.informPlayers(player.getName() + " has voted for free"); - } - } - } - - if (wildCount > 0) { + //Wild Votes + if (voteOneCount > 0) { Cards revealedCards = new CardsImpl(); + int cardsToReveal = voteOneCount; - while (wildCount > 0 && controller.getLibrary().size() > 0) { + while (cardsToReveal > 0 && controller.getLibrary().size() > 0) { Card card = controller.getLibrary().removeFromTop(game); if (card.getCardType().contains(CardType.CREATURE)) { controller.moveCards(card, Zone.BATTLEFIELD, source, game); - wildCount--; + cardsToReveal--; } else { revealedCards.add(card); } @@ -116,8 +104,9 @@ class SelvalasStampedeDilemmaEffect extends OneShotEffect { controller.shuffleLibrary(source, game); } - if (freeCount > 0) { - TargetCardInHand target = new TargetCardInHand(0, freeCount, new FilterPermanentCard("permanent cards")); + //Free Votes + if (voteTwoCount > 0) { + TargetCardInHand target = new TargetCardInHand(0, voteTwoCount, new FilterPermanentCard("permanent cards")); if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) { controller.moveCards(new CardsImpl(target.getTargets()), Zone.BATTLEFIELD, source, game); } diff --git a/Mage/src/main/java/mage/abilities/effects/common/CouncilsDilemmaVoteEffect.java b/Mage/src/main/java/mage/abilities/effects/common/CouncilsDilemmaVoteEffect.java new file mode 100644 index 00000000000..3402df0a008 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/CouncilsDilemmaVoteEffect.java @@ -0,0 +1,69 @@ +/* +* 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.abilities.effects.common; + +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.constants.Outcome; +import mage.game.Game; +import mage.players.Player; + +import java.util.UUID; + +/** + * @author JRHerlehy + */ +public abstract class CouncilsDilemmaVoteEffect extends OneShotEffect { + + protected int voteOneCount = 0, voteTwoCount = 0; + + public CouncilsDilemmaVoteEffect(Outcome outcome) { + super(outcome); + } + + public CouncilsDilemmaVoteEffect(final CouncilsDilemmaVoteEffect effect) { + super(effect); + } + + protected void vote(String choiceOne, String choiceTwo, Player controller, Game game, Ability source) { + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + Player player = game.getPlayer(playerId); + if (player != null) { + if (player.chooseUse(Outcome.Vote, "Choose " + choiceOne + "?", source, game)) { + voteOneCount++; + game.informPlayers(player.getName() + " has voted for " + choiceOne); + } else { + voteTwoCount++; + game.informPlayers(player.getName() + " has voted for " + choiceTwo); + } + } + } + } + +} diff --git a/Mage/src/main/java/mage/constants/Outcome.java b/Mage/src/main/java/mage/constants/Outcome.java index e6cc9a2ddc1..e736bbda392 100644 --- a/Mage/src/main/java/mage/constants/Outcome.java +++ b/Mage/src/main/java/mage/constants/Outcome.java @@ -39,7 +39,8 @@ public enum Outcome { Detriment(false), Neutral(true), Removal(false), - AIDontUseIt(false); + AIDontUseIt(false), + Vote(true); private final boolean good; private boolean canTargetAll;