fixes comodification exceptions (like http://www.slightlymagic.net/forum/viewtopic.php?p=115346#p115346 and viewtopic.php?p=114582#p114582)

This commit is contained in:
Maxmtg
2013-04-13 05:20:54 +00:00
parent b9ace52e8b
commit 145a0ce441
3 changed files with 48 additions and 142 deletions

View File

@@ -29,6 +29,8 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentSkipListMap;
import org.apache.commons.lang3.StringUtils;
import com.esotericsoftware.minlog.Log;
@@ -110,9 +112,9 @@ public class Card extends GameEntity implements Comparable<Card> {
private GameEntity enchanting = null;
private ArrayList<String> optionalAdditionalCostsPaid = null;
// changes by AF animate and continuous static effects
private ArrayList<CardType> changedCardTypes = new ArrayList<CardType>();
private List<CardKeywords> changedCardKeywords = new ArrayList<CardKeywords>();
// changes by AF animate and continuous static effects - timestamp is the key of maps
private Map<Long, CardType> changedCardTypes = new ConcurrentSkipListMap<Long, CardType>();
private Map<Long, CardKeywords> changedCardKeywords = new ConcurrentSkipListMap<Long, CardKeywords>();
private final ArrayList<Object> rememberedObjects = new ArrayList<Object>();
private final ArrayList<Card> imprintedCards = new ArrayList<Card>();
@@ -1583,16 +1585,9 @@ public class Card extends GameEntity implements Comparable<Card> {
if (this.isImmutable()) {
return new CardColor(this);
}
CardColor colors = null;
final ArrayList<CardColor> globalChanges;
if (Singletons.getModel().getGame() == null) {
globalChanges = new ArrayList<CardColor>();
}
else {
globalChanges = Singletons.getModel().getGame().getColorChanger().getColorChanges();
}
colors = this.determineColor(globalChanges);
final ArrayList<CardColor> globalChanges = getOwner() == null ? new ArrayList<CardColor>() : getOwner().getGame().getColorChanger().getColorChanges();
CardColor colors = this.determineColor(globalChanges);
colors.fixColorless();
return colors;
}
@@ -3469,13 +3464,8 @@ public class Card extends GameEntity implements Comparable<Card> {
public final ArrayList<String> getType() {
// see if type changes are in effect
if (!this.changedCardTypes.isEmpty()) {
final ArrayList<String> newType = new ArrayList<String>(this.getCharacteristics().getType());
final ArrayList<CardType> types = this.changedCardTypes;
Collections.sort(types); // sorts types by timeStamp
for (final CardType ct : types) {
for (final CardType ct : this.changedCardTypes.values()) {
final ArrayList<String> removeTypes = new ArrayList<String>();
if (ct.getRemoveType() != null) {
removeTypes.addAll(ct.getRemoveType());
@@ -3505,10 +3495,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
return newType;
}
// nothing changed
return new ArrayList<String>(this.getCharacteristics().getType());
}
/**
@@ -3534,8 +3521,7 @@ public class Card extends GameEntity implements Comparable<Card> {
final boolean removeSuperTypes, final boolean removeCardTypes, final boolean removeSubTypes,
final boolean removeCreatureTypes, final long timestamp) {
this.changedCardTypes.add(new CardType(types, removeTypes, removeSuperTypes, removeCardTypes, removeSubTypes,
removeCreatureTypes, timestamp));
this.changedCardTypes.put(timestamp, new CardType(types, removeTypes, removeSuperTypes, removeCardTypes, removeSubTypes, removeCreatureTypes));
}
/**
@@ -3582,12 +3568,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* long
*/
public final void removeChangedCardTypes(final long timestamp) {
for (int i = 0; i < this.changedCardTypes.size(); i++) {
final CardType cardT = this.changedCardTypes.get(i);
if (cardT.getTimestamp() == timestamp) {
this.changedCardTypes.remove(cardT);
}
}
this.changedCardTypes.remove(Long.valueOf(timestamp));
}
// values that are printed on card
@@ -4232,7 +4213,7 @@ public class Card extends GameEntity implements Comparable<Card> {
public final void addChangedCardKeywords(final ArrayList<String> keywords, final ArrayList<String> removeKeywords,
final boolean removeAllKeywords, final long timestamp) {
this.changedCardKeywords.add(new CardKeywords(keywords, removeKeywords, removeAllKeywords, timestamp));
this.changedCardKeywords.put(timestamp, new CardKeywords(keywords, removeKeywords, removeAllKeywords));
}
/**
@@ -4269,12 +4250,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* the timestamp
*/
public final void removeChangedCardKeywords(final long timestamp) {
for (int i = 0; i < this.changedCardKeywords.size(); i++) {
final CardKeywords cardK = this.changedCardKeywords.get(i);
if (cardK.getTimestamp() == timestamp) {
this.changedCardKeywords.remove(cardK);
}
}
changedCardKeywords.remove(Long.valueOf(timestamp));
}
// Hidden keywords will be left out
@@ -4291,12 +4267,7 @@ public class Card extends GameEntity implements Comparable<Card> {
keywords.addAll(this.getExtrinsicKeyword());
// see if keyword changes are in effect
if (!this.changedCardKeywords.isEmpty()) {
final ArrayList<CardKeywords> newKeywords = new ArrayList<CardKeywords>(this.changedCardKeywords);
Collections.sort(newKeywords); // sorts newKeywords by timeStamp
for (final CardKeywords ck : newKeywords) {
for (final CardKeywords ck : this.changedCardKeywords.values()) {
if (ck.isRemoveAllKeywords()) {
keywords.clear();
@@ -4308,7 +4279,6 @@ public class Card extends GameEntity implements Comparable<Card> {
keywords.addAll(ck.getKeywords());
}
}
}
return keywords;
}

View File

@@ -27,23 +27,11 @@ import java.util.ArrayList;
* @author Forge
* @version $Id$
*/
public class CardKeywords implements Comparable<CardKeywords> {
public class CardKeywords {
// takes care of individual card types
private ArrayList<String> keywords = new ArrayList<String>();
private ArrayList<String> removeKeywords = new ArrayList<String>();
private boolean removeAllKeywords = false;
private long timeStamp = 0;
/**
* <p>
* getTimestamp.
* </p>
*
* @return a long.
*/
public final long getTimestamp() {
return this.timeStamp;
}
/**
*
@@ -58,12 +46,10 @@ public class CardKeywords implements Comparable<CardKeywords> {
* @param stamp
* a long
*/
CardKeywords(final ArrayList<String> keywordList, final ArrayList<String> removeKeywordList,
final boolean removeAll, final long stamp) {
CardKeywords(final ArrayList<String> keywordList, final ArrayList<String> removeKeywordList, final boolean removeAll) {
this.keywords = keywordList;
this.removeKeywords = removeKeywordList;
this.removeAllKeywords = removeAll;
this.timeStamp = stamp;
}
/**
@@ -95,22 +81,4 @@ public class CardKeywords implements Comparable<CardKeywords> {
public final boolean isRemoveAllKeywords() {
return this.removeAllKeywords;
}
/*
* (non-Javadoc)
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public final int compareTo(final CardKeywords anotherCardKeywords) {
int returnValue = 0;
final long anotherTimeStamp = anotherCardKeywords.getTimestamp();
if (this.timeStamp < anotherTimeStamp) {
returnValue = -1;
} else if (this.timeStamp > anotherTimeStamp) {
returnValue = 1;
}
return returnValue;
}
}

View File

@@ -27,7 +27,7 @@ import java.util.ArrayList;
* @author Forge
* @version $Id$
*/
public class CardType implements Comparable<CardType> {
public class CardType {
// takes care of individual card types
private ArrayList<String> type = new ArrayList<String>();
private ArrayList<String> removeType = new ArrayList<String>();
@@ -35,18 +35,6 @@ public class CardType implements Comparable<CardType> {
private final boolean removeCardTypes;
private final boolean removeSubTypes;
private final boolean removeCreatureTypes;
private long timeStamp = 0;
/**
* <p>
* getTimestamp.
* </p>
*
* @return a long.
*/
public final long getTimestamp() {
return this.timeStamp;
}
/**
* Instantiates a new card_ type.
@@ -67,15 +55,13 @@ public class CardType implements Comparable<CardType> {
* a long
*/
CardType(final ArrayList<String> types, final ArrayList<String> removeTypes, final boolean removeSuperType,
final boolean removeCardType, final boolean removeSubType, final boolean removeCreatureType,
final long stamp) {
final boolean removeCardType, final boolean removeSubType, final boolean removeCreatureType) {
this.type = types;
this.removeType = removeTypes;
this.removeSuperTypes = removeSuperType;
this.removeCardTypes = removeCardType;
this.removeSubTypes = removeSubType;
this.removeCreatureTypes = removeCreatureType;
this.timeStamp = stamp;
}
/**
@@ -137,22 +123,4 @@ public class CardType implements Comparable<CardType> {
public final boolean isRemoveCreatureTypes() {
return this.removeCreatureTypes;
}
/*
* (non-Javadoc)
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public final int compareTo(final CardType anotherCardType) {
int returnValue = 0;
final long anotherTimeStamp = anotherCardType.getTimestamp();
if (this.timeStamp < anotherTimeStamp) {
returnValue = -1;
} else if (this.timeStamp > anotherTimeStamp) {
returnValue = 1;
}
return returnValue;
}
}