Search in sources :

Example 31 with Spell

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

the class ReplicateCopyEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.sourceId)) {
        StackObject spell = game.getStack().getStackObject(this.sourceId);
        if (spell instanceof Spell) {
            Card card = ((Spell) spell).getCard();
            if (card != null) {
                for (Ability ability : card.getAbilities(game)) {
                    if (ability instanceof ReplicateAbility) {
                        if (ability.isActivated()) {
                            for (Effect effect : this.getEffects()) {
                                effect.setValue("ReplicateSpell", spell);
                                effect.setValue("ReplicateCount", ((ReplicateAbility) ability).getActivateCount());
                            }
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : StaticAbility(mage.abilities.StaticAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) StackObject(mage.game.stack.StackObject) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 32 with Spell

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

the class ArclightPhoenixWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.SPELL_CAST) {
        Spell spell = game.getStack().getSpell(event.getTargetId());
        if (spell == null || !spell.isInstantOrSorcery(game)) {
            return;
        }
        this.instantSorceryCount.putIfAbsent(spell.getControllerId(), 0);
        this.instantSorceryCount.compute(spell.getControllerId(), (k, a) -> a + 1);
    }
}
Also used : Spell(mage.game.stack.Spell)

Example 33 with Spell

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

the class ArchfiendsVesselEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (super.checkTrigger(event, game)) {
        if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
            EntersTheBattlefieldEvent entersTheBattlefieldEvent = (EntersTheBattlefieldEvent) event;
            if (entersTheBattlefieldEvent.getTargetId().equals(getSourceId()) && entersTheBattlefieldEvent.getFromZone() == Zone.GRAVEYARD) {
                return true;
            } else {
                SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
                List<Spell> spellsCastFromGraveyard = watcher.getSpellsCastFromGraveyardThisTurn(getControllerId());
                if (spellsCastFromGraveyard != null) {
                    return spellsCastFromGraveyard.stream().anyMatch(spell -> spell.getMainCard().getId().equals((entersTheBattlefieldEvent.getTarget().getMainCard().getId())));
                }
            }
        }
    }
    return false;
}
Also used : EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) Spell(mage.game.stack.Spell)

Example 34 with Spell

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

the class BingoCount method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
    if (spell != null) {
        if (spell.getManaValue() > 9) {
            return true;
        }
        MageObject mageObject = game.getObject(source.getSourceId());
        if (mageObject != null) {
            // Map<number, amount of counters>
            Map<Integer, Integer> chipCounters = new HashMap<>();
            if (game.getState().getValue(mageObject.getId() + "_chip") != null) {
                chipCounters.putAll((Map<Integer, Integer>) game.getState().getValue(mageObject.getId() + "_chip"));
            }
            chipCounters.putIfAbsent(spell.getManaValue(), 0);
            chipCounters.put(spell.getManaValue(), chipCounters.get(spell.getManaValue()) + 1);
            game.getState().setValue(mageObject.getId() + "_chip", chipCounters);
            if (mageObject instanceof Permanent) {
                StringBuilder sb = new StringBuilder();
                int i = 0;
                for (Map.Entry<Integer, Integer> entry : chipCounters.entrySet()) {
                    i++;
                    sb.append(entry.getKey());
                    if (i < chipCounters.size()) {
                        sb.append(", ");
                    }
                }
                ((Permanent) mageObject).addInfo("chip counters", CardUtil.addToolTipMarkTags("Chip counters at: " + sb), game);
                new AddCountersSourceEffect(CounterType.CHIP.createInstance()).apply(game, source);
            }
            return true;
        }
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Permanent(mage.game.permanent.Permanent) HashMap(java.util.HashMap) MageObject(mage.MageObject) HashMap(java.util.HashMap) Map(java.util.Map) Spell(mage.game.stack.Spell) FilterSpell(mage.filter.FilterSpell)

Example 35 with Spell

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

the class BrineboundGiftTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    switch(event.getType()) {
        case ENTERS_THE_BATTLEFIELD:
            return event.getTargetId().equals(getSourceId());
        case TARGETED:
            break;
        default:
            return false;
    }
    Permanent permanent = this.getSourcePermanentOrLKI(game);
    if (permanent == null || !event.getTargetId().equals(permanent.getAttachedTo())) {
        return false;
    }
    Spell spell = game.getSpell(event.getSourceId());
    return spell != null && spell.hasSubtype(SubType.AURA, game);
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) 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