Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Card: copy getChangedCardTypes #6580

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions forge-ai/src/main/java/forge/ai/simulation/GameCopier.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,7 @@ private void addCard(Game newGame, ZoneType zone, Card c, Player aiPlayer) {
newCard.setDamage(c.getDamage());
newCard.setDamageReceivedThisTurn(c.getDamageReceivedThisTurn());

newCard.setChangedCardColors(c.getChangedCardColorsTable());
newCard.setChangedCardColorsCharacterDefining(c.getChangedCardColorsCharacterDefiningTable());

newCard.setChangedCardTypes(c.getChangedCardTypesTable());
newCard.setChangedCardTypesCharacterDefining(c.getChangedCardTypesCharacterDefiningTable());
newCard.setChangedCardKeywords(c.getChangedCardKeywords());
newCard.setChangedCardNames(c.getChangedCardNames());
newCard.copyFrom(c);

for (Table.Cell<Long, Long, List<String>> kw : c.getHiddenExtrinsicKeywordsTable().cellSet()) {
newCard.addHiddenExtrinsicKeywords(kw.getRowKey(), kw.getColumnKey(), kw.getValue());
Expand Down
130 changes: 49 additions & 81 deletions forge-game/src/main/java/forge/game/card/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
private CardDamageHistory damageHistory = new CardDamageHistory();
// Hidden keywords won't be displayed on the card
// x=timestamp y=StaticAbility id
private final Table<Long, Long, List<String>> hiddenExtrinsicKeywords = TreeBasedTable.create();
private final Table<Long, Long, List<String>> hiddenExtrinsicKeywords = Tables.synchronizedTable(TreeBasedTable.create());

// cards attached or otherwise linked to this card
private CardCollection hauntedBy, devouredCards, exploitedCards, delvedCards, imprintedCards,
Expand Down Expand Up @@ -120,46 +120,46 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr

protected CardChangedType changedTypeByText; // Layer 3 by Text Change
// x=timestamp y=StaticAbility id
private final Table<Long, Long, CardChangedType> changedCardTypesByText = TreeBasedTable.create(); // Layer 3
private final Table<Long, Long, CardChangedType> changedCardTypesCharacterDefining = TreeBasedTable.create(); // Layer 4 CDA
private final Table<Long, Long, CardChangedType> changedCardTypes = TreeBasedTable.create(); // Layer 4
private final Table<Long, Long, CardChangedType> changedCardTypesByText = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 3
private final Table<Long, Long, CardChangedType> changedCardTypesCharacterDefining = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 4 CDA
private final Table<Long, Long, CardChangedType> changedCardTypes = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 4

private final Table<Long, Long, CardChangedName> changedCardNames = TreeBasedTable.create(); // Layer 3
private final Table<Long, Long, KeywordsChange> changedCardKeywordsByText = TreeBasedTable.create(); // Layer 3 by Text Change
private final Table<Long, Long, CardChangedName> changedCardNames = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 3
private final Table<Long, Long, KeywordsChange> changedCardKeywordsByText = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 3 by Text Change
protected KeywordsChange changedCardKeywordsByWord = new KeywordsChange(ImmutableList.<KeywordInterface>of(), ImmutableList.<KeywordInterface>of(), false); // Layer 3 by Word Change
private final Table<Long, Long, KeywordsChange> changedCardKeywords = TreeBasedTable.create(); // Layer 6
private final Table<Long, Long, KeywordsChange> changedCardKeywords = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 6

// stores the keywords created by static abilities
private final Map<Triple<String, Long, Long>, KeywordInterface> storedKeywords = Maps.newHashMap();

// x=timestamp y=StaticAbility id
private final Table<Long, Long, CardTraitChanges> changedCardTraitsByText = TreeBasedTable.create(); // Layer 3 by Text Change
private final Table<Long, Long, CardTraitChanges> changedCardTraits = TreeBasedTable.create(); // Layer 6
private final Table<Long, Long, CardTraitChanges> changedCardTraitsByText = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 3 by Text Change
private final Table<Long, Long, CardTraitChanges> changedCardTraits = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 6

// stores the card traits created by static abilities
private final Table<StaticAbility, String, SpellAbility> storedSpellAbility = TreeBasedTable.create();
private final Table<StaticAbility, String, Trigger> storedTrigger = TreeBasedTable.create();
private final Table<StaticAbility, String, ReplacementEffect> storedReplacementEffect = TreeBasedTable.create();
private final Table<StaticAbility, String, StaticAbility> storedStaticAbility = TreeBasedTable.create();
private final Table<StaticAbility, String, SpellAbility> storedSpellAbility = Tables.synchronizedTable(TreeBasedTable.create());
private final Table<StaticAbility, String, Trigger> storedTrigger = Tables.synchronizedTable(TreeBasedTable.create());
private final Table<StaticAbility, String, ReplacementEffect> storedReplacementEffect = Tables.synchronizedTable(TreeBasedTable.create());
private final Table<StaticAbility, String, StaticAbility> storedStaticAbility = Tables.synchronizedTable(TreeBasedTable.create());

private final Table<StaticAbility, SpellAbility, SpellAbility> storedSpellAbililityByText = HashBasedTable.create();
private final Table<StaticAbility, String, SpellAbility> storedSpellAbililityGainedByText = TreeBasedTable.create();
private final Table<StaticAbility, Trigger, Trigger> storedTriggerByText = HashBasedTable.create();
private final Table<StaticAbility, ReplacementEffect, ReplacementEffect> storedReplacementEffectByText = HashBasedTable.create();
private final Table<StaticAbility, StaticAbility, StaticAbility> storedStaticAbilityByText = HashBasedTable.create();
private final Table<StaticAbility, SpellAbility, SpellAbility> storedSpellAbililityByText = Tables.synchronizedTable(HashBasedTable.create());
private final Table<StaticAbility, String, SpellAbility> storedSpellAbililityGainedByText = Tables.synchronizedTable(TreeBasedTable.create());
private final Table<StaticAbility, Trigger, Trigger> storedTriggerByText = Tables.synchronizedTable(HashBasedTable.create());
private final Table<StaticAbility, ReplacementEffect, ReplacementEffect> storedReplacementEffectByText = Tables.synchronizedTable(HashBasedTable.create());
private final Table<StaticAbility, StaticAbility, StaticAbility> storedStaticAbilityByText = Tables.synchronizedTable(HashBasedTable.create());

private final Map<Triple<String, Long, Long>, KeywordInterface> storedKeywordByText = Maps.newHashMap();

// x=timestamp y=StaticAbility id
private final Table<Long, Long, CardColor> changedCardColorsByText = TreeBasedTable.create(); // Layer 3 by Text Change
private final Table<Long, Long, CardColor> changedCardColorsCharacterDefining = TreeBasedTable.create(); // Layer 5 CDA
private final Table<Long, Long, CardColor> changedCardColors = TreeBasedTable.create(); // Layer 5
private final Table<Long, Long, CardColor> changedCardColorsByText = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 3 by Text Change
private final Table<Long, Long, CardColor> changedCardColorsCharacterDefining = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 5 CDA
private final Table<Long, Long, CardColor> changedCardColors = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 5

protected final Table<Long, Long, ManaCost> changedCardManaCost = TreeBasedTable.create(); // Layer 3
protected final Table<Long, Long, ManaCost> changedCardManaCost = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 3

private final NavigableMap<Long, CardCloneStates> clonedStates = Maps.newTreeMap(); // Layer 1

private final Table<Long, Long, Map<String, String>> changedSVars = TreeBasedTable.create();
private final Table<Long, Long, Map<String, String>> changedSVars = Tables.synchronizedTable(TreeBasedTable.create());

private final Map<Long, PlayerCollection> mayLook = Maps.newHashMap();
private final PlayerCollection mayLookFaceDownExile = new PlayerCollection();
Expand Down Expand Up @@ -262,10 +262,10 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr

// stack of set power/toughness
// x=timestamp y=StaticAbility id
private Table<Long, Long, Pair<Integer,Integer>> newPTText = TreeBasedTable.create(); // Text Change Layer 3
private Table<Long, Long, Pair<Integer,Integer>> newPTCharacterDefining = TreeBasedTable.create(); // Layer 7a
private Table<Long, Long, Pair<Integer,Integer>> newPT = TreeBasedTable.create(); // Layer 7b
private Table<Long, Long, Pair<Integer,Integer>> boostPT = TreeBasedTable.create(); // Layer 7c
private Table<Long, Long, Pair<Integer,Integer>> newPTText = Tables.synchronizedTable(TreeBasedTable.create()); // Text Change Layer 3
private Table<Long, Long, Pair<Integer,Integer>> newPTCharacterDefining = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 7a
private Table<Long, Long, Pair<Integer,Integer>> newPT = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 7b
private Table<Long, Long, Pair<Integer,Integer>> boostPT = Tables.synchronizedTable(TreeBasedTable.create()); // Layer 7c

private final Map<Card, Integer> assignedDamageMap = Maps.newTreeMap();
private Map<Integer, Integer> damage = Maps.newHashMap();
Expand Down Expand Up @@ -349,10 +349,10 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
private final Map<SpellAbility, List<String>> chosenModesYourCombat = Maps.newHashMap();
private final Map<SpellAbility, List<String>> chosenModesYourLastCombat = Maps.newHashMap();

private final Table<SpellAbility, StaticAbility, List<String>> chosenModesTurnStatic = HashBasedTable.create();
private final Table<SpellAbility, StaticAbility, List<String>> chosenModesGameStatic = HashBasedTable.create();
private final Table<SpellAbility, StaticAbility, List<String>> chosenModesYourCombatStatic = HashBasedTable.create();
private final Table<SpellAbility, StaticAbility, List<String>> chosenModesYourLastCombatStatic = HashBasedTable.create();
private final Table<SpellAbility, StaticAbility, List<String>> chosenModesTurnStatic = Tables.synchronizedTable(HashBasedTable.create());
private final Table<SpellAbility, StaticAbility, List<String>> chosenModesGameStatic = Tables.synchronizedTable(HashBasedTable.create());
private final Table<SpellAbility, StaticAbility, List<String>> chosenModesYourCombatStatic = Tables.synchronizedTable(HashBasedTable.create());
private final Table<SpellAbility, StaticAbility, List<String>> chosenModesYourLastCombatStatic = Tables.synchronizedTable(HashBasedTable.create());

private CombatLki combatLKI;

Expand Down Expand Up @@ -988,15 +988,6 @@ public void updateNameforView() {
currentState.getView().updateName(currentState);
}

public Table<Long, Long, CardChangedName> getChangedCardNames() {
return changedCardNames;
}

public void setChangedCardNames(Table<Long, Long, CardChangedName> changedCardNames) {
this.changedCardNames.clear();
this.changedCardNames.putAll(changedCardNames);
}

public void setGamePieceType(GamePieceType gamePieceType) {
this.gamePieceType = gamePieceType;
this.view.updateGamePieceType(this);
Expand Down Expand Up @@ -4137,14 +4128,7 @@ public final void setCreatureTypes(Collection<String> ctypes) {
}

public final CardTypeView getType() {
return getType(currentState);
}
public final CardTypeView getType(CardState state) {
final Iterable<CardChangedType> changedCardTypes = getChangedCardTypes();
if (Iterables.isEmpty(changedCardTypes)) {
return state.getType();
}
return state.getType().getTypeWithChanges(changedCardTypes);
return currentState.getTypeWithChanges();
}

public final CardTypeView getOriginalType() {
Expand All @@ -4162,19 +4146,12 @@ public Iterable<CardChangedType> getChangedCardTypes() {
return ImmutableList.of();
}
Iterable<CardChangedType> byText = changedTypeByText == null ? ImmutableList.of() : ImmutableList.of(this.changedTypeByText);
return Iterables.unmodifiableIterable(Iterables.concat(
return ImmutableList.copyOf(Iterables.concat(
changedCardTypesByText.values(), // Layer 3
byText, // Layer 3 by Word Changes,
changedCardTypesCharacterDefining.values(), // Layer 4
changedCardTypes.values() // Layer 6
));
}

public Table<Long, Long, CardChangedType> getChangedCardTypesTable() {
return Tables.unmodifiableTable(changedCardTypes);
}
public Table<Long, Long, CardChangedType> getChangedCardTypesCharacterDefiningTable() {
return Tables.unmodifiableTable(changedCardTypesCharacterDefining);
));
}

public boolean clearChangedCardTypes() {
Expand Down Expand Up @@ -4234,12 +4211,6 @@ public Table<Long, Long, KeywordsChange> getChangedCardKeywords() {
return changedCardKeywords;
}

public Table<Long, Long, CardColor> getChangedCardColorsTable() {
return changedCardColors;
}
public Table<Long, Long, CardColor> getChangedCardColorsCharacterDefiningTable() {
return changedCardColorsCharacterDefining;
}
public Iterable<CardColor> getChangedCardColors() {
return Iterables.concat(changedCardColorsByText.values(), changedCardColorsCharacterDefining.values(), changedCardColors.values());
}
Expand Down Expand Up @@ -7761,31 +7732,13 @@ public List<KeywordInterface> getKeywords() {
}
}

public void setChangedCardTypes(Table<Long, Long, CardChangedType> changedCardTypes) {
this.changedCardTypes.clear();
this.changedCardTypes.putAll(changedCardTypes);
}
public void setChangedCardTypesCharacterDefining(Table<Long, Long, CardChangedType> changedCardTypes) {
this.changedCardTypesCharacterDefining.clear();
this.changedCardTypesCharacterDefining.putAll(changedCardTypes);
}

public void setChangedCardKeywords(Table<Long, Long, KeywordsChange> changedCardKeywords) {
this.changedCardKeywords.clear();
for (Table.Cell<Long, Long, KeywordsChange> entry : changedCardKeywords.cellSet()) {
this.changedCardKeywords.put(entry.getRowKey(), entry.getColumnKey(), entry.getValue().copy(this, true));
}
}

public void setChangedCardColors(Table<Long, Long, CardColor> changedCardColors) {
this.changedCardColors.clear();
this.changedCardColors.putAll(changedCardColors);
}
public void setChangedCardColorsCharacterDefining(Table<Long, Long, CardColor> changedCardColors) {
this.changedCardColorsCharacterDefining.clear();
this.changedCardColorsCharacterDefining.putAll(changedCardColors);
}

public void cleanupCopiedChangesFrom(Card c) {
for (StaticAbility stAb : c.getStaticAbilities()) {
this.removeChangedCardTypes(c.getLayerTimestamp(), stAb.getId(), false);
Expand Down Expand Up @@ -8260,4 +8213,19 @@ public SpellAbility getUnlockAbility(CardStateName state) {
}
return unlockAbilities.get(state);
}

public void copyFrom(Card in) {
// clean is not needed?
this.changedCardColors.putAll(in.changedCardColors);
this.changedCardColorsCharacterDefining.putAll(in.changedCardColorsCharacterDefining);

setChangedCardKeywords(in.getChangedCardKeywords());

this.changedCardTypes.putAll(in.changedCardTypes);
this.changedCardTypesCharacterDefining.putAll(in.changedCardTypesCharacterDefining);

this.changedCardNames.putAll(in.changedCardNames);
setChangedCardTraits(in.getChangedCardTraits());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,7 @@ public Card getLKICopy(Map<Integer, Card> cachedMap) {

newCopy.setUnearthed(copyFrom.isUnearthed());

newCopy.setChangedCardColors(copyFrom.getChangedCardColorsTable());
newCopy.setChangedCardColorsCharacterDefining(copyFrom.getChangedCardColorsCharacterDefiningTable());
newCopy.setChangedCardKeywords(copyFrom.getChangedCardKeywords());
newCopy.setChangedCardTypes(copyFrom.getChangedCardTypesTable());
newCopy.setChangedCardTypesCharacterDefining(copyFrom.getChangedCardTypesCharacterDefiningTable());
newCopy.setChangedCardNames(copyFrom.getChangedCardNames());
newCopy.setChangedCardTraits(copyFrom.getChangedCardTraits());
newCopy.copyFrom(copyFrom);

// for getReplacementList (run after setChangedCardKeywords for caching)
newCopy.setStoredKeywords(copyFrom.getStoredKeywords(), true);
Expand Down
Loading