Search in sources :

Example 46 with SpellAbility

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

the class PermanentImpl method applyDamage.

@Override
public int applyDamage(Game game) {
    if (markedLifelink > 0) {
        Player player = game.getPlayer(this.getControllerId());
        player.gainLife(markedLifelink, game, null);
        markedLifelink = 0;
    }
    if (markedDamage == null) {
        return 0;
    }
    for (MarkedDamageInfo mdi : markedDamage) {
        Ability source = null;
        if (mdi.sourceObject instanceof PermanentToken) {
            /* Tokens dont have a spellAbility. We must make a phony one as the source so the events in addCounters
                 * can trace the source back to an object/controller.
                 */
            source = new SpellAbility(null, ((PermanentToken) mdi.sourceObject).name);
            source.setSourceId(((PermanentToken) mdi.sourceObject).objectId);
        } else if (mdi.sourceObject instanceof Permanent) {
            source = ((Permanent) mdi.sourceObject).getSpellAbility();
        }
        if (mdi.addCounters) {
            addCounters(mdi.counter, game.getControllerId(mdi.sourceObject.getId()), source, game);
        } else {
            removeCounters(mdi.counter, source, game);
        }
    }
    markedDamage.clear();
    return 0;
}
Also used : SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) SpellAbility(mage.abilities.SpellAbility)

Example 47 with SpellAbility

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

the class GenesisHydraPutOntoBattlefieldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Object obj = getValue(CastSourceTriggeredAbility.SOURCE_CAST_SPELL_ABILITY);
    if (controller != null && obj instanceof SpellAbility) {
        int count = ((SpellAbility) obj).getManaCostsToPay().getX();
        if (count > 0) {
            Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, count));
            controller.revealCards(source, cards, game);
            FilterCard filter = new FilterPermanentCard("a nonland permanent card with mana value " + count + " or less to put onto the battlefield");
            filter.add(Predicates.not(CardType.LAND.getPredicate()));
            filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, count + 1));
            TargetCard target1 = new TargetCard(Zone.LIBRARY, filter);
            target1.setRequired(false);
            if (cards.count(filter, controller.getId(), source.getSourceId(), game) > 0) {
                if (controller.choose(Outcome.PutCardInPlay, cards, target1, game)) {
                    Card card = cards.get(target1.getFirstTarget(), game);
                    if (card != null) {
                        cards.remove(card);
                        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                    }
                    target1.clearChosen();
                } else {
                    game.informPlayers(controller.getLogName() + " didn't choose anything");
                }
            } else {
                game.informPlayers("No nonland permanent card with mana value " + count + " or less to choose.");
            }
            if (!cards.isEmpty()) {
                controller.moveCards(cards, Zone.LIBRARY, source, game);
                controller.shuffleLibrary(source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) SpellAbility(mage.abilities.SpellAbility) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) TargetCard(mage.target.TargetCard)

Example 48 with SpellAbility

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

the class InfectiousCurseCostReductionEffect method applies.

@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
    if (!(abilityToModify instanceof SpellAbility)) {
        return false;
    }
    if (!source.isControlledBy(abilityToModify.getControllerId())) {
        return false;
    }
    Permanent enchantment = game.getPermanent(source.getSourceId());
    if (enchantment == null || enchantment.getAttachedTo() == null) {
        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);
    }
    // try to reduce all the time (if it possible to target)
    return allTargets.stream().anyMatch(target -> Objects.equals(target, enchantment.getAttachedTo()));
}
Also used : Permanent(mage.game.permanent.Permanent) SpellAbility(mage.abilities.SpellAbility) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 49 with SpellAbility

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

the class MinamosMeddlingCounterTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject == null) {
        return false;
    }
    for (UUID targetId : getTargetPointer().getTargets(game, source)) {
        Spell spell = game.getStack().getSpell(targetId);
        if (spell == null) {
            continue;
        }
        game.getStack().counter(targetId, source, game);
        Player spellController = game.getPlayer(spell.getControllerId());
        if (spellController == null) {
            continue;
        }
        spellController.revealCards(sourceObject.getName(), spellController.getHand(), game);
        Cards cardsToDiscard = new CardsImpl();
        for (SpellAbility spellAbility : spell.getSpellAbilities()) {
            if (spellAbility.getSpellAbilityType() == SpellAbilityType.SPLICE) {
                for (Card card : spellController.getHand().getCards(game)) {
                    if (card.getName().equals(spellAbility.getCardName())) {
                        cardsToDiscard.add(card);
                    }
                }
            }
        }
        if (!cardsToDiscard.isEmpty()) {
            spellController.discard(cardsToDiscard, false, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) SpellAbility(mage.abilities.SpellAbility) UUID(java.util.UUID) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell)

Example 50 with SpellAbility

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

the class NeverwinterHydraEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    if (permanent == null || player == null) {
        return true;
    }
    SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
    if (spellAbility == null || !spellAbility.getSourceId().equals(source.getSourceId()) || permanent.getZoneChangeCounter(game) != spellAbility.getSourceObjectZoneChangeCounter()) {
        return true;
    }
    if (!spellAbility.getSourceId().equals(source.getSourceId())) {
        return true;
    }
    // put into play by normal cast
    int xValue = spellAbility.getManaCostsToPay().getX();
    if (xValue < 1) {
        return false;
    }
    int amount = player.rollDice(outcome, source, game, 6, xValue, 0).stream().mapToInt(x -> x).sum();
    List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
    permanent.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game, appliedEffects);
    return true;
}
Also used : EntersBattlefieldEffect(mage.abilities.effects.EntersBattlefieldEffect) AsEntersBattlefieldAbility(mage.abilities.common.AsEntersBattlefieldAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) Player(mage.players.Player) ArrayList(java.util.ArrayList) CardSetInfo(mage.cards.CardSetInfo) SpellAbility(mage.abilities.SpellAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Game(mage.game.Game) List(java.util.List) WardAbility(mage.abilities.keyword.WardAbility) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) TrampleAbility(mage.abilities.keyword.TrampleAbility) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) SpellAbility(mage.abilities.SpellAbility) UUID(java.util.UUID)

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