- Implemented the keyword handling of "All creatures able to block CARDNAME do so." and "CARDNAME blocks each turn if able." for human blocking (was already implemented for the AI).

This commit is contained in:
jendave
2011-08-06 21:30:38 +00:00
parent 63f149e632
commit ae040cfd50
4 changed files with 45 additions and 50 deletions

View File

@@ -131,38 +131,6 @@ public class Combat {
return defendingPlayer; return defendingPlayer;
} }
public void setAttackersWithLure(CardList list) {
attackersWithLure = list;
}
public void addAttackersWithLure(Card a) {
attackersWithLure.add(a);
}
public CardList getAttackersWithLure() {
return attackersWithLure;
}
public boolean isAttackerWithLure(Card c) {
return attackersWithLure.contains(c);
}
public void setCanBlockAttackerWithLure(CardList list) {
canBlockAttackerWithLure = list;
}
public void addCanBlockAttackerWithLure(Card a) {
canBlockAttackerWithLure.add(a);
}
public CardList getCanBlockAttackerWithLure() {
return canBlockAttackerWithLure;
}
public boolean canBlockAttackerWithLure(Card c) {
return canBlockAttackerWithLure.contains(c);
}
// relates to defending player damage // relates to defending player damage
// public int getDefendingDamage() {return defendingDamage;} // public int getDefendingDamage() {return defendingDamage;}

View File

@@ -208,6 +208,38 @@ public class CombatUtil {
return true; return true;
} }
// Has the player chosen all mandatory blocks?
public static boolean finishedMandatotyBlocks(Combat combat) {
CardList blockers = AllZoneUtil.getCreaturesInPlay(AllZone.HumanPlayer);
//if a creature does not block but should, return false
for(Card blocker : blockers) {
if(!combat.getAllBlockers().contains(blocker)
&& (canBlockAnAttackerWithLure(blocker, combat) ||
blocker.getKeyword().contains("CARDNAME blocks each turn if able.")))
return false;
}
return true;
}
// can the blocker block an attacker with a lure effect?
public static boolean canBlockAnAttackerWithLure(Card blocker, Combat combat) {
if(blocker == null) return false;
if (canBlock(blocker, combat) == false) return false;
CardList attackersWithLure = new CardList(combat.getAttackers());
attackersWithLure = attackersWithLure.getKeyword("All creatures able to block CARDNAME do so.");
for(Card attacker : attackersWithLure) {
if(canBlock(blocker, combat) && canBlock(attacker, blocker)) return true;
}
return false;
}
// can the blocker block the attacker given the combat state? // can the blocker block the attacker given the combat state?
public static boolean canBlock(Card attacker, Card blocker, Combat combat) { public static boolean canBlock(Card attacker, Card blocker, Combat combat) {
@@ -217,7 +249,9 @@ public class CombatUtil {
if (canBlock(blocker, combat) == false) return false; if (canBlock(blocker, combat) == false) return false;
if (canBeBlocked(attacker, combat) == false) return false; if (canBeBlocked(attacker, combat) == false) return false;
if (!combat.isAttackerWithLure(attacker) && combat.canBlockAttackerWithLure(blocker)) return false; //if the attacker has no lure effect, but the blocker can block another attacker with lure, the blocker can't block the former
if (!attacker.getKeyword().contains("All creatures able to block CARDNAME do so.")
&& canBlockAnAttackerWithLure(blocker,combat)) return false;
return canBlock(attacker, blocker); return canBlock(attacker, blocker);
} }

View File

@@ -334,17 +334,6 @@ public class ComputerUtil_Block2
if(!CombatUtil.canBlock(b, combat)) blockersLeft.remove(b); if(!CombatUtil.canBlock(b, combat)) blockersLeft.remove(b);
} }
// Lure effects
CardList attackersWithLure = attackersLeft.getKeyword("All creatures able to block CARDNAME do so.");
combat.setAttackersWithLure(attackersWithLure);
CardList canBlockAttackerWithLure = new CardList();
for(Card attacker : attackersWithLure) {
for(Card b : possibleBlockers) {
if(CombatUtil.canBlock(attacker, b)) canBlockAttackerWithLure.add(b);
}
}
combat.setCanBlockAttackerWithLure(canBlockAttackerWithLure);
if (attackersLeft.size() == 0) if (attackersLeft.size() == 0)
return combat; return combat;
@@ -390,7 +379,7 @@ public class ComputerUtil_Block2
chumpBlockers = blockersLeft.getKeyword("CARDNAME blocks each turn if able."); chumpBlockers = blockersLeft.getKeyword("CARDNAME blocks each turn if able.");
// if an attacker with lure attacks - all that can block // if an attacker with lure attacks - all that can block
for(Card blocker : blockersLeft) { for(Card blocker : blockersLeft) {
if(canBlockAttackerWithLure.contains(blocker)) chumpBlockers.add(blocker); if(CombatUtil.canBlockAnAttackerWithLure(blocker,combat)) chumpBlockers.add(blocker);
} }
if (!chumpBlockers.isEmpty()) { if (!chumpBlockers.isEmpty()) {
attackers.shuffle(); attackers.shuffle();

View File

@@ -10,6 +10,7 @@ import forge.ButtonUtil;
import forge.Card; import forge.Card;
import forge.CardList; import forge.CardList;
import forge.CardUtil; import forge.CardUtil;
import forge.Combat;
import forge.CombatUtil; import forge.CombatUtil;
import forge.Command; import forge.Command;
import forge.Constant; import forge.Constant;
@@ -41,6 +42,7 @@ public class Input_Block extends Input {
if(currentAttacker == null) { if(currentAttacker == null) {
/*
//Lure //Lure
CardList attackers = new CardList(AllZone.Combat.getAttackers()); CardList attackers = new CardList(AllZone.Combat.getAttackers());
for(Card attacker:attackers) { for(Card attacker:attackers) {
@@ -53,7 +55,7 @@ public class Input_Block extends Input {
} }
} }
} }
} }*/
AllZone.Display.showMessage("To Block, click on your Opponents attacker first, then your blocker(s)"); AllZone.Display.showMessage("To Block, click on your Opponents attacker first, then your blocker(s)");
} }
@@ -68,11 +70,13 @@ public class Input_Block extends Input {
@Override @Override
public void selectButtonOK() { public void selectButtonOK() {
if(CombatUtil.finishedMandatotyBlocks(AllZone.Combat)) {
// Done blocking // Done blocking
ButtonUtil.reset(); ButtonUtil.reset();
AllZone.Phase.setNeedToNextPhase(true); AllZone.Phase.setNeedToNextPhase(true);
} }
}
@Override @Override
public void selectCard(Card card, PlayerZone zone) { public void selectCard(Card card, PlayerZone zone) {