From fdca147d4d5c987e69ad63579fe1850435062fe4 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 20 Sep 2013 11:18:38 +0200 Subject: [PATCH] * Balancing Act and Restore Balance - Fixed that range of players was ignored (cbt33). --- .../src/mage/sets/odyssey/BalancingAct.java | 95 +++++++------ .../mage/sets/timespiral/RestoreBalance.java | 131 +++++++++--------- 2 files changed, 118 insertions(+), 108 deletions(-) diff --git a/Mage.Sets/src/mage/sets/odyssey/BalancingAct.java b/Mage.Sets/src/mage/sets/odyssey/BalancingAct.java index 9623674ab6..355c746846 100644 --- a/Mage.Sets/src/mage/sets/odyssey/BalancingAct.java +++ b/Mage.Sets/src/mage/sets/odyssey/BalancingAct.java @@ -57,8 +57,8 @@ public class BalancingAct extends CardImpl { this.color.setWhite(true); - this.getSpellAbility().addEffect(new BalancingActEffect()); // Each player chooses a number of permanents he or she controls equal to the number of permanents controlled by the player who controls the fewest, then sacrifices the rest. Each player discards cards the same way. + this.getSpellAbility().addEffect(new BalancingActEffect()); } public BalancingAct(final BalancingAct card) { @@ -76,6 +76,7 @@ class BalancingActEffect extends OneShotEffect { public BalancingActEffect() { super(Outcome.Sacrifice); + staticText = "Each player chooses a number of lands he or she controls equal to the number of lands controlled by the player who controls the fewest, then sacrifices the rest. Players sacrifice creatures and discard cards the same way"; } public BalancingActEffect(final mage.sets.odyssey.BalancingActEffect effect) { @@ -89,65 +90,67 @@ class BalancingActEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int minPermanent = Integer.MAX_VALUE, minCard = Integer.MAX_VALUE; - //PERMANENTS - for(Player player : game.getPlayers().values()){ - if(player != null){ - int count = game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getId(), game).size(); - if(count < minPermanent){ - minPermanent = count; + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + int minPermanent = Integer.MAX_VALUE, minCard = Integer.MAX_VALUE; + // count minimal permanets + for(UUID playerId : controller.getInRange()){ + Player player = game.getPlayer(playerId); + if(player != null){ + int count = game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getId(), game).size(); + if(count < minPermanent){ + minPermanent = count; + } } } - } - - for(Player player : game.getPlayers().values()){ - if(player != null){ - TargetControlledPermanent target = new TargetControlledPermanent(minPermanent, minPermanent, new FilterControlledPermanent(), true); - target.setRequired(true); - if(target.choose(Outcome.Benefit, player.getId(), source.getId(), game)){ - for(Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getId(), game)){ - if(permanent != null && !target.getTargets().contains(permanent.getId())){ - permanent.sacrifice(source.getSourceId(), game); + // sacrifice permanents over the minimum + for(UUID playerId : controller.getInRange()){ + Player player = game.getPlayer(playerId); + if(player != null){ + TargetControlledPermanent target = new TargetControlledPermanent(minPermanent, minPermanent, new FilterControlledPermanent(), true); + target.setRequired(true); + if(target.choose(Outcome.Benefit, player.getId(), source.getId(), game)){ + for(Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getId(), game)){ + if(permanent != null && !target.getTargets().contains(permanent.getId())){ + permanent.sacrifice(source.getSourceId(), game); + } } } } } - } - - - - //CARD IN HAND - for(Player player : game.getPlayers().values()){ - if(player != null){ - int count = player.getHand().size(); - if(count < minCard){ - minCard = count; + // count minimal cards in hand + for(UUID playerId : controller.getInRange()){ + Player player = game.getPlayer(playerId); + if(player != null){ + int count = player.getHand().size(); + if(count < minCard){ + minCard = count; + } } } - } - - for(Player player : game.getPlayers().values()){ - if(player != null){ - TargetCardInHand target = new TargetCardInHand(minCard, new FilterCard()); - target.setRequired(true); - if(target.choose(Outcome.Benefit, player.getId(), source.getId(), game)){ - Cards cards = player.getHand().copy(); - for(UUID cardUUID : cards){ - Card card = player.getHand().get(cardUUID, game); - if(card != null && !target.getTargets().contains(cardUUID)){ - player.discard(card, source, game); + + // discard cards over the minimum + for(UUID playerId : controller.getInRange()){ + Player player = game.getPlayer(playerId); + if(player != null){ + TargetCardInHand target = new TargetCardInHand(minCard, new FilterCard()); + target.setRequired(true); + if(target.choose(Outcome.Benefit, player.getId(), source.getId(), game)){ + Cards cards = player.getHand().copy(); + for(UUID cardUUID : cards){ + Card card = player.getHand().get(cardUUID, game); + if(card != null && !target.getTargets().contains(cardUUID)){ + player.discard(card, source, game); + } } } } } + + return true; } - - return true; + return false; } - @Override - public String getText(Mode mode) { - return "Each player chooses a number of lands he or she controls equal to the number of lands controlled by the player who controls the fewest, then sacrifices the rest. Players sacrifice creatures and discard cards the same way"; - } } diff --git a/Mage.Sets/src/mage/sets/timespiral/RestoreBalance.java b/Mage.Sets/src/mage/sets/timespiral/RestoreBalance.java index 8708cbf042..b8a6c594c2 100644 --- a/Mage.Sets/src/mage/sets/timespiral/RestoreBalance.java +++ b/Mage.Sets/src/mage/sets/timespiral/RestoreBalance.java @@ -81,6 +81,7 @@ class RestoreBalanceEffect extends OneShotEffect { public RestoreBalanceEffect() { super(Outcome.Sacrifice); + staticText = "Each player chooses a number of lands he or she controls equal to the number of lands controlled by the player who controls the fewest, then sacrifices the rest. Players sacrifice creatures and discard cards the same way"; } public RestoreBalanceEffect(final RestoreBalanceEffect effect) { @@ -94,87 +95,93 @@ class RestoreBalanceEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int minLand = Integer.MAX_VALUE, minCreature = Integer.MAX_VALUE, minCard = Integer.MAX_VALUE; - //LAND - for(Player player : game.getPlayers().values()){ - if(player != null){ - int count = game.getBattlefield().getActivePermanents(new FilterControlledLandPermanent(), player.getId(), source.getId(), game).size(); - if(count < minLand){ - minLand = count; + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + int minLand = Integer.MAX_VALUE, minCreature = Integer.MAX_VALUE, minCard = Integer.MAX_VALUE; + //LAND + for(UUID playerId : controller.getInRange()){ + Player player = game.getPlayer(playerId); + if(player != null){ + int count = game.getBattlefield().getActivePermanents(new FilterControlledLandPermanent(), player.getId(), source.getId(), game).size(); + if(count < minLand){ + minLand = count; + } } } - } - - for(Player player : game.getPlayers().values()){ - if(player != null){ - TargetControlledPermanent target = new TargetControlledPermanent(minLand, minLand, new FilterControlledLandPermanent(), true); - target.setRequired(true); - if(target.choose(Outcome.Benefit, player.getId(), source.getId(), game)){ - for(Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledLandPermanent(), player.getId(), source.getId(), game)){ - if(permanent != null && !target.getTargets().contains(permanent.getId())){ - permanent.sacrifice(source.getSourceId(), game); + + for(UUID playerId : controller.getInRange()){ + Player player = game.getPlayer(playerId); + if(player != null){ + TargetControlledPermanent target = new TargetControlledPermanent(minLand, minLand, new FilterControlledLandPermanent(), true); + target.setRequired(true); + if(target.choose(Outcome.Benefit, player.getId(), source.getId(), game)){ + for(Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledLandPermanent(), player.getId(), source.getId(), game)){ + if(permanent != null && !target.getTargets().contains(permanent.getId())){ + permanent.sacrifice(source.getSourceId(), game); + } } } } } - } - - - //CREATURE - for(Player player : game.getPlayers().values()){ - if(player != null){ - int count = game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), player.getId(), source.getId(), game).size(); - if(count < minCreature){ - minCreature = count; + + + //CREATURE + for(UUID playerId : controller.getInRange()){ + Player player = game.getPlayer(playerId); + if(player != null){ + int count = game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), player.getId(), source.getId(), game).size(); + if(count < minCreature){ + minCreature = count; + } } } - } - - for(Player player : game.getPlayers().values()){ - if(player != null){ - TargetControlledPermanent target = new TargetControlledPermanent(minCreature, minCreature, new FilterControlledCreaturePermanent(), true); - target.setRequired(true); - if(target.choose(Outcome.Benefit, player.getId(), source.getId(), game)){ - for(Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), player.getId(), source.getId(), game)){ - if(permanent != null && !target.getTargets().contains(permanent.getId())){ - permanent.sacrifice(source.getSourceId(), game); + + for(UUID playerId : controller.getInRange()){ + Player player = game.getPlayer(playerId); + if(player != null){ + TargetControlledPermanent target = new TargetControlledPermanent(minCreature, minCreature, new FilterControlledCreaturePermanent(), true); + target.setRequired(true); + if(target.choose(Outcome.Benefit, player.getId(), source.getId(), game)){ + for(Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), player.getId(), source.getId(), game)){ + if(permanent != null && !target.getTargets().contains(permanent.getId())){ + permanent.sacrifice(source.getSourceId(), game); + } } } } } - } - - //CARD IN HAND - for(Player player : game.getPlayers().values()){ - if(player != null){ - int count = player.getHand().size(); - if(count < minCard){ - minCard = count; + + //CARD IN HAND + for(UUID playerId : controller.getInRange()){ + Player player = game.getPlayer(playerId); + if(player != null){ + int count = player.getHand().size(); + if(count < minCard){ + minCard = count; + } } } - } - - for(Player player : game.getPlayers().values()){ - if(player != null){ - TargetCardInHand target = new TargetCardInHand(minCard, new FilterCard()); - target.setRequired(true); - if(target.choose(Outcome.Benefit, player.getId(), source.getId(), game)){ - Cards cards = player.getHand().copy(); - for(UUID cardUUID : cards){ - Card card = player.getHand().get(cardUUID, game); - if(card != null && !target.getTargets().contains(cardUUID)){ - player.discard(card, source, game); + + for(UUID playerId : controller.getInRange()){ + Player player = game.getPlayer(playerId); + if(player != null){ + TargetCardInHand target = new TargetCardInHand(minCard, new FilterCard()); + target.setRequired(true); + if(target.choose(Outcome.Benefit, player.getId(), source.getId(), game)){ + Cards cards = player.getHand().copy(); + for(UUID cardUUID : cards){ + Card card = player.getHand().get(cardUUID, game); + if(card != null && !target.getTargets().contains(cardUUID)){ + player.discard(card, source, game); + } } } } } + + return true; } - - return true; + return false; } - @Override - public String getText(Mode mode) { - return "Each player chooses a number of lands he or she controls equal to the number of lands controlled by the player who controls the fewest, then sacrifices the rest. Players sacrifice creatures and discard cards the same way"; - } }