use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.
the class ComputerPlayer method getSortedProducers.
/**
* returns a list of Permanents that produce mana sorted by the number of
* mana the Permanent produces that match the unpaid costs in ascending
* order
* <p>
* the idea is that we should pay costs first from mana producers that
* produce only one type of mana and save the multi-mana producers for those
* costs that can't be paid by any other producers
*
* @param unpaid - the amount of unpaid mana costs
* @param game
* @return List<Permanent>
*/
private List<MageObject> getSortedProducers(ManaCosts<ManaCost> unpaid, Game game) {
List<MageObject> unsorted = this.getAvailableManaProducers(game);
unsorted.addAll(this.getAvailableManaProducersWithCost(game));
Map<MageObject, Integer> scored = new HashMap<>();
for (MageObject mageObject : unsorted) {
int score = 0;
for (ManaCost cost : unpaid) {
Abilities: for (ActivatedManaAbilityImpl ability : mageObject.getAbilities().getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, playerId, game)) {
for (Mana netMana : ability.getNetMana(game)) {
if (cost.testPay(netMana)) {
score++;
break Abilities;
}
}
}
}
if (score > 0) {
// score mana producers that produce other mana types and have other uses higher
score += mageObject.getAbilities().getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, playerId, game).size();
score += mageObject.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD).size();
if (!mageObject.getCardType(game).contains(CardType.LAND)) {
score += 2;
} else if (mageObject.getCardType(game).contains(CardType.CREATURE)) {
score += 2;
}
}
scored.put(mageObject, score);
}
return sortByValue(scored);
}
use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.
the class BenthicExplorersManaEffect method getManaTypes.
private Set<ManaType> getManaTypes(Game game, Ability source) {
Set<ManaType> types = EnumSet.noneOf(ManaType.class);
if (game == null || game.getPhase() == null) {
return types;
}
Permanent land = (Permanent) game.getState().getValue("UntapTargetCost" + source.getSourceId().toString());
if (land != null) {
Abilities<ActivatedManaAbilityImpl> mana = land.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD);
for (ActivatedManaAbilityImpl ability : mana) {
if (ability.definesMana(game)) {
types.addAll(ability.getProducableManaTypes(game));
}
}
}
return types;
}
use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.
the class BattlemagesBracersTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent equipment = game.getPermanent(this.getSourceId());
if (equipment == null || !equipment.isAttachedTo(event.getSourceId())) {
return false;
}
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (stackAbility == null || stackAbility.getStackAbility() instanceof ActivatedManaAbilityImpl) {
return false;
}
getEffects().setValue("stackAbility", stackAbility);
return true;
}
use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.
the class HumanPlayer method playManaAbilities.
protected void playManaAbilities(UUID objectId, Ability abilityToCast, ManaCost unpaid, Game game) {
updateGameStatePriority("playManaAbilities", game);
MageObject object = game.getObject(objectId);
if (object == null) {
return;
}
// can't see lands as playable and must know the reason (if they click on land then they get that message)
if (abilityToCast.getAbilityType() == AbilityType.SPELL) {
Spell spell = game.getStack().getSpell(abilityToCast.getSourceId());
boolean haveManaAbilities = object.getAbilities().stream().anyMatch(a -> a instanceof ManaAbility);
if (spell != null && !spell.isResolving() && haveManaAbilities) {
switch(spell.getCurrentActivatingManaAbilitiesStep()) {
// if you used special mana ability like convoke then normal mana abilities will be restricted to use, see Convoke for details
case BEFORE:
case NORMAL:
break;
case AFTER:
game.informPlayer(this, "You can no longer use activated mana abilities to pay for the current spell (special mana pay already used). Cancel and recast the spell to activate mana abilities first.");
return;
}
}
}
Zone zone = game.getState().getZone(object.getId());
if (zone != null) {
LinkedHashMap<UUID, ActivatedManaAbilityImpl> useableAbilities = getUseableManaAbilities(object, zone, game);
if (!useableAbilities.isEmpty()) {
// eliminates other abilities if one fits perfectly
useableAbilities = ManaUtil.tryToAutoPay(unpaid, useableAbilities);
currentlyUnpaidMana = unpaid;
activateAbility(useableAbilities, object, game);
currentlyUnpaidMana = null;
}
}
}
Aggregations