Search in sources :

Example 26 with StackAbility

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

the class RepeatedReverberationEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getPlayerId().equals(this.getControllerId())) {
        return false;
    }
    // activated ability
    if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) {
        StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
        if (stackAbility != null && stackAbility.getStackAbility() instanceof LoyaltyAbility) {
            this.getEffects().clear();
            this.addEffect(new RepeatedReverberationEffect().setTargetPointer(new FixedTarget(event.getTargetId(), game)));
            return true;
        }
    }
    // spell
    if (event.getType() == GameEvent.EventType.SPELL_CAST) {
        Spell spell = game.getStack().getSpell(event.getTargetId());
        if (spell != null && spell.isInstantOrSorcery(game)) {
            this.getEffects().clear();
            this.addEffect(new CopyTargetSpellEffect(true).setTargetPointer(new FixedTarget(event.getTargetId(), game)));
            this.addEffect(new CopyTargetSpellEffect(true).setTargetPointer(new FixedTarget(event.getTargetId(), game)));
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) LoyaltyAbility(mage.abilities.LoyaltyAbility) CopyTargetSpellEffect(mage.abilities.effects.common.CopyTargetSpellEffect) StackAbility(mage.game.stack.StackAbility) Spell(mage.game.stack.Spell)

Example 27 with StackAbility

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

the class UnboundFlourishingCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (player != null && controller != null) {
        Object needObject = game.getState().getValue(source.getSourceId() + UnboundFlourishing.needPrefix);
        // copy ability
        if (needObject instanceof StackAbility) {
            StackAbility stackAbility = (StackAbility) needObject;
            stackAbility.createCopyOnStack(game, source, source.getControllerId(), true);
            return true;
        }
        // copy spell
        if (needObject instanceof Spell) {
            Spell spell = (Spell) needObject;
            spell.createCopyOnStack(game, source, source.getControllerId(), true);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) StackAbility(mage.game.stack.StackAbility) Spell(mage.game.stack.Spell)

Example 28 with StackAbility

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

the class WeaverOfHarmonyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (stackAbility == null) {
        return false;
    }
    stackAbility.createCopyOnStack(game, source, source.getControllerId(), true);
    return true;
}
Also used : StackAbility(mage.game.stack.StackAbility)

Example 29 with StackAbility

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

the class GoblinArtisansTarget method canTarget.

@Override
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
    if (!super.canTarget(controllerId, id, source, game)) {
        return false;
    }
    MageObjectReference sourceRef = new MageObjectReference(source.getSourceObject(game), game);
    Spell spell = game.getSpell(id);
    if (spell == null) {
        return false;
    }
    for (StackObject stackObject : game.getStack()) {
        if (!(stackObject instanceof StackAbility)) {
            continue;
        }
        Permanent permanent = ((StackAbility) stackObject).getSourcePermanentOrLKI(game);
        if (permanent != null && !sourceRef.refersTo(permanent, game) && permanent.isCreature(game) && "Goblin Artisans".equals(permanent.getName()) && stackObject.getStackAbility().getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).anyMatch(id::equals)) {
            return false;
        }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) Collection(java.util.Collection) MageObjectReference(mage.MageObjectReference) FilterArtifactSpell(mage.filter.common.FilterArtifactSpell) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) StackAbility(mage.game.stack.StackAbility)

Example 30 with StackAbility

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

the class RingsOfBrighthearthTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getPlayerId().equals(getControllerId())) {
        return false;
    }
    StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
    if (stackAbility == null || stackAbility.getStackAbility() instanceof ActivatedManaAbilityImpl) {
        return false;
    }
    this.getEffects().setValue("stackAbility", stackAbility);
    return true;
}
Also used : ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) StackAbility(mage.game.stack.StackAbility)

Aggregations

StackAbility (mage.game.stack.StackAbility)42 Permanent (mage.game.permanent.Permanent)15 StackObject (mage.game.stack.StackObject)12 Player (mage.players.Player)11 Target (mage.target.Target)9 MageObject (mage.MageObject)8 Ability (mage.abilities.Ability)7 Spell (mage.game.stack.Spell)7 ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)6 GameEvent (mage.game.events.GameEvent)6 Game (mage.game.Game)5 UUID (java.util.UUID)4 MageObjectReference (mage.MageObjectReference)4 PassAbility (mage.abilities.common.PassAbility)4 Mode (mage.abilities.Mode)3 Card (mage.cards.Card)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 ActivatedAbility (mage.abilities.ActivatedAbility)2 LoyaltyAbility (mage.abilities.LoyaltyAbility)2 SpellAbility (mage.abilities.SpellAbility)2