Fixed that creatures forced to attack that have to pay a cost to attack lock the UI (not completed for all existing cards yet).

This commit is contained in:
LevelX2 2015-07-01 02:00:07 +02:00
parent 5f5513f4ed
commit 15fe85c5da
13 changed files with 326 additions and 301 deletions

View file

@ -1,36 +1,38 @@
/*
* 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.
*/
* 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.costs.mana;
import java.util.List;
import java.util.UUID;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.costs.VariableCost;
import mage.game.Game;
/**
*
@ -40,12 +42,18 @@ import mage.abilities.costs.VariableCost;
public interface ManaCosts<T extends ManaCost> extends List<T>, ManaCost {
ManaCosts<T> getUnpaidVariableCosts();
List<VariableCost> getVariableCosts();
int getX();
void setX(int x);
void load(String mana);
List<String> getSymbols();
boolean payOrRollback(Ability ability, Game game, UUID sourceId, UUID payingPlayerId);
@Override
Mana getMana();

View file

@ -1,31 +1,30 @@
/*
* 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.
*/
* 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.costs.mana;
import java.util.ArrayList;
@ -134,14 +133,16 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
}
/**
* bookmarks the current state and restores it if player doesn't pay the mana cost
*
* bookmarks the current state and restores it if player doesn't pay the
* mana cost
*
* @param ability
* @param game
* @param sourceId
* @param payingPlayerId
* @return true if the cost was paid
*/
@Override
public boolean payOrRollback(Ability ability, Game game, UUID sourceId, UUID payingPlayerId) {
int bookmark = game.bookmarkState();
if (pay(ability, game, sourceId, payingPlayerId, false)) {
@ -174,7 +175,6 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
return unpaid;
}
@Override
public List<VariableCost> getVariableCosts() {
List<VariableCost> variableCosts = new ArrayList<>();
@ -216,7 +216,6 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
}
//attempt to pay colored costs first
for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof ColoredManaCost) {
cost.assignPayment(game, ability, pool);
@ -234,15 +233,13 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
cost.assignPayment(game, ability, pool);
}
}
for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof SnowManaCost) {
cost.assignPayment(game, ability, pool);
}
}
for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof GenericManaCost) {
cost.assignPayment(game, ability, pool);
@ -280,8 +277,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
} else {
if (!symbol.equals("X")) {
this.add((T) new ColoredManaCost(ColoredManaSymbol.lookup(symbol.charAt(0))));
}
else {
} else {
// check X wasn't added before
if (modifierForX == 0) {
// count X occurence
@ -296,11 +292,9 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
//TODO: handle multiple {X} and/or {Y} symbols
}
} else {
if(symbol.equals("snow"))
{
if (symbol.equals("snow")) {
this.add((T) new SnowManaCost());
}
else if (Character.isDigit(symbol.charAt(0))) {
} else if (Character.isDigit(symbol.charAt(0))) {
this.add((T) new MonoHybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(2))));
} else if (symbol.contains("P")) {
this.add((T) new PhyrexianManaCost(ColoredManaSymbol.lookup(symbol.charAt(0))));
@ -443,7 +437,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
@Override
public boolean containsColor(ColoredManaSymbol coloredManaSymbol) {
for(ManaCost manaCost: this) {
for (ManaCost manaCost : this) {
if (manaCost.containsColor(coloredManaSymbol)) {
return true;
}

View file

@ -324,6 +324,30 @@ public class ContinuousEffects implements Serializable {
return effects;
}
public boolean checkIfThereArePayCostToAttackBlockEffects(GameEvent event, Game game) {
for (ReplacementEffect effect : replacementEffects) {
if (!effect.checksEventType(event, game)) {
continue;
}
if (effect instanceof PayCostToAttackBlockEffect) {
HashSet<Ability> abilities = replacementEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
// for replacment effects of static abilities do not use LKI to check if to apply
if (ability.getAbilityType() != AbilityType.STATIC || ability.isInUseableZone(game, null, event)) {
if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) {
if (!game.getScopeRelevant() || effect.hasSelfScope() || !event.getTargetId().equals(ability.getSourceId())) {
if (effect.applies(event, ability, game)) {
return true;
}
}
}
}
}
}
}
return false;
}
/**
*
* @param event

View file

@ -29,6 +29,7 @@ package mage.abilities.effects;
import mage.abilities.Ability;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.ManaCosts;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -38,5 +39,7 @@ import mage.game.events.GameEvent;
*/
public interface PayCostToAttackBlockEffect extends ReplacementEffect {
Cost getCostToPay(GameEvent event, Ability source, Game game);
ManaCosts getManaCostToPay(GameEvent event, Ability source, Game game);
Cost getOtherCostToPay(GameEvent event, Ability source, Game game);
}

View file

@ -29,12 +29,13 @@ package mage.abilities.effects;
import mage.abilities.Ability;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.ManaCostImpl;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.players.Player;
/**
@ -49,12 +50,29 @@ public abstract class PayCostToAttackBlockEffectImpl extends ReplacementEffectIm
}
private final Cost cost;
private final ManaCosts manaCosts;
private final RestrictType restrictType;
public PayCostToAttackBlockEffectImpl(Duration duration, Outcome outcome, RestrictType restrictType) {
super(duration, outcome, false);
this.restrictType = restrictType;
this.cost = null;
this.manaCosts = null;
}
public PayCostToAttackBlockEffectImpl(Duration duration, Outcome outcome, RestrictType restrictType, Cost cost) {
super(duration, outcome, false);
this.restrictType = restrictType;
this.cost = cost;
this.manaCosts = null;
}
public PayCostToAttackBlockEffectImpl(Duration duration, Outcome outcome, RestrictType restrictType, ManaCosts manaCosts) {
super(duration, outcome, false);
this.restrictType = restrictType;
this.cost = null;
this.manaCosts = manaCosts;
}
public PayCostToAttackBlockEffectImpl(PayCostToAttackBlockEffectImpl effect) {
@ -64,6 +82,11 @@ public abstract class PayCostToAttackBlockEffectImpl extends ReplacementEffectIm
} else {
this.cost = null;
}
if (effect.manaCosts != null) {
this.manaCosts = effect.manaCosts.copy();
} else {
this.manaCosts = null;
}
this.restrictType = effect.restrictType;
}
@ -82,20 +105,31 @@ public abstract class PayCostToAttackBlockEffectImpl extends ReplacementEffectIm
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
ManaCosts attackBlockManaTax = getManaCostToPay(event, source, game);
if (attackBlockManaTax != null) {
return handleManaCosts(attackBlockManaTax, event, source, game);
}
Cost attackBlockOtherTax = getOtherCostToPay(event, source, game);
if (attackBlockOtherTax != null) {
return handleOtherCosts(attackBlockOtherTax, event, source, game);
}
return false;
}
private boolean handleManaCosts(ManaCosts attackBlockManaTax, GameEvent event, Ability source, Game game) {
Player player = game.getPlayer(event.getPlayerId());
Cost attackBlockTax = getCostToPay(event, source, game);
if (player != null && attackBlockTax != null) {
if (player != null) {
String chooseText;
if (event.getType().equals(GameEvent.EventType.DECLARE_ATTACKER)) {
chooseText = "Pay " + attackBlockTax.getText() + " to attack?";
chooseText = "Pay " + attackBlockManaTax.getText() + " to attack?";
} else {
chooseText = "Pay " + attackBlockTax.getText() + " to block?";
chooseText = "Pay " + attackBlockManaTax.getText() + " to block?";
}
if (attackBlockTax.canPay(source, source.getSourceId(), player.getId(), game)
attackBlockManaTax.clearPaid();
if (attackBlockManaTax.canPay(source, source.getSourceId(), player.getId(), game)
&& player.chooseUse(Outcome.Neutral, chooseText, source, game)) {
if (attackBlockTax instanceof ManaCostImpl) {
ManaCostsImpl manaCosts = new ManaCostsImpl(attackBlockTax.getText());
if (manaCosts.payOrRollback(source, game, source.getSourceId(), event.getPlayerId())) {
if (attackBlockManaTax instanceof ManaCostsImpl) {
if (attackBlockManaTax.payOrRollback(source, game, source.getSourceId(), event.getPlayerId())) {
return false;
}
}
@ -105,9 +139,30 @@ public abstract class PayCostToAttackBlockEffectImpl extends ReplacementEffectIm
return false;
}
private boolean handleOtherCosts(Cost attackBlockOtherTax, GameEvent event, Ability source, Game game) {
Player player = game.getPlayer(event.getPlayerId());
if (player != null) {
attackBlockOtherTax.clearPaid();
if (attackBlockOtherTax.canPay(source, source.getSourceId(), event.getPlayerId(), game)
&& player.chooseUse(Outcome.Neutral,
attackBlockOtherTax.getText() + " to " + (event.getType().equals(EventType.DECLARE_ATTACKER) ? "attack?" : "block?"), source, game)) {
if (attackBlockOtherTax.pay(source, game, source.getSourceId(), event.getPlayerId(), false)) {
return false;
}
}
return true;
}
return false;
}
@Override
public Cost getCostToPay(GameEvent event, Ability source, Game game) {
public Cost getOtherCostToPay(GameEvent event, Ability source, Game game) {
return cost;
}
@Override
public ManaCosts getManaCostToPay(GameEvent event, Ability source, Game game) {
return manaCosts;
}
}

View file

@ -0,0 +1,41 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.effects.common.replacement;
import mage.abilities.Ability;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.effects.PayCostToAttackBlockEffectImpl;
import mage.abilities.effects.PayCostToAttackBlockEffectImpl.RestrictType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.events.GameEvent;
/**
*
* @author LevelX2
*/
public class CantAttackYouUnlessPayManaAllEffect extends PayCostToAttackBlockEffectImpl {
public CantAttackYouUnlessPayManaAllEffect(ManaCosts manaCosts) {
super(Duration.WhileOnBattlefield, Outcome.Detriment, RestrictType.ATTACK, manaCosts);
staticText = "Creatures can't attack you unless their controller pays " + manaCosts.getText() + " for each creature he or she controls that's attacking you";
}
CantAttackYouUnlessPayManaAllEffect(CantAttackYouUnlessPayManaAllEffect effect) {
super(effect);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return source.getControllerId().equals(event.getTargetId());
}
@Override
public CantAttackYouUnlessPayManaAllEffect copy() {
return new CantAttackYouUnlessPayManaAllEffect(this);
}
}

View file

@ -27,6 +27,15 @@
*/
package mage.game.combat;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.RequirementEffect;
import mage.abilities.effects.RestrictionEffect;
@ -37,6 +46,7 @@ import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.common.FilterCreatureForCombatBlock;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.common.FilterPlaneswalkerPermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -48,10 +58,6 @@ import mage.util.CardUtil;
import mage.util.Copyable;
import mage.util.trace.TraceUtil;
import java.io.Serializable;
import java.util.*;
import mage.filter.common.FilterCreaturePermanent;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -92,8 +98,8 @@ public class Combat implements Serializable, Copyable<Combat> {
this.useToughnessForDamage = combat.useToughnessForDamage;
for (Map.Entry<UUID, Set<UUID>> group : combat.numberCreaturesDefenderAttackedBy.entrySet()) {
this.numberCreaturesDefenderAttackedBy.put(group.getKey(), group.getValue());
}
}
for (Map.Entry<UUID, Set<UUID>> group : combat.creatureMustBlockAttackers.entrySet()) {
this.creatureMustBlockAttackers.put(group.getKey(), group.getValue());
}
@ -133,7 +139,7 @@ public class Combat implements Serializable, Copyable<Combat> {
public boolean useToughnessForDamage(Permanent permanent, Game game) {
if (useToughnessForDamage) {
for(FilterCreaturePermanent filter: useToughnessForDamageFilters) {
for (FilterCreaturePermanent filter : useToughnessForDamageFilters) {
if (filter.match(permanent, game)) {
return true;
}
@ -231,7 +237,7 @@ public class Combat implements Serializable, Copyable<Combat> {
}
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, attackerId, attackerId));
if (!game.isSimulation()) {
game.informPlayers(new StringBuilder(player.getLogName()).append(" attacks with ").append(groups.size()).append(groups.size() == 1 ? " creature":" creatures").toString());
game.informPlayers(new StringBuilder(player.getLogName()).append(" attacks with ").append(groups.size()).append(groups.size() == 1 ? " creature" : " creatures").toString());
}
}
@ -256,20 +262,38 @@ public class Combat implements Serializable, Copyable<Combat> {
}
}
if (mustAttack) {
creaturesForcedToAttack.put(creature.getId(), defendersForcedToAttack);
if (defendersForcedToAttack.isEmpty()) {
if (defenders.size() == 1) {
player.declareAttacker(creature.getId(), defenders.iterator().next(), game, false);
} else {
TargetDefender target = new TargetDefender(defenders, creature.getId());
target.setRequired(true);
if (player.chooseTarget(Outcome.Damage, target, null, game)) {
player.declareAttacker(creature.getId(), target.getFirstTarget(), game, false);
}
// check which defenders the forced to attck creature can attack without paying a cost
HashSet<UUID> defendersCostlessAttackable = new HashSet<>();
defendersCostlessAttackable.addAll(defenders);
for (UUID defenderId : defenders) {
if (game.getContinuousEffects().checkIfThereArePayCostToAttackBlockEffects(
GameEvent.getEvent(GameEvent.EventType.DECLARE_ATTACKER,
defenderId, creature.getId(), creature.getControllerId()), game)) {
defendersCostlessAttackable.remove(defenderId);
defendersForcedToAttack.remove(defenderId);
}
} else {
player.declareAttacker(creature.getId(), defendersForcedToAttack.iterator().next(), game, false);
}
// force attack only if a defender can be attacked without paying a cost
if (!defendersCostlessAttackable.isEmpty()) {
// No need to attack a special defender
if (defendersForcedToAttack.isEmpty()) {
creaturesForcedToAttack.put(creature.getId(), defendersForcedToAttack);
if (defendersForcedToAttack.isEmpty()) {
if (defendersCostlessAttackable.size() == 1) {
player.declareAttacker(creature.getId(), defenders.iterator().next(), game, false);
}
} else {
TargetDefender target = new TargetDefender(defendersCostlessAttackable, creature.getId());
target.setRequired(true);
if (player.chooseTarget(Outcome.Damage, target, null, game)) {
player.declareAttacker(creature.getId(), target.getFirstTarget(), game, false);
}
}
} else {
player.declareAttacker(creature.getId(), defendersForcedToAttack.iterator().next(), game, false);
}
}
}
}
@ -457,17 +481,18 @@ 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>>
*
* 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
* @param game
* @param game
*/
private void retrieveMustBlockAttackerRequirements(Player attackingPlayer, Game game) {
if (!game.getContinuousEffects().existRequirementEffects()) {
return;
}
}
for (Permanent possibleBlocker : game.getBattlefield().getActivePermanents(filterBlockers, attackingPlayer.getId(), game)) {
for (Map.Entry<RequirementEffect, HashSet<Ability>> requirementEntry : game.getContinuousEffects().getApplicableRequirementEffects(possibleBlocker, game).entrySet()) {
if (requirementEntry.getKey().mustBlock(game)) {
@ -582,7 +607,7 @@ public class Combat implements Serializable, Copyable<Combat> {
// 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()) {
for (CombatGroup group : getGroups()) {
if (group.getAttackers().contains(attackingCreatureId)) {
alreadyBlockingCreatures = group.getBlockers().size();
break;
@ -874,7 +899,7 @@ public class Combat implements Serializable, Copyable<Combat> {
Permanent attacker = game.getPermanent(attackerId);
attacker.setAttacking(true);
groups.add(newGroup);
return true;
return true;
}
public boolean canDefenderBeAttacked(UUID attackerId, UUID defenderId, Game game) {
@ -999,7 +1024,6 @@ public class Combat implements Serializable, Copyable<Combat> {
// }
// return total;
// }
public boolean attacksAlone() {
return (groups.size() == 1 && groups.get(0).getAttackers().size() == 1);
}
@ -1106,10 +1130,9 @@ public class Combat implements Serializable, Copyable<Combat> {
}
}
public void removeBlockerGromGroup(UUID blockerId, CombatGroup groupToUnblock, Game game) {
Permanent creature = game.getPermanent(blockerId);
if (creature != null) {
if (creature != null) {
for (CombatGroup group : groups) {
if (group.equals(groupToUnblock) && group.blockers.contains(blockerId)) {
group.blockers.remove(blockerId);
@ -1124,9 +1147,9 @@ public class Combat implements Serializable, Copyable<Combat> {
}
}
}
}
}
}
public void removeBlocker(UUID blockerId, Game game) {
for (CombatGroup group : groups) {
if (group.blockers.contains(blockerId)) {