Stored kw idx (#3089)

* Card: Static Ability Keywords now use idx
This commit is contained in:
Hans Mackowiak
2023-05-10 11:31:01 +02:00
committed by GitHub
parent dbf8be8372
commit 5ed76b8171
3 changed files with 28 additions and 17 deletions

View File

@@ -73,6 +73,7 @@ import io.sentry.Sentry;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import java.util.*;
import java.util.Map.Entry;
@@ -140,7 +141,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
private final Table<Long, Long, KeywordsChange> changedCardKeywords = TreeBasedTable.create(); // Layer 6
// stores the keywords created by static abilities
private final Table<Long, String, KeywordInterface> storedKeywords = TreeBasedTable.create();
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
@@ -4638,8 +4639,10 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
final boolean removeAllKeywords, final long timestamp, final long staticId, final boolean updateView) {
List<KeywordInterface> kws = Lists.newArrayList();
if (keywords != null) {
long idx = 1;
for (String kw : keywords) {
kws.add(getKeywordForStaticAbility(kw, staticId));
kws.add(getKeywordForStaticAbility(kw, staticId, idx));
idx++;
}
}
@@ -4653,45 +4656,46 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
}
}
public final KeywordInterface getKeywordForStaticAbility(String kw, final long staticId) {
public final KeywordInterface getKeywordForStaticAbility(String kw, final long staticId, final long idx) {
KeywordInterface result;
if (staticId < 1 || !storedKeywords.contains(staticId, kw)) {
Triple<String, Long, Long> triple = Triple.of(kw, staticId, idx);
if (staticId < 1 || !storedKeywords.containsKey(triple)) {
result = Keyword.getInstance(kw);
result.setStaticId(staticId);
result.createTraits(this, false);
if (staticId > 0) {
storedKeywords.put(staticId, kw, result);
storedKeywords.put(triple, result);
}
} else {
result = storedKeywords.get(staticId, kw);
result = storedKeywords.get(triple);
}
return result;
}
public final void addKeywordForStaticAbility(KeywordInterface kw) {
if (kw.getStaticId() > 0) {
storedKeywords.put(kw.getStaticId(), kw.getOriginal(), kw);
storedKeywords.put(Triple.of(kw.getOriginal(), kw.getStaticId(), 0l), kw);
}
}
public Table<Long, String, KeywordInterface> getStoredKeywords() {
public Map<Triple<String, Long, Long>, KeywordInterface> getStoredKeywords() {
return storedKeywords;
}
public void setStoredKeywords(Table<Long, String, KeywordInterface> table, boolean lki) {
public void setStoredKeywords(Map<Triple<String, Long, Long>, KeywordInterface> map, boolean lki) {
storedKeywords.clear();
for (Table.Cell<Long, String, KeywordInterface> c : table.cellSet()) {
storedKeywords.put(c.getRowKey(), c.getColumnKey(), getCopyForStoredKeyword(c, lki));
for (Map.Entry<Triple<String, Long, Long>, KeywordInterface> e : map.entrySet()) {
storedKeywords.put(e.getKey(), getCopyForStoredKeyword(e, lki));
}
}
private final KeywordInterface getCopyForStoredKeyword(Table.Cell<Long, String, KeywordInterface> c, boolean lki) {
private final KeywordInterface getCopyForStoredKeyword(Map.Entry<Triple<String, Long, Long>, KeywordInterface> e, boolean lki) {
// for performance check if we already copied this
if (lki) {
for (KeywordsChange kc : changedCardKeywords.column(c.getRowKey()).values()) {
for (KeywordsChange kc : changedCardKeywords.column(e.getKey().getMiddle()).values()) {
// same static id
for (KeywordInterface kw : kc.getKeywords()) {
if (kw.getOriginal().equals(c.getValue().getOriginal())) {
if (kw.getOriginal().equals(e.getValue().getOriginal())) {
// same kw
return kw;
}
@@ -4699,7 +4703,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
}
}
return c.getValue().copy(this, lki);
return e.getValue().copy(this, lki);
}
public final void addChangedCardKeywordsByText(final List<KeywordInterface> keywords, final long timestamp, final long staticId, final boolean updateView) {

View File

@@ -3,6 +3,6 @@ ManaCost:2 U B R
Types:Legendary Creature Astartes Warrior
PT:5/5
K:Trample
S:Mode$ Continuous | EffectZone$ Battlefield | Condition$ PlayerTurn | Affected$ Card.YouCtrl+YouOwn+wasCastFromHand+cmcLEX | AffectedZone$ Stack | AddKeyword$ Cascade | Description$ Mark of Chaos Ascendant — During your turn, spells you cast from your hand with mana value X or less have cascade, where X is the total amount of life your opponents have lost this turn.
S:Mode$ Continuous | Condition$ PlayerTurn | Affected$ Card.YouCtrl+YouOwn+wasCastFromHand+cmcLEX | AffectedZone$ Stack | AddKeyword$ Cascade | Description$ Mark of Chaos Ascendant — During your turn, spells you cast from your hand with mana value X or less have cascade, where X is the total amount of life your opponents have lost this turn.
SVar:X:Count$LifeOppsLostThisTurn
Oracle:Trample\nMark of Chaos Ascendant — During your turn, spells you cast from your hand with mana value X or less have cascade, where X is the total amount of life your opponents have lost this turn.

View File

@@ -0,0 +1,7 @@
Name:Zhulodok, Void Gorger
ManaCost:5 C
Types:Legendary Creature Eldrazi
PT:7/4
S:Mode$ Continuous | Affected$ Card.Colorless+YouCtrl+YouOwn+wasCastFromHand+cmcGE7 | AffectedZone$ Stack | AddKeyword$ Cascade & Cascade | Description$ Spells you cast with mana value 6 or greater have cascade.
DeckHints:Type$Eldrazi|Construct|Golem
Oracle:Colorless spells you cast from your hand with mana value 7 or greater have “Cascade, cascade.” (When you cast one, exile cards from the top of your library until you exile a nonland card that costs less. You may cast it without paying its mana cost. Put the exiled cards on the bottom of your library in a random order. Then do it again.)