Search in sources :

Example 11 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class JusticeEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    MageObject sourceObject = game.getObject(event.getSourceId());
    if (sourceObject != null && sourceObject.getColor(game).isRed()) {
        if (sourceObject instanceof Permanent && sourceObject.isCreature(game) || sourceObject instanceof Spell) {
            this.getEffects().get(0).setValue("damageAmount", event.getAmount());
            this.getEffects().get(0).setTargetPointer(new FixedTarget(game.getControllerId(sourceObject.getId())));
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) Spell(mage.game.stack.Spell)

Example 12 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class KaervekTheMercilessEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
    if (spell != null) {
        int cost = spell.getManaValue();
        Player target = game.getPlayer(source.getFirstTarget());
        if (target != null) {
            target.damage(cost, source.getSourceId(), source, game);
            return true;
        }
        Permanent targetCreature = game.getPermanent(source.getFirstTarget());
        if (targetCreature != null) {
            targetCreature.damage(cost, source.getSourceId(), source, game, false, true);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) Spell(mage.game.stack.Spell)

Example 13 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class KotoseTheSilentSpiderWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.CLEANUP_STEP_POST) {
        morMap.entrySet().removeIf(e -> !e.getKey().zoneCounterIsCurrent(game));
        morMap.values().stream().flatMap(Collection::stream).map(set -> set.removeIf(mor -> !mor.zoneCounterIsCurrent(game)));
        morMap.values().removeIf(Set::isEmpty);
        return;
    }
    if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getAdditionalReference() == null) {
        return;
    }
    Spell spell = game.getSpell(event.getTargetId());
    if (spell == null) {
        return;
    }
    morMap.getOrDefault(event.getAdditionalReference().getApprovingMageObjectReference(), Collections.emptySet()).removeIf(set -> set.stream().anyMatch(mor -> mor.getSourceId().equals(spell.getMainCard().getId()) && mor.getZoneChangeCounter() + 1 == spell.getZoneChangeCounter(game)));
}
Also used : FilterCard(mage.filter.FilterCard) java.util(java.util) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) mage.cards(mage.cards) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Condition(mage.abilities.condition.Condition) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) Collectors(java.util.stream.Collectors) Player(mage.players.Player) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) Spell(mage.game.stack.Spell) mage.constants(mage.constants) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) Ability(mage.abilities.Ability) Spell(mage.game.stack.Spell)

Example 14 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class KozilekDiscardCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    Spell targetSpell = game.getStack().getSpell(ability.getFirstTarget());
    if (targetSpell == null) {
        return false;
    }
    Player player = game.getPlayer(controllerId);
    if (player == null) {
        return false;
    }
    FilterCard filter = new FilterCard("card with mana value of " + targetSpell.getManaValue());
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, targetSpell.getManaValue()));
    TargetCardInHand target = new TargetCardInHand(filter);
    this.getTargets().clear();
    this.getTargets().add(target);
    if (targets.choose(Outcome.Discard, controllerId, source.getSourceId(), game)) {
        for (UUID targetId : targets.get(0).getTargets()) {
            Card card = player.getHand().get(targetId, game);
            if (card == null) {
                return false;
            }
            player.discard(card, true, source, game);
            paid = true;
        }
    }
    return paid;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) FilterSpell(mage.filter.FilterSpell) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 15 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class KumanoFacesKakkazanCounterEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (this.isControlledBy(event.getPlayerId())) {
        Spell spell = game.getSpell(event.getTargetId());
        if (spell != null && spell.isCreature(game)) {
            this.getEffects().clear();
            this.getEffects().add(new KumanoFacesKakkazanCounterEffect(spell.getSourceId()));
            return true;
        }
    }
    return false;
}
Also used : Spell(mage.game.stack.Spell)

Aggregations

Spell (mage.game.stack.Spell)311 Player (mage.players.Player)155 Permanent (mage.game.permanent.Permanent)90 UUID (java.util.UUID)79 MageObject (mage.MageObject)69 Card (mage.cards.Card)51 TargetSpell (mage.target.TargetSpell)48 StackObject (mage.game.stack.StackObject)42 FilterCard (mage.filter.FilterCard)38 FilterSpell (mage.filter.FilterSpell)36 FixedTarget (mage.target.targetpointer.FixedTarget)33 MageObjectReference (mage.MageObjectReference)24 Effect (mage.abilities.effects.Effect)22 OneShotEffect (mage.abilities.effects.OneShotEffect)22 Target (mage.target.Target)22 Ability (mage.abilities.Ability)20 SpellAbility (mage.abilities.SpellAbility)16 FilterPermanent (mage.filter.FilterPermanent)15 TargetCard (mage.target.TargetCard)15 TargetPlayer (mage.target.TargetPlayer)14