From 6e74e948788dc243b7d80516aeb0d47b22c0451f Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 23:59:07 +0000 Subject: [PATCH] finish plumbing in stAnimate for Lignify to become an Aura --- src/forge/Card.java | 31 ++- src/forge/DefaultPlayerZone.java | 395 +++++++++++++++---------------- src/forge/GameActionUtil.java | 74 ++++-- src/forge/StaticEffect.java | 127 +++++++++- 4 files changed, 393 insertions(+), 234 deletions(-) diff --git a/src/forge/Card.java b/src/forge/Card.java index 7504afccc23..33a6ec08726 100644 --- a/src/forge/Card.java +++ b/src/forge/Card.java @@ -979,8 +979,8 @@ public class Card extends MyObservable { else if(k.length > 5) sbLong.append(k[6]).append("\r\n"); else sbLong.append(k[3]).append("\r\n"); } else if (keyword.get(i).toString().contains("stAnimate")) { - String k[] = keyword.get(i).split(":", 7); - if (!k[4].contains("no text")) sbLong.append(k[6]).append("\r\n"); + String k[] = keyword.get(i).split(":", 8); + if (!k[7].contains("no text")) sbLong.append(k[7]).append("\r\n"); }else if (keyword.get(i).toString().contains("Protection:")) { String k[] = keyword.get(i).split(":"); sbLong.append(k[2]).append("\r\n"); @@ -1245,6 +1245,22 @@ public class Card extends MyObservable { spellAbility.remove(0); } + public void clearAllButFirstSpellAbility(){ + SpellAbility first = spellAbility.get(0); + spellAbility.clear(); + spellAbility.add(first); + manaAbility.clear(); + } + + public ArrayList getAllButFirstSpellAbility() { + ArrayList sas = new ArrayList(); + sas.addAll(spellAbility); + sas.addAll(manaAbility); + SpellAbility first = spellAbility.get(0); + sas.remove(first); + return sas; + } + public void clearSpellAbility() { spellAbility.clear(); manaAbility.clear(); @@ -2211,11 +2227,22 @@ public class Card extends MyObservable { return new ArrayList(intrinsicKeyword); } + public void clearIntrinsicKeyword() { + intrinsicKeyword.clear(); + } + public void setIntrinsicKeyword(ArrayList a) { intrinsicKeyword = new ArrayList(a); this.updateObservers(); } + public void clearAllKeywords() { + intrinsicKeyword.clear(); + extrinsicKeyword.clear(); + otherExtrinsicKeyword.clear(); + HiddenExtrinsicKeyword.clear(); //Hidden keywords won't be displayed on the card + } + public void setIntrinsicAbilities(ArrayList a) { intrinsicAbility = new ArrayList(a); diff --git a/src/forge/DefaultPlayerZone.java b/src/forge/DefaultPlayerZone.java index 8b264082f24..bfc9db0e276 100644 --- a/src/forge/DefaultPlayerZone.java +++ b/src/forge/DefaultPlayerZone.java @@ -5,219 +5,212 @@ import java.util.Observable; public class DefaultPlayerZone extends PlayerZone implements java.io.Serializable { - private static final long serialVersionUID = -5687652485777639176L; + private static final long serialVersionUID = -5687652485777639176L; - private ArrayList cards = new ArrayList(); - private String zoneName; - private Player player; - private boolean update = true; + private ArrayList cards = new ArrayList(); + private String zoneName; + private Player player; + private boolean update = true; - private CardList cardsAddedThisTurn = new CardList(); - private ArrayList cardsAddedThisTurnSource = new ArrayList(); + private CardList cardsAddedThisTurn = new CardList(); + private ArrayList cardsAddedThisTurnSource = new ArrayList(); - public DefaultPlayerZone(String zone, Player inPlayer) - { - zoneName = zone; - player = inPlayer; - } - //************ BEGIN - these methods fire updateObservers() ************* - public void add(Object o) - { - /* - if (is("Graveyard")) - System.out.println("GRAAAAAAAAAAAAAAAVE"); - */ - - Card c = (Card)o; + public DefaultPlayerZone(String zone, Player inPlayer) + { + zoneName = zone; + player = inPlayer; + } + //************ BEGIN - these methods fire updateObservers() ************* + public void add(Object o) + { + Card c = (Card)o; - cardsAddedThisTurn.add(c); - if(AllZone.getZone(c) != null) - { - cardsAddedThisTurnSource.add(AllZone.getZone(c).getZoneName()); - } - else - { - cardsAddedThisTurnSource.add("None"); - } + cardsAddedThisTurn.add(c); + if(AllZone.getZone(c) != null) + { + cardsAddedThisTurnSource.add(AllZone.getZone(c).getZoneName()); + } + else + { + cardsAddedThisTurnSource.add("None"); + } - if (is("Graveyard") - && c.getKeyword().contains("When CARDNAME is put into a graveyard from anywhere, reveal CARDNAME and shuffle it into its owner's library instead.")) - { - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, c.getOwner()); - lib.add(c); - c.getOwner().shuffle(); - return; - } - //slight difference from above I guess, the card gets put into the grave first, then shuffled into library. - //key is that this would trigger abilities that trigger on cards hitting the graveyard - else if (is("Graveyard") && c.getKeyword().contains("When CARDNAME is put into a graveyard from anywhere, shuffle it into its owner's library.")) - { - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, c.getOwner()); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, c.getOwner()); - - grave.addOnce(c); - grave.remove(c); - lib.add(c); - c.getOwner().shuffle(); - return; - } - - - if (is("Graveyard") - && c.getKeyword().contains("When CARDNAME is put into a graveyard from anywhere, reveal CARDNAME and its owner shuffles his or her graveyard into his or her library.")) - { - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, c.getOwner()); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, c.getOwner()); - lib.add(c); - for(Card gc : AllZoneUtil.getPlayerGraveyard(c.getOwner())) - lib.add(gc); - grave.reset(); - c.getOwner().shuffle(); - return; - } - - - - if (c.isUnearthed() && (is("Graveyard") || is("Hand") || is("Library"))) - { - PlayerZone removed = AllZone.getZone(Constant.Zone.Exile, c.getOwner()); - removed.add(c); - c.setUnearthed(false); - return; - } - - - c.addObserver(this); + if (is("Graveyard") + && c.getKeyword().contains("When CARDNAME is put into a graveyard from anywhere, reveal CARDNAME and shuffle it into its owner's library instead.")) + { + PlayerZone lib = AllZone.getZone(Constant.Zone.Library, c.getOwner()); + lib.add(c); + c.getOwner().shuffle(); + return; + } + //slight difference from above I guess, the card gets put into the grave first, then shuffled into library. + //key is that this would trigger abilities that trigger on cards hitting the graveyard + else if (is("Graveyard") && c.getKeyword().contains("When CARDNAME is put into a graveyard from anywhere, shuffle it into its owner's library.")) + { + PlayerZone lib = AllZone.getZone(Constant.Zone.Library, c.getOwner()); + PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, c.getOwner()); - c.setTurnInZone(AllZone.Phase.getTurn()); + grave.addOnce(c); + grave.remove(c); + lib.add(c); + c.getOwner().shuffle(); + return; + } - cards.add((Card)c); - update(); - } - - //hack... use for adding Dread / Serra Avenger to grave - public void addOnce(Object o) - { - Card c = (Card)o; - cardsAddedThisTurn.add(c); - if(AllZone.getZone(c) != null) - { - cardsAddedThisTurnSource.add(AllZone.getZone(c).getZoneName()); - } - else - { - cardsAddedThisTurnSource.add("None"); - } + if (is("Graveyard") + && c.getKeyword().contains("When CARDNAME is put into a graveyard from anywhere, reveal CARDNAME and its owner shuffles his or her graveyard into his or her library.")) + { + PlayerZone lib = AllZone.getZone(Constant.Zone.Library, c.getOwner()); + PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, c.getOwner()); + lib.add(c); + for(Card gc : AllZoneUtil.getPlayerGraveyard(c.getOwner())) + lib.add(gc); + grave.reset(); + c.getOwner().shuffle(); + return; + } - c.addObserver(this); - - cards.add((Card)c); - update(); - } - public void update(Observable ob, Object object) - { - this.update(); - } - public void add(Card c, int index) - { - cardsAddedThisTurn.add(c); - if(AllZone.getZone(c) != null) - { - cardsAddedThisTurnSource.add(AllZone.getZone(c).getZoneName()); - } - else - { - cardsAddedThisTurnSource.add("None"); - } + if (c.isUnearthed() && (is("Graveyard") || is("Hand") || is("Library"))) + { + PlayerZone removed = AllZone.getZone(Constant.Zone.Exile, c.getOwner()); + removed.add(c); + c.setUnearthed(false); + return; + } - cards.add(index, c); - c.setTurnInZone(AllZone.Phase.getTurn()); - update(); - } - public void remove(Object c) - { - cards.remove((Card)c); - update(); - } - public void setCards(Card c[]) - { - cards = new ArrayList(Arrays.asList(c)); - update(); - } - //removes all cards - public void reset() - { - cards.clear(); - update(); - } - //************ END - these methods fire updateObservers() ************* - public boolean is(String zone) - { - return zone.equals(zoneName); - } - public boolean is(String zone, Player player) - { - return (zone.equals(zoneName) && player.isPlayer(player)); - } - public Player getPlayer() - { - return player; - } - public String getZoneName() - { - return zoneName; - } - public int size() - { - return cards.size(); - } - public Card get(int index) - { - return (Card)cards.get(index); - } + c.addObserver(this); - public Card[] getCards() - { - Card c[] = new Card[cards.size()]; - cards.toArray(c); - return c; - } - public void update() - { - if(update) - updateObservers(); - } - public void setUpdate(boolean b) {update = b;} - public boolean getUpdate() {return update;} - - public String toString(){ - StringBuilder sb = new StringBuilder(); - if (player != null) - sb.append(player.toString()).append(" "); - sb.append(zoneName); - return sb.toString(); - } + c.setTurnInZone(AllZone.Phase.getTurn()); - public CardList getCardsAddedThisTurn(String origin) - { - System.out.print("Request cards put into " + getZoneName() + " from " + origin + ".Amount: "); - CardList ret = new CardList(); - for(int i=0;i(Arrays.asList(c)); + update(); + } + //removes all cards + public void reset() + { + cards.clear(); + update(); + } + //************ END - these methods fire updateObservers() ************* + + public boolean is(String zone) + { + return zone.equals(zoneName); + } + public boolean is(String zone, Player player) + { + return (zone.equals(zoneName) && player.isPlayer(player)); + } + public Player getPlayer() + { + return player; + } + public String getZoneName() + { + return zoneName; + } + public int size() + { + return cards.size(); + } + public Card get(int index) + { + return (Card)cards.get(index); + } + + public Card[] getCards() + { + Card c[] = new Card[cards.size()]; + cards.toArray(c); + return c; + } + public void update() + { + if(update) + updateObservers(); + } + public void setUpdate(boolean b) {update = b;} + public boolean getUpdate() {return update;} + + public String toString(){ + StringBuilder sb = new StringBuilder(); + if (player != null) + sb.append(player.toString()).append(" "); + sb.append(zoneName); + return sb.toString(); + } + + public CardList getCardsAddedThisTurn(String origin) + { + System.out.print("Request cards put into " + getZoneName() + " from " + origin + ".Amount: "); + CardList ret = new CardList(); + for(int i=0;i(Arrays.asList(k[4].split(",")))); } + if(k[2].contains("Overwrite")) { + se.setOverwriteKeywords(true); + } + + if(k[5].contains("Overwrite")) { + se.setOverwriteAbilities(true); + } + addStaticEffects(se, cardWithKeyword, affectedCards, k[2], types, colors); //give the boni to the affected cards storage.add(se); // store the information @@ -7485,7 +7493,6 @@ public class GameActionUtil { String[] keyword = details.split("/", 3); String powerStr = keyword[0]; String toughStr = keyword[1]; - boolean overwriteTypes = se.isOverwriteTypes(); for(int i = 0; i < affectedCards.size(); i++) { Card affectedCard = affectedCards.get(i); @@ -7496,7 +7503,7 @@ public class GameActionUtil { affectedCard.setBaseAttack(power); affectedCard.setBaseDefense(toughness); - if(overwriteTypes) { + if(se.isOverwriteTypes()) { se.addOriginalTypes(affectedCard, affectedCard.getType()); affectedCard.clearAllTypes(); } @@ -7509,28 +7516,42 @@ public class GameActionUtil { se.removeType(affectedCard, type); } } - - if(keyword.length > 2) { - String keywords[] = keyword[2].split(" & "); - for(int j = 0; j < keywords.length; j++) { - String kw = keywords[j]; - /*if(kw.startsWith("SVar=")) { + if(se.isOverwriteKeywords()) { + se.addOriginalKeywords(affectedCard, affectedCard.getIntrinsicKeyword()); + affectedCard.clearAllKeywords(); + } + else { + if(keyword.length > 2) { + String keywords[] = keyword[2].split(" & "); + for(int j = 0; j < keywords.length; j++) { + String kw = keywords[j]; + /*if(kw.startsWith("SVar=")) { String sVar = source.getSVar(kw.split("SVar=")[1]); if (sVar.startsWith("AB")) { // grant the ability AbilityFactory AF = new AbilityFactory(); SpellAbility sa = AF.getAbility(sVar, affectedCard); sa.setType("Temporary"); - + affectedCard.addSpellAbility(sa); } else { // Copy this SVar affectedCard.setSVar(kw.split("SVar=")[1], sVar); } } - + else */ affectedCard.addExtrinsicKeyword(kw); + } } } + //Abilities + if(se.isOverwriteAbilities()) { + se.addOriginalAbilities(affectedCard, affectedCard.getAllButFirstSpellAbility()); + affectedCard.clearAllButFirstSpellAbility(); + } + else { + //TODO - adding SpellAbilities statically here not supported at this time + } + long t = affectedCard.addColor(colors, affectedCard, true, true); se.addTimestamp(affectedCard, t); }//end for @@ -7562,11 +7583,15 @@ public class GameActionUtil { for(String type : se.getOriginalTypes(affectedCard)) affectedCard.addType(type); } - String[] kw = details[2].split("/", 3); - if (kw.length > 2) { - String kws[] = kw[2].split(" & "); - for(int j = 0; j < kws.length; j++) { - String keyword = kws[j]; + if(se.isOverwriteKeywords()) { + for(String kw : se.getOriginalKeywords(affectedCard)) affectedCard.addIntrinsicKeyword(kw); + } + else { + String[] kw = details[2].split("/", 3); + if (kw.length > 2) { + String kws[] = kw[2].split(" & "); + for(int j = 0; j < kws.length; j++) { + String keyword = kws[j]; /* if(keyword.startsWith("SVar=")) { String sVar = source.getSVar(keyword.split("SVar=")[1]); @@ -7580,8 +7605,17 @@ public class GameActionUtil { } } else */ affectedCard.removeExtrinsicKeyword(keyword); + } } } + //Abilities + if(se.isOverwriteAbilities()) { + for(SpellAbility sa : se.getOriginalAbilities(affectedCard)) affectedCard.addSpellAbility(sa); + } + else { + //TODO - adding SpellAbilities statically here not supported at this time + } + affectedCard.removeColor(se.getColorDesc(), affectedCard, true, se.getTimestamp(affectedCard)); }//end removeStaticEffects diff --git a/src/forge/StaticEffect.java b/src/forge/StaticEffect.java index d0eee4ea753..3afa4882565 100644 --- a/src/forge/StaticEffect.java +++ b/src/forge/StaticEffect.java @@ -4,26 +4,131 @@ package forge; import java.util.ArrayList; import java.util.HashMap; +import forge.card.spellability.SpellAbility; public class StaticEffect { - private Card source = new Card(); - private int keywordNumber = 0; - private CardList affectedCards = new CardList(); - private int xValue = 0; - private int yValue = 0; + private Card source = new Card(); + private int keywordNumber = 0; + private CardList affectedCards = new CardList(); + private int xValue = 0; + private int yValue = 0; //for P/T - private HashMap originalPT = new HashMap(); + private HashMap originalPT = new HashMap(); //for types - private HashMap> types = new HashMap>(); - private HashMap> originalTypes = new HashMap>(); - private boolean overwriteTypes = false; + private boolean overwriteTypes = false; + private HashMap> types = new HashMap>(); + private HashMap> originalTypes = new HashMap>(); + //keywords + private boolean overwriteKeywords = false; + private HashMap> originalKeywords = new HashMap>(); + + //for abilities + private boolean overwriteAbilities = false; + private HashMap> originalAbilities = new HashMap>(); //for colors - private String colorDesc = ""; - private HashMap timestamps = new HashMap(); + private String colorDesc = ""; + private HashMap timestamps = new HashMap(); + + + //overwrite SAs + public boolean isOverwriteAbilities() { + return overwriteAbilities; + } + + public void setOverwriteAbilities(boolean overwriteAbilities) { + this.overwriteAbilities = overwriteAbilities; + } + + //original SAs + public void addOriginalAbilities(Card c, SpellAbility sa) { + if(!originalAbilities.containsKey(c)) { + ArrayList list = new ArrayList(); + list.add(sa); + originalAbilities.put(c, list); + } + else originalAbilities.get(c).add(sa); + } + + public void addOriginalAbilities(Card c, ArrayList s) { + ArrayList list = new ArrayList(s); + if(!originalAbilities.containsKey(c)) { + originalAbilities.put(c, list); + } + else { + originalAbilities.remove(c); + originalAbilities.put(c, list); + } + } + + public ArrayList getOriginalAbilities(Card c) { + ArrayList returnList = new ArrayList(); + if(originalAbilities.containsKey(c)) { + returnList.addAll(originalAbilities.get(c)); + } + return returnList; + } + + public void clearOriginalAbilities(Card c) { + if(originalAbilities.containsKey(c)) { + originalAbilities.get(c).clear(); + } + } + + public void clearAllOriginalAbilities() { + originalAbilities.clear(); + } + + //overwrite keywords + public boolean isOverwriteKeywords() { + return overwriteKeywords; + } + + public void setOverwriteKeywords(boolean overwriteKeywords) { + this.overwriteKeywords = overwriteKeywords; + } + + //original keywords + public void addOriginalKeyword(Card c, String s) { + if(!originalKeywords.containsKey(c)) { + ArrayList list = new ArrayList(); + list.add(s); + originalKeywords.put(c, list); + } + else originalKeywords.get(c).add(s); + } + + public void addOriginalKeywords(Card c, ArrayList s) { + ArrayList list = new ArrayList(s); + if(!originalKeywords.containsKey(c)) { + originalKeywords.put(c, list); + } + else { + originalKeywords.remove(c); + originalKeywords.put(c, list); + } + } + + public ArrayList getOriginalKeywords(Card c) { + ArrayList returnList = new ArrayList(); + if(originalKeywords.containsKey(c)) { + returnList.addAll(originalKeywords.get(c)); + } + return returnList; + } + + public void clearOriginalKeywords(Card c) { + if(originalKeywords.containsKey(c)) { + originalKeywords.get(c).clear(); + } + } + + public void clearAllOriginalKeywords() { + originalKeywords.clear(); + } //original power/toughness public void addOriginalPT(Card c, int power, int toughness) {