mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
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:
@@ -1,6 +1,9 @@
|
|||||||
package forge;
|
package forge;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import net.slightlymagic.braids.util.UtilFunctions;
|
import net.slightlymagic.braids.util.UtilFunctions;
|
||||||
import forge.Constant.Zone;
|
import forge.Constant.Zone;
|
||||||
import forge.card.cardFactory.CardFactoryInterface;
|
import forge.card.cardFactory.CardFactoryInterface;
|
||||||
@@ -101,6 +104,15 @@ public final class AllZone implements NewConstants {
|
|||||||
return Singletons.getModel().getGameState().getComputerPlayer();
|
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>
|
* <p>getQuestData.</p>
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -235,19 +235,6 @@ public final class AllZoneUtil {
|
|||||||
return player.getCardsIn(Zone.Battlefield).contains(card);
|
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
|
//////////////// getting all cards of a given color
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -424,24 +411,8 @@ public final class AllZoneUtil {
|
|||||||
* @return a int.
|
* @return a int.
|
||||||
*/
|
*/
|
||||||
public static int getDoublingSeasonMagnitude(final Player player) {
|
public static int getDoublingSeasonMagnitude(final Player player) {
|
||||||
int multiplier = 1;
|
|
||||||
int doublingSeasons = player.getCardsIn(Zone.Battlefield, "Doubling Season").size();
|
int doublingSeasons = player.getCardsIn(Zone.Battlefield, "Doubling Season").size();
|
||||||
if (doublingSeasons > 0) {
|
return (int) Math.pow(2, doublingSeasons); // pow(a,0) = 1; pow(a,1) = a ... no worries about size = 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -556,7 +556,7 @@ public class CombatUtil {
|
|||||||
|
|
||||||
|
|
||||||
if (c.getName().equals("Harbor Serpent")) {
|
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;
|
if (allislands.size() < 5) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -815,7 +815,7 @@ public class GameAction {
|
|||||||
*/
|
*/
|
||||||
private void destroyPlaneswalkers() {
|
private void destroyPlaneswalkers() {
|
||||||
//get all Planeswalkers
|
//get all Planeswalkers
|
||||||
CardList list = AllZoneUtil.getTypeIn(Zone.Battlefield, "Planeswalker");
|
CardList list = AllZoneUtil.getCardsIn(Zone.Battlefield).getType("Planeswalker");
|
||||||
|
|
||||||
Card c;
|
Card c;
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
@@ -841,7 +841,7 @@ public class GameAction {
|
|||||||
* <p>destroyLegendaryCreatures.</p>
|
* <p>destroyLegendaryCreatures.</p>
|
||||||
*/
|
*/
|
||||||
private void destroyLegendaryCreatures() {
|
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")) {
|
while (!a.isEmpty() && !AllZoneUtil.isCardInPlay("Mirror Gallery")) {
|
||||||
CardList b = AllZoneUtil.getCardsIn(Zone.Battlefield, a.get(0).getName());
|
CardList b = AllZoneUtil.getCardsIn(Zone.Battlefield, a.get(0).getName());
|
||||||
|
|||||||
@@ -1539,7 +1539,7 @@ public final class GuiDisplayUtil implements NewConstants {
|
|||||||
* @since 1.1.3
|
* @since 1.1.3
|
||||||
*/
|
*/
|
||||||
public static void devModeSetLife() {
|
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());
|
Object o = GuiUtils.getChoiceOptional("Set life for which player?", players.toArray());
|
||||||
if (null == o) {
|
if (null == o) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -966,7 +966,7 @@ public class AbilityFactory_DealDamage {
|
|||||||
for (Card c : list) c.addDamage(dmg, card);
|
for (Card c : list) c.addDamage(dmg, card);
|
||||||
|
|
||||||
if (players.equals("Each")) {
|
if (players.equals("Each")) {
|
||||||
for (Player p : AllZoneUtil.getPlayersInGame())
|
for (Player p : AllZone.getPlayersInGame())
|
||||||
p.addDamage(dmg, card);
|
p.addDamage(dmg, card);
|
||||||
} else if (players.equals("EachOpponent")) {
|
} else if (players.equals("EachOpponent")) {
|
||||||
for (Player p : AllZoneUtil.getOpponents(card.getController())) p.addDamage(dmg, card);
|
for (Player p : AllZoneUtil.getOpponents(card.getController())) p.addDamage(dmg, card);
|
||||||
|
|||||||
@@ -1820,14 +1820,14 @@ public abstract class AbstractCardFactory implements NewConstants, CardFactoryIn
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlayAI() {
|
public boolean canPlayAI() {
|
||||||
CardList arts = AllZoneUtil.getTypeIn(Zone.Battlefield, "Artifact");
|
CardList arts = AllZoneUtil.getCardsIn(Zone.Battlefield).filter(CardListFilter.artifacts);
|
||||||
return !arts.isEmpty();
|
return !arts.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resolve() {
|
public void resolve() {
|
||||||
if (card.getController().isComputer()) {
|
if (card.getController().isComputer()) {
|
||||||
CardList arts = AllZoneUtil.getTypeIn(Zone.Battlefield, "Artifact");
|
CardList arts = AllZoneUtil.getCardsIn(Zone.Battlefield).filter(CardListFilter.artifacts);
|
||||||
if (!arts.isEmpty()) {
|
if (!arts.isEmpty()) {
|
||||||
copyTarget[0] = CardFactoryUtil.AI_getBestArtifact(arts);
|
copyTarget[0] = CardFactoryUtil.AI_getBestArtifact(arts);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4955,7 +4955,7 @@ public class CardFactoryUtil {
|
|||||||
private static final long serialVersionUID = 6536398032388958127L;
|
private static final long serialVersionUID = 6536398032388958127L;
|
||||||
|
|
||||||
public void execute() {
|
public void execute() {
|
||||||
CardList cardsInPlay = AllZoneUtil.getTypeIn(Zone.Battlefield, "World");
|
CardList cardsInPlay = AllZoneUtil.getCardsIn(Zone.Battlefield).getType("World");
|
||||||
cardsInPlay.remove(card);
|
cardsInPlay.remove(card);
|
||||||
for (int i = 0; i < cardsInPlay.size(); i++) {
|
for (int i = 0; i < cardsInPlay.size(); i++) {
|
||||||
AllZone.getGameAction().sacrificeDestroy(cardsInPlay.get(i));
|
AllZone.getGameAction().sacrificeDestroy(cardsInPlay.get(i));
|
||||||
|
|||||||
@@ -448,7 +448,7 @@ class CardFactory_Auras {
|
|||||||
public CardList getCreturesInGrave() {
|
public CardList getCreturesInGrave() {
|
||||||
// This includes creatures Animate Dead can't enchant once in play.
|
// This includes creatures Animate Dead can't enchant once in play.
|
||||||
// The human may try to Animate them, the AI will not.
|
// 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() {
|
public boolean canPlay() {
|
||||||
|
|||||||
@@ -1381,7 +1381,7 @@ public class CardFactory_Instants {
|
|||||||
@Override
|
@Override
|
||||||
public void resolve() {
|
public void resolve() {
|
||||||
final Player you = card.getController();
|
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() {
|
CardList toReturn = ens.filter(new CardListFilter() {
|
||||||
public boolean addCard(final Card c) {
|
public boolean addCard(final Card c) {
|
||||||
Card enchanting = c.getEnchantingCard();
|
Card enchanting = c.getEnchantingCard();
|
||||||
|
|||||||
Reference in New Issue
Block a user