Search in sources :

Example 41 with SpellAbility

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

the class HydroidKrasisEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Object obj = getValue(CastSourceTriggeredAbility.SOURCE_CAST_SPELL_ABILITY);
    if (!(obj instanceof SpellAbility)) {
        return false;
    }
    int halfCost = Math.floorDiv(((SpellAbility) obj).getManaCostsToPay().getX(), 2);
    player.drawCards(halfCost, source, game);
    player.gainLife(halfCost, game, source);
    return true;
}
Also used : Player(mage.players.Player) SpellAbility(mage.abilities.SpellAbility)

Example 42 with SpellAbility

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

the class EntersBattlefieldWithXCountersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        if (source.getAbilityType() == AbilityType.STATIC) {
            permanent = game.getPermanentEntering(source.getSourceId());
        }
    }
    if (permanent != null) {
        SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
        if (spellAbility != null && spellAbility.getSourceId().equals(source.getSourceId()) && permanent.getZoneChangeCounter(game) == spellAbility.getSourceObjectZoneChangeCounter()) {
            if (spellAbility.getSourceId().equals(source.getSourceId())) {
                // put into play by normal cast
                int amount = spellAbility.getManaCostsToPay().getX();
                if (amount > 0) {
                    Counter counterToAdd = counter.copy();
                    counterToAdd.add(amount - counter.getCount());
                    List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
                    permanent.addCounters(counterToAdd, source.getControllerId(), source, game, appliedEffects);
                }
            }
        }
    }
    return true;
}
Also used : Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) SpellAbility(mage.abilities.SpellAbility) UUID(java.util.UUID)

Example 43 with SpellAbility

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

the class SpellsCostIncreasingAllEffect method applies.

@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
    if (abilityToModify instanceof SpellAbility) {
        Player abilityController = game.getPlayer(abilityToModify.getControllerId());
        Player sourceController = game.getPlayer(source.getControllerId());
        if (abilityController == null || sourceController == null) {
            return false;
        }
        switch(this.targetController) {
            case YOU:
                if (!sourceController.getId().equals(abilityController.getId())) {
                    return false;
                }
                break;
            case OPPONENT:
                if (!sourceController.hasOpponent(abilityController.getId(), game)) {
                    return false;
                }
                break;
            case ANY:
                break;
            default:
                throw new IllegalArgumentException("Unsupported TargetController " + this.targetController);
        }
        Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
        if (spell != null) {
            // real cast with put on stack
            return this.filter.match(spell, game);
        } else {
            // get playable and other staff without put on stack
            // used at least for flashback ability because Flashback ability doesn't use stack
            Card sourceCard = game.getCard(abilityToModify.getSourceId());
            return this.filter.match(sourceCard, game);
        }
    }
    return false;
}
Also used : Player(mage.players.Player) SpellAbility(mage.abilities.SpellAbility) Spell(mage.game.stack.Spell) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 44 with SpellAbility

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

the class SplitCard method getAbilities.

@Override
public Abilities<Ability> getAbilities(Game game) {
    Abilities<Ability> allAbilites = new AbilitiesImpl<>();
    for (Ability ability : super.getAbilities(game)) {
        // TODO: why it here, for GUI's cleanup in card texts? Maybe it can be removed, see mdf cards
        if (ability instanceof SpellAbility && (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT || ((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT_AFTERMATH)) {
            continue;
        }
        allAbilites.add(ability);
    }
    allAbilites.addAll(leftHalfCard.getAbilities(game));
    allAbilites.addAll(rightHalfCard.getAbilities(game));
    return allAbilites;
}
Also used : SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) AbilitiesImpl(mage.abilities.AbilitiesImpl) SpellAbility(mage.abilities.SpellAbility)

Example 45 with SpellAbility

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

the class SplitCard method getAbilities.

@Override
public Abilities<Ability> getAbilities() {
    Abilities<Ability> allAbilites = new AbilitiesImpl<>();
    for (Ability ability : super.getAbilities()) {
        // TODO: why it here, for GUI's cleanup in card texts? Maybe it can be removed, see mdf cards
        if (ability instanceof SpellAbility && (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT || ((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT_AFTERMATH)) {
            continue;
        }
        allAbilites.add(ability);
    }
    allAbilites.addAll(leftHalfCard.getAbilities());
    allAbilites.addAll(rightHalfCard.getAbilities());
    return allAbilites;
}
Also used : SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) AbilitiesImpl(mage.abilities.AbilitiesImpl) 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