diff --git a/Mage.Sets/src/mage/sets/magic2013/PredatoryRampage.java b/Mage.Sets/src/mage/sets/magic2013/PredatoryRampage.java index 28e9660d25..05e131a924 100644 --- a/Mage.Sets/src/mage/sets/magic2013/PredatoryRampage.java +++ b/Mage.Sets/src/mage/sets/magic2013/PredatoryRampage.java @@ -33,7 +33,6 @@ import mage.constants.Rarity; import mage.constants.TargetController; import mage.abilities.Ability; import mage.abilities.effects.RequirementEffect; -import mage.abilities.effects.common.AddContinuousEffectToGame; import mage.abilities.effects.common.continuous.BoostControlledEffect; import mage.abilities.effects.common.continuous.GainAbilityAllEffect; import mage.abilities.keyword.BlocksThisTurnMarkerAbility; @@ -45,13 +44,14 @@ import mage.game.permanent.Permanent; import mage.players.Player; import java.util.UUID; +import mage.abilities.effects.common.combat.BlocksIfAbleAllEffect; /** * @author magenoxx_at_gmail.com */ public class PredatoryRampage extends CardImpl { - private static final FilterCreaturePermanent filter = new FilterCreaturePermanent(); + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("Each creature your opponents control"); static { filter.add(new ControllerPredicate(TargetController.OPPONENT)); @@ -66,7 +66,7 @@ public class PredatoryRampage extends CardImpl { // Creatures you control get +3/+3 until end of turn. this.getSpellAbility().addEffect(new BoostControlledEffect(3, 3, Duration.EndOfTurn)); // Each creature your opponents control blocks this turn if able. - this.getSpellAbility().addEffect(new AddContinuousEffectToGame(new PredatoryRampageEffect(Duration.EndOfTurn))); + this.getSpellAbility().addEffect(new BlocksIfAbleAllEffect(filter, Duration.EndOfTurn)); this.getSpellAbility().addEffect(new GainAbilityAllEffect(BlocksThisTurnMarkerAbility.getInstance(), Duration.EndOfTurn, filter, "")); } @@ -79,44 +79,3 @@ public class PredatoryRampage extends CardImpl { return new PredatoryRampage(this); } } - -class PredatoryRampageEffect extends RequirementEffect { - - public PredatoryRampageEffect(Duration duration) { - super(duration); - this.staticText = "Each creature your opponents control blocks this turn if able"; - } - - public PredatoryRampageEffect(final PredatoryRampageEffect effect) { - super(effect); - } - - @Override - public PredatoryRampageEffect copy() { - return new PredatoryRampageEffect(this); - } - - @Override - public boolean applies(Permanent permanent, Ability source, Game game) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null && game.getOpponents(controller.getId()).contains(permanent.getControllerId())) { - return true; - } - return false; - } - - @Override - public boolean mustAttack(Game game) { - return false; - } - - @Override - public boolean mustBlock(Game game) { - return false; - } - - @Override - public boolean mustBlockAny(Game game) { - return true; - } -} diff --git a/Mage/src/mage/abilities/effects/common/combat/BlocksIfAbleAllEffect.java b/Mage/src/mage/abilities/effects/common/combat/BlocksIfAbleAllEffect.java index d8f0ab6f92..c2fa854ce4 100644 --- a/Mage/src/mage/abilities/effects/common/combat/BlocksIfAbleAllEffect.java +++ b/Mage/src/mage/abilities/effects/common/combat/BlocksIfAbleAllEffect.java @@ -69,15 +69,22 @@ public class BlocksIfAbleAllEffect extends RequirementEffect { public boolean applies(Permanent permanent, Ability source, Game game) { return filter.match(permanent, source.getSourceId(), source.getControllerId(), game); } - + + @Override + public boolean mustBlock(Game game) { + return true; + } + + @Override + public boolean mustBlockAny(Game game) { + return true; + } + @Override public boolean mustAttack(Game game) { return false; } - @Override - public boolean mustBlock(Game game) { - return true; - } + } diff --git a/Mage/src/mage/game/combat/Combat.java b/Mage/src/mage/game/combat/Combat.java index 143a1dd9de..3fa6ea0d24 100644 --- a/Mage/src/mage/game/combat/Combat.java +++ b/Mage/src/mage/game/combat/Combat.java @@ -61,7 +61,7 @@ public class Combat implements Serializable, Copyable { private static FilterCreatureForCombatBlock filterBlockers = new FilterCreatureForCombatBlock(); // There are effects that let creatures assigns combat damage equal to its toughness rather than its power private boolean useToughnessForDamage; - private List useToughnessForDamageFilters = new ArrayList<>(); + private final List useToughnessForDamageFilters = new ArrayList<>(); protected List groups = new ArrayList<>(); protected Map blockingGroups = new HashMap<>(); @@ -447,6 +447,7 @@ public class Combat implements Serializable, Copyable { /** * Retrieves all requirements that apply and creates a Map with blockers and attackers + * it contains only records if attackers can be retrieved * // Map> * * @param attackingPlayer - attacker @@ -565,14 +566,31 @@ public class Combat implements Serializable, Copyable { boolean mayBlock = false; for (UUID attackingCreatureId : getAttackers()) { if (creature.canBlock(attackingCreatureId, game)) { - // check restrictions of the creature to block that prevent it can be blocked Permanent attackingCreature = game.getPermanent(attackingCreatureId); - if (attackingCreature != null && attackingCreature.getMinBlockedBy() > 1) { - // TODO: check if enough possible blockers are available, if true, mayBlock can be set to true + if (attackingCreature != null) { + // check if the attacker is already blocked by a max of blockers, so blocker can't block it also + if (attackingCreature.getMaxBlockedBy() != 0) { // 0 = no restriction about the number of possible blockers + int alreadyBlockingCreatures = 0; + for(CombatGroup group :getGroups()) { + if (group.getAttackers().contains(attackingCreatureId)) { + alreadyBlockingCreatures = group.getBlockers().size(); + break; + } + } + if (attackingCreature.getMaxBlockedBy() <= alreadyBlockingCreatures) { + // Attacker can't be blocked by more blockers so check next attacker + continue; + } + } + // check restrictions of the creature to block that prevent it can be blocked - } else { - mayBlock = true; - break; + if (attackingCreature.getMinBlockedBy() > 1) { + // TODO: check if enough possible blockers are available, if true, mayBlock can be set to true + + } else { + mayBlock = true; + break; + } } } }