Card: changed Color/Type as Table

This commit is contained in:
Hans Mackowiak
2021-10-08 07:22:00 +02:00
parent cb5f0f360b
commit b83174e6ee
8 changed files with 76 additions and 64 deletions

View File

@@ -285,11 +285,11 @@ public class GameCopier {
newCard.setPTBoost(c.getPTBoostTable());
newCard.setDamage(c.getDamage());
newCard.setChangedCardColors(c.getChangedCardColorsMap());
newCard.setChangedCardColorsCharacterDefining(c.getChangedCardColorsCharacterDefiningMap());
newCard.setChangedCardColors(c.getChangedCardColorsTable());
newCard.setChangedCardColorsCharacterDefining(c.getChangedCardColorsCharacterDefiningTable());
newCard.setChangedCardTypes(c.getChangedCardTypesMap());
newCard.setChangedCardTypesCharacterDefining(c.getChangedCardTypesCharacterDefiningMap());
newCard.setChangedCardTypes(c.getChangedCardTypesTable());
newCard.setChangedCardTypesCharacterDefining(c.getChangedCardTypesCharacterDefiningTable());
newCard.setChangedCardKeywords(c.getChangedCardKeywords());
newCard.setChangedCardNames(c.getChangedCardNames());

View File

@@ -274,11 +274,11 @@ public class GameAction {
if (zoneTo.is(ZoneType.Stack)) {
// when moving to stack, copy changed card information
copied.setChangedCardColors(c.getChangedCardColorsMap());
copied.setChangedCardColorsCharacterDefining(c.getChangedCardColorsCharacterDefiningMap());
copied.setChangedCardColors(c.getChangedCardColorsTable());
copied.setChangedCardColorsCharacterDefining(c.getChangedCardColorsCharacterDefiningTable());
copied.setChangedCardKeywords(c.getChangedCardKeywords());
copied.setChangedCardTypes(c.getChangedCardTypesMap());
copied.setChangedCardTypesCharacterDefining(c.getChangedCardTypesCharacterDefiningMap());
copied.setChangedCardTypes(c.getChangedCardTypesTable());
copied.setChangedCardTypesCharacterDefining(c.getChangedCardTypesCharacterDefiningTable());
copied.setChangedCardNames(c.getChangedCardNames());
copied.setChangedCardTraits(c.getChangedCardTraits());

View File

@@ -244,12 +244,12 @@ public class StaticEffect {
// remove Types
if (hasParam("AddType") || hasParam("RemoveType")) {
// the view is updated in GameAction#checkStaticAbilities to avoid flickering
affectedCard.removeChangedCardTypes(getTimestamp(), false);
affectedCard.removeChangedCardTypes(getTimestamp(), ability.getId(), false);
}
// remove colors
if (hasParam("AddColor") || hasParam("SetColor")) {
affectedCard.removeColor(getTimestamp());
affectedCard.removeColor(getTimestamp(), ability.getId());
}
// remove may look at

View File

@@ -94,7 +94,7 @@ public abstract class AnimateEffectBase extends SpellAbilityEffect {
if (!addType.isEmpty() || !removeType.isEmpty() || removeCreatureTypes) {
c.addChangedCardTypes(addType, removeType, removeSuperTypes, removeCardTypes, removeSubTypes,
removeLandTypes, removeCreatureTypes, removeArtifactTypes, removeEnchantmentTypes, timestamp, true, false);
removeLandTypes, removeCreatureTypes, removeArtifactTypes, removeEnchantmentTypes, timestamp, 0, true, false);
}
c.addChangedCardKeywords(keywords, removeKeywords, removeAll, timestamp, 0);
@@ -107,7 +107,7 @@ public abstract class AnimateEffectBase extends SpellAbilityEffect {
c.addHiddenExtrinsicKeywords(timestamp, 0, hiddenKeywords);
}
c.addColor(colors, !sa.hasParam("OverwriteColors"), timestamp, false);
c.addColor(colors, !sa.hasParam("OverwriteColors"), timestamp, 0, false);
if (sa.hasParam("LeaveBattlefield")) {
addLeaveBattlefieldReplacement(c, sa, sa.getParam("LeaveBattlefield"));
@@ -223,8 +223,8 @@ public abstract class AnimateEffectBase extends SpellAbilityEffect {
c.removeChangedCardKeywords(timestamp, 0);
c.removeChangedCardTypes(timestamp);
c.removeColor(timestamp);
c.removeChangedCardTypes(timestamp, 0);
c.removeColor(timestamp, 0);
c.removeChangedCardTraits(timestamp, 0);

View File

@@ -123,16 +123,17 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
private final Map<StaticAbility, CardPlayOption> mayPlay = Maps.newHashMap();
// changes by AF animate and continuous static effects - timestamp is the key of maps
private final Map<Long, CardChangedType> changedCardTypes = Maps.newTreeMap();
// changes by AF animate and continuous static effects
// x=timestamp y=StaticAbility id
private final Table<Long, Long, CardChangedType> changedCardTypes = TreeBasedTable.create();
private final NavigableMap<Long, String> changedCardNames = Maps.newTreeMap();
private final Table<Long, Long, KeywordsChange> changedCardKeywords = TreeBasedTable.create();
// x=timestamp y=StaticAbility id
private final Table<Long, Long, CardTraitChanges> changedCardTraits = TreeBasedTable.create();
private final Map<Long, CardColor> changedCardColors = Maps.newTreeMap();
private final Table<Long, Long, CardColor> changedCardColors = TreeBasedTable.create();
private final Map<Long, CardChangedType> changedCardTypesCharacterDefining = Maps.newTreeMap();
private final Map<Long, CardColor> changedCardColorsCharacterDefining = Maps.newTreeMap();
private final Table<Long, Long, CardChangedType> changedCardTypesCharacterDefining = TreeBasedTable.create();
private final Table<Long, Long, CardColor> changedCardColorsCharacterDefining = TreeBasedTable.create();
private final NavigableMap<Long, CardCloneStates> clonedStates = Maps.newTreeMap();
private final NavigableMap<Long, CardCloneStates> textChangeStates = Maps.newTreeMap();
@@ -152,6 +153,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
// changes that say "replace each instance of one [color,type] by another - timestamp is the key of maps
private final CardChangedWords changedTextColors = new CardChangedWords();
private final CardChangedWords changedTextTypes = new CardChangedWords();
/** List of the keywords that have been added by text changes. */
private final List<KeywordInterface> keywordsGrantedByTextChanges = Lists.newArrayList();
@@ -1467,7 +1469,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
long timestamp = game.getNextTimestamp();
counterTypeTimestamps.put(counterType, timestamp);
// becomes land in instead of other card types
addChangedCardTypes(new CardType(ImmutableList.of("Land"), false), null, false, true, true, false, false, false, false, timestamp, updateView, false);
addChangedCardTypes(new CardType(ImmutableList.of("Land"), false), null, false, true, true, false, false, false, false, timestamp, 0, updateView, false);
String abStr = "AB$ ManaReflected | Cost$ T | Valid$ Defined.Self | ColorOrType$ Color | ReflectProperty$ Is | SpellDescription$ Add one mana of any of this card's colors.";
@@ -1494,7 +1496,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
public boolean removeCounterTimestamp(CounterType counterType, boolean updateView) {
Long old = counterTypeTimestamps.remove(counterType);
if (old != null) {
removeChangedCardTypes(old, updateView);
removeChangedCardTypes(old, 0, updateView);
removeChangedCardTraits(old, 0);
removeChangedCardKeywords(old, 0, updateView);
}
@@ -3558,15 +3560,24 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
return types;
}
public final CardTypeView getOriginalType() {
return getOriginalType(currentState);
}
public final CardTypeView getOriginalType(CardState state) {
return state.getType();
}
// TODO add changed type by card text
public Iterable<CardChangedType> getChangedCardTypes() {
return Iterables.unmodifiableIterable(Iterables.concat(changedCardTypesCharacterDefining.values(), changedCardTypes.values()));
}
public Map<Long, CardChangedType> getChangedCardTypesMap() {
return Collections.unmodifiableMap(changedCardTypes);
public Table<Long, Long, CardChangedType> getChangedCardTypesTable() {
return Tables.unmodifiableTable(changedCardTypes);
}
public Map<Long, CardChangedType> getChangedCardTypesCharacterDefiningMap() {
return Collections.unmodifiableMap(changedCardTypesCharacterDefining);
public Table<Long, Long, CardChangedType> getChangedCardTypesCharacterDefiningTable() {
return Tables.unmodifiableTable(changedCardTypesCharacterDefining);
}
public boolean clearChangedCardTypes() {
@@ -3601,10 +3612,10 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
return changedCardKeywords;
}
public Map<Long, CardColor> getChangedCardColorsMap() {
public Table<Long, Long, CardColor> getChangedCardColorsTable() {
return changedCardColors;
}
public Map<Long, CardColor> getChangedCardColorsCharacterDefiningMap() {
public Table<Long, Long, CardColor> getChangedCardColorsCharacterDefiningTable() {
return changedCardColorsCharacterDefining;
}
public Iterable<CardColor> getChangedCardColors() {
@@ -3615,8 +3626,8 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
final boolean removeSuperTypes, final boolean removeCardTypes, final boolean removeSubTypes,
final boolean removeLandTypes, final boolean removeCreatureTypes, final boolean removeArtifactTypes,
final boolean removeEnchantmentTypes,
final long timestamp, final boolean updateView, final boolean cda) {
(cda ? changedCardTypesCharacterDefining : changedCardTypes).put(timestamp, new CardChangedType(
final long timestamp, final long staticId, final boolean updateView, final boolean cda) {
(cda ? changedCardTypesCharacterDefining : changedCardTypes).put(timestamp, staticId, new CardChangedType(
addType, removeType, removeSuperTypes, removeCardTypes, removeSubTypes,
removeLandTypes, removeCreatureTypes, removeArtifactTypes, removeEnchantmentTypes));
if (updateView) {
@@ -3628,7 +3639,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
final boolean removeSuperTypes, final boolean removeCardTypes, final boolean removeSubTypes,
final boolean removeLandTypes, final boolean removeCreatureTypes, final boolean removeArtifactTypes,
final boolean removeEnchantmentTypes,
final long timestamp, final boolean updateView, final boolean cda) {
final long timestamp, final long staticId, final boolean updateView, final boolean cda) {
CardType addType = null;
CardType removeType = null;
if (types != null) {
@@ -3641,31 +3652,31 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
addChangedCardTypes(addType, removeType, removeSuperTypes, removeCardTypes, removeSubTypes,
removeLandTypes, removeCreatureTypes, removeArtifactTypes, removeEnchantmentTypes,
timestamp, updateView, cda);
timestamp, staticId, updateView, cda);
}
public final void removeChangedCardTypes(final long timestamp) {
removeChangedCardTypes(timestamp, true);
public final void removeChangedCardTypes(final long timestamp, final long staticId) {
removeChangedCardTypes(timestamp, staticId, true);
}
public final void removeChangedCardTypes(final long timestamp, final boolean updateView) {
public final void removeChangedCardTypes(final long timestamp, final long staticId, final boolean updateView) {
boolean removed = false;
removed |= changedCardTypes.remove(timestamp) != null;
removed |= changedCardTypesCharacterDefining.remove(timestamp) != null;
removed |= changedCardTypes.remove(timestamp, staticId) != null;
removed |= changedCardTypesCharacterDefining.remove(timestamp, staticId) != null;
if (removed && updateView) {
currentState.getView().updateType(currentState);
}
}
public final void addColor(final String s, final boolean addToColors, final long timestamp, final boolean cda) {
(cda ? changedCardColorsCharacterDefining : changedCardColors).put(timestamp, new CardColor(s, addToColors, timestamp));
public final void addColor(final String s, final boolean addToColors, final long timestamp, final long staticId, final boolean cda) {
(cda ? changedCardColorsCharacterDefining : changedCardColors).put(timestamp, staticId, new CardColor(s, addToColors, timestamp));
currentState.getView().updateColors(this);
currentState.getView().updateHasChangeColors(!Iterables.isEmpty(getChangedCardColors()));
}
public final void removeColor(final long timestampIn) {
public final void removeColor(final long timestampIn, final long staticId) {
boolean removed = false;
removed |= changedCardColors.remove(timestampIn) != null;
removed |= changedCardColorsCharacterDefining.remove(timestampIn) != null;
removed |= changedCardColors.remove(timestampIn, staticId) != null;
removed |= changedCardColorsCharacterDefining.remove(timestampIn, staticId) != null;
if (removed) {
currentState.getView().updateColors(this);
@@ -4358,8 +4369,9 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
public final void addChangedTextTypeWord(final String originalWord, final String newWord, final Long timestamp, final long staticId) {
changedTextTypes.add(timestamp, originalWord, newWord);
if (getType().hasSubtype(originalWord)) {
// need other table because different layer
addChangedCardTypes(CardType.parse(newWord, true), CardType.parse(originalWord, true),
false, false, false, false, false, false, false, timestamp, true, false);
false, false, false, false, false, false, false, timestamp, staticId, true, false);
}
updateKeywordsChangedText(timestamp, staticId);
updateChangedText();
@@ -4367,7 +4379,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
public final void removeChangedTextTypeWord(final Long timestamp, final long staticId) {
changedTextTypes.remove(timestamp);
removeChangedCardTypes(timestamp);
removeChangedCardTypes(timestamp, staticId);
updateKeywordsOnRemoveChangedText(
removeChangedCardKeywords(timestamp, staticId));
updateChangedText();
@@ -5564,7 +5576,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
bestowTimestamp = getGame().getNextTimestamp();
addChangedCardTypes(new CardType(Collections.singletonList("Aura"), true),
new CardType(Collections.singletonList("Creature"), true),
false, false, false, false, false, false, true, bestowTimestamp, updateView, false);
false, false, false, false, false, false, true, bestowTimestamp, 0, updateView, false);
addChangedCardKeywords(Collections.singletonList("Enchant creature"), Lists.newArrayList(),
false, bestowTimestamp, 0, updateView);
}
@@ -5578,7 +5590,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
}
removeChangedCardKeywords(bestowTimestamp, 0, updateView);
removeChangedCardTypes(bestowTimestamp, updateView);
removeChangedCardTypes(bestowTimestamp, 0, updateView);
bestowTimestamp = -1;
}
@@ -6617,16 +6629,16 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
}
}
public void setChangedCardTypes(Map<Long, CardChangedType> changedCardTypes) {
public void setChangedCardTypes(Table<Long, Long, CardChangedType> changedCardTypes) {
this.changedCardTypes.clear();
for (Entry<Long, CardChangedType> entry : changedCardTypes.entrySet()) {
this.changedCardTypes.put(entry.getKey(), entry.getValue());
for (Table.Cell<Long, Long, CardChangedType> entry : changedCardTypes.cellSet()) {
this.changedCardTypes.put(entry.getRowKey(), entry.getColumnKey(), entry.getValue());
}
}
public void setChangedCardTypesCharacterDefining(Map<Long, CardChangedType> changedCardTypes) {
public void setChangedCardTypesCharacterDefining(Table<Long, Long, CardChangedType> changedCardTypes) {
this.changedCardTypesCharacterDefining.clear();
for (Entry<Long, CardChangedType> entry : changedCardTypes.entrySet()) {
this.changedCardTypesCharacterDefining.put(entry.getKey(), entry.getValue());
for (Table.Cell<Long, Long, CardChangedType> entry : changedCardTypes.cellSet()) {
this.changedCardTypesCharacterDefining.put(entry.getRowKey(), entry.getColumnKey(), entry.getValue());
}
}
@@ -6637,16 +6649,16 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
}
}
public void setChangedCardColors(Map<Long, CardColor> changedCardColors) {
public void setChangedCardColors(Table<Long, Long, CardColor> changedCardColors) {
this.changedCardColors.clear();
for (Entry<Long, CardColor> entry : changedCardColors.entrySet()) {
this.changedCardColors.put(entry.getKey(), entry.getValue());
for (Table.Cell<Long, Long, CardColor> entry : changedCardColors.cellSet()) {
this.changedCardColors.put(entry.getRowKey(), entry.getColumnKey(), entry.getValue());
}
}
public void setChangedCardColorsCharacterDefining(Map<Long, CardColor> changedCardColors) {
public void setChangedCardColorsCharacterDefining(Table<Long, Long, CardColor> changedCardColors) {
this.changedCardColorsCharacterDefining.clear();
for (Entry<Long, CardColor> entry : changedCardColors.entrySet()) {
this.changedCardColorsCharacterDefining.put(entry.getKey(), entry.getValue());
for (Table.Cell<Long, Long, CardColor> entry : changedCardColors.cellSet()) {
this.changedCardColorsCharacterDefining.put(entry.getRowKey(), entry.getColumnKey(), entry.getValue());
}
}

View File

@@ -140,7 +140,7 @@ public class CardFactory {
}
final String finalColors = tmp;
c.addColor(finalColors, !sourceSA.hasParam("OverwriteColors"), c.getTimestamp(), false);
c.addColor(finalColors, !sourceSA.hasParam("OverwriteColors"), c.getTimestamp(), 0, false);
}
c.clearControllers();

View File

@@ -281,11 +281,11 @@ public final class CardUtil {
newCopy.setUnearthed(in.isUnearthed());
newCopy.setChangedCardColors(in.getChangedCardColorsMap());
newCopy.setChangedCardColorsCharacterDefining(in.getChangedCardColorsCharacterDefiningMap());
newCopy.setChangedCardColors(in.getChangedCardColorsTable());
newCopy.setChangedCardColorsCharacterDefining(in.getChangedCardColorsCharacterDefiningTable());
newCopy.setChangedCardKeywords(in.getChangedCardKeywords());
newCopy.setChangedCardTypes(in.getChangedCardTypesMap());
newCopy.setChangedCardTypesCharacterDefining(in.getChangedCardTypesCharacterDefiningMap());
newCopy.setChangedCardTypes(in.getChangedCardTypesTable());
newCopy.setChangedCardTypesCharacterDefining(in.getChangedCardTypesCharacterDefiningTable());
newCopy.setChangedCardNames(in.getChangedCardNames());
newCopy.setChangedCardTraits(in.getChangedCardTraits());

View File

@@ -846,12 +846,12 @@ public final class StaticAbilityContinuous {
if ((addTypes != null) || (removeTypes != null)) {
affectedCard.addChangedCardTypes(addTypes, removeTypes, removeSuperTypes, removeCardTypes,
removeSubTypes, removeLandTypes, removeCreatureTypes, removeArtifactTypes,
removeEnchantmentTypes, hostCard.getTimestamp(), true, stAb.hasParam("CharacteristicDefining"));
removeEnchantmentTypes, hostCard.getTimestamp(), stAb.getId(), true, stAb.hasParam("CharacteristicDefining"));
}
// add colors
if (addColors != null) {
affectedCard.addColor(addColors, !overwriteColors, hostCard.getTimestamp(), stAb.hasParam("CharacteristicDefining"));
affectedCard.addColor(addColors, !overwriteColors, hostCard.getTimestamp(), stAb.getId(), stAb.hasParam("CharacteristicDefining"));
}
if (layer == StaticAbilityLayer.RULES) {