Search in sources :

Example 16 with SpellAbility

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

the class InvasionOfTheGiantsWatcher method applies.

@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
    InvasionOfTheGiantsWatcher watcher = game.getState().getWatcher(InvasionOfTheGiantsWatcher.class);
    if (watcher == null) {
        return false;
    }
    if (watcher.getCount(source.getControllerId()) > spellsCast) {
        // only one use
        discard();
        return false;
    }
    if (!(abilityToModify instanceof SpellAbility) || !abilityToModify.isControlledBy(source.getControllerId())) {
        return false;
    }
    Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
    return spellCard != null && spellCard.hasSubtype(SubType.GIANT, game);
}
Also used : SpellAbility(mage.abilities.SpellAbility) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 17 with SpellAbility

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

the class RetetherEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Map<Card, Permanent> auraMap = new HashMap<>();
        auraCardsInGraveyard: for (Card aura : controller.getGraveyard().getCards(filterAura, source.getSourceId(), source.getControllerId(), game)) {
            if (aura != null) {
                FilterCreaturePermanent filter = new FilterCreaturePermanent("creature to enchant (" + aura.getLogName() + ')');
                filter.add(new CanBeEnchantedByPredicate(aura));
                Target target = null;
                auraLegalitySearch: for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, playerId, game)) {
                        if (permanent != null) {
                            for (Ability ability : aura.getAbilities()) {
                                if (ability instanceof SpellAbility) {
                                    for (Target abilityTarget : ability.getTargets()) {
                                        if (abilityTarget.possibleTargets(controller.getId(), game).contains(permanent.getId())) {
                                            target = abilityTarget.copy();
                                            break auraLegalitySearch;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (target != null) {
                    target.getFilter().add(CardType.CREATURE.getPredicate());
                    target.setNotTarget(true);
                    if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
                        target.setTargetName("creature to enchant (" + aura.getLogName() + ')');
                        if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
                            Permanent permanent = game.getPermanent(target.getFirstTarget());
                            if (permanent != null && !permanent.cantBeAttachedBy(aura, source, game, true)) {
                                auraMap.put(aura, permanent);
                                game.getState().setValue("attachTo:" + aura.getId(), permanent);
                                continue auraCardsInGraveyard;
                            }
                        }
                    }
                }
                game.informPlayers("No valid creature targets for " + aura.getLogName());
            }
        }
        controller.moveCards(auraMap.keySet(), Zone.BATTLEFIELD, source, game);
        for (Entry<Card, Permanent> entry : auraMap.entrySet()) {
            Card aura = entry.getKey();
            Permanent permanent = entry.getValue();
            if (aura != null && permanent != null) {
                permanent.addAttachment(aura.getId(), source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) HashMap(java.util.HashMap) SpellAbility(mage.abilities.SpellAbility) CanBeEnchantedByPredicate(mage.filter.predicate.permanent.CanBeEnchantedByPredicate) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 18 with SpellAbility

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

the class SenatorLottDodSpellsTargetingYouCostModificationEffect method applies.

@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
    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 19 with SpellAbility

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

the class TitheTakerCostReductionEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    if (abilityToModify.getAbilityType() == AbilityType.SPELL) {
        SpellAbility spellAbility = (SpellAbility) abilityToModify;
        CardUtil.adjustCost(spellAbility, -1);
    }
    if (abilityToModify.getAbilityType() == AbilityType.ACTIVATED) {
        CardUtil.increaseCost(abilityToModify, 1);
    }
    return true;
}
Also used : SpellAbility(mage.abilities.SpellAbility)

Example 20 with SpellAbility

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

the class TizerusChargerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null && source.getAbilityType() == AbilityType.STATIC) {
        permanent = game.getPermanentEntering(source.getSourceId());
    }
    Player player = game.getPlayer(source.getControllerId());
    if (permanent == null || player == null) {
        return false;
    }
    SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
    if (!(spellAbility instanceof EscapeAbility) || !spellAbility.getSourceId().equals(source.getSourceId()) || permanent.getZoneChangeCounter(game) != spellAbility.getSourceObjectZoneChangeCounter()) {
        return false;
    }
    List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
    CounterType counterType = player.chooseUse(outcome, "Choose +1/+1 or flying", null, "+1/+1", "Flying", source, game) ? CounterType.P1P1 : CounterType.FLYING;
    permanent.addCounters(counterType.createInstance(), source.getControllerId(), source, game, appliedEffects);
    return true;
}
Also used : Player(mage.players.Player) CounterType(mage.counters.CounterType) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) SpellAbility(mage.abilities.SpellAbility) UUID(java.util.UUID) EscapeAbility(mage.abilities.keyword.EscapeAbility)

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