Search in sources :

Example 26 with SpellAbility

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

the class TargetPriorityTest method test_targetAmount_BadCase.

@Test
public void test_targetAmount_BadCase() {
    // choose targets as enters battlefield (e.g. can't be canceled)
    SpellAbility spell = new SpellAbility(new ManaCostsImpl("R"), "damage 3", Zone.HAND);
    Ability ability = new EntersBattlefieldTriggeredAbility(new DamageMultiEffect(3));
    ability.addTarget(new TargetCreaturePermanentAmount(3));
    addCustomCardWithSpell(playerA, spell, ability, CardType.ENCHANTMENT);
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
    // 
    // 1/1
    addCard(Zone.BATTLEFIELD, playerA, "Memnite", 3);
    // 2/2
    addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 3);
    // 2/2 with ability
    addCard(Zone.BATTLEFIELD, playerA, "Ashcoat Bear", 3);
    // 4/3
    addCard(Zone.BATTLEFIELD, playerA, "Golden Bear", 3);
    // 4/4 with ability
    addCard(Zone.BATTLEFIELD, playerA, "Battering Sliver", 3);
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "damage 3");
    // must damage x3 Balduvian Bears by -1 to keep alive
    checkDamage("pt after", 1, PhaseStep.BEGIN_COMBAT, playerA, "Balduvian Bears", 1);
    // showBattlefield("after", 1, PhaseStep.BEGIN_COMBAT, playerA);
    setStopAt(1, PhaseStep.BEGIN_COMBAT);
    execute();
    assertAllCommandsUsed();
    assertPermanentCount(playerA, "damage 3", 1);
    assertPermanentCount(playerA, "Memnite", 3);
    assertPermanentCount(playerA, "Balduvian Bears", 3);
    assertPermanentCount(playerA, "Ashcoat Bear", 3);
    assertPermanentCount(playerA, "Golden Bear", 3);
    assertPermanentCount(playerA, "Battering Sliver", 3);
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) TargetCreaturePermanentAmount(mage.target.common.TargetCreaturePermanentAmount) DamageMultiEffect(mage.abilities.effects.common.DamageMultiEffect) SpellAbility(mage.abilities.SpellAbility) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Test(org.junit.Test)

Example 27 with SpellAbility

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

the class PolukranosUnchainedEffect 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());
    }
    if (permanent == null) {
        return false;
    }
    SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
    int counters = 12;
    if (!(spellAbility instanceof EscapeAbility) || !spellAbility.getSourceId().equals(source.getSourceId()) || permanent.getZoneChangeCounter(game) != spellAbility.getSourceObjectZoneChangeCounter()) {
        counters = 6;
    }
    List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
    permanent.addCounters(CounterType.P1P1.createInstance(counters), source.getControllerId(), source, game, appliedEffects);
    return true;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) SpellAbility(mage.abilities.SpellAbility) UUID(java.util.UUID) EscapeAbility(mage.abilities.keyword.EscapeAbility)

Example 28 with SpellAbility

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

the class ValkmiraProtectorsShieldTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    SpellAbility spellAbility = (SpellAbility) abilityToModify;
    CardUtil.adjustCost(spellAbility, -2);
    return true;
}
Also used : SpellAbility(mage.abilities.SpellAbility)

Example 29 with SpellAbility

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

the class SealOfTheGuildpactCostReductionEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    MageObject sourceObject = game.getObject(abilityToModify.getSourceId());
    if (sourceObject != null) {
        ObjectColor color1 = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color1");
        ObjectColor color2 = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color2");
        int amount = 0;
        if (color1 != null && sourceObject.getColor(game).contains(color1)) {
            amount++;
        }
        if (color2 != null && sourceObject.getColor(game).contains(color2)) {
            amount++;
        }
        if (amount > 0) {
            SpellAbility spellAbility = (SpellAbility) abilityToModify;
            CardUtil.adjustCost(spellAbility, amount);
        }
        return true;
    }
    return false;
}
Also used : MageObject(mage.MageObject) ObjectColor(mage.ObjectColor) SpellAbility(mage.abilities.SpellAbility)

Example 30 with SpellAbility

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

the class DackFaydenEmblemEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    boolean returnValue = false;
    List<UUID> targetedPermanentIds = new ArrayList<>(0);
    Player player = game.getPlayer(this.getControllerId());
    if (player != null) {
        if (event.getPlayerId().equals(this.getControllerId())) {
            Spell spell = game.getStack().getSpell(event.getTargetId());
            if (spell != null) {
                SpellAbility spellAbility = spell.getSpellAbility();
                for (Mode mode : spellAbility.getModes().values()) {
                    for (Target target : mode.getTargets()) {
                        if (!target.isNotTarget()) {
                            for (UUID targetId : target.getTargets()) {
                                if (game.getBattlefield().containsPermanent(targetId)) {
                                    returnValue = true;
                                    targetedPermanentIds.add(targetId);
                                }
                            }
                        }
                    }
                }
                for (Effect effect : spellAbility.getEffects()) {
                    for (UUID targetId : effect.getTargetPointer().getTargets(game, spellAbility)) {
                        if (game.getBattlefield().containsPermanent(targetId)) {
                            returnValue = true;
                            targetedPermanentIds.add(targetId);
                        }
                    }
                }
            }
        }
    }
    for (Effect effect : this.getEffects()) {
        if (effect instanceof DackFaydenEmblemEffect) {
            DackFaydenEmblemEffect dackEffect = (DackFaydenEmblemEffect) effect;
            List<Permanent> permanents = new ArrayList<>();
            for (UUID permanentId : targetedPermanentIds) {
                Permanent permanent = game.getPermanent(permanentId);
                if (permanent != null) {
                    permanents.add(permanent);
                }
            }
            dackEffect.setTargets(permanents, game);
        }
    }
    return returnValue;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) Mode(mage.abilities.Mode) ArrayList(java.util.ArrayList) SpellAbility(mage.abilities.SpellAbility) Spell(mage.game.stack.Spell) Target(mage.target.Target) Effect(mage.abilities.effects.Effect) 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