From e5d7bac16a8b06d44be808bff83e2d56ce1134b4 Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 09:32:40 +0000 Subject: [PATCH] - Completely rewrote stPump. This increased the performance and fixed some bugs (but maybe introduced some new ones). First steps towards allowing xCount are also made. --- .gitattributes | 1 + src/forge/GameActionUtil.java | 112 +++++++++++++++++++++++++++++++--- src/forge/StaticEffect.java | 42 +++++++++++++ 3 files changed, 148 insertions(+), 7 deletions(-) create mode 100644 src/forge/StaticEffect.java diff --git a/.gitattributes b/.gitattributes index da90c85a8f9..f879dec480b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5524,6 +5524,7 @@ src/forge/SpellAbility_Restriction.java -text svneol=native#text/plain src/forge/Spell_Evoke.java svneol=native#text/plain src/forge/Spell_Permanent.java svneol=native#text/plain src/forge/StackObserver.java svneol=native#text/plain +src/forge/StaticEffect.java -text svneol=native#text/plain src/forge/StaticEffects.java -text svneol=native#text/plain src/forge/TableModel.java -text svneol=native#text/plain src/forge/TableSorter.java svneol=native#text/plain diff --git a/src/forge/GameActionUtil.java b/src/forge/GameActionUtil.java index 5670e3cb5e5..e0ca29f2f62 100644 --- a/src/forge/GameActionUtil.java +++ b/src/forge/GameActionUtil.java @@ -11514,6 +11514,10 @@ public class GameActionUtil { */ private static final long serialVersionUID = -7853346190458174501L; + private ArrayList storage = new ArrayList(); + // storage stores the source card and the cards it gave its bonus to + + /* int max = 100; CardList[] old = new CardList[max]; CardList[] next = new CardList[max]; @@ -11521,9 +11525,61 @@ public class GameActionUtil { String[] InfoStorage = new String[max]; int KeywordsActive = 0; int ActivationNumber = 0; - + */ + public void execute() { + + // remove all static effects + for (int i = 0; i < storage.size(); i++) { + removeStaticEffect(storage.get(i)); + } + + //clear the list + storage = new ArrayList(); + + //Gather Cards on the Battlefield with the stPump Keyword + PlayerZone Hplay = AllZone.getZone(Constant.Zone.Play, AllZone.HumanPlayer); + PlayerZone Cplay = AllZone.getZone(Constant.Zone.Play, AllZone.ComputerPlayer); + CardList cards_WithKeyword = new CardList(); + + cards_WithKeyword.add(new CardList(Hplay.getCards())); + cards_WithKeyword.add(new CardList(Cplay.getCards())); + cards_WithKeyword.getKeywordsContain("stPump"); + + for (int i = 0; i < cards_WithKeyword.size(); i++) { + Card cardWithKeyword = cards_WithKeyword.get(i); + ArrayList keywords = cardWithKeyword.getKeyword(); + + for (int j = 0; j < keywords.size(); j++) { + String keyword = keywords.get(j); + + if(keyword.startsWith("stPump")) { + StaticEffect se = new StaticEffect(); //create a new StaticEffect + se.setSource(cardWithKeyword); + se.setKeywordNumber(j); + se.setXValue(0); //ToDo + + //get the affected cards + String k[] = keyword.split(":"); + + if(SpecialConditionsMet(cardWithKeyword, k[3])) { //special Conditions are Threshold, etc. + + final String affected = k[1]; + final String specific[] = affected.split(","); + CardList affectedCards = AffectedCards(cardWithKeyword, k); // options are All, Other, Self. etc. + affectedCards = affectedCards.getValidCards(specific, cardWithKeyword.getController(), cardWithKeyword); + + addStaticEffects(affectedCards,k[2],j); //give the boni to the affected cards + se.setAffectedCards(affectedCards); + storage.add(se); // store the information + } + } + } + } + + // Initialize Variables + /* if(old[0] == null) { for(int i = 0; i < max; i++) { old[i] = new CardList(); @@ -11536,6 +11592,7 @@ public class GameActionUtil { // Reset Variables at Start of Game if(AllZone.GameAction.StaticEffectKeywordReset) { AllZone.GameAction.StaticEffectKeywordReset = false; + for(int i = 0; i < max; i++) { old[i] = new CardList(); next[i] = new CardList(); @@ -11553,10 +11610,6 @@ public class GameActionUtil { removeKeyword(old[i],CardsWithKeyword.get(z),i,Integer.valueOf(InfoSplit[1]),InfoSplit[2]); } // Gather Cards in Play and Graveyards with the Keyword - PlayerZone Hplay = AllZone.getZone(Constant.Zone.Play, AllZone.HumanPlayer); - PlayerZone Cplay = AllZone.getZone(Constant.Zone.Play, AllZone.ComputerPlayer); - - CardList Cards_WithKeyword = new CardList(); Cards_WithKeyword.add(new CardList(Hplay.getCards())); Cards_WithKeyword.add(new CardList(Cplay.getCards())); Cards_WithKeyword = Cards_WithKeyword.filter(new CardListFilter() { @@ -11621,9 +11674,27 @@ public class GameActionUtil { } } } - } + }*/ }// execute() - + + void addStaticEffects(CardList affectedCards, String Keyword_Details, int xValue) { + + String[] Keyword = Keyword_Details.replace("+","").split("/"); + + for(int i = 0; i < affectedCards.size(); i++) { + Card affectedCard = affectedCards.get(i); + affectedCard.addSemiPermanentAttackBoost(Integer.valueOf(Keyword[0])); + affectedCard.addSemiPermanentDefenseBoost(Integer.valueOf(Keyword[1])); + if (Keyword.length > 2) { + String Keywords[] = Keyword[2].split(" & "); + for(int j = 0; j < Keywords.length; j++) { + affectedCard.addExtrinsicKeyword(Keywords[j]); + } + } + } + } + + /* void addKeyword(Card SourceCard, int ANumber, String[] Keyword_Details) { // Initialize Variables next[ANumber].clear(); @@ -11662,7 +11733,33 @@ public class GameActionUtil { } } } + */ + void removeStaticEffect(StaticEffect se) { + Card Source = se.getSource(); + CardList affected = se.getAffectedCards(); + int KeywordNumber = se.getKeywordNumber(); + int xValue = se.getXValue(); + String parse = Source.getKeyword().get(KeywordNumber).toString(); + String k[] = parse.split(":"); + for(int i = 0; i < affected.size(); i++) { + removeStaticEffect(affected.get(i),k,xValue); + } + } + + void removeStaticEffect(Card affectedCard, String[] Keyword_Details, int xValue) { + String[] Keyword = Keyword_Details[2].replace("+","").split("/"); + affectedCard.addSemiPermanentAttackBoost(Integer.valueOf(Keyword[0]) * -1); + affectedCard.addSemiPermanentDefenseBoost(Integer.valueOf(Keyword[1]) * -1); + if (Keyword.length > 2) { + String Keywords[] = Keyword[2].split(" & "); + for(int j = 0; j < Keywords.length; j++) { + affectedCard.removeExtrinsicKeyword(Keywords[j]); + } + } + } + + /* void removeKeyword(CardList list , Card Source,int ANumber, int AbilityNumber, String LastKnownController) { // Initialize Variables String parse = Source.getKeyword().get(AbilityNumber).toString(); @@ -11716,6 +11813,7 @@ public class GameActionUtil { } } } + */ // Special Conditions boolean SpecialConditionsMet(Card SourceCard, String SpecialConditions) { diff --git a/src/forge/StaticEffect.java b/src/forge/StaticEffect.java new file mode 100644 index 00000000000..3d0ec0cc30e --- /dev/null +++ b/src/forge/StaticEffect.java @@ -0,0 +1,42 @@ +package forge; + + +public class StaticEffect { + private Card source = new Card(); + private int keywordNumber = 0; + private CardList affectedCards = new CardList(); + private int xValue = 0; + + + public void setSource(Card card) { + source = card; + } + + public Card getSource() { + return source; + } + + public void setKeywordNumber(int i) { + keywordNumber = i; + } + + public int getKeywordNumber() { + return keywordNumber; + } + + public CardList getAffectedCards() { + return affectedCards; + } + + public void setAffectedCards(CardList list) { + affectedCards = list; + } + + public void setXValue(int x) { + xValue = x; + } + + public int getXValue() { + return xValue; + } +}