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
22 changes: 11 additions & 11 deletions forge-game/src/main/java/forge/game/card/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
private final Table<Long, Long, ICardChangedType> changedCardTypes = TreeBasedTable.create(); // Layer 4

private final Table<Long, Long, CardChangedName> changedCardNames = TreeBasedTable.create(); // Layer 3
private final Table<Long, Long, KeywordsChange> changedCardKeywordsByText = TreeBasedTable.create(); // Layer 3 by Text Change
private final Table<Long, Long, IKeywordsChange> changedCardKeywordsByText = TreeBasedTable.create(); // Layer 3 by Text Change
protected KeywordsChange changedCardKeywordsByWord = new KeywordsChange(ImmutableList.<KeywordInterface>of(), ImmutableList.<KeywordInterface>of(), false); // Layer 3 by Word Change
private final Table<Long, Long, KeywordsChange> changedCardKeywords = TreeBasedTable.create(); // Layer 6

Expand Down Expand Up @@ -3481,7 +3481,7 @@ public void updateSpellAbilities(List<SpellAbility> list, CardState state) {

// keywords should already been cleanup by layers
for (KeywordInterface kw : getUnhiddenKeywords(state)) {
list.addAll(kw.getAbilities());
kw.applySpellAbility(list);
}
}

Expand Down Expand Up @@ -4130,15 +4130,15 @@ public boolean clearChangedCardColors() {
return changed;
}

