use of mage.constants.ManaType in project mage by magefree.
the class SquanderedResourcesEffect method getNetMana.
@Override
public List<Mana> getNetMana(Game game, Ability source) {
if (game != null && game.inCheckPlayableState()) {
// add color combinations of available mana
ManaOptions allPossibleMana = new ManaOptions();
for (Permanent land : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_LAND, source.getControllerId(), game)) {
ManaOptions currentPossibleMana = new ManaOptions();
Set<ManaType> manaTypes = AnyColorLandsProduceManaAbility.getManaTypesFromPermanent(land, game);
if (manaTypes.size() == 5 && !manaTypes.contains(ManaType.COLORLESS) || manaTypes.size() == 6) {
currentPossibleMana.add(Mana.AnyMana(1));
if (manaTypes.contains(ManaType.COLORLESS)) {
currentPossibleMana.add(new Mana(ManaType.COLORLESS));
}
} else {
for (ManaType manaType : manaTypes) {
currentPossibleMana.add(new Mana(manaType));
}
}
allPossibleMana.addMana(currentPossibleMana);
}
allPossibleMana.removeDuplicated();
return allPossibleMana.stream().collect(Collectors.toList());
}
return ManaType.getManaListFromManaTypes(getManaTypesFromSacrificedPermanent(game, source), false);
}
use of mage.constants.ManaType in project mage by magefree.
the class AddConditionalManaEffect method getNetMana.
@Override
public List<Mana> getNetMana(Game game, Ability source) {
if (game != null && game.inCheckPlayableState() && netAmount != null) {
List<Mana> maxAvailableMana = new ArrayList<>();
int amountAvailableMana = netAmount.calculate(game, source, this);
if (amountAvailableMana > 0) {
Mana calculatedMana = mana.copy();
for (ManaType manaType : ManaType.getTrueManaTypes()) {
calculatedMana.set(manaType, CardUtil.overflowMultiply(calculatedMana.get(manaType), amountAvailableMana));
}
maxAvailableMana.add(manaBuilder.setMana(calculatedMana, source, game).build());
}
return maxAvailableMana;
}
// To change body of generated methods, choose Tools | Templates.
return super.getNetMana(game, source);
}
use of mage.constants.ManaType in project mage by magefree.
the class ManaCostsImpl method assignPayment.
@Override
public void assignPayment(Game game, Ability ability, ManaPool pool, Cost costToPay) {
// try to assign mana from pool to payment in priority order (color first)
// auto-payment allows to use any mana type, if not then only unlocked can be used (mana type that were clicked in mana pool)
ManaType canUseManaType;
if (pool.isAutoPayment()) {
// can use any type
canUseManaType = null;
} else {
canUseManaType = pool.getUnlockedManaType();
if (canUseManaType == null) {
// auto payment is inactive and no mana type was clicked manually - do nothing
return;
}
}
ManaCosts referenceCosts = null;
if (pool.isForcedToPay()) {
referenceCosts = this.copy();
}
// colorless costs (not generic)
for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof ColorlessManaCost) {
cost.assignPayment(game, ability, pool, costToPay);
if (pool.isEmpty()) {
return;
}
}
}
// colored
for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof ColoredManaCost) {
cost.assignPayment(game, ability, pool, costToPay);
if (pool.isEmpty()) {
return;
}
}
}
// hybrid
for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof HybridManaCost) {
cost.assignPayment(game, ability, pool, costToPay);
if (pool.isEmpty()) {
return;
}
}
}
// try to pay colored part
for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof MonoHybridManaCost) {
if (canPayColoredManaFromPool(ManaType.WHITE, cost, canUseManaType, pool) || canPayColoredManaFromPool(ManaType.BLACK, cost, canUseManaType, pool) || canPayColoredManaFromPool(ManaType.RED, cost, canUseManaType, pool) || canPayColoredManaFromPool(ManaType.GREEN, cost, canUseManaType, pool) || canPayColoredManaFromPool(ManaType.BLUE, cost, canUseManaType, pool)) {
cost.assignPayment(game, ability, pool, costToPay);
if (pool.isEmpty() && pool.getConditionalMana().isEmpty()) {
return;
}
}
}
}
// try to pay generic part
for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof MonoHybridManaCost) {
cost.assignPayment(game, ability, pool, costToPay);
if (pool.isEmpty()) {
return;
}
}
}
// snow
for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof SnowManaCost) {
cost.assignPayment(game, ability, pool, costToPay);
if (pool.isEmpty()) {
return;
}
}
}
// generic
for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof GenericManaCost) {
cost.assignPayment(game, ability, pool, costToPay);
if (pool.isEmpty()) {
return;
}
}
}
// variable (generic)
for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof VariableManaCost) {
cost.assignPayment(game, ability, pool, costToPay);
}
}
// stop using mana of the clicked mana type
pool.lockManaType();
if (canUseManaType == null) {
handleForcedToPayOnlyForCurrentPayment(game, pool, referenceCosts);
}
}
use of mage.constants.ManaType in project mage by magefree.
the class ManaWebeffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = (Permanent) getValue("tappedPermanent");
if (permanent == null) {
return false;
}
Set<ManaType> manaTypesSource = AnyColorLandsProduceManaAbility.getManaTypesFromPermanent(permanent, game);
boolean tappedLands = false;
for (Permanent opponentPermanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND, permanent.getControllerId(), source.getSourceId(), game)) {
Set<ManaType> manaTypes = AnyColorLandsProduceManaAbility.getManaTypesFromPermanent(opponentPermanent, game);
if (!Collections.disjoint(manaTypes, manaTypesSource)) {
opponentPermanent.tap(source, game);
}
}
return tappedLands;
}
use of mage.constants.ManaType in project mage by magefree.
the class ManaPool method pay.
/**
* @param manaType the mana type that should be paid
* @param ability
* @param filter
* @param game
* @param costToPay complete costs to pay (needed to check conditional
* mana)
* @param usedManaToPay the information about what mana was paid
* @return
*/
public boolean pay(ManaType manaType, Ability ability, Filter filter, Game game, Cost costToPay, Mana usedManaToPay) {
if (!isAutoPayment() && manaType != unlockedManaType) {
// if manual payment and the needed mana type was not unlocked, nothing will be paid
return false;
}
ManaType possibleAsThoughPoolManaType = null;
if (isAutoPayment() && isAutoPaymentRestricted() && // was not more mana added than at the start of casting something
!wasManaAddedBeyondStock() && manaType != unlockedManaType) {
// and the needed mana type was not unlocked, nothing will be paid
if (unlockedManaType != null) {
ManaPoolItem checkItem = new ManaPoolItem();
checkItem.add(unlockedManaType, 1);
possibleAsThoughPoolManaType = game.getContinuousEffects().asThoughMana(manaType, checkItem, ability.getSourceId(), ability, ability.getControllerId(), game);
}
// Check if it's possible to use mana as thought for the unlocked manatype in the mana pool for this ability
if (possibleAsThoughPoolManaType == null || possibleAsThoughPoolManaType != unlockedManaType) {
// if it's not possible return
return false;
}
}
// first try to pay from conditional mana (the returned manaType can be changed if AsThoughEffects are active)
ConditionalManaInfo manaInfo = getConditional(manaType, ability, filter, game, costToPay, possibleAsThoughPoolManaType);
if (manaInfo != null) {
removeConditional(manaInfo, ability, game, costToPay, usedManaToPay);
// pay only one mana if mana payment is set to manually
lockManaType();
return true;
}
for (ManaPoolItem mana : manaItems) {
if (filter != null) {
if (!filter.match(mana.getSourceObject(), game)) {
// Prevent that cost reduction by convoke is filtered out
if (!(mana.getSourceObject() instanceof Spell) || ability.getSourceId().equals(mana.getSourceId())) {
continue;
}
}
}
if (possibleAsThoughPoolManaType == null && manaType != unlockedManaType && isAutoPayment() && isAutoPaymentRestricted() && mana.count() == mana.getStock()) {
// no mana added beyond the stock so don't auto pay this
continue;
}
ManaType usableManaType = game.getContinuousEffects().asThoughMana(manaType, mana, ability.getSourceId(), ability, ability.getControllerId(), game);
if (usableManaType == null) {
continue;
}
if (mana.get(usableManaType) > 0) {
GameEvent event = new ManaPaidEvent(ability, mana.getSourceId(), mana.getFlag(), mana.getOriginalId(), mana.getSourceObject(), usableManaType);
game.fireEvent(event);
usedManaToPay.increase(usableManaType);
mana.remove(usableManaType);
if (mana.count() == 0) {
// so no items with count 0 stay in list
manaItems.remove(mana);
}
// pay only one mana if mana payment is set to manually
lockManaType();
return true;
}
}
return false;
}
Aggregations