mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
ReplacementHandler: found better way to Prevent StackOverflow for Riot
This commit is contained in:
@@ -20,6 +20,7 @@ package forge.game.card;
|
|||||||
import com.esotericsoftware.minlog.Log;
|
import com.esotericsoftware.minlog.Log;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.*;
|
import com.google.common.collect.*;
|
||||||
|
|
||||||
import forge.GameCommand;
|
import forge.GameCommand;
|
||||||
import forge.StaticData;
|
import forge.StaticData;
|
||||||
import forge.card.*;
|
import forge.card.*;
|
||||||
@@ -4587,6 +4588,17 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Table<Long, String, KeywordInterface> getStoredKeywords() {
|
||||||
|
return storedKeywords;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoredKeywords(Table<Long, String, KeywordInterface> table, boolean lki) {
|
||||||
|
storedKeywords.clear();
|
||||||
|
for (Table.Cell<Long, String, KeywordInterface> c : table.cellSet()) {
|
||||||
|
storedKeywords.put(c.getRowKey(), c.getColumnKey(), c.getValue().copy(this, lki));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public final void addChangedCardKeywordsByText(final List<KeywordInterface> keywords, final long timestamp, final long staticId, final boolean updateView) {
|
public final void addChangedCardKeywordsByText(final List<KeywordInterface> keywords, final long timestamp, final long staticId, final boolean updateView) {
|
||||||
// keywords should already created for Card, so no addKeywordsToCard
|
// keywords should already created for Card, so no addKeywordsToCard
|
||||||
// this one is done for Volrath's Shapeshifter which replaces all the card text
|
// this one is done for Volrath's Shapeshifter which replaces all the card text
|
||||||
|
|||||||
@@ -293,6 +293,8 @@ public final class CardUtil {
|
|||||||
newCopy.setChangedCardNames(in.getChangedCardNames());
|
newCopy.setChangedCardNames(in.getChangedCardNames());
|
||||||
newCopy.setChangedCardTraits(in.getChangedCardTraits());
|
newCopy.setChangedCardTraits(in.getChangedCardTraits());
|
||||||
|
|
||||||
|
newCopy.setStoredKeywords(in.getStoredKeywords(), true);
|
||||||
|
|
||||||
newCopy.copyChangedTextFrom(in);
|
newCopy.copyChangedTextFrom(in);
|
||||||
|
|
||||||
newCopy.setTimestamp(in.getTimestamp());
|
newCopy.setTimestamp(in.getTimestamp());
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.common.collect.Table;
|
|
||||||
|
|
||||||
import forge.game.CardTraitBase;
|
import forge.game.CardTraitBase;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
@@ -48,10 +47,7 @@ import forge.game.card.CardCollection;
|
|||||||
import forge.game.card.CardCollectionView;
|
import forge.game.card.CardCollectionView;
|
||||||
import forge.game.card.CardDamageMap;
|
import forge.game.card.CardDamageMap;
|
||||||
import forge.game.card.CardState;
|
import forge.game.card.CardState;
|
||||||
import forge.game.card.CardTraitChanges;
|
|
||||||
import forge.game.card.CardUtil;
|
import forge.game.card.CardUtil;
|
||||||
import forge.game.keyword.KeywordInterface;
|
|
||||||
import forge.game.keyword.KeywordsChange;
|
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.player.PlayerCollection;
|
import forge.game.player.PlayerCollection;
|
||||||
import forge.game.spellability.AbilitySub;
|
import forge.game.spellability.AbilitySub;
|
||||||
@@ -110,53 +106,6 @@ public class ReplacementHandler {
|
|||||||
game.getAction().checkStaticAbilities(false, Sets.newHashSet(affectedLKI), preList);
|
game.getAction().checkStaticAbilities(false, Sets.newHashSet(affectedLKI), preList);
|
||||||
checkAgain = true;
|
checkAgain = true;
|
||||||
|
|
||||||
// need to check if Intrinsic has run
|
|
||||||
for (ReplacementEffect re : affectedLKI.getReplacementEffects()) {
|
|
||||||
if (re.isIntrinsic() && this.hasRun.contains(re)) {
|
|
||||||
re.setHasRun(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// need to check non Intrinsic
|
|
||||||
for (Table.Cell<Long, Long, CardTraitChanges> e : affectedLKI.getChangedCardTraits().cellSet()) {
|
|
||||||
boolean hasRunRE = false;
|
|
||||||
String skey = String.valueOf(e.getRowKey()) + ":" + String.valueOf(e.getColumnKey());
|
|
||||||
|
|
||||||
for (ReplacementEffect re : this.hasRun) {
|
|
||||||
if (!re.isIntrinsic() && skey.equals(re.getSVar("_ReplacedTimestamp"))) {
|
|
||||||
hasRunRE = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ReplacementEffect re : e.getValue().getReplacements()) {
|
|
||||||
re.setSVar("_ReplacedTimestamp", skey);
|
|
||||||
if (hasRunRE) {
|
|
||||||
re.setHasRun(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Table.Cell<Long, Long, KeywordsChange> e : affectedLKI.getChangedCardKeywords().cellSet()) {
|
|
||||||
boolean hasRunRE = false;
|
|
||||||
String skey = String.valueOf(e.getRowKey()) + ":" + String.valueOf(e.getColumnKey());
|
|
||||||
|
|
||||||
for (ReplacementEffect re : this.hasRun) {
|
|
||||||
if (!re.isIntrinsic() && skey.equals(re.getSVar("_ReplacedTimestamp"))) {
|
|
||||||
hasRunRE = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (KeywordInterface k : e.getValue().getKeywords()) {
|
|
||||||
for (ReplacementEffect re : k.getReplacements()) {
|
|
||||||
re.setSVar("_ReplacedTimestamp", skey);
|
|
||||||
if (hasRunRE) {
|
|
||||||
re.setHasRun(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
runParams.put(AbilityKey.Affected, affectedLKI);
|
runParams.put(AbilityKey.Affected, affectedLKI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,6 +171,8 @@ public class ReplacementHandler {
|
|||||||
for (final ReplacementEffect re : affectedLKI.getReplacementEffects()) {
|
for (final ReplacementEffect re : affectedLKI.getReplacementEffects()) {
|
||||||
re.setHostCard(affectedCard);
|
re.setHostCard(affectedCard);
|
||||||
}
|
}
|
||||||
|
// need to copy stored keywords from lki into real object to prevent the replacement effect from making new ones
|
||||||
|
affectedCard.setStoredKeywords(affectedLKI.getStoredKeywords(), true);
|
||||||
runParams.put(AbilityKey.Affected, affectedCard);
|
runParams.put(AbilityKey.Affected, affectedCard);
|
||||||
runParams.put(AbilityKey.NewCard, CardUtil.getLKICopy(affectedLKI));
|
runParams.put(AbilityKey.NewCard, CardUtil.getLKICopy(affectedLKI));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user