mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
* Combat - Fixed a bug that creatures that have to block were not forced to block.
This commit is contained in:
parent
254d057218
commit
a137ec1633
3 changed files with 40 additions and 56 deletions
|
@ -33,7 +33,6 @@ import mage.constants.Rarity;
|
||||||
import mage.constants.TargetController;
|
import mage.constants.TargetController;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.effects.RequirementEffect;
|
import mage.abilities.effects.RequirementEffect;
|
||||||
import mage.abilities.effects.common.AddContinuousEffectToGame;
|
|
||||||
import mage.abilities.effects.common.continuous.BoostControlledEffect;
|
import mage.abilities.effects.common.continuous.BoostControlledEffect;
|
||||||
import mage.abilities.effects.common.continuous.GainAbilityAllEffect;
|
import mage.abilities.effects.common.continuous.GainAbilityAllEffect;
|
||||||
import mage.abilities.keyword.BlocksThisTurnMarkerAbility;
|
import mage.abilities.keyword.BlocksThisTurnMarkerAbility;
|
||||||
|
@ -45,13 +44,14 @@ import mage.game.permanent.Permanent;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.abilities.effects.common.combat.BlocksIfAbleAllEffect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author magenoxx_at_gmail.com
|
* @author magenoxx_at_gmail.com
|
||||||
*/
|
*/
|
||||||
public class PredatoryRampage extends CardImpl {
|
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 {
|
static {
|
||||||
filter.add(new ControllerPredicate(TargetController.OPPONENT));
|
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.
|
// Creatures you control get +3/+3 until end of turn.
|
||||||
this.getSpellAbility().addEffect(new BoostControlledEffect(3, 3, Duration.EndOfTurn));
|
this.getSpellAbility().addEffect(new BoostControlledEffect(3, 3, Duration.EndOfTurn));
|
||||||
// Each creature your opponents control blocks this turn if able.
|
// 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, ""));
|
this.getSpellAbility().addEffect(new GainAbilityAllEffect(BlocksThisTurnMarkerAbility.getInstance(), Duration.EndOfTurn, filter, ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,44 +79,3 @@ public class PredatoryRampage extends CardImpl {
|
||||||
return new PredatoryRampage(this);
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -69,15 +69,22 @@ public class BlocksIfAbleAllEffect extends RequirementEffect {
|
||||||
public boolean applies(Permanent permanent, Ability source, Game game) {
|
public boolean applies(Permanent permanent, Ability source, Game game) {
|
||||||
return filter.match(permanent, source.getSourceId(), source.getControllerId(), 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
|
@Override
|
||||||
public boolean mustAttack(Game game) {
|
public boolean mustAttack(Game game) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mustBlock(Game game) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class Combat implements Serializable, Copyable<Combat> {
|
||||||
private static FilterCreatureForCombatBlock filterBlockers = new FilterCreatureForCombatBlock();
|
private static FilterCreatureForCombatBlock filterBlockers = new FilterCreatureForCombatBlock();
|
||||||
// There are effects that let creatures assigns combat damage equal to its toughness rather than its power
|
// There are effects that let creatures assigns combat damage equal to its toughness rather than its power
|
||||||
private boolean useToughnessForDamage;
|
private boolean useToughnessForDamage;
|
||||||
private List<FilterCreaturePermanent> useToughnessForDamageFilters = new ArrayList<>();
|
private final List<FilterCreaturePermanent> useToughnessForDamageFilters = new ArrayList<>();
|
||||||
|
|
||||||
protected List<CombatGroup> groups = new ArrayList<>();
|
protected List<CombatGroup> groups = new ArrayList<>();
|
||||||
protected Map<UUID, CombatGroup> blockingGroups = new HashMap<>();
|
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
|
* 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>>
|
* // Map<creature that can block, Set< all attackers the creature can block and force it to block the attacker>>
|
||||||
*
|
*
|
||||||
* @param attackingPlayer - attacker
|
* @param attackingPlayer - attacker
|
||||||
|
@ -565,14 +566,31 @@ public class Combat implements Serializable, Copyable<Combat> {
|
||||||
boolean mayBlock = false;
|
boolean mayBlock = false;
|
||||||
for (UUID attackingCreatureId : getAttackers()) {
|
for (UUID attackingCreatureId : getAttackers()) {
|
||||||
if (creature.canBlock(attackingCreatureId, game)) {
|
if (creature.canBlock(attackingCreatureId, game)) {
|
||||||
// check restrictions of the creature to block that prevent it can be blocked
|
|
||||||
Permanent attackingCreature = game.getPermanent(attackingCreatureId);
|
Permanent attackingCreature = game.getPermanent(attackingCreatureId);
|
||||||
if (attackingCreature != null && attackingCreature.getMinBlockedBy() > 1) {
|
if (attackingCreature != null) {
|
||||||
// TODO: check if enough possible blockers are available, if true, mayBlock can be set to true
|
// 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 {
|
if (attackingCreature.getMinBlockedBy() > 1) {
|
||||||
mayBlock = true;
|
// TODO: check if enough possible blockers are available, if true, mayBlock can be set to true
|
||||||
break;
|
|
||||||
|
} else {
|
||||||
|
mayBlock = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue