Fixed bugs related to Animate AF (see bug issue #137)

This commit is contained in:
ArsenalNut
2011-08-15 13:44:18 +00:00
parent eda721d0c1
commit 99b0303d6f
3 changed files with 33 additions and 29 deletions

View File

@@ -4,6 +4,7 @@ package forge;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@@ -3174,7 +3175,11 @@ public class Card extends MyObservable implements Comparable<Card> {
if (!changedCardTypes.isEmpty()) { if (!changedCardTypes.isEmpty()) {
ArrayList<String> newType = new ArrayList<String>(type); ArrayList<String> newType = new ArrayList<String>(type);
ArrayList<Card_Type> types = sortByTimestamp(changedCardTypes); ArrayList<Card_Type> types = changedCardTypes;
//TODO: Any reason why changedCardTypes can't be sorted in place
// Does changedCardTypes ever get out of increasing time
// stamp order?
Collections.sort(types); // sorts types by timeStamp
for (Card_Type ct : types) { for (Card_Type ct : types) {
ArrayList<String> removeTypes = new ArrayList<String>(); ArrayList<String> removeTypes = new ArrayList<String>();
@@ -3203,20 +3208,6 @@ public class Card extends MyObservable implements Comparable<Card> {
return new ArrayList<String>(type); return new ArrayList<String>(type);
} }
private ArrayList<Card_Type> sortByTimestamp(ArrayList<Card_Type> cardTypes) {
ArrayList<Card_Type> remainingCardTypes = cardTypes;
ArrayList<Card_Type> types = new ArrayList<Card_Type>();
for(int i = 0; i < cardTypes.size(); i++) {
Card_Type nextCT = remainingCardTypes.get(i);
long nextLowest = nextCT.getTimestamp();
for(Card_Type ct : remainingCardTypes) {
if (nextLowest > ct.getTimestamp())
nextCT = ct;
}
types.add(nextCT);
}
return types;
}
public void addChangedCardTypes(ArrayList<String> types, boolean removeSuperTypes, boolean removeCardTypes, public void addChangedCardTypes(ArrayList<String> types, boolean removeSuperTypes, boolean removeCardTypes,
boolean removeSubTypes, boolean removeCreatureTypes, long timestamp) { boolean removeSubTypes, boolean removeCreatureTypes, long timestamp) {

View File

@@ -2,13 +2,14 @@ package forge;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* <p>Card_Color class.</p> * <p>Card_Color class.</p>
* *
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class Card_Type { public class Card_Type implements Comparable<Card_Type> {
// takes care of individual card types // takes care of individual card types
private ArrayList<String> type = new ArrayList<String>(); private ArrayList<String> type = new ArrayList<String>();
private boolean removeSuperTypes; private boolean removeSuperTypes;
@@ -63,4 +64,16 @@ public class Card_Type {
public boolean isRemoveCreatureTypes() { public boolean isRemoveCreatureTypes() {
return removeCreatureTypes; return removeCreatureTypes;
} }
@Override
public int compareTo(final Card_Type anotherCardType) {
int returnValue = 0;
long anotherTimeStamp = anotherCardType.getTimestamp();
if (this.timeStamp < anotherTimeStamp)
returnValue = -1;
else if (this.timeStamp > anotherTimeStamp)
returnValue = 1;
return returnValue;
}
} }

View File

@@ -355,8 +355,8 @@ public class AbilityFactory_Animate {
if (params.containsKey("Toughness")) if (params.containsKey("Toughness"))
toughness = AbilityFactory.calculateAmount(host, params.get("Toughness"), sa); toughness = AbilityFactory.calculateAmount(host, params.get("Toughness"), sa);
if (power != -1 || toughness != -1) // Every Animate event needs a unique time stamp
timest = AllZone.getNextTimestamp(); timest = AllZone.getNextTimestamp();
final long timestamp = timest; final long timestamp = timest;
@@ -785,8 +785,8 @@ public class AbilityFactory_Animate {
if (params.containsKey("Toughness")) if (params.containsKey("Toughness"))
toughness = AbilityFactory.calculateAmount(host, params.get("Toughness"), sa); toughness = AbilityFactory.calculateAmount(host, params.get("Toughness"), sa);
if (power != -1 || toughness != -1) // Every Animate event needs a unique time stamp
timest = AllZone.getNextTimestamp(); timest = AllZone.getNextTimestamp();
final long timestamp = timest; final long timestamp = timest;