use of mage.Mana in project mage by magefree.
the class ManaOptions method addMana.
public void addMana(List<ActivatedManaAbilityImpl> abilities, Game game) {
if (isEmpty()) {
this.add(new Mana());
}
if (!abilities.isEmpty()) {
if (abilities.size() == 1) {
// if there is only one mana option available add it to all the existing options
List<Mana> netManas = abilities.get(0).getNetMana(game);
if (netManas.size() == 1) {
checkManaReplacementAndTriggeredMana(abilities.get(0), game, netManas.get(0));
addMana(netManas.get(0));
addTriggeredMana(game, abilities.get(0));
} else if (netManas.size() > 1) {
addManaVariation(netManas, abilities.get(0), game);
}
} else {
// mana source has more than 1 ability
// perform a union of all existing options and the new options
List<Mana> copy = copy();
this.clear();
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);
if (moreValuable != null) {
// only keep the more valuable mana
existingMana.setToMana(moreValuable);
continue SkipAddMana;
}
}
this.add(newMana);
}
}
}
}
}
}
forceManaDeduplication();
}
use of mage.Mana in project mage by magefree.
the class ManaOptions method addManaCombination.
public static void addManaCombination(Mana mana, Mana existingMana, List<Mana> payCombinations, List<String> payCombinationsStrings) {
Mana newMana = existingMana.copy();
newMana.add(mana);
payCombinations.add(newMana);
payCombinationsStrings.add(newMana.toString());
}
use of mage.Mana in project mage by magefree.
the class ManaOptions method getTriggeredManaVariations.
public static List<Mana> getTriggeredManaVariations(Game game, Ability ability, Mana baseMana) {
List<Mana> baseManaPlusTriggeredMana = new ArrayList<>();
baseManaPlusTriggeredMana.add(baseMana);
List<List<Mana>> availableTriggeredManaList = ManaOptions.getSimulatedTriggeredManaFromPlayer(game, ability);
for (List<Mana> availableTriggeredMana : availableTriggeredManaList) {
if (availableTriggeredMana.size() == 1) {
for (Mana prevMana : baseManaPlusTriggeredMana) {
prevMana.add(availableTriggeredMana.get(0));
}
} else if (availableTriggeredMana.size() > 1) {
List<Mana> copy = new ArrayList<>(baseManaPlusTriggeredMana);
baseManaPlusTriggeredMana.clear();
for (Mana triggeredMana : availableTriggeredMana) {
for (Mana prevMana : copy) {
Mana newMana = new Mana();
newMana.add(prevMana);
newMana.add(triggeredMana);
baseManaPlusTriggeredMana.add(newMana);
}
}
}
}
return baseManaPlusTriggeredMana;
}
use of mage.Mana in project mage by magefree.
the class ManaOptions method removeEqualMana.
public boolean removeEqualMana(Mana manaToRemove) {
boolean result = false;
for (Iterator<Mana> iterator = this.iterator(); iterator.hasNext(); ) {
Mana next = iterator.next();
if (next.equalManaValue(manaToRemove)) {
iterator.remove();
result = true;
}
}
return result;
}
use of mage.Mana in project mage by magefree.
the class ManaOptions method addManaPoolDependant.
public boolean addManaPoolDependant(List<ActivatedManaAbilityImpl> abilities, Game game) {
boolean wasUsable = false;
if (!abilities.isEmpty()) {
if (abilities.size() == 1) {
ActivatedManaAbilityImpl ability = (ActivatedManaAbilityImpl) abilities.get(0);
List<Mana> copy = copy();
this.clear();
for (Mana previousMana : copy) {
Mana startingMana = previousMana.copy();
Mana manaCosts = ability.getManaCosts().getMana();
if (startingMana.includesMana(manaCosts)) {
// can pay the mana costs to use the ability
for (Mana manaOption : ability.getManaCosts().getManaOptions()) {
if (!subtractCostAddMana(manaOption, null, ability.getCosts().isEmpty(), startingMana, ability, game)) {
// the starting mana includes mana parts that the increased mana does not include, so add starting mana also as an option
add(previousMana);
}
}
wasUsable = true;
} else {
// mana costs can't be paid so keep starting mana
add(previousMana);
}
}
}
}
return wasUsable;
}
Aggregations