public Table<Long, Long, KeywordsChange> getChangedCardKeywordsByText() {
public Table<Long, Long, IKeywordsChange> getChangedCardKeywordsByText() {
return changedCardKeywordsByText;
}

public Iterable<KeywordsChange> getChangedCardKeywordsList() {
public Iterable<IKeywordsChange> getChangedCardKeywordsList(final CardState state) {
return Iterables.concat(
changedCardKeywordsByText.values(), // Layer 3
ImmutableList.of(changedCardKeywordsByWord), // Layer 3
ImmutableList.of(new KeywordsChange(ImmutableList.<KeywordInterface>of(), ImmutableList.<KeywordInterface>of(), this.hasRemoveIntrinsic())), // Layer 4
ImmutableList.of(state.getLandTraitChanges()), // Layer 4
changedCardKeywords.values() // Layer 6
);
}
Expand Down Expand Up @@ -5146,9 +5146,9 @@ public final void addChangedCardKeywordsByText(final List<KeywordInterface> keyw
}
}

public void setChangedCardKeywordsByText(Table<Long, Long, KeywordsChange> changedCardKeywords) {
public void setChangedCardKeywordsByText(Table<Long, Long, IKeywordsChange> changedCardKeywords) {
this.changedCardKeywordsByText.clear();
for (Table.Cell<Long, Long, KeywordsChange> entry : changedCardKeywords.cellSet()) {
for (Table.Cell<Long, Long, IKeywordsChange> entry : changedCardKeywords.cellSet()) {
this.changedCardKeywordsByText.put(entry.getRowKey(), entry.getColumnKey(), entry.getValue().copy(this, true));
}
}
Expand Down Expand Up @@ -5236,7 +5236,7 @@ public final void updateKeywordsCache(final CardState state) {
}
}

keywords.applyChanges(getChangedCardKeywordsList());
keywords.applyChanges(getChangedCardKeywordsList(state));

// remove Can't have keywords
for (Keyword k : getCantHaveKeyword()) {
Expand Down Expand Up @@ -7101,7 +7101,7 @@ public void updateStaticAbilities(List<StaticAbility> list, CardState state) {

// keywords are already sorted by Layer
for (KeywordInterface kw : getUnhiddenKeywords(state)) {
list.addAll(kw.getStaticAbilities());
kw.applyStaticAbility(list);
}
}

Expand Down Expand Up @@ -7140,7 +7140,7 @@ public void updateTriggers(List<Trigger> list, CardState state) {

// Keywords are already sorted by Layer
for (KeywordInterface kw : getUnhiddenKeywords(state)) {
list.addAll(kw.getTriggers());
kw.applyTrigger(list);
}
}

Expand All @@ -7160,7 +7160,7 @@ public void updateReplacementEffects(List<ReplacementEffect> list, CardState sta

// Keywords are already sorted by Layer
for (KeywordInterface kw : getUnhiddenKeywords(state)) {
list.addAll(kw.getReplacements());
kw.applyReplacementEffect(list);
}

// Shield Counter aren't affected by Changed Card Traits
Expand Down
10 changes: 8 additions & 2 deletions forge-game/src/main/java/forge/game/card/CardState.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import forge.game.ability.AbilityFactory;
import forge.game.ability.ApiType;
import forge.game.card.CardView.CardStateView;
import forge.game.keyword.IKeywordsChange;
import forge.game.keyword.Keyword;
import forge.game.keyword.KeywordCollection;
import forge.game.keyword.KeywordInterface;
Expand Down Expand Up @@ -483,7 +484,7 @@ protected final void updateSpellAbilities(FCollection<SpellAbility> newCol) {

public LandTraitChanges getLandTraitChanges() { return this.landTraitChanges; }

record LandTraitChanges(CardState state, Map<MagicColor.Color, SpellAbility> map) implements ICardTraitChanges
record LandTraitChanges(CardState state, Map<MagicColor.Color, SpellAbility> map) implements ICardTraitChanges, IKeywordsChange
{
LandTraitChanges(CardState state) {
this(state, Maps.newEnumMap(MagicColor.Color.class));
Expand Down Expand Up @@ -531,7 +532,12 @@ public List<StaticAbility> applyStaticAbility(List<StaticAbility> list) {
}
return list;
}
public ICardTraitChanges copy(Card host, boolean lki) { return this; }
public void applyKeywords(KeywordCollection list) {
if (state.getCard().hasRemoveIntrinsic()) {
list.clear();
}
}
public LandTraitChanges copy(Card host, boolean lki) { return this; }
}

public final Iterable<SpellAbility> getIntrinsicSpellAbilities() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package forge.game.keyword;

import forge.game.card.Card;

public interface IKeywordsChange {
void applyKeywords(KeywordCollection list);
public IKeywordsChange copy(final Card host, final boolean lki);
}
17 changes: 3 additions & 14 deletions forge-game/src/main/java/forge/game/keyword/KeywordCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,9 @@ public KeywordCollectionView getView() {
return view;
}

public void applyChanges(Iterable<KeywordsChange> changes) {
for (final KeywordsChange ck : changes) {
if (ck.isRemoveAllKeywords()) {
clear();
}
else if (ck.getRemoveKeywords() != null) {
removeAll(ck.getRemoveKeywords());
}

removeInstances(ck.getRemovedKeywordInstances());

if (ck.getKeywords() != null) {
insertAll(ck.getKeywords());
}
public void applyChanges(Iterable<IKeywordsChange> changes) {
for (final IKeywordsChange ck : changes) {
ck.applyKeywords(this);
}
}

Expand Down
34 changes: 32 additions & 2 deletions forge-game/src/main/java/forge/game/keyword/KeywordInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void createTraits(Player player, boolean clear) {
}
try {
String msg = "KeywordInstance:createTraits: make Traits for Keyword";

Breadcrumb bread = new Breadcrumb(msg);
bread.setData("Player", player.getName());
bread.setData("Keyword", this.original);
Expand Down Expand Up @@ -212,6 +212,18 @@ public final void addStaticAbility(final StaticAbility st) {
staticAbilities.add(st);
}

public boolean hasTraits() {
if (!getAbilities().isEmpty())
return true;
if (!getTriggers().isEmpty())
return true;
if (!getReplacements().isEmpty())
return true;
if (!getStaticAbilities().isEmpty())
return true;
return false;
}

/*
* (non-Javadoc)
* @see forge.game.keyword.KeywordInterface#getTriggers()
Expand Down Expand Up @@ -241,6 +253,24 @@ public Collection<StaticAbility> getStaticAbilities() {
return staticAbilities;
}


public List<SpellAbility> applySpellAbility(List<SpellAbility> list) {
list.addAll(getAbilities());
return list;
}
public List<Trigger> applyTrigger(List<Trigger> list) {
list.addAll(getTriggers());
return list;
}
public List<ReplacementEffect> applyReplacementEffect(List<ReplacementEffect> list) {
list.addAll(getReplacements());
return list;
}
public List<StaticAbility> applyStaticAbility(List<StaticAbility> list) {
list.addAll(getStaticAbilities());
return list;
}

/*
* (non-Javadoc)
* @see forge.game.keyword.KeywordInterface#copy()
Expand Down Expand Up @@ -393,7 +423,7 @@ public boolean hasSVar(final String name) {

@Override
public final void setSVar(final String name, final String value) {

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

import forge.game.IHasSVars;
import forge.game.card.Card;
import forge.game.card.ICardTraitChanges;
import forge.game.player.Player;
import forge.game.replacement.ReplacementEffect;
import forge.game.spellability.SpellAbility;
import forge.game.staticability.StaticAbility;
import forge.game.trigger.Trigger;

public interface KeywordInterface extends Cloneable, IHasSVars {
public interface KeywordInterface extends Cloneable, IHasSVars, ICardTraitChanges {

Card getHostCard();
void setHostCard(final Card host);
Expand Down Expand Up @@ -38,6 +39,8 @@ public interface KeywordInterface extends Cloneable, IHasSVars {
void createTraits(final Player player);
void createTraits(final Player player, final boolean clear);

boolean hasTraits();

void addTrigger(final Trigger trg);

void addReplacement(final ReplacementEffect trg);
Expand Down
34 changes: 22 additions & 12 deletions forge-game/src/main/java/forge/game/keyword/KeywordsChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* @author Forge
*/
public class KeywordsChange implements ICardTraitChanges, Cloneable {
public class KeywordsChange implements ICardTraitChanges, IKeywordsChange, Cloneable {
private KeywordCollection keywords = new KeywordCollection();
private List<KeywordInterface> removeKeywordInterfaces = Lists.newArrayList();
private List<String> removeKeywords = Lists.newArrayList();
Expand Down Expand Up @@ -152,39 +152,49 @@ public KeywordsChange copy(final Card host, final boolean lki) {

public List<SpellAbility> applySpellAbility(List<SpellAbility> list) {
for (KeywordInterface k : this.keywords.getValues()) {
list.addAll(k.getAbilities());
k.applySpellAbility(list);
}
return list;
}
public List<Trigger> applyTrigger(List<Trigger> list) {
for (KeywordInterface k : this.keywords.getValues()) {
list.addAll(k.getTriggers());
k.applyTrigger(list);
}
return list;
}
public List<ReplacementEffect> applyReplacementEffect(List<ReplacementEffect> list) {
for (KeywordInterface k : this.keywords.getValues()) {
list.addAll(k.getReplacements());
k.applyReplacementEffect(list);
}
return list;
}
public List<StaticAbility> applyStaticAbility(List<StaticAbility> list) {
for (KeywordInterface k : this.keywords.getValues()) {
list.addAll(k.getStaticAbilities());
k.applyStaticAbility(list);
}
return list;
}

public void applyKeywords(KeywordCollection list) {
if (isRemoveAllKeywords()) {
list.clear();
}
else if (getRemoveKeywords() != null) {
list.removeAll(getRemoveKeywords());
}

list.removeInstances(getRemovedKeywordInstances());

if (getKeywords() != null) {
list.insertAll(getKeywords());
}
}

public boolean hasTraits() {
for (KeywordInterface k : this.keywords.getValues()) {
if (!k.getAbilities().isEmpty())
return true;
if (!k.getTriggers().isEmpty())
return true;
if (!k.getReplacements().isEmpty())
return true;
if (!k.getStaticAbilities().isEmpty())
if (k.hasTraits()) {
return true;
}
}
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions forge-game/src/main/java/forge/game/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public class Player extends GameEntity implements Comparable<Player> {
private KeywordCollection keywords = new KeywordCollection();
// stores the keywords created by static abilities
private final Table<Long, String, KeywordInterface> storedKeywords = TreeBasedTable.create();
private Table<Long, Long, KeywordsChange> changedKeywords = TreeBasedTable.create();
private Table<Long, Long, IKeywordsChange> changedKeywords = TreeBasedTable.create();

private Map<GameEntity, List<Card>> attackedThisTurn = new HashMap<>();
private List<Player> attackedPlayersLastTurn = new ArrayList<>();
Expand Down Expand Up @@ -1008,8 +1008,8 @@ public final KeywordInterface getKeywordForStaticAbility(String kw, final long s
return result;
}

public final KeywordsChange removeChangedKeywords(final Long timestamp, final long staticId) {
KeywordsChange change = changedKeywords.remove(timestamp, staticId);
public final IKeywordsChange removeChangedKeywords(final Long timestamp, final long staticId) {
IKeywordsChange change = changedKeywords.remove(timestamp, staticId);
if (change != null) {
if (keywordEffect != null) {
getKeywordCard().removeChangedCardTraits(timestamp, staticId);
Expand Down