Search in sources :

Example 6 with TriggeredAbility

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

the class HushbringerEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    Ability ability = (Ability) getValue("targetAbility");
    if (ability == null || ability.getAbilityType() != AbilityType.TRIGGERED) {
        return false;
    }
    Permanent permanent;
    switch(event.getType()) {
        case ENTERS_THE_BATTLEFIELD:
            permanent = ((EntersTheBattlefieldEvent) event).getTarget();
            break;
        case ZONE_CHANGE:
            ZoneChangeEvent zEvent = ((ZoneChangeEvent) event);
            if (!zEvent.isDiesEvent()) {
                return false;
            }
            permanent = zEvent.getTarget();
            break;
        default:
            return false;
    }
    if (permanent == null || !permanent.isCreature(game)) {
        return false;
    }
    return (((TriggeredAbility) ability).checkTrigger(event, game));
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) LifelinkAbility(mage.abilities.keyword.LifelinkAbility) TriggeredAbility(mage.abilities.TriggeredAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) Ability(mage.abilities.Ability) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent)

Example 7 with TriggeredAbility

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

the class OrTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    boolean toRet = false;
    for (int i = 0; i < triggeredAbilities.length; i++) {
        TriggeredAbility ability = triggeredAbilities[i];
        if (ability.checkEventType(event, game) && ability.checkTrigger(event, game)) {
            triggeringAbilities.add(i);
            toRet = true;
        }
    }
    return toRet;
}
Also used : TriggeredAbility(mage.abilities.TriggeredAbility)

Example 8 with TriggeredAbility

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

the class ForceProjectionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (controller != null && permanent != null) {
        // Create a token that is a copy of target creature
        CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, true);
        effect.setTargetPointer(new FixedTarget(permanent, game));
        // except that it is an Illusion in addition to its other types
        effect.setAdditionalSubType(SubType.SPIRIT);
        effect.apply(game, source);
        // and gains "When this creature becomes the target of a spell, sacrifice it."
        Effect sacrificeEffect = new SacrificeSourceEffect();
        sacrificeEffect.setTargetPointer(new FixedTarget(effect.getAddedPermanents().get(0), game));
        TriggeredAbility ability = new BecomesTargetTriggeredAbility(sacrificeEffect, new FilterSpell());
        game.addTriggeredAbility(ability, null);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) BecomesTargetTriggeredAbility(mage.abilities.common.BecomesTargetTriggeredAbility) Player(mage.players.Player) FilterSpell(mage.filter.FilterSpell) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) SacrificeSourceEffect(mage.abilities.effects.common.SacrificeSourceEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) ScryEffect(mage.abilities.effects.keyword.ScryEffect) Effect(mage.abilities.effects.Effect) SacrificeSourceEffect(mage.abilities.effects.common.SacrificeSourceEffect) TriggeredAbility(mage.abilities.TriggeredAbility) BecomesTargetTriggeredAbility(mage.abilities.common.BecomesTargetTriggeredAbility) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect)

Example 9 with TriggeredAbility

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

the class TheBookOfVileDarknessEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Set<MageObjectReference> morSet = (Set<MageObjectReference>) getValue("BookEyeHand");
    if (morSet == null) {
        return false;
    }
    Token token = new VecnaToken();
    for (MageObjectReference mor : morSet) {
        // the card object in the mor doesn't work, so the permanent object is used
        Permanent card = mor.getPermanentOrLKIBattlefield(game);
        if (card == null) {
            continue;
        }
        for (Ability ability : card.getAbilities(game)) {
            if (ability instanceof TriggeredAbility) {
                Ability copyAbility = ability.copy();
                copyAbility.newId();
                copyAbility.setControllerId(source.getControllerId());
                token.addAbility(copyAbility);
            }
        }
    }
    return token.putOntoBattlefield(1, game, source, source.getControllerId());
}
Also used : BeginningOfEndStepTriggeredAbility(mage.abilities.common.BeginningOfEndStepTriggeredAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TriggeredAbility(mage.abilities.TriggeredAbility) Ability(mage.abilities.Ability) HashSet(java.util.HashSet) Set(java.util.Set) FilterPermanent(mage.filter.FilterPermanent) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) VecnaToken(mage.game.permanent.token.VecnaToken) Token(mage.game.permanent.token.Token) ZombieToken(mage.game.permanent.token.ZombieToken) VecnaToken(mage.game.permanent.token.VecnaToken) BeginningOfEndStepTriggeredAbility(mage.abilities.common.BeginningOfEndStepTriggeredAbility) TriggeredAbility(mage.abilities.TriggeredAbility) MageObjectReference(mage.MageObjectReference)

Aggregations

TriggeredAbility (mage.abilities.TriggeredAbility)9 Ability (mage.abilities.Ability)4 Permanent (mage.game.permanent.Permanent)3 Player (mage.players.Player)3 ActivatedAbility (mage.abilities.ActivatedAbility)2 PassAbility (mage.abilities.common.PassAbility)2 GameEvent (mage.game.events.GameEvent)2 StackAbility (mage.game.stack.StackAbility)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 MageObject (mage.MageObject)1 MageObjectReference (mage.MageObjectReference)1 Mana (mage.Mana)1 SpellAbility (mage.abilities.SpellAbility)1 BecomesTargetTriggeredAbility (mage.abilities.common.BecomesTargetTriggeredAbility)1 BeginningOfEndStepTriggeredAbility (mage.abilities.common.BeginningOfEndStepTriggeredAbility)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 InvertCondition (mage.abilities.condition.InvertCondition)1 ConditionalInterveningIfTriggeredAbility (mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility)1