- Simplified the code found in forge.card.cardFactory.CardFactoryUtil.

This commit is contained in:
jendave
2011-08-07 01:00:48 +00:00
parent eb8c70ea17
commit 26f90893a5

View File

@@ -820,7 +820,7 @@ public class CardFactoryUtil {
CardList list = AllZoneUtil.getPlayerCardsInLibrary(sourceCard.getController()); CardList list = AllZoneUtil.getPlayerCardsInLibrary(sourceCard.getController());
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(Card c) {
return ((c.getType().contains("Rebel") || c.getKeyword().contains("Changeling"))) return ((c.getType().contains("Rebel") || c.hasKeyword("Changeling")))
&& c.isPermanent(); && c.isPermanent();
} }
}); });
@@ -867,7 +867,7 @@ public class CardFactoryUtil {
AllZone.GameAction.moveToPlay(rebel); AllZone.GameAction.moveToPlay(rebel);
if(rebel.isAura()) { if(rebel.isAura()) {
Object obj = null; Object obj = null;
if(rebel.getKeyword().contains("Enchant creature")) { if(rebel.hasKeyword("Enchant creature")) {
CardList creats = AllZoneUtil.getCreaturesInPlay(); CardList creats = AllZoneUtil.getCreaturesInPlay();
obj = GuiUtils.getChoiceOptional("Pick a creature to attach " obj = GuiUtils.getChoiceOptional("Pick a creature to attach "
+ rebel.getName() + " to", creats.toArray()); + rebel.getName() + " to", creats.toArray());
@@ -1235,7 +1235,7 @@ public class CardFactoryUtil {
for (String s : extKeywords) { for (String s : extKeywords) {
// We want to give a new keyword // We want to give a new keyword
if (!c.getKeyword().contains(s)) if (! c.hasKeyword(s))
return true; return true;
} }
//no new keywords: //no new keywords:
@@ -1273,7 +1273,8 @@ public class CardFactoryUtil {
for (int i = 0; i < extrinsicKeywords.length; i ++) for (int i = 0; i < extrinsicKeywords.length; i ++)
{ {
if (! (extrinsicKeywords[i].equals ("none")) && (! crd.getKeyword().contains(extrinsicKeywords[i]))) // prevent Flying, Flying if (! (extrinsicKeywords[i].equals ("none"))
&& (! crd.hasKeyword(extrinsicKeywords[i]))) // prevent Flying, Flying
crd.addExtrinsicKeyword(extrinsicKeywords[i]); crd.addExtrinsicKeyword(extrinsicKeywords[i]);
} }
@@ -1353,7 +1354,9 @@ public class CardFactoryUtil {
public boolean addCard(Card c){ public boolean addCard(Card c){
ArrayList<String> extKeywords = new ArrayList<String>(Arrays.asList(extrinsicKeywords)); ArrayList<String> extKeywords = new ArrayList<String>(Arrays.asList(extrinsicKeywords));
for (String s:extKeywords) { for (String s:extKeywords) {
if (!c.getKeyword().contains(s) && !c.getKeyword().contains("Defender") && !c.isEnchanted()) if (!c.hasKeyword(s)
&& !c.hasKeyword("Defender")
&& !c.isEnchanted())
return true; return true;
} }
// no new keywords: // no new keywords:
@@ -1371,9 +1374,11 @@ public class CardFactoryUtil {
CardListUtil.sortFlying(list); CardListUtil.sortFlying(list);
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
if (CardFactoryUtil.canTarget(sourceCard, list.get(i)) && if (CardFactoryUtil.canTarget(sourceCard, list.get(i))
list.get(i).getNetAttack() + Power > 0 && list.get(i).getNetDefense() + Tough > 0 && && list.get(i).getNetAttack() + Power > 0
!list.get(i).getKeyword().contains("Defender") && !list.get(i).isEnchanted()) { && list.get(i).getNetDefense() + Tough > 0
&& !list.get(i).hasKeyword("Defender")
&& !list.get(i).isEnchanted()) {
setTargetCard(list.get(i)); setTargetCard(list.get(i));
return true; return true;
} }
@@ -1414,7 +1419,8 @@ public class CardFactoryUtil {
Card crd = sourceCard.getEnchanting().get(0); Card crd = sourceCard.getEnchanting().get(0);
for(int i = 0; i < extrinsicKeywords.length; i ++) { for(int i = 0; i < extrinsicKeywords.length; i ++) {
if (! (extrinsicKeywords[i].equals ("none")) && (! crd.getKeyword().contains(extrinsicKeywords[i]))) // prevent Flying, Flying if (! (extrinsicKeywords[i].equals ("none"))
&& (! crd.hasKeyword(extrinsicKeywords[i]))) // prevent Flying, Flying
crd.addExtrinsicKeyword(extrinsicKeywords[i]); crd.addExtrinsicKeyword(extrinsicKeywords[i]);
} }
@@ -1559,8 +1565,10 @@ public class CardFactoryUtil {
if (extKeywords.contains("CARDNAME can't attack.") || extKeywords.contains("CARDNAME can't attack or block.")) { if (extKeywords.contains("CARDNAME can't attack.") || extKeywords.contains("CARDNAME can't attack or block.")) {
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(Card c) {
return c.isCreature() && !c.getKeyword().contains("Defender") && return c.isCreature()
!c.getKeyword().contains("CARDNAME can't attack.") && !c.getKeyword().contains("CARDNAME can't attack or block."); && !c.hasKeyword("Defender")
&& !c.hasKeyword("CARDNAME can't attack.")
&& !c.hasKeyword("CARDNAME can't attack or block.");
} }
}); });
} }
@@ -1571,10 +1579,10 @@ public class CardFactoryUtil {
if (extKeywords.contains("HIDDEN CARDNAME doesn't untap during your untap step.")) { if (extKeywords.contains("HIDDEN CARDNAME doesn't untap during your untap step.")) {
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(Card c) {
if (c.getKeyword().contains("CARDNAME doesn't untap during your untap step.")) if (c.hasKeyword("CARDNAME doesn't untap during your untap step."))
return false; return false;
if (c.getKeyword().contains("Vigilance") && c.isUntapped()) if (c.hasKeyword("Vigilance") && c.isUntapped())
return false; return false;
return c.isCreature() && (c.isTapped() || Power < 1); return c.isCreature() && (c.isTapped() || Power < 1);
@@ -1589,7 +1597,7 @@ public class CardFactoryUtil {
public boolean addCard(Card c){ public boolean addCard(Card c){
ArrayList<String> extKeywords = new ArrayList<String>(Arrays.asList(extrinsicKeywords)); ArrayList<String> extKeywords = new ArrayList<String>(Arrays.asList(extrinsicKeywords));
for (String s:extKeywords) { for (String s:extKeywords) {
if (!c.getKeyword().contains(s)) if (!c.hasKeyword(s))
return true; return true;
} }
//no new keywords: //no new keywords:
@@ -2009,8 +2017,13 @@ public class CardFactoryUtil {
CardList creature = AllZoneUtil.getPlayerCardsInPlay(AllZone.HumanPlayer); 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)
else return c.isCreature() && c.getKeyword().contains(keyword); return c.isCreature()
&& c.hasKeyword(keyword)
&& canTarget(spell, c);
else
return c.isCreature()
&& c.hasKeyword(keyword);
} }
}); });
return creature; return creature;
@@ -2272,7 +2285,7 @@ public class CardFactoryUtil {
} }
public static boolean isCounterable(Card c) { public static boolean isCounterable(Card c) {
if(!c.getKeyword().contains("CARDNAME can't be countered.")) return true; if (!c.hasKeyword("CARDNAME can't be countered.")) return true;
else return false; else return false;
} }
@@ -3520,10 +3533,10 @@ public class CardFactoryUtil {
public static String checkEmblemKeyword(Card c) public static String checkEmblemKeyword(Card c)
{ {
if (c.getKeyword().contains("Artifacts, creatures, enchantments, and lands you control are indestructible.")) if (c.hasKeyword("Artifacts, creatures, enchantments, and lands you control are indestructible."))
return "Elspeth_Emblem"; return "Elspeth_Emblem";
if (c.getKeyword().contains("Mountains you control have 'tap: This land deals 1 damage to target creature or player.'")) if (c.hasKeyword("Mountains you control have 'tap: This land deals 1 damage to target creature or player.'"))
return "Koth_Emblem"; return "Koth_Emblem";
return ""; return "";
@@ -3535,7 +3548,7 @@ public class CardFactoryUtil {
//if (AllZoneUtil.isCardInPlay(c)) //if (AllZoneUtil.isCardInPlay(c))
//{ //{
if (c.getKeyword().contains("When CARDNAME becomes the target of a spell or ability, return CARDNAME to its owner's hand.") if (c.hasKeyword("When CARDNAME becomes the target of a spell or ability, return CARDNAME to its owner's hand.")
|| (c.isCreature() && AllZoneUtil.isCardInPlay("Cowardice"))) { || (c.isCreature() && AllZoneUtil.isCardInPlay("Cowardice"))) {
SpellAbility ability = new Ability(c, "0") SpellAbility ability = new Ability(c, "0")
{ {
@@ -3550,7 +3563,7 @@ public class CardFactoryUtil {
AllZone.Stack.add(ability); AllZone.Stack.add(ability);
} }
if (c.getKeyword().contains("When CARDNAME becomes the target of a spell or ability, destroy CARDNAME.") if (c.hasKeyword("When CARDNAME becomes the target of a spell or ability, destroy CARDNAME.")
|| AllZoneUtil.isCardInPlay("Horobi, Death's Wail")) { || AllZoneUtil.isCardInPlay("Horobi, Death's Wail")) {
SpellAbility ability = new Ability(c, "0") SpellAbility ability = new Ability(c, "0")
@@ -3566,7 +3579,7 @@ public class CardFactoryUtil {
AllZone.Stack.add(ability); AllZone.Stack.add(ability);
} }
if (c.getKeyword().contains("When CARDNAME becomes the target of a spell or ability, sacrifice it.")) { if (c.hasKeyword("When CARDNAME becomes the target of a spell or ability, sacrifice it.")) {
SpellAbility ability = new Ability(c, "0") SpellAbility ability = new Ability(c, "0")
{ {
public void resolve() public void resolve()