Skip to content
Open
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
32 changes: 9 additions & 23 deletions Mage/src/main/java/mage/abilities/mana/ManaOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import mage.ConditionalMana;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.constants.ManaType;
import mage.game.Game;
import mage.game.events.GameEvent;
Expand Down Expand Up @@ -61,34 +62,20 @@ public void addMana(List<ActivatedManaAbilityImpl> abilities, Game game) {

} else { // mana source has more than 1 ability
//perform a union of all existing options and the new options
List<Mana> copy = new ArrayList<>(this);
this.clear();
ManaOptions out = new ManaOptions();
for (ActivatedManaAbilityImpl ability : abilities) {
for (Mana netMana : ability.getNetMana(game)) {
checkManaReplacementAndTriggeredMana(ability, game, netMana);
for (Mana triggeredManaVariation : getTriggeredManaVariations(game, ability, netMana)) {
SkipAddMana:
for (Mana mana : copy) {
Mana newMana = new Mana();
newMana.add(mana);
newMana.add(triggeredManaVariation);
for (Mana existingMana : this) {
if (existingMana.equalManaValue(newMana)) {
continue SkipAddMana;
}
Mana moreValuable = Mana.getMoreValuableMana(newMana, existingMana);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a more complex logic -- ignore duplicated mana option, ignore useless mana option. New code will add any mana option to the list.

New simplified code must be a better solution cause it run mana optimization anyway, but it must be researched. Too much useless mana options (that can't be removed after optimization) can generate bad performance and memory overflow. So need additional research.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look at it later

if (moreValuable != null) {
// only keep the more valuable mana
existingMana.setToMana(moreValuable);
continue SkipAddMana;
}
}
this.add(newMana);
}
ManaOptions copy = new ManaOptions(this);
copy.addMana(triggeredManaVariation);
out.addAll(copy);
}

}
}
out.removeFullyIncludedVariations();
this.clear();
this.addAll(out);
}
}

Expand Down Expand Up @@ -348,7 +335,6 @@ public void addMana(Mana addMana) {
}
}
}

public void addMana(ManaOptions options) {
if (isEmpty()) {
this.add(new Mana());
Expand Down Expand Up @@ -693,4 +679,4 @@ public static <T> void verifyTransitivity(Comparator<T> comparator, Collection<T

private Comparators() {
}
}
}