* Combat - Fixed a bug that creatures that have to block were not forced to block.

This commit is contained in:
LevelX2 2015-03-23 16:50:32 +01:00
parent 254d057218
commit a137ec1633
3 changed files with 40 additions and 56 deletions

View file

@ -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;
}
}

View file

@ -70,14 +70,21 @@ public class BlocksIfAbleAllEffect extends RequirementEffect {
return filter.match(permanent, source.getSourceId(), source.getControllerId(), game);
}
@Override
public boolean mustAttack(Game game) {
return false;
}
@Override
public boolean mustBlock(Game game) {
return true;
}
@Override
public boolean mustBlockAny(Game game) {
return true;
}
@Override
public boolean mustAttack(Game game) {
return false;
}
}

View file

@ -61,7 +61,7 @@ public class Combat implements Serializable, Copyable<Combat> {
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<FilterCreaturePermanent> useToughnessForDamageFilters = new ArrayList<>();
private final List<FilterCreaturePermanent> useToughnessForDamageFilters = new ArrayList<>();
protected List<CombatGroup> groups = new ArrayList<>();
protected Map<UUID, CombatGroup> blockingGroups = new HashMap<>();
@ -447,6 +447,7 @@ public class Combat implements Serializable, Copyable<Combat> {
/**
* Retrieves all requirements that apply and creates a Map with blockers and attackers
* it contains only records if attackers can be retrieved
* // Map<creature that can block, Set< all attackers the creature can block and force it to block the attacker>>
*
* @param attackingPlayer - attacker
@ -565,9 +566,25 @@ public class Combat implements Serializable, Copyable<Combat> {
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) {
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
if (attackingCreature.getMinBlockedBy() > 1) {
// TODO: check if enough possible blockers are available, if true, mayBlock can be set to true
} else {
@ -576,6 +593,7 @@ public class Combat implements Serializable, Copyable<Combat> {
}
}
}
}
// if so inform human player or set block for AI player
if (mayBlock) {
if (controller.isHuman()) {