Search in sources :

Example 46 with ManaOptions

use of mage.abilities.mana.ManaOptions in project mage by magefree.

the class PlayerImpl method getManaAvailable.

/**
 * Returns the mana options the player currently has. That means which
 * combinations of mana are available to cast spells or activate abilities
 * etc.
 *
 * @param game
 * @return
 */
@Override
public ManaOptions getManaAvailable(Game game) {
    boolean oldState = game.inCheckPlayableState();
    game.setCheckPlayableState(true);
    ManaOptions availableMana = new ManaOptions();
    availableMana.addMana(manaPool.getMana());
    // conditional mana
    for (ConditionalMana conditionalMana : manaPool.getConditionalMana()) {
        availableMana.addMana(conditionalMana);
    }
    List<Abilities<ActivatedManaAbilityImpl>> sourceWithoutManaCosts = new ArrayList<>();
    List<Abilities<ActivatedManaAbilityImpl>> sourceWithCosts = new ArrayList<>();
    for (Card card : getHand().getCards(game)) {
        Abilities<ActivatedManaAbilityImpl> manaAbilities = card.getAbilities(game).getAvailableActivatedManaAbilities(Zone.HAND, playerId, game);
        for (Iterator<ActivatedManaAbilityImpl> it = manaAbilities.iterator(); it.hasNext(); ) {
            ActivatedManaAbilityImpl ability = it.next();
            Abilities<ActivatedManaAbilityImpl> noTapAbilities = new AbilitiesImpl<>(ability);
            if (ability.getManaCosts().isEmpty() && !ability.isPoolDependant()) {
                sourceWithoutManaCosts.add(noTapAbilities);
            } else {
                sourceWithCosts.add(noTapAbilities);
            }
        }
    }
    for (Permanent permanent : game.getBattlefield().getActivePermanents(playerId, game)) {
        // Some permanents allow use of abilities from non controlling players. so check all permanents in range
        Boolean canUse = null;
        boolean canAdd = false;
        // sources with mana costs or mana pool dependency
        boolean useLater = false;
        Abilities<ActivatedManaAbilityImpl> manaAbilities = // returns ability only if canActivate is true
        permanent.getAbilities(game).getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, playerId, game);
        for (Iterator<ActivatedManaAbilityImpl> it = manaAbilities.iterator(); it.hasNext(); ) {
            ActivatedManaAbilityImpl ability = it.next();
            if (canUse == null) {
                canUse = permanent.canUseActivatedAbilities(game);
            }
            if (canUse) {
                // abilities without Tap costs have to be handled as separate sources, because they can be used also
                if (!ability.hasTapCost()) {
                    it.remove();
                    Abilities<ActivatedManaAbilityImpl> noTapAbilities = new AbilitiesImpl<>(ability);
                    if (ability.getManaCosts().isEmpty() && !ability.isPoolDependant()) {
                        sourceWithoutManaCosts.add(noTapAbilities);
                    } else {
                        sourceWithCosts.add(noTapAbilities);
                    }
                    continue;
                }
                canAdd = true;
                if (!ability.getManaCosts().isEmpty() || ability.isPoolDependant()) {
                    useLater = true;
                    break;
                }
            }
        }
        if (canAdd) {
            if (useLater) {
                sourceWithCosts.add(manaAbilities);
            } else {
                sourceWithoutManaCosts.add(manaAbilities);
            }
        }
    }
    for (Abilities<ActivatedManaAbilityImpl> manaAbilities : sourceWithoutManaCosts) {
        availableMana.addMana(manaAbilities, game);
    }
    boolean anAbilityWasUsed = true;
    // use such abilities later than other if possible because it can maximize mana production
    boolean usePoolDependantAbilities = false;
    while (anAbilityWasUsed && !sourceWithCosts.isEmpty()) {
        anAbilityWasUsed = false;
        for (Iterator<Abilities<ActivatedManaAbilityImpl>> iterator = sourceWithCosts.iterator(); iterator.hasNext(); ) {
            Abilities<ActivatedManaAbilityImpl> manaAbilities = iterator.next();
            if (usePoolDependantAbilities || !manaAbilities.hasPoolDependantAbilities()) {
                boolean used;
                if (manaAbilities.hasPoolDependantAbilities()) {
                    used = availableMana.addManaPoolDependant(manaAbilities, game);
                } else {
                    used = availableMana.addManaWithCost(manaAbilities, game);
                }
                if (used) {
                    iterator.remove();
                    availableMana.removeDuplicated();
                    anAbilityWasUsed = true;
                }
            }
        }
        if (!anAbilityWasUsed && !usePoolDependantAbilities) {
            usePoolDependantAbilities = true;
            anAbilityWasUsed = true;
        }
    }
    // remove duplicated variants (see ManaOptionsTest for info - when that rises)
    availableMana.removeDuplicated();
    game.setCheckPlayableState(oldState);
    return availableMana;
}
Also used : ManaOptions(mage.abilities.mana.ManaOptions) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) TargetPermanent(mage.target.TargetPermanent) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 47 with ManaOptions

