Skip to content
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
9 changes: 9 additions & 0 deletions forge-core/src/main/java/forge/card/StateChangedType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package forge.card;

public record StateChangedType(CardTypeView type) implements ICardChangedType {

@Override
public CardType applyChanges(CardType newType) {
return new CardType(type);
}
}
18 changes: 0 additions & 18 deletions forge-core/src/main/java/forge/card/TextChangedType.java

This file was deleted.

13 changes: 13 additions & 0 deletions forge-core/src/main/java/forge/card/WordChangedType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package forge.card;

public record WordChangedType(String oldWord, String newWord) implements ICardChangedType {

@Override
public CardType applyChanges(CardType newType) {
if (newType.hasStringType(oldWord)) {
newType.subtypes.remove(oldWord);
newType.subtypes.add(newWord);
}
return newType;
}
}
1 change: 1 addition & 0 deletions forge-game/src/main/java/forge/game/GameAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,7 @@ public boolean visit(final Card c) {
if (affectedPerLayer.containsKey(StaticAbilityLayer.TEXT)) {
affectedPerLayer.get(StaticAbilityLayer.TEXT).forEach(Card::updateNameforView);
affectedKeywords.addAll(affectedPerLayer.get(StaticAbilityLayer.TEXT));
affectedPT.addAll(affectedPerLayer.get(StaticAbilityLayer.TEXT));
}
if (affectedPerLayer.containsKey(StaticAbilityLayer.TYPE)) {
affectedPerLayer.get(StaticAbilityLayer.TYPE).forEach(Card::updateTypesForView);
Expand Down
42 changes: 19 additions & 23 deletions forge-game/src/main/java/forge/game/card/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr

// changes by AF animate and continuous static effects

protected ICardChangedType changedTypeByText; // Layer 3 by Text Change
// x=timestamp y=StaticAbility id
private final Table<Long, Long, ICardChangedType> changedCardTypesByText = TreeBasedTable.create(); // Layer 3
private final Table<Long, Long, ICardChangedType> changedCardTypesCharacterDefining = TreeBasedTable.create(); // Layer 4 CDA
Expand Down Expand Up @@ -4140,25 +4139,19 @@ public Iterable<ICardChangedType> getChangedCardTypes() {
// If there are no changed types, just return an empty immutable list, which actually
// produces a surprisingly large speedup by avoid lots of temp objects and making iteration
// over the result much faster. (This function gets called a lot!)
if (changedCardTypesByText.isEmpty() && changedTypeByText == null && changedCardTypesCharacterDefining.isEmpty() && changedCardTypes.isEmpty()) {
if (changedCardTypesByText.isEmpty() && changedCardTypesCharacterDefining.isEmpty() && changedCardTypes.isEmpty()) {
return ImmutableList.of();
}
Iterable<ICardChangedType> byText = changedTypeByText == null ? ImmutableList.of() : ImmutableList.of(this.changedTypeByText);
return ImmutableList.copyOf(Iterables.concat(
changedCardTypesByText.values(), // Layer 3
byText, // Layer 3 by Word Changes,
changedCardTypesCharacterDefining.values(), // Layer 4
changedCardTypes.values() // Layer 6
changedCardTypes.values() // Layer 4
));
}

public boolean clearChangedCardTypes() {
boolean changed = false;

if (changedTypeByText != null)
changed = true;
changedTypeByText = null;

if (!changedCardTypesByText.isEmpty())
changed = true;
changedCardTypesByText.clear();
Expand Down Expand Up @@ -4210,18 +4203,16 @@ public void setChangedCardKeywords(Table<Long, Long, KeywordsChange> changedCard
}
}

public final void addChangedCardTypesByText(final CardType addType, final long timestamp, final long staticId) {
changedCardTypesByText.put(timestamp, staticId, new CardChangedType(addType, null, false,
EnumSet.of(RemoveType.SuperTypes, RemoveType.CardTypes, RemoveType.SubTypes)));

// setting card type via text, does overwrite any other word change effects?
this.changedTextColors.addEmpty(timestamp, staticId);
this.changedTextTypes.addEmpty(timestamp, staticId);

this.updateChangedText();
public final void addChangedCardTypesByText(final CardTypeView addType, final long timestamp, final long staticId) {
changedCardTypesByText.put(timestamp, staticId, new StateChangedType(addType));
updateTypeCache();
}
public final boolean removeChangedCardTypesByText(final long timestamp, final long staticId) {
return changedCardTypesByText.remove(timestamp, staticId) != null;
boolean removed = changedCardTypesByText.remove(timestamp, staticId) != null;
if (removed) {
updateTypeCache();
}
return removed;
}

public final void addChangedCardTypes(final CardType addType, final CardType removeType, final boolean addAllCreatureTypes,
Expand Down Expand Up @@ -4472,7 +4463,6 @@ public final void setPTCharacterDefiningTable(Table<Long, Long, Pair<Integer, In

public final void addNewPTByText(final Integer power, final Integer toughness, final long timestamp, final long staticId) {
newPTText.put(timestamp, staticId, Pair.of(power, toughness));
updatePTforView();
}
public final boolean removeNewPTbyText(final long timestamp, final long staticId) {
return newPTText.remove(timestamp, staticId) != null;
Expand Down Expand Up @@ -4993,7 +4983,11 @@ public final void addChangedCardTraitsByText(Collection<SpellAbility> spells,
changedCardTraitsByText.put(timestamp, staticId, new CardTraitChanges(
spells, null, trigger, replacements, statics, true, false
));
updateAbilityTextForView();

// setting card traits via text, does overwrite any other word change effects?
this.changedTextColors.addEmpty(timestamp, staticId);
this.changedTextTypes.addEmpty(timestamp, staticId);
updateChangedText();
}

public final CardTraitChanges addChangedCardTraits(Collection<SpellAbility> spells, Collection<SpellAbility> removedAbilities,
Expand Down Expand Up @@ -5536,10 +5530,14 @@ public final void removeChangedTextColorWord(final Long timestamp, final long st
*/
public final void addChangedTextTypeWord(final String originalWord, final String newWord, final Long timestamp, final long staticId) {
changedTextTypes.add(timestamp, staticId, originalWord, newWord);
changedCardTypesByText.put(timestamp, staticId, new WordChangedType(originalWord, newWord));
updateChangedText();
}

public final void removeChangedTextTypeWord(final Long timestamp, final long staticId) {
if (changedCardTypesByText.remove(timestamp, staticId) != null) {
updateTypeCache();
}
if (changedTextTypes.remove(timestamp, staticId)) {
updateChangedText();
}
Expand All @@ -5549,8 +5547,6 @@ public final void removeChangedTextTypeWord(final Long timestamp, final long sta
* Update the changed text of the intrinsic spell abilities and keywords.
*/
public void updateChangedText() {
this.changedTypeByText = new TextChangedType(this.changedTextTypes);

currentState.updateChangedText();

// update changed text in the layer, for Volrath's Shapeshifter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ public Card getLKICopy(Map<Integer, Card> cachedMap) {
newCopy.setStoredReplacements(copyFrom.getStoredReplacements());

newCopy.copyChangedTextFrom(copyFrom);
newCopy.changedTypeByText = copyFrom.changedTypeByText;
newCopy.changedCardKeywordsByWord = copyFrom.changedCardKeywordsByWord.copy(newCopy, true);

newCopy.setGameTimestamp(copyFrom.getGameTimestamp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,10 @@ public static CardCollectionView applyContinuousAbility(final StaticAbility stAb
// color
affectedCard.addColorByText(state.getColor(), false, se.getTimestamp(), stAb);
// type
affectedCard.addChangedCardTypesByText(new CardType(state.getType()), se.getTimestamp(), stAb.getId());
affectedCard.addChangedCardTypesByText(state.getType(), se.getTimestamp(), stAb.getId());
// abilities
affectedCard.addChangedCardTraitsByText(spellAbilities, trigger, replacementEffects, staticAbilities, se.getTimestamp(), stAb.getId());
affectedCard.addChangedCardKeywordsByText(keywords, se.getTimestamp(), stAb.getId(), false);

// power and toughness
affectedCard.addNewPTByText(state.getBasePower(), state.getBaseToughness(), se.getTimestamp(), stAb.getId());
}
Expand Down