- Simplified the code found in forge.GameActionUtil and forge.PlayerZone_ComesIntoPlay and forge.RunTest. Updating c.getType().contains(string) to c.isType(string).

This commit is contained in:
jendave
2011-08-07 01:30:14 +00:00
parent 55f8f4e8ee
commit 94b1702aad
3 changed files with 41 additions and 38 deletions

View File

@@ -276,27 +276,28 @@ public class GameActionUtil {
CardList topOfLibrary = AllZoneUtil.getPlayerCardsInLibrary(controller); CardList topOfLibrary = AllZoneUtil.getPlayerCardsInLibrary(controller);
CardList revealed = new CardList(); CardList revealed = new CardList();
int RippleNumber = RippleCount; int RippleNumber = RippleCount;
if(topOfLibrary.size() == 0) return; if (topOfLibrary.size() == 0) return;
int RippleMax = 10; // Shouldn't Have more than Ripple 10, seeing as no cards exist with a ripple greater than 4 int RippleMax = 10; // Shouldn't Have more than Ripple 10, seeing as no cards exist with a ripple greater than 4
Card[] RippledCards = new Card[RippleMax]; Card[] RippledCards = new Card[RippleMax];
Card crd; Card crd;
if(topOfLibrary.size() < RippleNumber) RippleNumber = topOfLibrary.size(); if (topOfLibrary.size() < RippleNumber) RippleNumber = topOfLibrary.size();
for(int i = 0; i < RippleNumber; i++){ for(int i = 0; i < RippleNumber; i++){
crd = topOfLibrary.get(i); crd = topOfLibrary.get(i);
revealed.add(crd); revealed.add(crd);
if(crd.getName().equals(RippleCard.getName())) RippledCards[i] = crd; if (crd.getName().equals(RippleCard.getName())) RippledCards[i] = crd;
}//For }//For
GuiUtils.getChoiceOptional("Revealed cards:", revealed.toArray()); GuiUtils.getChoiceOptional("Revealed cards:", revealed.toArray());
for(int i = 0; i < RippleMax; i++) { for (int i = 0; i < RippleMax; i++) {
if(RippledCards[i] != null && !RippledCards[i].isUnCastable()) { if (RippledCards[i] != null
&& !RippledCards[i].isUnCastable()) {
if(RippledCards[i].getController().isHuman()) { if (RippledCards[i].getController().isHuman()) {
Object[] possibleValues = {"Yes", "No"}; Object[] possibleValues = {"Yes", "No"};
Object q = JOptionPane.showOptionDialog(null, "Cast " + RippledCards[i].getName() + "?", "Ripple", Object q = JOptionPane.showOptionDialog(null, "Cast " + RippledCards[i].getName() + "?", "Ripple",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
null, possibleValues, possibleValues[0]); null, possibleValues, possibleValues[0]);
if(q.equals(0)) { if (q.equals(0)) {
AllZone.GameAction.playCardNoCost(RippledCards[i]); AllZone.GameAction.playCardNoCost(RippledCards[i]);
revealed.remove(RippledCards[i]); revealed.remove(RippledCards[i]);
} }
@@ -304,8 +305,9 @@ public class GameActionUtil {
{ {
ArrayList<SpellAbility> choices = RippledCards[i].getBasicSpells(); ArrayList<SpellAbility> choices = RippledCards[i].getBasicSpells();
for(SpellAbility sa:choices) { for (SpellAbility sa:choices) {
if(sa.canPlayAI() && !sa.getSourceCard().getType().contains("Legendary")) { if (sa.canPlayAI()
&& !sa.getSourceCard().isType("Legendary")) {
ComputerUtil.playStackFree(sa); ComputerUtil.playStackFree(sa);
revealed.remove(RippledCards[i]); revealed.remove(RippledCards[i]);
break; break;
@@ -315,7 +317,7 @@ public class GameActionUtil {
} }
} }
revealed.shuffle(); revealed.shuffle();
for(Card bottom:revealed) { for (Card bottom:revealed) {
AllZone.GameAction.moveToBottomOfLibrary(bottom); AllZone.GameAction.moveToBottomOfLibrary(bottom);
} }
} }
@@ -543,7 +545,8 @@ public class GameActionUtil {
final int cmc = CardUtil.getConvertedManaCost(c.getManaCost()); final int cmc = CardUtil.getConvertedManaCost(c.getManaCost());
list = list.getName("Dovescape"); list = list.getName("Dovescape");
final CardList cl = list; final CardList cl = list;
if(!c.getType().contains("Creature") && list.size() > 0) { if (!c.isType("Creature")
&& list.size() > 0) {
final Card card = list.get(0); final Card card = list.get(0);
Ability ability2 = new Ability(card, "0") { Ability ability2 = new Ability(card, "0") {
@@ -552,14 +555,14 @@ public class GameActionUtil {
SpellAbility sa = AllZone.Stack.peek(); SpellAbility sa = AllZone.Stack.peek();
if(sa.getSourceCard().equals(c)) { if (sa.getSourceCard().equals(c)) {
sa = AllZone.Stack.pop(); sa = AllZone.Stack.pop();
AllZone.GameAction.moveToGraveyard(sa.getSourceCard()); AllZone.GameAction.moveToGraveyard(sa.getSourceCard());
for(int j = 0; j < cl.size() * cmc; j++) { for (int j = 0; j < cl.size() * cmc; j++) {
CardFactoryUtil.makeToken("Bird", "WU 1 1 Bird", sa.getSourceCard().getController(), "W U", new String[] { CardFactoryUtil.makeToken("Bird", "WU 1 1 Bird", sa.getSourceCard().getController(), "W U",
"Creature", "Bird"}, 1, 1, new String[] {"Flying"}); new String[] {"Creature", "Bird"}, 1, 1, new String[] {"Flying"});
} }
/* /*
@@ -3652,7 +3655,7 @@ public class GameActionUtil {
for (int i = 0; i < max; i++) { for (int i = 0; i < max; i++) {
Card c = libraryList.get(i); Card c = libraryList.get(i);
cardsToReveal.add(c); cardsToReveal.add(c);
if (c.getType().contains("Creature")) { if (c.isType("Creature")) {
AllZone.GameAction.moveTo(battlefield, c); AllZone.GameAction.moveTo(battlefield, c);
break; break;
} }
@@ -5006,11 +5009,11 @@ public class GameActionUtil {
{ {
public boolean addCard(Card crd) public boolean addCard(Card crd)
{ {
return crd.getType().contains("Mountain"); return crd.isType("Mountain");
} }
}); });
for(int j = 0; j < mountains.size(); j++) { for (int j = 0; j < mountains.size(); j++) {
final Card c = mountains.get(j); final Card c = mountains.get(j);
boolean hasAbility = false; boolean hasAbility = false;
SpellAbility[] sas = c.getSpellAbility(); SpellAbility[] sas = c.getSpellAbility();
@@ -5020,7 +5023,7 @@ public class GameActionUtil {
hasAbility = true; hasAbility = true;
} }
if(!hasAbility) { if (!hasAbility) {
Cost abCost = new Cost("T", c.getName(), true); Cost abCost = new Cost("T", c.getName(), true);
Target target = new Target(c,"TgtCP"); Target target = new Target(c,"TgtCP");
final Ability_Activated ability = new Ability_Activated(c, abCost, target) final Ability_Activated ability = new Ability_Activated(c, abCost, target)
@@ -5031,7 +5034,7 @@ public class GameActionUtil {
CardList list = CardFactoryUtil.AI_getHumanCreature(1, c, true); CardList list = CardFactoryUtil.AI_getHumanCreature(1, c, true);
list.shuffle(); list.shuffle();
if(list.isEmpty() || AllZone.HumanPlayer.getLife() < 5) if (list.isEmpty() || AllZone.HumanPlayer.getLife() < 5)
setTargetPlayer(AllZone.HumanPlayer); setTargetPlayer(AllZone.HumanPlayer);
else else
setTargetCard(list.get(0)); setTargetCard(list.get(0));
@@ -5624,7 +5627,7 @@ public class GameActionUtil {
public void execute() { public void execute() {
CardList list = gloriousAnthemList; CardList list = gloriousAnthemList;
// reset all cards in list - aka "old" cards // reset all cards in list - aka "old" cards
for(int i2 = 0; i2 < list.size(); i2++) { for (int i2 = 0; i2 < list.size(); i2++) {
list.get(i2).addSemiPermanentAttackBoost(-1); list.get(i2).addSemiPermanentAttackBoost(-1);
list.get(i2).addSemiPermanentDefenseBoost(-1); list.get(i2).addSemiPermanentDefenseBoost(-1);
} }
@@ -5633,10 +5636,10 @@ public class GameActionUtil {
PlayerZone[] zone = getZone("Coat of Arms"); PlayerZone[] zone = getZone("Coat of Arms");
// for each zone found add +1/+1 to each card // for each zone found add +1/+1 to each card
for(int outer = 0; outer < zone.length; outer++) { for (int outer = 0; outer < zone.length; outer++) {
CardList creature = AllZoneUtil.getCardsInPlay(); CardList creature = AllZoneUtil.getCardsInPlay();
for(int i = 0; i < creature.size(); i++) { for (int i = 0; i < creature.size(); i++) {
final Card crd = creature.get(i); final Card crd = creature.get(i);
CardList Type = AllZoneUtil.getCardsInPlay(); CardList Type = AllZoneUtil.getCardsInPlay();
Type = Type.filter(new CardListFilter() { Type = Type.filter(new CardListFilter() {
@@ -5645,13 +5648,13 @@ public class GameActionUtil {
} }
}); });
CardList Already_Added = new CardList(); CardList Already_Added = new CardList();
for(int x = 0; x < Type.size(); x++) { for (int x = 0; x < Type.size(); x++) {
Already_Added.clear(); Already_Added.clear();
for(int x2 = 0; x2 < Type.get(x).getType().size(); x2++) { for (int x2 = 0; x2 < Type.get(x).getType().size(); x2++) {
if(!Already_Added.contains(Type.get(x))) { if (!Already_Added.contains(Type.get(x))) {
if(!Type.get(x).getType().get(x2).equals("Creature") && !Type.get(x).getType().get(x2).equals("Legendary") if (!Type.get(x).getType().get(x2).equals("Creature") && !Type.get(x).getType().get(x2).equals("Legendary")
&& !Type.get(x).getType().get(x2).equals("Artifact") ) { && !Type.get(x).getType().get(x2).equals("Artifact") ) {
if (crd.getType().contains(Type.get(x).getType().get(x2)) if (crd.isType(Type.get(x).getType().get(x2))
|| crd.hasKeyword("Changeling") || crd.hasKeyword("Changeling")
|| Type.get(x).hasKeyword("Changeling")) { || Type.get(x).hasKeyword("Changeling")) {
Already_Added.add(Type.get(x)); Already_Added.add(Type.get(x));

View File

@@ -88,7 +88,7 @@ public class PlayerZone_ComesIntoPlay extends DefaultPlayerZone {
} }
/* /*
// Check for a mountain // Check for a mountain
if (!listValakut.isEmpty() && c.getType().contains("Mountain") ) { if (!listValakut.isEmpty() && c.isType("Mountain") ) {
for (int i = 0; i < listValakut.size(); i++) { for (int i = 0; i < listValakut.size(); i++) {
boolean b = GameActionUtil.executeValakutEffect(listValakut.get(i),c); boolean b = GameActionUtil.executeValakutEffect(listValakut.get(i),c);
if (!b) { if (!b) {
@@ -101,14 +101,14 @@ public class PlayerZone_ComesIntoPlay extends DefaultPlayerZone {
//Tectonic Instability //Tectonic Instability
CardList tis = AllZoneUtil.getCardsInPlay("Tectonic Instability"); CardList tis = AllZoneUtil.getCardsInPlay("Tectonic Instability");
final Card tisLand = c; final Card tisLand = c;
for(Card ti:tis) { for (Card ti:tis) {
final Card source = ti; final Card source = ti;
SpellAbility ability = new Ability(source, "") { SpellAbility ability = new Ability(source, "") {
@Override @Override
public void resolve() { public void resolve() {
CardList lands = AllZoneUtil.getPlayerCardsInPlay(tisLand.getController()); CardList lands = AllZoneUtil.getPlayerCardsInPlay(tisLand.getController());
lands = lands.filter(AllZoneUtil.lands); lands = lands.filter(AllZoneUtil.lands);
for(Card land:lands) land.tap(); for (Card land : lands) land.tap();
} }
}; };
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

View File

@@ -20,23 +20,23 @@ public class RunTest
check("1", c.getOwner().isComputer()); check("1", c.getOwner().isComputer());
check("1.1", c.getName().equals("Elvish Warrior")); check("1.1", c.getName().equals("Elvish Warrior"));
check("2", c.getManaCost().equals("G G")); check("2", c.getManaCost().equals("G G"));
check("2.1", c.getType().contains("Creature")); check("2.1", c.isType("Creature"));
check("2.2", c.getType().contains("Elf")); check("2.2", c.isType("Elf"));
check("2.3", c.getType().contains("Warrior")); check("2.3", c.isType("Warrior"));
check("3", c.getText().equals("")); check("3", c.getText().equals(""));
check("4", c.getNetAttack() == 2); check("4", c.getNetAttack() == 2);
check("5", c.getNetDefense() == 3); check("5", c.getNetDefense() == 3);
check("6", c.getKeyword().isEmpty()); check("6", c.getKeyword().isEmpty());
c = cf.getCard("Shock", null); c = cf.getCard("Shock", null);
check("14", c.getType().contains("Instant")); check("14", c.isType("Instant"));
//check("15", c.getText().equals("Shock deals 2 damge to target creature or player.")); //check("15", c.getText().equals("Shock deals 2 damge to target creature or player."));
c = cf.getCard("Bayou", null); c = cf.getCard("Bayou", null);
check("17", c.getManaCost().equals("")); check("17", c.getManaCost().equals(""));
check("18", c.getType().contains("Land")); check("18", c.isType("Land"));
check("19", c.getType().contains("Swamp")); check("19", c.isType("Swamp"));
check("20", c.getType().contains("Forest")); check("20", c.isType("Forest"));
//********* test ManaCost //********* test ManaCost
ManaCost manaCost = new ManaCost("G"); ManaCost manaCost = new ManaCost("G");