mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
- 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:
@@ -130,38 +130,6 @@ public class Combat {
|
||||
public Player getDefendingPlayer() {
|
||||
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
|
||||
// public int getDefendingDamage() {return defendingDamage;}
|
||||
|
||||
@@ -207,7 +207,39 @@ public class CombatUtil {
|
||||
}
|
||||
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?
|
||||
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 (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);
|
||||
}
|
||||
|
||||
@@ -334,17 +334,6 @@ public class ComputerUtil_Block2
|
||||
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)
|
||||
return combat;
|
||||
|
||||
@@ -390,7 +379,7 @@ public class ComputerUtil_Block2
|
||||
chumpBlockers = blockersLeft.getKeyword("CARDNAME blocks each turn if able.");
|
||||
// if an attacker with lure attacks - all that can block
|
||||
for(Card blocker : blockersLeft) {
|
||||
if(canBlockAttackerWithLure.contains(blocker)) chumpBlockers.add(blocker);
|
||||
if(CombatUtil.canBlockAnAttackerWithLure(blocker,combat)) chumpBlockers.add(blocker);
|
||||
}
|
||||
if (!chumpBlockers.isEmpty()) {
|
||||
attackers.shuffle();
|
||||
|
||||
@@ -10,6 +10,7 @@ import forge.ButtonUtil;
|
||||
import forge.Card;
|
||||
import forge.CardList;
|
||||
import forge.CardUtil;
|
||||
import forge.Combat;
|
||||
import forge.CombatUtil;
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
@@ -41,6 +42,7 @@ public class Input_Block extends Input {
|
||||
|
||||
|
||||
if(currentAttacker == null) {
|
||||
/*
|
||||
//Lure
|
||||
CardList attackers = new CardList(AllZone.Combat.getAttackers());
|
||||
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)");
|
||||
}
|
||||
@@ -68,10 +70,12 @@ public class Input_Block extends Input {
|
||||
|
||||
@Override
|
||||
public void selectButtonOK() {
|
||||
// Done blocking
|
||||
ButtonUtil.reset();
|
||||
|
||||
AllZone.Phase.setNeedToNextPhase(true);
|
||||
if(CombatUtil.finishedMandatotyBlocks(AllZone.Combat)) {
|
||||
// Done blocking
|
||||
ButtonUtil.reset();
|
||||
|
||||
AllZone.Phase.setNeedToNextPhase(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user