use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.
the class PlayerImpl method canPlay.
/**
* @param ability
* @param availableMana if null, it won't be checked if enough mana is
* available
* @param sourceObject
* @param game
* @return
*/
protected boolean canPlay(ActivatedAbility ability, ManaOptions availableMana, MageObject sourceObject, Game game) {
if (!(ability instanceof ActivatedManaAbilityImpl)) {
// Copy is needed because cost reduction effects modify e.g. the mana to activate/cast the ability
ActivatedAbility copy = ability.copy();
if (!copy.canActivate(playerId, game).canActivate()) {
return false;
}
if (availableMana != null) {
sourceObject.adjustCosts(copy, game);
game.getContinuousEffects().costModification(copy, game);
}
boolean canBeCastRegularly = true;
if (copy instanceof SpellAbility && copy.getManaCosts().isEmpty() && copy.getCosts().isEmpty()) {
// 117.6. Some mana costs contain no mana symbols. This represents an unpayable cost...
// 117.6a (...) If an alternative cost is applied to an unpayable cost,
// including an effect that allows a player to cast a spell without paying its mana cost, the alternative cost may be paid.
canBeCastRegularly = false;
}
if (canBeCastRegularly) {
if (canPayMinimumManaCost(copy, availableMana, game)) {
return true;
}
}
// ALTERNATIVE COST FROM dynamic effects
if (getCastSourceIdWithAlternateMana().contains(copy.getSourceId())) {
ManaCosts alternateCosts = getCastSourceIdManaCosts().get(copy.getSourceId());
Costs<Cost> costs = getCastSourceIdCosts().get(copy.getSourceId());
boolean canPutToPlay = true;
if (alternateCosts != null && !alternateCosts.canPay(copy, copy, playerId, game)) {
canPutToPlay = false;
}
if (costs != null && !costs.canPay(copy, copy, playerId, game)) {
canPutToPlay = false;
}
if (canPutToPlay) {
return true;
}
}
// ALTERNATIVE COST from source card (any AlternativeSourceCosts)
if (AbilityType.SPELL.equals(ability.getAbilityType())) {
return canPlayCardByAlternateCost(game.getCard(ability.getSourceId()), availableMana, copy, game);
}
}
return false;
}
use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.
the class RowanKenrithEmblemTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!event.getPlayerId().equals(getControllerId())) {
return false;
}
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (stackAbility == null || stackAbility.getStackAbility() instanceof ActivatedManaAbilityImpl) {
return false;
}
this.getEffects().setValue("stackAbility", stackAbility);
return true;
}
use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.
the class RevelInSilenceEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!game.getOpponents(event.getPlayerId()).contains(getControllerId())) {
return false;
}
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (stackAbility.getStackAbility() instanceof ActivatedManaAbilityImpl) {
return false;
}
getEffects().setTargetPointer(new FixedTarget(event.getPlayerId()));
return true;
}
use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.
the class AnyColorLandsProduceManaEffect method getManaTypes.
private Mana getManaTypes(Game game, Ability source) {
Mana types = new Mana();
if (game == null || game.getPhase() == null) {
return types;
}
if (inManaTypeCalculation) {
return types;
}
inManaTypeCalculation = true;
List<Permanent> lands = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND, source.getControllerId(), source.getSourceId(), game);
for (Permanent land : lands) {
Abilities<ActivatedManaAbilityImpl> mana = land.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD);
for (ActivatedManaAbilityImpl ability : mana) {
if (!ability.equals(source) && ability.definesMana(game)) {
for (Mana netMana : ability.getNetMana(game)) {
types.add(netMana);
}
}
}
}
inManaTypeCalculation = false;
return types;
}
use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.
the class PlayerImpl method getUseableManaAbilities.
protected LinkedHashMap<UUID, ActivatedManaAbilityImpl> getUseableManaAbilities(MageObject object, Zone zone, Game game) {
LinkedHashMap<UUID, ActivatedManaAbilityImpl> useable = new LinkedHashMap<>();
boolean canUse = !(object instanceof Permanent) || ((Permanent) object).canUseActivatedAbilities(game);
for (ActivatedManaAbilityImpl ability : object.getAbilities().getActivatedManaAbilities(zone)) {
if (canUse || ability.getAbilityType() == AbilityType.SPECIAL_ACTION) {
if (ability.canActivate(playerId, game).canActivate()) {
useable.put(ability.getId(), ability);
}
}
}
return useable;
}
Aggregations