Skip to content

Commit 60bb4f3

Browse files
authored
Card: Combine Card type Changes by text (Card-Forge#9577)
* Card: separate TypeChange by Text --------- Co-authored-by: tool4EvEr <tool4EvEr@>
1 parent 9297654 commit 60bb4f3

File tree

7 files changed

+43
-44
lines changed

7 files changed

+43
-44
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package forge.card;
2+
3+
public record StateChangedType(CardTypeView type) implements ICardChangedType {
4+
5+
@Override
6+
public CardType applyChanges(CardType newType) {
7+
return new CardType(type);
8+
}
9+
}

forge-core/src/main/java/forge/card/TextChangedType.java

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package forge.card;
2+
3+
public record WordChangedType(String oldWord, String newWord) implements ICardChangedType {
4+
5+
@Override
6+
public CardType applyChanges(CardType newType) {
7+
if (newType.hasStringType(oldWord)) {
8+
newType.subtypes.remove(oldWord);
9+
newType.subtypes.add(newWord);
10+
}
11+
return newType;
12+
}
13+
}

forge-game/src/main/java/forge/game/GameAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,7 @@ public boolean visit(final Card c) {
12341234
if (affectedPerLayer.containsKey(StaticAbilityLayer.TEXT)) {
12351235
affectedPerLayer.get(StaticAbilityLayer.TEXT).forEach(Card::updateNameforView);
12361236
affectedKeywords.addAll(affectedPerLayer.get(StaticAbilityLayer.TEXT));
1237+
affectedPT.addAll(affectedPerLayer.get(StaticAbilityLayer.TEXT));
12371238
}
12381239
if (affectedPerLayer.containsKey(StaticAbilityLayer.TYPE)) {
12391240
affectedPerLayer.get(StaticAbilityLayer.TYPE).forEach(Card::updateTypesForView);

forge-game/src/main/java/forge/game/card/Card.java

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
120120

121121
// changes by AF animate and continuous static effects
122122

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

41554152
public boolean clearChangedCardTypes() {
41564153
boolean changed = false;
41574154

4158-
if (changedTypeByText != null)
4159-
changed = true;
4160-
changedTypeByText = null;
4161-
41624155
if (!changedCardTypesByText.isEmpty())
41634156
changed = true;
41644157
changedCardTypesByText.clear();
@@ -4210,18 +4203,16 @@ public void setChangedCardKeywords(Table<Long, Long, KeywordsChange> changedCard
42104203
}
42114204
}
42124205

4213-
public final void addChangedCardTypesByText(final CardType addType, final long timestamp, final long staticId) {
4214-
changedCardTypesByText.put(timestamp, staticId, new CardChangedType(addType, null, false,
4215-
EnumSet.of(RemoveType.SuperTypes, RemoveType.CardTypes, RemoveType.SubTypes)));
4216-
4217-
// setting card type via text, does overwrite any other word change effects?
4218-
this.changedTextColors.addEmpty(timestamp, staticId);
4219-
this.changedTextTypes.addEmpty(timestamp, staticId);
4220-
4221-
this.updateChangedText();
4206+
public final void addChangedCardTypesByText(final CardTypeView addType, final long timestamp, final long staticId) {
4207+
changedCardTypesByText.put(timestamp, staticId, new StateChangedType(addType));
4208+
updateTypeCache();
42224209
}
42234210
public final boolean removeChangedCardTypesByText(final long timestamp, final long staticId) {
4224-
return changedCardTypesByText.remove(timestamp, staticId) != null;
4211+
boolean removed = changedCardTypesByText.remove(timestamp, staticId) != null;
4212+
if (removed) {
4213+
updateTypeCache();
4214+
}
4215+
return removed;
42254216
}
42264217

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

44734464
public final void addNewPTByText(final Integer power, final Integer toughness, final long timestamp, final long staticId) {
44744465
newPTText.put(timestamp, staticId, Pair.of(power, toughness));
4475-
updatePTforView();
44764466
}
44774467
public final boolean removeNewPTbyText(final long timestamp, final long staticId) {
44784468
return newPTText.remove(timestamp, staticId) != null;
@@ -4993,7 +4983,11 @@ public final void addChangedCardTraitsByText(Collection<SpellAbility> spells,
49934983
changedCardTraitsByText.put(timestamp, staticId, new CardTraitChanges(
49944984
spells, null, trigger, replacements, statics, true, false
49954985
));
4996-
updateAbilityTextForView();
4986+
4987+
// setting card traits via text, does overwrite any other word change effects?
4988+
this.changedTextColors.addEmpty(timestamp, staticId);
4989+
this.changedTextTypes.addEmpty(timestamp, staticId);
4990+
updateChangedText();
49974991
}
49984992

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

55425537
public final void removeChangedTextTypeWord(final Long timestamp, final long staticId) {
5538+
if (changedCardTypesByText.remove(timestamp, staticId) != null) {
5539+
updateTypeCache();
5540+
}
55435541
if (changedTextTypes.remove(timestamp, staticId)) {
55445542
updateChangedText();
55455543
}
@@ -5549,8 +5547,6 @@ public final void removeChangedTextTypeWord(final Long timestamp, final long sta
55495547
* Update the changed text of the intrinsic spell abilities and keywords.
55505548
*/
55515549
public void updateChangedText() {
5552-
this.changedTypeByText = new TextChangedType(this.changedTextTypes);
5553-
55545550
currentState.updateChangedText();
55555551

55565552
// update changed text in the layer, for Volrath's Shapeshifter

forge-game/src/main/java/forge/game/card/CardCopyService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ public Card getLKICopy(Map<Integer, Card> cachedMap) {
358358
newCopy.setStoredReplacements(copyFrom.getStoredReplacements());
359359

360360
newCopy.copyChangedTextFrom(copyFrom);
361-
newCopy.changedTypeByText = copyFrom.changedTypeByText;
362361
newCopy.changedCardKeywordsByWord = copyFrom.changedCardKeywordsByWord.copy(newCopy, true);
363362

364363
newCopy.setGameTimestamp(copyFrom.getGameTimestamp());

forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,10 @@ public static CardCollectionView applyContinuousAbility(final StaticAbility stAb
624624
// color
625625
affectedCard.addColorByText(state.getColor(), false, se.getTimestamp(), stAb);
626626
// type
627-
affectedCard.addChangedCardTypesByText(new CardType(state.getType()), se.getTimestamp(), stAb.getId());
627+
affectedCard.addChangedCardTypesByText(state.getType(), se.getTimestamp(), stAb.getId());
628628
// abilities
629629
affectedCard.addChangedCardTraitsByText(spellAbilities, trigger, replacementEffects, staticAbilities, se.getTimestamp(), stAb.getId());
630630
affectedCard.addChangedCardKeywordsByText(keywords, se.getTimestamp(), stAb.getId(), false);
631-
632631
// power and toughness
633632
affectedCard.addNewPTByText(state.getBasePower(), state.getBaseToughness(), se.getTimestamp(), stAb.getId());
634633
}

0 commit comments

Comments
 (0)