code simplification in CF_Creatures and CF_Instants

This commit is contained in:
jendave
2011-08-07 00:48:07 +00:00
parent c93f867473
commit 0397755f12
2 changed files with 120 additions and 160 deletions

View File

@@ -124,17 +124,15 @@ public class CardFactory_Creatures {
@Override @Override
public void resolve() { public void resolve() {
final Card[] c = AllZone.getZone(Constant.Zone.Battlefield, card.getController()).getCards(); final CardList creatures = AllZoneUtil.getCreaturesInPlay(card.getController());
for(int i = 0; i < c.length; i++) for(Card creature : creatures) creature.addShield();
if(c[i].isCreature()) c[i].addShield();
AllZone.EndOfTurn.addUntil(new Command() { AllZone.EndOfTurn.addUntil(new Command() {
private static final long serialVersionUID = 5853778391858472471L; private static final long serialVersionUID = 5853778391858472471L;
public void execute() { public void execute() {
for(int i = 0; i < c.length; i++) for(Card creature : creatures) creature.resetShield();
c[i].resetShield();
} }
}); });
}//resolve() }//resolve()
@@ -955,12 +953,8 @@ public class CardFactory_Creatures {
private static final long serialVersionUID = 4414609319033894302L; private static final long serialVersionUID = 4414609319033894302L;
@Override @Override
public boolean canPlay() { public boolean canPlay() {
CardList possible = new CardList(AllZone.getZone(Constant.Zone.Hand, card.getController()).getCards()); CardList possible = AllZoneUtil.getPlayerHand(card.getController());
possible.filter(new CardListFilter(){ possible = possible.filter(AllZoneUtil.nonlands);
public boolean addCard(Card c){
return !c.isLand();
}
});
return !possible.isEmpty() && super.canPlay(); return !possible.isEmpty() && super.canPlay();
} }
@@ -1024,7 +1018,7 @@ public class CardFactory_Creatures {
} }
CardList getCreature() { CardList getCreature() {
CardList list = new CardList(AllZone.Computer_Battlefield.getCards()); CardList list = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer);
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(Card c) {
return c.isCreature() && return c.isCreature() &&
@@ -1075,7 +1069,7 @@ public class CardFactory_Creatures {
{ {
public void resolve() public void resolve()
{ {
final CardList list = new CardList(AllZone.getZone(Constant.Zone.Battlefield, card.getController()).getCards()).getType("Creature"); final CardList list = AllZoneUtil.getCreaturesInPlay(card.getController());
final int[] originalAttack = new int[list.size()]; final int[] originalAttack = new int[list.size()];
final int[] originalDefense = new int[list.size()]; final int[] originalDefense = new int[list.size()];
for(int i = 0; i < list.size(); i++) { for(int i = 0; i < list.size(); i++) {
@@ -1108,8 +1102,8 @@ public class CardFactory_Creatures {
{ {
return false; return false;
/* /*
CardList Clist = new CardList(AllZone.getZone(Constant.Zone.Play, AllZone.ComputerPlayer).getCards()).getType("Creature"); CardList Clist = AllZoneUtil.getCreaturesInPlay(AllZone.ComputerPlayer);
CardList Hlist = new CardList(AllZone.getZone(Constant.Zone.Play, AllZone.HumanPlayer).getCards()).getType("Creature"); CardList Hlist = AllZoneUtil.getCreaturesInPlay(AllZone.HumanPlayer);
return((Clist.size() - Hlist.size() * ComputerUtil.getAvailableMana().size() > AllZone.HumanPlayer.getLife()) return((Clist.size() - Hlist.size() * ComputerUtil.getAvailableMana().size() > AllZone.HumanPlayer.getLife())
&& AllZone.Phase.getPhase().equals(Constant.Phase.Main1)); && AllZone.Phase.getPhase().equals(Constant.Phase.Main1));
*/ */
@@ -1162,7 +1156,7 @@ public class CardFactory_Creatures {
//may return null //may return null
public Card getCreature() { public Card getCreature() {
CardList untapped = new CardList(AllZone.getZone(Constant.Zone.Battlefield, card.getController()).getCards()).getType("Creature"); CardList untapped = AllZoneUtil.getCreaturesInPlay(card.getController());
untapped = untapped.filter(new CardListFilter() { untapped = untapped.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(Card c) {
return c.isUntapped() && 6 > c.getNetAttack(); return c.isUntapped() && 6 > c.getNetAttack();
@@ -1210,9 +1204,7 @@ public class CardFactory_Creatures {
@Override @Override
public void showMessage() { public void showMessage() {
Player player = card.getController(); CardList targets = AllZoneUtil.getCreaturesInPlay(card.getController());
CardList targets = new CardList(AllZone.getZone(Constant.Zone.Battlefield, player).getCards());
targets = targets.getType("Creature");
stopSetNext(CardFactoryUtil.input_targetSpecific(ability, targets, stopSetNext(CardFactoryUtil.input_targetSpecific(ability, targets,
"Select a creature you control", true, false)); "Select a creature you control", true, false));
} }
@@ -1561,8 +1553,7 @@ public class CardFactory_Creatures {
public boolean canPlayAI() { public boolean canPlayAI() {
if(CardFactoryUtil.AI_doesCreatureAttack(card)) return false; if(CardFactoryUtil.AI_doesCreatureAttack(card)) return false;
CardList land = new CardList(AllZone.Human_Battlefield.getCards()); CardList land = AllZoneUtil.getPlayerLandsInPlay(AllZone.HumanPlayer);
land = land.getType("Land");
return land.size() != 0; return land.size() != 0;
} }
@@ -1626,8 +1617,8 @@ public class CardFactory_Creatures {
@Override @Override
public boolean canPlayAI() { public boolean canPlayAI() {
Card[] hand = AllZone.Computer_Hand.getCards(); CardList hand = AllZoneUtil.getPlayerHand(AllZone.ComputerPlayer);
return CardFactoryUtil.AI_doesCreatureAttack(card) && (hand.length > 3); return CardFactoryUtil.AI_doesCreatureAttack(card) && (hand.size() > 3);
} }
@Override @Override
@@ -1648,12 +1639,10 @@ public class CardFactory_Creatures {
card.setChosenColor(color[0]); card.setChosenColor(color[0]);
} else { } else {
// wild mongrel will choose a color that appears the most, but that might not be right way to choose // wild mongrel will choose a color that appears the most, but that might not be right way to choose
PlayerZone lib = AllZone.getZone(Constant.Zone.Library, AllZone.ComputerPlayer);
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer);
CardList list = new CardList(); CardList list = new CardList();
list.addAll(lib.getCards()); list.addAll(AllZoneUtil.getPlayerCardsInLibrary(AllZone.ComputerPlayer));
list.addAll(hand.getCards()); list.addAll(AllZoneUtil.getPlayerHand(AllZone.ComputerPlayer));
list.addAll(AllZone.Computer_Battlefield.getCards()); list.addAll(AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer));
color[0] = Constant.Color.White; color[0] = Constant.Color.White;
int max = list.getKeywordsContain(color[0]).size(); int max = list.getKeywordsContain(color[0]).size();
@@ -1771,12 +1760,10 @@ public class CardFactory_Creatures {
card.setChosenColor(color[0]); card.setChosenColor(color[0]);
} else { } else {
// AI chooses the color that appears in the keywords of the most cards in its deck, hand and on battlefield // AI chooses the color that appears in the keywords of the most cards in its deck, hand and on battlefield
PlayerZone lib = AllZone.getZone(Constant.Zone.Library, AllZone.ComputerPlayer);
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer);
CardList list = new CardList(); CardList list = new CardList();
list.addAll(lib.getCards()); list.addAll(AllZoneUtil.getPlayerCardsInLibrary(AllZone.ComputerPlayer));
list.addAll(hand.getCards()); list.addAll(AllZoneUtil.getPlayerHand(AllZone.ComputerPlayer));
list.addAll(AllZone.Computer_Battlefield.getCards()); list.addAll(AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer));
color[0] = Constant.Color.White; color[0] = Constant.Color.White;
int max = list.getKeywordsContain(color[0]).size(); int max = list.getKeywordsContain(color[0]).size();
@@ -1906,10 +1893,9 @@ public class CardFactory_Creatures {
final Ability ability = new Ability(card, "W") { final Ability ability = new Ability(card, "W") {
@Override @Override
public boolean canPlayAI() { /* public boolean canPlayAI() {
CardList list = new CardList(AllZone.Human_Play.getCards()); /*
list = list.getType("Creature"); CardList list = AllZoneUtil.getCreaturesInPlay(AllZone.HumanPlayer);
String phase = AllZone.Phase.getPhase(); String phase = AllZone.Phase.getPhase();
return phase.equals(Constant.Phase.Main2) && list.size() != 0; return phase.equals(Constant.Phase.Main2) && list.size() != 0;
*/ */
@@ -1976,7 +1962,7 @@ public class CardFactory_Creatures {
} }
CardList getCreature() { CardList getCreature() {
CardList list = new CardList(AllZone.Human_Battlefield.getCards()); CardList list = AllZoneUtil.getPlayerCardsInPlay(AllZone.HumanPlayer);
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(Card c) {
return c.isCreature() && (!c.isArtifact()) && CardFactoryUtil.canTarget(card, c); return c.isCreature() && (!c.isArtifact()) && CardFactoryUtil.canTarget(card, c);
@@ -2074,10 +2060,7 @@ public class CardFactory_Creatures {
setTargetCard(human.get(0)); setTargetCard(human.get(0));
} }
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer); CardList assassins = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer);
CardList assassins = new CardList();
assassins.addAll(play.getCards());
assassins = assassins.filter(new CardListFilter() { assassins = assassins.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(Card c) {
return c.isCreature() && (!c.hasSickness() || c.getKeyword().contains("Haste")) && c.isUntapped() && return c.isCreature() && (!c.hasSickness() || c.getKeyword().contains("Haste")) && c.isUntapped() &&
@@ -2140,22 +2123,19 @@ public class CardFactory_Creatures {
@Override @Override
public boolean canPlay() { public boolean canPlay() {
return getCreatures().length != 0 && AllZoneUtil.isCardInPlay(card) && super.canPlay(); return getCreatures().size() != 0 && AllZoneUtil.isCardInPlay(card) && super.canPlay();
} }
public Card[] getCreatures() { public CardList getCreatures() {
CardList creature = new CardList(); CardList creatures = AllZoneUtil.getPlayerTypeInGraveyard(card.getController(), "Elemental");
PlayerZone zone = AllZone.getZone(Constant.Zone.Graveyard, card.getController()); return creatures;
creature.addAll(zone.getCards());
creature = creature.getType("Elemental");
return creature.toArray();
} }
public Card getAIElemental() { public Card getAIElemental() {
Card c[] = getCreatures(); CardList c = getCreatures();
Card biggest = c[0]; Card biggest = c.get(0);
for(int i = 0; i < c.length; i++) for(int i = 0; i < c.size(); i++)
if(biggest.getNetAttack() < c[i].getNetAttack()) biggest = c[i]; if(biggest.getNetAttack() < c.get(i).getNetAttack()) biggest = c.get(i);
return biggest; return biggest;
} }
@@ -2241,8 +2221,7 @@ public class CardFactory_Creatures {
@Override @Override
public void resolve() { public void resolve() {
Player opponent = card.getController().getOpponent(); Player opponent = card.getController().getOpponent();
PlayerZone lib = AllZone.getZone(Constant.Zone.Library, opponent); CardList cards = AllZoneUtil.getPlayerCardsInLibrary(opponent);
CardList cards = new CardList(lib.getCards());
if(cards.size() > 0) { if(cards.size() > 0) {
if(card.getController().isHuman()) { if(card.getController().isHuman()) {
@@ -2252,7 +2231,7 @@ public class CardFactory_Creatures {
AllZone.GameAction.exile(c); AllZone.GameAction.exile(c);
opponent.shuffle(); opponent.shuffle();
} else { } else {
Card c = lib.get(0); Card c = cards.get(0);
AllZone.GameAction.exile(c); AllZone.GameAction.exile(c);
opponent.shuffle(); opponent.shuffle();
} }

View File

@@ -82,11 +82,9 @@ public class CardFactory_Instants {
color = (String)o; color = (String)o;
} }
else { else {
PlayerZone lib = AllZone.getZone(Constant.Zone.Library, AllZone.HumanPlayer);
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, AllZone.HumanPlayer);
CardList list = new CardList(); CardList list = new CardList();
list.addAll(lib.getCards()); list.addAll(AllZoneUtil.getPlayerCardsInLibrary(AllZone.HumanPlayer));
list.addAll(hand.getCards()); list.addAll(AllZoneUtil.getPlayerHand(AllZone.HumanPlayer));
if (list.size() > 0) { if (list.size() > 0) {
String mpcolor = CardFactoryUtil.getMostProminentColor(list); String mpcolor = CardFactoryUtil.getMostProminentColor(list);
@@ -106,14 +104,8 @@ public class CardFactory_Instants {
public void resolve() { public void resolve() {
final String kboost = getKeywordBoost(); final String kboost = getKeywordBoost();
CardList list = new CardList(); CardList list = AllZoneUtil.getPlayerCardsInPlay(card.getController());
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController()); list = list.filter(AllZoneUtil.white);
list.addAll(play.getCards());
list = list.filter(new CardListFilter() {
public boolean addCard(Card c) {
return c.isWhite();
}
});
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
final Card[] target = new Card[1]; final Card[] target = new Card[1];
@@ -786,17 +778,15 @@ public class CardFactory_Instants {
@Override @Override
public void resolve() { public void resolve() {
final Card[] c = AllZone.getZone(Constant.Zone.Battlefield, card.getController()).getCards(); final CardList creatures = AllZoneUtil.getCreaturesInPlay(card.getController());
for(int i = 0; i < c.length; i++) for(Card creature : creatures) creature.addShield();
if(c[i].isCreature()) c[i].addShield();
AllZone.EndOfTurn.addUntil(new Command() { AllZone.EndOfTurn.addUntil(new Command() {
private static final long serialVersionUID = -3946800525315027053L; private static final long serialVersionUID = -3946800525315027053L;
public void execute() { public void execute() {
for(int i = 0; i < c.length; i++) for(Card creature : creatures) creature.resetShield();
c[i].resetShield();
} }
}); });
@@ -810,6 +800,7 @@ public class CardFactory_Instants {
card.setSVar("PlayMain1", "TRUE"); card.setSVar("PlayMain1", "TRUE");
}//*************** END ************ END ************************** }//*************** END ************ END **************************
//*************** START *********** START ************************** //*************** START *********** START **************************
else if(cardName.equals("Banishing Knack")) { else if(cardName.equals("Banishing Knack")) {
SpellAbility spell = new Spell(card) { SpellAbility spell = new Spell(card) {
@@ -883,7 +874,7 @@ public class CardFactory_Instants {
} }
public void humanResolve() { public void humanResolve() {
CardList libraryList = new CardList(AllZone.Human_Library.getCards()); CardList libraryList = AllZoneUtil.getPlayerCardsInLibrary(AllZone.HumanPlayer);
CardList selectedCards = new CardList(); CardList selectedCards = new CardList();
Object o = GuiUtils.getChoiceOptional("Select first card", libraryList.toArray()); Object o = GuiUtils.getChoiceOptional("Select first card", libraryList.toArray());
@@ -984,31 +975,21 @@ public class CardFactory_Instants {
private static final long serialVersionUID = 1504792204536793942L; private static final long serialVersionUID = 1504792204536793942L;
public boolean oppMoreLand() { public boolean oppMoreLand() {
Player oppPlayer = card.getController().getOpponent(); Player player = card.getController();
CardList self = AllZoneUtil.getPlayerLandsInPlay(player);
PlayerZone selfZone = AllZone.getZone(Constant.Zone.Battlefield, card.getController()); CardList opp = AllZoneUtil.getPlayerLandsInPlay(player.getOpponent());
PlayerZone oppZone = AllZone.getZone(Constant.Zone.Battlefield, oppPlayer);
CardList self = new CardList(selfZone.getCards());
CardList opp = new CardList(oppZone.getCards());
self = self.getType("Land");
opp = opp.getType("Land");
return (self.size() < opp.size()); // && super.canPlay(); return (self.size() < opp.size()); // && super.canPlay();
}//oppoMoreLand() }//oppoMoreLand()
@Override @Override
public void resolve() { public void resolve() {
PlayerZone library = AllZone.getZone(Constant.Zone.Library, card.getController()); CardList plains = AllZoneUtil.getPlayerCardsInLibrary(card.getController());
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, card.getController());
CardList plains = new CardList(library.getCards());
plains = plains.getType("Plains"); plains = plains.getType("Plains");
if(0 < plains.size()) AllZone.GameAction.moveTo(hand, plains.get(0)); if(0 < plains.size()) AllZone.GameAction.moveToHand(plains.get(0));
if(oppMoreLand() && 1 < plains.size()) AllZone.GameAction.moveTo(hand, plains.get(1)); if(oppMoreLand() && 1 < plains.size()) AllZone.GameAction.moveToHand(plains.get(1));
}//resolve() }//resolve()
};//SpellAbility };//SpellAbility