Search in sources :

Example 11 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class MonasterySiegeCostIncreaseEffect method applies.

@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
    if (!modeDragons.apply(game, source)) {
        return false;
    }
    if (!(abilityToModify instanceof SpellAbility)) {
        return false;
    }
    if (!game.getOpponents(source.getControllerId()).contains(abilityToModify.getControllerId())) {
        return false;
    }
    Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
    Set<UUID> allTargets;
    if (spell != null) {
        // real cast
        allTargets = CardUtil.getAllSelectedTargets(abilityToModify, game);
    } else {
        // playable
        allTargets = CardUtil.getAllPossibleTargets(abilityToModify, game);
        // can target without cost increase
        if (allTargets.stream().anyMatch(target -> !isTargetCompatible(target, source, game))) {
            return false;
        }
        ;
    }
    return allTargets.stream().anyMatch(target -> isTargetCompatible(target, source, game));
}
Also used : SpellAbility(mage.abilities.SpellAbility) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 12 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class TargetsHaveToTargetPermanentIfAbleEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetingPlayer = game.getPlayer(event.getPlayerId());
    if (controller != null && // TODO: This target handling does only work for non AI players so AI logic
    targetingPlayer.isHuman() && controller.hasOpponent(event.getPlayerId(), game)) {
        StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
        if (stackObject.isCopy()) {
            return false;
        }
        Ability stackAbility = stackObject.getStackAbility();
        // Ensure that this ability is activated or a cast spell, because Flag Bearer effects don't require triggered abilities to choose a Standard Bearer
        if (!(stackAbility instanceof ActivatedAbility) && !(stackAbility instanceof SpellAbility)) {
            return false;
        }
        // Also check that targeting player controls the ability
        if (!stackAbility.isControlledBy(targetingPlayer.getId())) {
            return false;
        }
        Ability ability = (Ability) getValue("targetAbility");
        if (ability != null) {
            // Get all the allowed permanents on the battlefield in range of the abilities controller
            List<Permanent> allowedPermanents = game.getBattlefield().getActivePermanents(filter, event.getPlayerId(), event.getSourceId(), game);
            if (!allowedPermanents.isEmpty()) {
                boolean canTargetAllowedPermanent = false;
                for (UUID modeId : ability.getModes().getSelectedModes()) {
                    ability.getModes().setActiveMode(modeId);
                    for (Target target : ability.getTargets()) {
                        // Check if already targeted
                        for (Permanent allowedPermanent : allowedPermanents) {
                            if (target.getTargets().contains(allowedPermanent.getId())) {
                                return false;
                            }
                            if (target.canTarget(stackObject.getControllerId(), allowedPermanent.getId(), source, game)) {
                                canTargetAllowedPermanent = true;
                            }
                        }
                    }
                }
                return canTargetAllowedPermanent;
            }
        }
    }
    return false;
}
Also used : SpellAbility(mage.abilities.SpellAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) ActivatedAbility(mage.abilities.ActivatedAbility) SpellAbility(mage.abilities.SpellAbility) UUID(java.util.UUID)

Example 13 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class ComputerPlayer6 method checkForRepeatedAction.

private boolean checkForRepeatedAction(Game sim, SimulationNode2 node, Ability action, UUID playerId) {
    // pass or casting two times a spell multiple times on hand is ok
    if (action instanceof PassAbility || action instanceof SpellAbility || action.getAbilityType() == AbilityType.MANA) {
        return false;
    }
    int newVal = GameStateEvaluator2.evaluate(playerId, sim).getTotalScore();
    SimulationNode2 test = node.getParent();
    while (test != null) {
        if (test.getPlayerId().equals(playerId)) {
            if (test.getAbilities() != null && test.getAbilities().size() == 1) {
                if (action.toString().equals(test.getAbilities().get(0).toString())) {
                    if (test.getParent() != null) {
                        Game prevGame = node.getGame();
                        if (prevGame != null) {
                            int oldVal = GameStateEvaluator2.evaluate(playerId, prevGame).getTotalScore();
                            if (oldVal >= newVal) {
                                return true;
                            }
                        }
                    }
                }
            }
        }
        test = test.getParent();
    }
    return false;
}
Also used : PassAbility(mage.abilities.common.PassAbility) Game(mage.game.Game) SpellAbility(mage.abilities.SpellAbility)

Example 14 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class CurseOfSilenceTriggeredAbility method applies.

@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
    if (abilityToModify instanceof SpellAbility) {
        Permanent enchantment = source.getSourcePermanentIfItStillExists(game);
        if (enchantment != null && abilityToModify.isControlledBy(enchantment.getAttachedTo())) {
            Card card = game.getCard(abilityToModify.getSourceId());
            String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
            if (card != null && cardName != null && !cardName.isEmpty()) {
                return CardUtil.haveSameNames(card, cardName, game);
            }
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) SpellAbility(mage.abilities.SpellAbility) Card(mage.cards.Card)

Example 15 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class ExplosiveSingularityEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    SpellAbility spellAbility = (SpellAbility) abilityToModify;
    int reduction;
    if (game.inCheckPlayableState()) {
        reduction = game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_UNTAPPED_CREATURES, source.getSourceId(), source.getControllerId(), game);
    } else {
        reduction = ((List<Permanent>) spellAbility.getEffects().get(0).getValue("tappedPermanents")).size();
    }
    CardUtil.adjustCost(spellAbility, reduction);
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) SpellAbility(mage.abilities.SpellAbility)

Aggregations

SpellAbility (mage.abilities.SpellAbility)75 Player (mage.players.Player)32 UUID (java.util.UUID)22 Card (mage.cards.Card)21 Permanent (mage.game.permanent.Permanent)21 Ability (mage.abilities.Ability)16 Spell (mage.game.stack.Spell)12 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)10 FilterCard (mage.filter.FilterCard)9 Iterator (java.util.Iterator)8 MageObject (mage.MageObject)7 Target (mage.target.Target)7 ArrayList (java.util.ArrayList)6 ApprovingObject (mage.ApprovingObject)4 ActivatedAbility (mage.abilities.ActivatedAbility)4 Cost (mage.abilities.costs.Cost)4 Effect (mage.abilities.effects.Effect)4 Outcome (mage.constants.Outcome)4 FilterPermanent (mage.filter.FilterPermanent)4 PassAbility (mage.abilities.common.PassAbility)3