code simplifications in CombatUtil and ComputerUtil

This commit is contained in:
jendave
2011-08-07 00:53:27 +00:00
parent 6ca1e7013f
commit 8422ae18e2
2 changed files with 22 additions and 49 deletions

View File

@@ -84,8 +84,7 @@ public class CombatUtil {
//Landwalk //Landwalk
if (!AllZoneUtil.isCardInPlay("Staff of the Ages")) { //"Creatures with landwalk abilities can be blocked as though they didn't have those abilities." if (!AllZoneUtil.isCardInPlay("Staff of the Ages")) { //"Creatures with landwalk abilities can be blocked as though they didn't have those abilities."
PlayerZone blkPZ = AllZone.getZone(Constant.Zone.Battlefield, attacker.getController().getOpponent()); CardList blkCL = AllZoneUtil.getPlayerCardsInPlay(attacker.getController().getOpponent());
CardList blkCL = new CardList(blkPZ.getCards());
CardList temp = new CardList(); CardList temp = new CardList();
if(attacker.getKeyword().contains("Plainswalk")) { if(attacker.getKeyword().contains("Plainswalk")) {
@@ -532,18 +531,14 @@ public class CombatUtil {
if (AllZoneUtil.isCardInPlay("Ensnaring Bridge")) { if (AllZoneUtil.isCardInPlay("Ensnaring Bridge")) {
int limit = Integer.MAX_VALUE; int limit = Integer.MAX_VALUE;
CardList Human = new CardList(); CardList Human = AllZoneUtil.getPlayerCardsInPlay(AllZone.HumanPlayer);
Human.addAll(AllZone.Human_Battlefield.getCards());
if (Human.getName("Ensnaring Bridge").size() > 0) { if (Human.getName("Ensnaring Bridge").size() > 0) {
CardList Hand = new CardList(); CardList Hand = AllZoneUtil.getPlayerHand(AllZone.HumanPlayer);
Hand.addAll(AllZone.getZone(Constant.Zone.Hand, AllZone.HumanPlayer).getCards());
limit = Hand.size(); limit = Hand.size();
} }
CardList Compi = new CardList(); CardList Compi = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer);
Compi.addAll(AllZone.Computer_Battlefield.getCards());
if (Compi.getName("Ensnaring Bridge").size() > 0) { if (Compi.getName("Ensnaring Bridge").size() > 0) {
CardList Hand = new CardList(); CardList Hand = AllZoneUtil.getPlayerHand(AllZone.ComputerPlayer);
Hand.addAll(AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer).getCards());
if (Hand.size() < limit) limit = Hand.size(); if (Hand.size() < limit) limit = Hand.size();
} }
if (c.getNetAttack() > limit) return false; if (c.getNetAttack() > limit) return false;
@@ -1198,13 +1193,10 @@ public class CombatUtil {
}//canDestroyBlocker }//canDestroyBlocker
public static void removeAllDamage() { public static void removeAllDamage() {
Card[] c = AllZone.Human_Battlefield.getCards(); CardList cl = AllZoneUtil.getCardsInPlay();
for(int i = 0; i < c.length; i++) for(Card c : cl) {
c[i].setDamage(0); c.setDamage(0);
}
c = AllZone.Computer_Battlefield.getCards();
for(int i = 0; i < c.length; i++)
c[i].setDamage(0);
} }
public static void showCombat() { public static void showCombat() {
@@ -1365,7 +1357,7 @@ public class CombatUtil {
{ {
if (crd.getController().isHuman()) if (crd.getController().isHuman())
{ {
CardList list = new CardList(AllZone.Computer_Battlefield.getCards()); CardList list = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer);
ComputerUtil.sacrificePermanents(a, list); ComputerUtil.sacrificePermanents(a, list);
} }
else else
@@ -1399,13 +1391,8 @@ public class CombatUtil {
if(c.getName().equals("Zur the Enchanter") && !c.getCreatureAttackedThisCombat()) { if(c.getName().equals("Zur the Enchanter") && !c.getCreatureAttackedThisCombat()) {
//hack, to make sure this doesn't break grabbing an oblivion ring: //hack, to make sure this doesn't break grabbing an oblivion ring:
c.setCreatureAttackedThisCombat(true); c.setCreatureAttackedThisCombat(true);
PlayerZone library = AllZone.getZone(Constant.Zone.Library, c.getController());
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, c.getController());
PlayerZone oppPlay = AllZone.getZone(Constant.Zone.Battlefield,
c.getController().getOpponent());
CardList enchantments = new CardList(library.getCards()); CardList enchantments = AllZoneUtil.getPlayerCardsInLibrary(c.getController());
enchantments = enchantments.filter(new CardListFilter() { enchantments = enchantments.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(Card c) {
if(c.isEnchantment() && c.getCMC() <= 3) return true; if(c.isEnchantment() && c.getCMC() <= 3) return true;
@@ -1424,16 +1411,12 @@ public class CombatUtil {
if(crd.isAura()) { if(crd.isAura()) {
Object obj = null; Object obj = null;
if(crd.getKeyword().contains("Enchant creature")) { if(crd.getKeyword().contains("Enchant creature")) {
CardList creats = new CardList(play.getCards()); CardList creats = AllZoneUtil.getCreaturesInPlay();
creats.addAll(oppPlay.getCards());
creats = creats.getType("Creature");
obj = GuiUtils.getChoiceOptional("Pick a creature to attach " obj = GuiUtils.getChoiceOptional("Pick a creature to attach "
+ crd.getName() + " to", creats.toArray()); + crd.getName() + " to", creats.toArray());
} else if(crd.getKeyword().contains("Enchant land") } else if(crd.getKeyword().contains("Enchant land")
|| crd.getKeyword().contains("Enchant land you control")) { || crd.getKeyword().contains("Enchant land you control")) {
CardList lands = new CardList(play.getCards()); CardList lands = AllZoneUtil.getLandsInPlay();
//lands.addAll(oppPlay.getCards());
lands = lands.getType("Land");
if(lands.size() > 0) obj = GuiUtils.getChoiceOptional( if(lands.size() > 0) obj = GuiUtils.getChoiceOptional(
"Pick a land to attach " + crd.getName() + " to", lands.toArray()); "Pick a land to attach " + crd.getName() + " to", lands.toArray());
} }
@@ -1472,8 +1455,7 @@ public class CombatUtil {
else if(c.getName().equals("Spectral Bears")) { else if(c.getName().equals("Spectral Bears")) {
Player opp = c.getController().getOpponent(); Player opp = c.getController().getOpponent();
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, opp); CardList list = AllZoneUtil.getPlayerCardsInPlay(opp);
CardList list = new CardList(play.getCards());
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {
public boolean addCard(Card crd) { public boolean addCard(Card crd) {
return crd.isBlack() && !crd.isToken(); return crd.isBlack() && !crd.isToken();
@@ -1486,13 +1468,8 @@ public class CombatUtil {
else if(c.getName().equals("Spectral Force")) { else if(c.getName().equals("Spectral Force")) {
Player opp = c.getController().getOpponent(); Player opp = c.getController().getOpponent();
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, opp); CardList list = AllZoneUtil.getPlayerCardsInPlay(opp);
CardList list = new CardList(play.getCards()); list = list.filter(AllZoneUtil.black);
list = list.filter(new CardListFilter() {
public boolean addCard(Card crd) {
return crd.isBlack();
}
});
if(list.size() == 0) { if(list.size() == 0) {
c.addExtrinsicKeyword("This card doesn't untap during your next untap step."); c.addExtrinsicKeyword("This card doesn't untap during your next untap step.");
} }
@@ -1533,9 +1510,8 @@ public class CombatUtil {
else if(c.getName().equals("Preeminent Captain") && !c.getCreatureAttackedThisCombat()) { else if(c.getName().equals("Preeminent Captain") && !c.getCreatureAttackedThisCombat()) {
System.out.println("Preeminent Captain Attacks"); System.out.println("Preeminent Captain Attacks");
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, c.getController());
CardList soldiers = new CardList(hand.getCards()); CardList soldiers = AllZoneUtil.getPlayerHand(c.getController());
soldiers = soldiers.getType("Soldier"); soldiers = soldiers.getType("Soldier");
if(soldiers.size() > 0) { if(soldiers.size() > 0) {
@@ -1694,8 +1670,7 @@ public class CombatUtil {
if (a.getName().equals("Robber Fly") && !a.getCreatureGotBlockedThisCombat()) { if (a.getName().equals("Robber Fly") && !a.getCreatureGotBlockedThisCombat()) {
Player opp = b.getController(); Player opp = b.getController();
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, opp); CardList list = AllZoneUtil.getPlayerHand(opp);
CardList list = new CardList(hand.getCards());
int handSize = list.size(); int handSize = list.size();
// opponent discards their hand, // opponent discards their hand,
@@ -1784,9 +1759,7 @@ public class CombatUtil {
Ability ability4 = new Ability(c, "0") { Ability ability4 = new Ability(c, "0") {
@Override @Override
public void resolve() { public void resolve() {
PlayerZone library = AllZone.getZone(Constant.Zone.Library, attacker.getController()); CardList enchantments = AllZoneUtil.getPlayerCardsInLibrary(attacker.getController());
CardList enchantments = new CardList(library.getCards());
//final String turn = attacker.getController(); //final String turn = attacker.getController();
enchantments = enchantments.filter(new CardListFilter() { enchantments = enchantments.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(Card c) {

View File

@@ -259,12 +259,12 @@ public class ComputerUtil
static public SpellAbility[] getSpellAbility() static public SpellAbility[] getSpellAbility()
{ {
CardList all = new CardList(); CardList all = new CardList();
all.addAll(AllZone.Computer_Battlefield.getCards()); all.addAll(AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer));
all.addAll(AllZone.Computer_Hand.getCards()); all.addAll(AllZoneUtil.getPlayerHand(AllZone.ComputerPlayer));
all.addAll(CardFactoryUtil.getGraveyardActivationCards(AllZone.ComputerPlayer).toArray()); all.addAll(CardFactoryUtil.getGraveyardActivationCards(AllZone.ComputerPlayer).toArray());
CardList humanPlayable = new CardList(); CardList humanPlayable = new CardList();
humanPlayable.addAll(AllZone.Human_Battlefield.getCards()); humanPlayable.addAll(AllZoneUtil.getPlayerCardsInPlay(AllZone.HumanPlayer));
humanPlayable = humanPlayable.filter(new CardListFilter() humanPlayable = humanPlayable.filter(new CardListFilter()
{ {
public boolean addCard(Card c) public boolean addCard(Card c)