mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
several code simplifications in CardFactoryUtil.java
This commit is contained in:
@@ -1075,9 +1075,7 @@ public class CardFactoryUtil {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resolve() {
|
public void resolve() {
|
||||||
PlayerZone lib = AllZone.getZone(Constant.Zone.Library, sourceCard.getController());
|
CardList cards = AllZoneUtil.getPlayerCardsInLibrary(sourceCard.getController());
|
||||||
|
|
||||||
CardList cards = new CardList(lib.getCards());
|
|
||||||
CardList sameType = new CardList();
|
CardList sameType = new CardList();
|
||||||
|
|
||||||
for(int i = 0; i < cards.size(); i++) {
|
for(int i = 0; i < cards.size(); i++) {
|
||||||
@@ -1086,13 +1084,11 @@ public class CardFactoryUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(sameType.size() == 0) {
|
if(sameType.size() == 0) {
|
||||||
sourceCard.getController().discard(sourceCard, this);
|
sourceCard.getController().discard(sourceCard, this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Object o = GuiUtils.getChoiceOptional("Select a card", sameType.toArray());
|
Object o = GuiUtils.getChoiceOptional("Select a card", sameType.toArray());
|
||||||
if(o != null) {
|
if(o != null) {
|
||||||
//ability.setTargetCard((Card)o);
|
//ability.setTargetCard((Card)o);
|
||||||
@@ -1151,10 +1147,7 @@ public class CardFactoryUtil {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resolve() {
|
public void resolve() {
|
||||||
PlayerZone lib = AllZone.getZone(Constant.Zone.Library, sourceCard.getController());
|
CardList cards = AllZoneUtil.getPlayerCardsInLibrary(sourceCard.getController());
|
||||||
|
|
||||||
|
|
||||||
CardList cards = new CardList(lib.getCards());
|
|
||||||
CardList sameCost = new CardList();
|
CardList sameCost = new CardList();
|
||||||
|
|
||||||
for(int i = 0; i < cards.size(); i++) {
|
for(int i = 0; i < cards.size(); i++) {
|
||||||
@@ -1278,7 +1271,7 @@ public class CardFactoryUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
@@ -1404,15 +1397,14 @@ public class CardFactoryUtil {
|
|||||||
}// CanPlay (for auras with Flash)
|
}// CanPlay (for auras with Flash)
|
||||||
|
|
||||||
public boolean canPlayAI() {
|
public boolean canPlayAI() {
|
||||||
CardList list = new CardList(AllZone.Computer_Battlefield.getCards());
|
CardList list = AllZoneUtil.getCreaturesInPlay(AllZone.ComputerPlayer);
|
||||||
list = list.getType("Creature");
|
|
||||||
|
|
||||||
if (list.isEmpty()) return false;
|
if (list.isEmpty()) return false;
|
||||||
|
|
||||||
//else (is there a Rabid Wombat or a Uril, the Miststalker to target?)
|
//else (is there a Rabid Wombat or a Uril, the Miststalker to target?)
|
||||||
|
|
||||||
if (Tough >= -1) { // we want Rabid Wombat or a Uril, the Miststalker to gain at least +1 toughness
|
if (Tough >= -1) { // we want Rabid Wombat or a Uril, the Miststalker to gain at least +1 toughness
|
||||||
CardList auraMagnetList = new CardList(AllZone.Computer_Battlefield.getCards());
|
CardList auraMagnetList = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer);
|
||||||
auraMagnetList = auraMagnetList.getEnchantMagnets();
|
auraMagnetList = auraMagnetList.getEnchantMagnets();
|
||||||
|
|
||||||
if (! auraMagnetList.isEmpty()) { // AI has a special target creature(s) to enchant
|
if (! auraMagnetList.isEmpty()) { // AI has a special target creature(s) to enchant
|
||||||
@@ -1592,8 +1584,7 @@ public class CardFactoryUtil {
|
|||||||
}// CanPlay (for auras with Flash)
|
}// CanPlay (for auras with Flash)
|
||||||
|
|
||||||
public boolean canPlayAI() {
|
public boolean canPlayAI() {
|
||||||
CardList list = new CardList(AllZone.Human_Battlefield.getCards()); // Target human creature
|
CardList list = AllZoneUtil.getCreaturesInPlay(AllZone.HumanPlayer);
|
||||||
list = list.getType("Creature");
|
|
||||||
|
|
||||||
if (list.isEmpty()) return false;
|
if (list.isEmpty()) return false;
|
||||||
|
|
||||||
@@ -1756,9 +1747,7 @@ public class CardFactoryUtil {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resolve() {
|
public void resolve() {
|
||||||
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, sourceCard.getController());
|
CardList cards = AllZoneUtil.getPlayerGraveyard(sourceCard.getController());
|
||||||
|
|
||||||
CardList cards = new CardList(grave.getCards());
|
|
||||||
CardList sameCost = new CardList();
|
CardList sameCost = new CardList();
|
||||||
int Cost = CardUtil.getConvertedManaCost(Manacost);
|
int Cost = CardUtil.getConvertedManaCost(Manacost);
|
||||||
for (int i = 0; i < cards.size(); i++) {
|
for (int i = 0; i < cards.size(); i++) {
|
||||||
@@ -2134,20 +2123,15 @@ public class CardFactoryUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static CardList AI_getHumanCreature(final Card spell, boolean targeted) {
|
public static CardList AI_getHumanCreature(final Card spell, boolean targeted) {
|
||||||
CardList creature = new CardList(AllZone.Human_Battlefield.getCards());
|
CardList creature = AllZoneUtil.getCreaturesInPlay(AllZone.HumanPlayer);
|
||||||
creature = creature.getType("Creature");
|
|
||||||
if(targeted) {
|
if(targeted) {
|
||||||
creature = creature.filter(new CardListFilter() {
|
creature = creature.filter(AllZoneUtil.getCanTargetFilter(spell));
|
||||||
public boolean addCard(Card c) {
|
|
||||||
return canTarget(spell, c);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return creature;
|
return creature;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CardList AI_getHumanCreature(final String keyword, final Card spell, final boolean targeted) {
|
public static CardList AI_getHumanCreature(final String keyword, final Card spell, final boolean targeted) {
|
||||||
CardList creature = new CardList(AllZone.Human_Battlefield.getCards());
|
CardList creature = AllZoneUtil.getPlayerCardsInPlay(AllZone.HumanPlayer);
|
||||||
creature = creature.filter(new CardListFilter() {
|
creature = creature.filter(new CardListFilter() {
|
||||||
public boolean addCard(Card c) {
|
public boolean addCard(Card c) {
|
||||||
if(targeted) return c.isCreature() && c.getKeyword().contains(keyword) && canTarget(spell, c);
|
if(targeted) return c.isCreature() && c.getKeyword().contains(keyword) && canTarget(spell, c);
|
||||||
@@ -2158,7 +2142,7 @@ public class CardFactoryUtil {
|
|||||||
}//AI_getHumanCreature()
|
}//AI_getHumanCreature()
|
||||||
|
|
||||||
public static CardList AI_getHumanCreature(final int toughness, final Card spell, final boolean targeted) {
|
public static CardList AI_getHumanCreature(final int toughness, final Card spell, final boolean targeted) {
|
||||||
CardList creature = new CardList(AllZone.Human_Battlefield.getCards());
|
CardList creature = AllZoneUtil.getPlayerCardsInPlay(AllZone.HumanPlayer);
|
||||||
creature = creature.filter(new CardListFilter() {
|
creature = creature.filter(new CardListFilter() {
|
||||||
public boolean addCard(Card c) {
|
public boolean addCard(Card c) {
|
||||||
if(targeted) return c.isCreature() && (c.getNetDefense() <= toughness) && canTarget(spell, c);
|
if(targeted) return c.isCreature() && (c.getNetDefense() <= toughness) && canTarget(spell, c);
|
||||||
@@ -2200,8 +2184,7 @@ public class CardFactoryUtil {
|
|||||||
|
|
||||||
public static boolean oppHasKismet(Player player) {
|
public static boolean oppHasKismet(Player player) {
|
||||||
Player opp = player.getOpponent();
|
Player opp = player.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 c) {
|
public boolean addCard(Card c) {
|
||||||
return c.getName().equals("Kismet") || c.getName().equals("Frozen AEther")
|
return c.getName().equals("Kismet") || c.getName().equals("Frozen AEther")
|
||||||
@@ -2437,8 +2420,7 @@ public class CardFactoryUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static CardList getGraveyardActivationCards(final Player player) {
|
public static CardList getGraveyardActivationCards(final Player player) {
|
||||||
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player);
|
CardList cl = AllZoneUtil.getPlayerGraveyard(player);
|
||||||
CardList cl = new CardList(grave.getCards());
|
|
||||||
cl = cl.filter(new CardListFilter() {
|
cl = cl.filter(new CardListFilter() {
|
||||||
public boolean addCard(Card c) {
|
public boolean addCard(Card c) {
|
||||||
return activateFromGrave(c, player);
|
return activateFromGrave(c, player);
|
||||||
@@ -2562,9 +2544,7 @@ public class CardFactoryUtil {
|
|||||||
String restrictions = l[0].replace("Valid ", "");
|
String restrictions = l[0].replace("Valid ", "");
|
||||||
restrictions = restrictions.replace("Count$", "");
|
restrictions = restrictions.replace("Count$", "");
|
||||||
final String rest[] = restrictions.split(",");
|
final String rest[] = restrictions.split(",");
|
||||||
CardList cardsonbattlefield = new CardList();
|
CardList cardsonbattlefield = AllZoneUtil.getCardsInPlay();
|
||||||
cardsonbattlefield.addAll(myField.getCards());
|
|
||||||
cardsonbattlefield.addAll(opField.getCards());
|
|
||||||
cardsonbattlefield = cardsonbattlefield.getValidCards(rest, cardController, c);
|
cardsonbattlefield = cardsonbattlefield.getValidCards(rest, cardController, c);
|
||||||
|
|
||||||
n = cardsonbattlefield.size();
|
n = cardsonbattlefield.size();
|
||||||
@@ -3256,21 +3236,16 @@ public class CardFactoryUtil {
|
|||||||
String s = "";
|
String s = "";
|
||||||
//TODO, take into account what human has
|
//TODO, take into account what human has
|
||||||
|
|
||||||
PlayerZone humanPlayZone = AllZone.getZone(Constant.Zone.Battlefield, AllZone.HumanPlayer);
|
CardList humanPlay = AllZoneUtil.getPlayerCardsInPlay(AllZone.HumanPlayer);
|
||||||
PlayerZone humanLibZone = AllZone.getZone(Constant.Zone.Library, AllZone.HumanPlayer);
|
CardList humanLib = AllZoneUtil.getPlayerCardsInLibrary(AllZone.HumanPlayer);
|
||||||
|
|
||||||
CardList humanPlay = new CardList(humanPlayZone.getCards());
|
CardList compPlay = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer);
|
||||||
CardList humanLib = new CardList(humanLibZone.getCards());
|
CardList compHand = AllZoneUtil.getPlayerHand(AllZone.ComputerPlayer);
|
||||||
|
CardList compLib = AllZoneUtil.getPlayerCardsInLibrary(AllZone.ComputerPlayer);
|
||||||
PlayerZone compPlayZone = AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer);
|
CardList compAll = new CardList();
|
||||||
PlayerZone compLibZone = AllZone.getZone(Constant.Zone.Library, AllZone.ComputerPlayer);
|
compAll.addAll(compLib);
|
||||||
PlayerZone compHandZone = AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer);
|
compAll.addAll(compHand);
|
||||||
|
compAll.addAll(compPlay);
|
||||||
CardList compPlay = new CardList(compPlayZone.getCards());
|
|
||||||
CardList compHand = new CardList(compHandZone.getCards());
|
|
||||||
CardList compAll = new CardList(compPlayZone.getCards());
|
|
||||||
compAll.addAll(compLibZone.getCards());
|
|
||||||
compAll.addAll(compHandZone.getCards());
|
|
||||||
|
|
||||||
humanPlay = humanPlay.getType("Creature");
|
humanPlay = humanPlay.getType("Creature");
|
||||||
humanLib = humanLib.getType("Creature");
|
humanLib = humanLib.getType("Creature");
|
||||||
@@ -3329,8 +3304,7 @@ public class CardFactoryUtil {
|
|||||||
|
|
||||||
public static int countBasicLandTypes(Player player) {
|
public static int countBasicLandTypes(Player player) {
|
||||||
String basic[] = {"Forest", "Plains", "Mountain", "Island", "Swamp"};
|
String basic[] = {"Forest", "Plains", "Mountain", "Island", "Swamp"};
|
||||||
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, player);
|
CardList list = AllZoneUtil.getPlayerCardsInPlay(player);
|
||||||
CardList list = new CardList(play.getCards());
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
for(int i = 0; i < basic.length; i++)
|
for(int i = 0; i < basic.length; i++)
|
||||||
@@ -3343,8 +3317,7 @@ public class CardFactoryUtil {
|
|||||||
public static String getPropagandaCost(Card c) {
|
public static String getPropagandaCost(Card c) {
|
||||||
String s = "";
|
String s = "";
|
||||||
|
|
||||||
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, c.getController().getOpponent());
|
CardList list = AllZoneUtil.getPlayerCardsInPlay(c.getController().getOpponent());
|
||||||
CardList list = new CardList(play.getCards());
|
|
||||||
list = list.filter(new CardListFilter() {
|
list = list.filter(new CardListFilter() {
|
||||||
public boolean addCard(Card c) {
|
public boolean addCard(Card c) {
|
||||||
return c.getName().equals("Propaganda") || c.getName().equals("Windborn Muse")
|
return c.getName().equals("Propaganda") || c.getName().equals("Windborn Muse")
|
||||||
@@ -3353,8 +3326,7 @@ public class CardFactoryUtil {
|
|||||||
});
|
});
|
||||||
int cost = list.size() * 2;
|
int cost = list.size() * 2;
|
||||||
|
|
||||||
list = new CardList(play.getCards());
|
list = AllZoneUtil.getPlayerCardsInPlay(c.getController().getOpponent(), "Collective Restraint");
|
||||||
list = list.getName("Collective Restraint");
|
|
||||||
|
|
||||||
int domain = countBasicLandTypes(c.getController().getOpponent());
|
int domain = countBasicLandTypes(c.getController().getOpponent());
|
||||||
|
|
||||||
@@ -3366,8 +3338,7 @@ public class CardFactoryUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getUsableManaSources(Player player) {
|
public static int getUsableManaSources(Player player) {
|
||||||
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, player);
|
CardList list = AllZoneUtil.getPlayerCardsInPlay(player);
|
||||||
CardList list = new CardList(play.getCards());
|
|
||||||
list = list.filter(new CardListFilter() {
|
list = list.filter(new CardListFilter() {
|
||||||
public boolean addCard(Card c) {
|
public boolean addCard(Card c) {
|
||||||
for(Ability_Mana am:c.getAIPlayableMana())
|
for(Ability_Mana am:c.getAIPlayableMana())
|
||||||
|
|||||||
Reference in New Issue
Block a user