use of mage.abilities.mana.ManaOptions in project mage by magefree.

the class DoublingCubeTest method test_AvailableMana.

@Test
public void test_AvailableMana() {
    setStrictChooseMode(true);
    // {3}, {T}: Double the amount of each type of mana in your mana pool.
    addCard(Zone.BATTLEFIELD, playerA, cube);
    addCard(Zone.BATTLEFIELD, playerA, "Forest", 4);
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4);
    setStopAt(1, PhaseStep.PRECOMBAT_MAIN);
    execute();
    assertAllCommandsUsed();
    ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
    Assert.assertEquals("mana variations don't fit", 4, manaOptions.size());
    assertManaOptions("{R}{R}{R}{R}{R}{R}{R}{R}{G}{G}", manaOptions);
    assertManaOptions("{R}{R}{R}{R}{R}{R}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{R}{R}{R}{R}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{R}{R}{G}{G}{G}{G}{G}{G}{G}{G}", manaOptions);
}
Also used : ManaOptions(mage.abilities.mana.ManaOptions) ManaOptionsTestUtils.assertManaOptions(org.mage.test.utils.ManaOptionsTestUtils.assertManaOptions) Test(org.junit.Test)

Example 48 with ManaOptions

use of mage.abilities.mana.ManaOptions in project mage by magefree.

the class DoublingCubeTest method test_AvailableMana2.

@Test
public void test_AvailableMana2() {
    setStrictChooseMode(true);
    // {3}, {T}: Double the amount of each type of mana in your mana pool.
    addCard(Zone.BATTLEFIELD, playerA, cube, 2);
    // {T}: Add Colorless.
    // {1}, {T}: Add Black.
    // {2}, {T}: Add Blue or Red.
    addCard(Zone.BATTLEFIELD, playerA, "Castle Sengir", 2);
    addCard(Zone.BATTLEFIELD, playerA, "Forest", 4);
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4);
    setStopAt(1, PhaseStep.UPKEEP);
    execute();
    assertAllCommandsUsed();
    ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
    Assert.assertEquals("mana variations don't fit", 138, manaOptions.size());
    assertManaOptions("{C}{C}{C}{C}{C}{C}{C}{C}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{C}{C}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{C}{C}{C}{C}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{C}{C}{C}{C}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{C}{C}{C}{C}{R}{R}{R}{R}{R}{R}{R}{R}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{C}{C}{C}{C}{R}{R}{R}{R}{R}{R}{G}{G}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{C}{C}{C}{C}{R}{R}{R}{R}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{C}{C}{C}{C}{R}{R}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{C}{C}{C}{C}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{B}{B}{R}{R}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{B}{B}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{B}{B}{B}{B}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{B}{B}{R}{R}{R}{R}{R}{R}{R}{R}{R}{R}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{B}{B}{R}{R}{R}{R}{R}{R}{R}{R}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{B}{B}{B}{B}{R}{R}{R}{R}{R}{R}{R}{R}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{B}{B}{B}{B}{R}{R}{R}{R}{R}{R}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{B}{B}{R}{R}{R}{R}{R}{R}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{B}{B}{R}{R}{R}{R}{G}{G}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{B}{B}{B}{B}{R}{R}{R}{R}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{B}{B}{B}{B}{R}{R}{G}{G}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{B}{B}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{B}{B}{B}{B}{G}{G}{G}{G}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{U}{U}{R}{R}{R}{R}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{U}{U}{U}{U}{R}{R}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{G}{G}{U}{U}{R}{R}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{G}{G}{G}{G}{U}{U}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{G}{G}{U}{U}{U}{U}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{G}{G}{G}{G}{U}{U}{U}{U}{R}{R}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{G}{G}{G}{G}{G}{G}{U}{U}{R}{R}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{G}{G}{G}{G}{G}{G}{G}{G}{U}{U}", manaOptions);
    assertManaOptions("{C}{C}{C}{C}{G}{G}{G}{G}{G}{G}{U}{U}{U}{U}", manaOptions);
    assertManaOptions("{B}{B}{B}{B}{B}{B}{R}{R}{R}{R}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{B}{B}{B}{B}{B}{B}{B}{B}{R}{R}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{B}{B}{B}{B}{B}{B}{R}{R}{R}{R}{R}{R}{G}{G}", manaOptions);
    assertManaOptions("{B}{B}{B}{B}{B}{B}{R}{R}{R}{R}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{B}{B}{B}{B}{B}{B}{B}{B}{R}{R}{R}{R}{G}{G}", manaOptions);
    assertManaOptions("{B}{B}{B}{B}{B}{B}{B}{B}{R}{R}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{B}{B}{B}{B}{B}{B}{R}{R}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{B}{B}{B}{B}{B}{B}{G}{G}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{B}{B}{B}{B}{B}{B}{B}{B}{G}{G}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{U}{U}{B}{B}{R}{R}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{U}{U}{U}{U}{B}{B}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{U}{U}{B}{B}{B}{B}{R}{R}{R}{R}", manaOptions);
    assertManaOptions("{U}{U}{U}{U}{B}{B}{B}{B}{R}{R}", manaOptions);
    assertManaOptions("{U}{U}{B}{B}{R}{R}{R}{R}{G}{G}", manaOptions);
    assertManaOptions("{U}{U}{B}{B}{R}{R}{G}{G}{G}{G}", manaOptions);
    assertManaOptions("{U}{U}{U}{U}{B}{B}{R}{R}{G}{G}", manaOptions);
    assertManaOptions("{B}{B}{G}{G}{G}{G}{U}{U}{U}{U}", manaOptions);
    assertManaOptions("{U}{U}{B}{B}{B}{B}{R}{R}{G}{G}", manaOptions);
    assertManaOptions("{B}{B}{B}{B}{G}{G}{G}{G}{U}{U}", manaOptions);
    assertManaOptions("{B}{B}{B}{B}{G}{G}{U}{U}{U}{U}", manaOptions);
    assertManaOptions("{B}{B}{G}{G}{G}{G}{G}{G}{U}{U}", manaOptions);
    assertManaOptions("{U}{U}{U}{U}{U}{U}", manaOptions);
}
Also used : ManaOptions(mage.abilities.mana.ManaOptions) ManaOptionsTestUtils.assertManaOptions(org.mage.test.utils.ManaOptionsTestUtils.assertManaOptions) Test(org.junit.Test)

