Card: fix addChangedCardTraits when multiple StaticAbilities has the same timestamp

This commit is contained in:
Hans Mackowiak
2020-06-01 22:04:55 +02:00
parent 8714399b51
commit 1b40987bbd
2 changed files with 23 additions and 10 deletions

View File

@@ -3657,9 +3657,16 @@ public class Card extends GameEntity implements Comparable<Card> {
public final void addChangedCardTraits(Collection<SpellAbility> spells, Collection<SpellAbility> removedAbilities, public final void addChangedCardTraits(Collection<SpellAbility> spells, Collection<SpellAbility> removedAbilities,
Collection<Trigger> trigger, Collection<ReplacementEffect> replacements, Collection<StaticAbility> statics, Collection<Trigger> trigger, Collection<ReplacementEffect> replacements, Collection<StaticAbility> statics,
boolean removeAll, boolean removeNonMana, boolean removeIntrinsic, long timestamp) { boolean removeAll, boolean removeNonMana, boolean removeIntrinsic, long timestamp) {
changedCardTraits.put(timestamp, new CardTraitChanges( // in case two static abilities has the same timestamp
spells, removedAbilities, trigger, replacements, statics, removeAll, removeNonMana, removeIntrinsic if (changedCardTraits.containsKey(timestamp)) {
)); changedCardTraits.get(timestamp).merge(
spells, removedAbilities, trigger, replacements, statics, removeAll, removeNonMana, removeIntrinsic
);
} else {
changedCardTraits.put(timestamp, new CardTraitChanges(
spells, removedAbilities, trigger, replacements, statics, removeAll, removeNonMana, removeIntrinsic
));
}
// update view // update view
updateAbilityTextForView(); updateAbilityTextForView();
} }

View File

@@ -19,13 +19,19 @@ public class CardTraitChanges implements Cloneable {
private List<SpellAbility> removedAbilities = Lists.newArrayList(); private List<SpellAbility> removedAbilities = Lists.newArrayList();
private boolean removeAll; private boolean removeAll = false;
private boolean removeNonMana; private boolean removeNonMana = false;
private boolean removeIntrinsic; private boolean removeIntrinsic = false;
public CardTraitChanges(Collection<SpellAbility> spells, Collection<SpellAbility> removedAbilities, public CardTraitChanges(Collection<SpellAbility> spells, Collection<SpellAbility> removedAbilities,
Collection<Trigger> trigger, Collection<ReplacementEffect> res, Collection<StaticAbility> st, Collection<Trigger> trigger, Collection<ReplacementEffect> res, Collection<StaticAbility> st,
boolean removeAll, boolean removeNonMana, boolean removeIntrinsic) { boolean removeAll, boolean removeNonMana, boolean removeIntrinsic) {
merge(spells, removedAbilities, trigger, res, st, removeAll, removeNonMana, removeIntrinsic);
}
public void merge(Collection<SpellAbility> spells, Collection<SpellAbility> removedAbilities,
Collection<Trigger> trigger, Collection<ReplacementEffect> res, Collection<StaticAbility> st,
boolean removeAll, boolean removeNonMana, boolean removeIntrinsic) {
if (spells != null) { if (spells != null) {
this.abilities.addAll(spells); this.abilities.addAll(spells);
} }
@@ -41,10 +47,10 @@ public class CardTraitChanges implements Cloneable {
if (st != null) { if (st != null) {
this.staticAbilities.addAll(st); this.staticAbilities.addAll(st);
} }
this.removeAll = removeAll; this.removeAll |= removeAll;
this.removeNonMana = removeNonMana; this.removeNonMana |= removeNonMana;
this.removeIntrinsic = removeIntrinsic; this.removeIntrinsic |= removeIntrinsic;
} }
/** /**