From b83174e6ee52f5a6f7995e0e35455cd82b4599bd Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 8 Oct 2021 07:22:00 +0200 Subject: [PATCH] Card: changed Color/Type as Table --- .../java/forge/ai/simulation/GameCopier.java | 8 +- .../src/main/java/forge/game/GameAction.java | 8 +- .../main/java/forge/game/StaticEffect.java | 4 +- .../ability/effects/AnimateEffectBase.java | 8 +- .../src/main/java/forge/game/card/Card.java | 98 +++++++++++-------- .../java/forge/game/card/CardFactory.java | 2 +- .../main/java/forge/game/card/CardUtil.java | 8 +- .../StaticAbilityContinuous.java | 4 +- 8 files changed, 76 insertions(+), 64 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/simulation/GameCopier.java b/forge-ai/src/main/java/forge/ai/simulation/GameCopier.java index 58d4cea4fbe..49bfdd66e2d 100644 --- a/forge-ai/src/main/java/forge/ai/simulation/GameCopier.java +++ b/forge-ai/src/main/java/forge/ai/simulation/GameCopier.java @@ -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()); diff --git a/forge-game/src/main/java/forge/game/GameAction.java b/forge-game/src/main/java/forge/game/GameAction.java index cc67f0bad4a..4ba4286662c 100644 --- a/forge-game/src/main/java/forge/game/GameAction.java +++ b/forge-game/src/main/java/forge/game/GameAction.java @@ -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()); diff --git a/forge-game/src/main/java/forge/game/StaticEffect.java b/forge-game/src/main/java/forge/game/StaticEffect.java index 40e795e0cb2..0ad39061d58 100644 --- a/forge-game/src/main/java/forge/game/StaticEffect.java +++ b/forge-game/src/main/java/forge/game/StaticEffect.java @@ -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 diff --git a/forge-game/src/main/java/forge/game/ability/effects/AnimateEffectBase.java b/forge-game/src/main/java/forge/game/ability/effects/AnimateEffectBase.java index a5cb502145f..03f5b7a196f 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/AnimateEffectBase.java +++ b/forge-game/src/main/java/forge/game/ability/effects/AnimateEffectBase.java @@ -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); diff --git a/forge-game/src/main/java/forge/game/card/Card.java b/forge-game/src/main/java/forge/game/card/Card.java index b53afd8652e..a6946a58738 100644 --- a/forge-game/src/main/java/forge/game/card/Card.java +++ b/forge-game/src/main/java/forge/game/card/Card.java @@ -123,16 +123,17 @@ public class Card extends GameEntity implements Comparable, IHasSVars { private final Map mayPlay = Maps.newHashMap(); - // changes by AF animate and continuous static effects - timestamp is the key of maps - private final Map changedCardTypes = Maps.newTreeMap(); + // changes by AF animate and continuous static effects + // x=timestamp y=StaticAbility id + private final Table changedCardTypes = TreeBasedTable.create(); private final NavigableMap changedCardNames = Maps.newTreeMap(); private final Table changedCardKeywords = TreeBasedTable.create(); // x=timestamp y=StaticAbility id private final Table changedCardTraits = TreeBasedTable.create(); - private final Map changedCardColors = Maps.newTreeMap(); + private final Table changedCardColors = TreeBasedTable.create(); - private final Map changedCardTypesCharacterDefining = Maps.newTreeMap(); - private final Map changedCardColorsCharacterDefining = Maps.newTreeMap(); + private final Table changedCardTypesCharacterDefining = TreeBasedTable.create(); + private final Table changedCardColorsCharacterDefining = TreeBasedTable.create(); private final NavigableMap clonedStates = Maps.newTreeMap(); private final NavigableMap textChangeStates = Maps.newTreeMap(); @@ -152,6 +153,7 @@ public class Card extends GameEntity implements Comparable, 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 keywordsGrantedByTextChanges = Lists.newArrayList(); @@ -1467,7 +1469,7 @@ public class Card extends GameEntity implements Comparable, 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, 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, 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 getChangedCardTypes() { return Iterables.unmodifiableIterable(Iterables.concat(changedCardTypesCharacterDefining.values(), changedCardTypes.values())); } - public Map getChangedCardTypesMap() { - return Collections.unmodifiableMap(changedCardTypes); + public Table getChangedCardTypesTable() { + return Tables.unmodifiableTable(changedCardTypes); } - public Map getChangedCardTypesCharacterDefiningMap() { - return Collections.unmodifiableMap(changedCardTypesCharacterDefining); + public Table getChangedCardTypesCharacterDefiningTable() { + return Tables.unmodifiableTable(changedCardTypesCharacterDefining); } public boolean clearChangedCardTypes() { @@ -3601,10 +3612,10 @@ public class Card extends GameEntity implements Comparable, IHasSVars { return changedCardKeywords; } - public Map getChangedCardColorsMap() { + public Table getChangedCardColorsTable() { return changedCardColors; } - public Map getChangedCardColorsCharacterDefiningMap() { + public Table getChangedCardColorsCharacterDefiningTable() { return changedCardColorsCharacterDefining; } public Iterable getChangedCardColors() { @@ -3615,8 +3626,8 @@ public class Card extends GameEntity implements Comparable, 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, 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, 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, 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, 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, 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, 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, IHasSVars { } } - public void setChangedCardTypes(Map changedCardTypes) { + public void setChangedCardTypes(Table changedCardTypes) { this.changedCardTypes.clear(); - for (Entry entry : changedCardTypes.entrySet()) { - this.changedCardTypes.put(entry.getKey(), entry.getValue()); + for (Table.Cell entry : changedCardTypes.cellSet()) { + this.changedCardTypes.put(entry.getRowKey(), entry.getColumnKey(), entry.getValue()); } } - public void setChangedCardTypesCharacterDefining(Map changedCardTypes) { + public void setChangedCardTypesCharacterDefining(Table changedCardTypes) { this.changedCardTypesCharacterDefining.clear(); - for (Entry entry : changedCardTypes.entrySet()) { - this.changedCardTypesCharacterDefining.put(entry.getKey(), entry.getValue()); + for (Table.Cell entry : changedCardTypes.cellSet()) { + this.changedCardTypesCharacterDefining.put(entry.getRowKey(), entry.getColumnKey(), entry.getValue()); } } @@ -6637,16 +6649,16 @@ public class Card extends GameEntity implements Comparable, IHasSVars { } } - public void setChangedCardColors(Map changedCardColors) { + public void setChangedCardColors(Table changedCardColors) { this.changedCardColors.clear(); - for (Entry entry : changedCardColors.entrySet()) { - this.changedCardColors.put(entry.getKey(), entry.getValue()); + for (Table.Cell entry : changedCardColors.cellSet()) { + this.changedCardColors.put(entry.getRowKey(), entry.getColumnKey(), entry.getValue()); } } - public void setChangedCardColorsCharacterDefining(Map changedCardColors) { + public void setChangedCardColorsCharacterDefining(Table changedCardColors) { this.changedCardColorsCharacterDefining.clear(); - for (Entry entry : changedCardColors.entrySet()) { - this.changedCardColorsCharacterDefining.put(entry.getKey(), entry.getValue()); + for (Table.Cell entry : changedCardColors.cellSet()) { + this.changedCardColorsCharacterDefining.put(entry.getRowKey(), entry.getColumnKey(), entry.getValue()); } } diff --git a/forge-game/src/main/java/forge/game/card/CardFactory.java b/forge-game/src/main/java/forge/game/card/CardFactory.java index a677a19c483..fad49fbdbc4 100644 --- a/forge-game/src/main/java/forge/game/card/CardFactory.java +++ b/forge-game/src/main/java/forge/game/card/CardFactory.java @@ -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(); diff --git a/forge-game/src/main/java/forge/game/card/CardUtil.java b/forge-game/src/main/java/forge/game/card/CardUtil.java index 9447ce99f0b..d5b2df735df 100644 --- a/forge-game/src/main/java/forge/game/card/CardUtil.java +++ b/forge-game/src/main/java/forge/game/card/CardUtil.java @@ -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()); diff --git a/forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java b/forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java index 6326e9c5374..febfa8a3918 100644 --- a/forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java +++ b/forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java @@ -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) {