moved getPlayersInGame from AllZoneUtil to AllZone (together with getHumanPlayer and getComputerPlayer)

removed getTypeIn() from AllZoneUtil, all ocurrencies use getCardsIn().filter(CardListFilter.type)... does not allocate memory for filter each time.
This commit is contained in:
Maxmtg
2011-09-20 01:46:24 +00:00
parent 035ab8cfb6
commit d326149ba6
10 changed files with 23 additions and 40 deletions

View File

@@ -1,6 +1,9 @@
package forge;
import java.util.Arrays;
import java.util.List;
import net.slightlymagic.braids.util.UtilFunctions;
import forge.Constant.Zone;
import forge.card.cardFactory.CardFactoryInterface;
@@ -101,6 +104,15 @@ public final class AllZone implements NewConstants {
return Singletons.getModel().getGameState().getComputerPlayer();
}
/**
* get a list of all players participating in this game.
*
* @return a list of all player participating in this game
*/
public static List<Player> getPlayersInGame() {
return Arrays.asList(Singletons.getModel().getGameState().getPlayers());
}
/**
* <p>getQuestData.</p>
*

View File

@@ -235,19 +235,6 @@ public final class AllZoneUtil {
return player.getCardsIn(Zone.Battlefield).contains(card);
}
///get a list of certain types are in play (like Mountain, Elf, etc...)
/**
* gets a list of all cards with a certain type (Mountain, Elf, etc...) in play.
*
* @param cardType the type to find in play
* @return a CardList with all cards of the given type in play
*/
public static CardList getTypeIn(final Zone zone, final String cardType) {
return getCardsIn(zone).getType(cardType);
}
//////////////// getting all cards of a given color
/**
@@ -424,24 +411,8 @@ public final class AllZoneUtil {
* @return a int.
*/
public static int getDoublingSeasonMagnitude(final Player player) {
int multiplier = 1;
int doublingSeasons = player.getCardsIn(Zone.Battlefield, "Doubling Season").size();
if (doublingSeasons > 0) {
multiplier = (int) Math.pow(2, doublingSeasons);
}
return multiplier;
}
/**
* get a list of all players participating in this game.
*
* @return a list of all player participating in this game
*/
public static ArrayList<Player> getPlayersInGame() {
ArrayList<Player> list = new ArrayList<Player>();
list.add(AllZone.getHumanPlayer());
list.add(AllZone.getComputerPlayer());
return list;
return (int) Math.pow(2, doublingSeasons); // pow(a,0) = 1; pow(a,1) = a ... no worries about size = 0
}
/**

View File

@@ -556,7 +556,7 @@ public class CombatUtil {
if (c.getName().equals("Harbor Serpent")) {
CardList allislands = AllZoneUtil.getTypeIn(Zone.Battlefield, "Island");
CardList allislands = AllZoneUtil.getCardsIn(Zone.Battlefield).getType("Island");
if (allislands.size() < 5) return false;
}

View File

@@ -815,7 +815,7 @@ public class GameAction {
*/
private void destroyPlaneswalkers() {
//get all Planeswalkers
CardList list = AllZoneUtil.getTypeIn(Zone.Battlefield, "Planeswalker");
CardList list = AllZoneUtil.getCardsIn(Zone.Battlefield).getType("Planeswalker");
Card c;
for (int i = 0; i < list.size(); i++) {
@@ -841,7 +841,7 @@ public class GameAction {
* <p>destroyLegendaryCreatures.</p>
*/
private void destroyLegendaryCreatures() {
CardList a = AllZoneUtil.getTypeIn(Zone.Battlefield, "Legendary");
CardList a = AllZoneUtil.getCardsIn(Zone.Battlefield).getType("Legendary");
while (!a.isEmpty() && !AllZoneUtil.isCardInPlay("Mirror Gallery")) {
CardList b = AllZoneUtil.getCardsIn(Zone.Battlefield, a.get(0).getName());

View File

@@ -1539,7 +1539,7 @@ public final class GuiDisplayUtil implements NewConstants {
* @since 1.1.3
*/
public static void devModeSetLife() {
ArrayList<Player> players = AllZoneUtil.getPlayersInGame();
List<Player> players = AllZone.getPlayersInGame();
Object o = GuiUtils.getChoiceOptional("Set life for which player?", players.toArray());
if (null == o) {
return;

View File

@@ -966,7 +966,7 @@ public class AbilityFactory_DealDamage {
for (Card c : list) c.addDamage(dmg, card);
if (players.equals("Each")) {
for (Player p : AllZoneUtil.getPlayersInGame())
for (Player p : AllZone.getPlayersInGame())
p.addDamage(dmg, card);
} else if (players.equals("EachOpponent")) {
for (Player p : AllZoneUtil.getOpponents(card.getController())) p.addDamage(dmg, card);

View File

@@ -1820,14 +1820,14 @@ public abstract class AbstractCardFactory implements NewConstants, CardFactoryIn
@Override
public boolean canPlayAI() {
CardList arts = AllZoneUtil.getTypeIn(Zone.Battlefield, "Artifact");
CardList arts = AllZoneUtil.getCardsIn(Zone.Battlefield).filter(CardListFilter.artifacts);
return !arts.isEmpty();
}
@Override
public void resolve() {
if (card.getController().isComputer()) {
CardList arts = AllZoneUtil.getTypeIn(Zone.Battlefield, "Artifact");
CardList arts = AllZoneUtil.getCardsIn(Zone.Battlefield).filter(CardListFilter.artifacts);
if (!arts.isEmpty()) {
copyTarget[0] = CardFactoryUtil.AI_getBestArtifact(arts);
}

View File

@@ -4955,7 +4955,7 @@ public class CardFactoryUtil {
private static final long serialVersionUID = 6536398032388958127L;
public void execute() {
CardList cardsInPlay = AllZoneUtil.getTypeIn(Zone.Battlefield, "World");
CardList cardsInPlay = AllZoneUtil.getCardsIn(Zone.Battlefield).getType("World");
cardsInPlay.remove(card);
for (int i = 0; i < cardsInPlay.size(); i++) {
AllZone.getGameAction().sacrificeDestroy(cardsInPlay.get(i));

View File

@@ -448,7 +448,7 @@ class CardFactory_Auras {
public CardList getCreturesInGrave() {
// This includes creatures Animate Dead can't enchant once in play.
// The human may try to Animate them, the AI will not.
return AllZoneUtil.getTypeIn(Zone.Graveyard, "Creature");
return AllZoneUtil.getCardsIn(Zone.Graveyard).filter(CardListFilter.creatures);
}
public boolean canPlay() {

View File

@@ -1381,7 +1381,7 @@ public class CardFactory_Instants {
@Override
public void resolve() {
final Player you = card.getController();
CardList ens = AllZoneUtil.getTypeIn(Zone.Battlefield,"Enchantment");
CardList ens = AllZoneUtil.getCardsIn(Zone.Battlefield).filter(CardListFilter.enchantments);
CardList toReturn = ens.filter(new CardListFilter() {
public boolean addCard(final Card c) {
Card enchanting = c.getEnchantingCard();