Example 49 with ManaOptions

use of mage.abilities.mana.ManaOptions in project mage by magefree.

the class NonTappingManaAbilitiesTest method TestWorkhorse.

@Test
public void TestWorkhorse() {
    setStrictChooseMode(true);
    // Workhorse enters the battlefield with four +1/+1 counters on it.
    // Remove a +1/+1 counter from Workhorse: Add {C}.
    addCard(Zone.BATTLEFIELD, playerA, "Workhorse", 1);
    setStopAt(1, PhaseStep.PRECOMBAT_MAIN);
    execute();
    assertAllCommandsUsed();
    ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
    Assert.assertEquals("mana variations don't fit", 1, manaOptions.size());
    assertManaOptions("{C}{C}{C}{C}", manaOptions);
}
Also used : ManaOptions(mage.abilities.mana.ManaOptions) ManaOptionsTestUtils.assertManaOptions(org.mage.test.utils.ManaOptionsTestUtils.assertManaOptions) Test(org.junit.Test)

Example 50 with ManaOptions

use of mage.abilities.mana.ManaOptions in project mage by magefree.

the class NonTappingManaAbilitiesTest method TestMorselhoarder.

@Test
public void TestMorselhoarder() {
    setStrictChooseMode(true);
    // Morselhoarder enters the battlefield with two -1/-1 counters on it.
    // Remove a -1/-1 counter from Morselhoarder: Add one mana of any color.
    addCard(Zone.BATTLEFIELD, playerA, "Morselhoarder", 2);
    addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
    setStopAt(1, PhaseStep.BEGIN_COMBAT);
    execute();
    assertAllCommandsUsed();
    ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
    Assert.assertEquals("mana variations don't fit", 1, manaOptions.size());
    assertManaOptions("{B}{B}{Any}{Any}{Any}{Any}", manaOptions);
}
Also used : ManaOptions(mage.abilities.mana.ManaOptions) ManaOptionsTestUtils.assertManaOptions(org.mage.test.utils.ManaOptionsTestUtils.assertManaOptions) Test(org.junit.Test)

Aggregations

ManaOptions (mage.abilities.mana.ManaOptions)99 Test (org.junit.Test)85 ManaOptionsTestUtils.assertManaOptions (org.mage.test.utils.ManaOptionsTestUtils.assertManaOptions)75 ManaOptionsTestUtils.assertDuplicatedManaOptions (org.mage.test.utils.ManaOptionsTestUtils.assertDuplicatedManaOptions)38 Permanent (mage.game.permanent.Permanent)9 Mana (mage.Mana)8 Player (mage.players.Player)5 ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)4 FilterCard (mage.filter.FilterCard)4 FilterPermanent (mage.filter.FilterPermanent)4 TargetPermanent (mage.target.TargetPermanent)4 AlternateManaPaymentAbility (mage.abilities.costs.mana.AlternateManaPaymentAbility)3 ManaCost (mage.abilities.costs.mana.ManaCost)3 ValueHint (mage.abilities.hint.ValueHint)3 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)3 UUID (java.util.UUID)2 ConditionalMana (mage.ConditionalMana)2 PassAbility (mage.abilities.common.PassAbility)2 PlayLandAsCommanderAbility (mage.abilities.common.PlayLandAsCommanderAbility)2 WhileSearchingPlayFromLibraryAbility (mage.abilities.common.WhileSearchingPlayFromLibraryAbility)2