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

Merged
merged 3 commits into from
Nov 25, 2024
Merged
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
68 changes: 18 additions & 50 deletions forge-game/src/main/java/forge/game/card/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -989,15 +989,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 @@ -4153,14 +4144,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 @@ -4178,19 +4162,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 @@ -4250,12 +4227,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 @@ -7777,31 +7748,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 @@ -8276,4 +8229,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