Search in sources :

Example 41 with GainAbilityTargetEffect

use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.

the class HallOfTheBanditLordWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.MANA_PAID) {
        MageObject target = game.getObject(event.getTargetId());
        if (event.getSourceId() != null && event.getSourceId().equals(this.getSourceId()) && target != null && target.isCreature(game) && event.getFlag()) {
            if (target instanceof Spell) {
                this.creatures.add(((Spell) target).getCard().getId());
            }
        }
    }
    if (event.getType() == GameEvent.EventType.COUNTERED) {
        if (creatures.contains(event.getTargetId())) {
            creatures.remove(event.getSourceId());
        }
    }
    if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
        if (creatures.contains(event.getSourceId())) {
            ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
            // spell was e.g. exiled and goes again to stack, so previous cast has not resolved.
            if (zEvent.getToZone() == Zone.STACK) {
                creatures.remove(event.getSourceId());
            }
        }
    }
    if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
        if (creatures.contains(event.getSourceId())) {
            ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
            effect.setTargetPointer(new FixedTarget(event.getSourceId(), game));
            game.addEffect(effect, source);
            creatures.remove(event.getSourceId());
        }
    }
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) MageObject(mage.MageObject) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Spell(mage.game.stack.Spell)

Example 42 with GainAbilityTargetEffect

use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.

the class InsurrectionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean result = false;
    ContinuousEffect gainControl = new GainControlTargetEffect(Duration.EndOfTurn);
    ContinuousEffect gainHaste = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
    for (Permanent creature : game.getBattlefield().getAllActivePermanents(CardType.CREATURE, game)) {
        creature.untap(game);
        gainControl.setTargetPointer(new FixedTarget(creature.getId(), game));
        gainHaste.setTargetPointer(new FixedTarget(creature.getId(), game));
        game.addEffect(gainControl, source);
        game.addEffect(gainHaste, source);
        result = true;
    }
    return result;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 43 with GainAbilityTargetEffect

use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.

the class KillerInstinctEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
    if (player == null || sourceObject == null) {
        return false;
    }
    Library library = player.getLibrary();
    if (library == null || !library.hasCards()) {
        return false;
    }
    Card card = library.getFromTop(game);
    if (card == null) {
        return false;
    }
    player.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
    if (card.isCreature(game) && player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
        Permanent permanent = game.getPermanent(card.getId());
        if (permanent != null) {
            FixedTarget ft = new FixedTarget(permanent, game);
            ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
            effect.setTargetPointer(ft);
            game.addEffect(effect, source);
            Effect sacrificeEffect = new SacrificeTargetEffect("Sacrifice it at the beginning of the next end step", source.getControllerId());
            sacrificeEffect.setTargetPointer(ft);
            game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect), source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SacrificeTargetEffect(mage.abilities.effects.common.SacrificeTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) Library(mage.players.Library) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SacrificeTargetEffect(mage.abilities.effects.common.SacrificeTargetEffect) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 44 with GainAbilityTargetEffect

use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.

the class StrefanMaurerProgenitorPlayVampireEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetCard target = new TargetCardInHand(0, 1, vampireCardFilter);
    if (!player.choose(outcome, player.getHand(), target, game)) {
        return false;
    }
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, true, null);
    Permanent permanent = game.getPermanent(card.getId());
    if (permanent == null) {
        return false;
    }
    game.getCombat().addAttackingCreature(permanent.getId(), game);
    // Gains indestructable until end of turn
    ContinuousEffect effect = new GainAbilityTargetEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn);
    effect.setTargetPointer(new FixedTarget(permanent.getId(), game));
    game.addEffect(effect, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetCardInHand(mage.target.common.TargetCardInHand) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) TargetCard(mage.target.TargetCard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 45 with GainAbilityTargetEffect

use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.

the class UginTheIneffableLookAtFaceDownEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (player == null || sourceObject == null) {
        return false;
    }
    Card card = player.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    // exile and look
    UUID exileZoneId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
    if (player.moveCardsToExile(card, source, game, false, exileZoneId, sourceObject.getIdName() + " (" + player.getName() + ")")) {
        card.turnFaceDown(source, game, source.getControllerId());
        player.lookAtCards(player.getName() + " - " + card.getIdName() + " - " + CardUtil.sdf.format(System.currentTimeMillis()), card, game);
    }
    // create token
    Set<MageObjectReference> tokenObjs = new HashSet<>();
    CreateTokenEffect effect = new CreateTokenEffect(new UginTheIneffableToken());
    effect.apply(game, source);
    // with return ability
    for (UUID addedTokenId : effect.getLastAddedTokenIds()) {
        // display referenced exiled face-down card on token
        SimpleStaticAbility sa = new SimpleStaticAbility(Zone.BATTLEFIELD, new InfoEffect("Referenced object: " + card.getId().toString().substring(0, 3)));
        GainAbilityTargetEffect gainAbilityEffect = new GainAbilityTargetEffect(sa, Duration.WhileOnBattlefield);
        gainAbilityEffect.setTargetPointer(new FixedTarget(addedTokenId));
        game.addEffect(gainAbilityEffect, source);
        // look at face-down card in exile
        UginTheIneffableLookAtFaceDownEffect lookAtEffect = new UginTheIneffableLookAtFaceDownEffect();
        lookAtEffect.setTargetPointer(new FixedTarget(card.getId(), game));
        game.addEffect(lookAtEffect, source);
        tokenObjs.add(new MageObjectReference(addedTokenId, game));
        game.addDelayedTriggeredAbility(new UginTheIneffableDelayedTriggeredAbility(tokenObjs, new MageObjectReference(card, game)), source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) UginTheIneffableToken(mage.game.permanent.token.UginTheIneffableToken) MageObject(mage.MageObject) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) InfoEffect(mage.abilities.effects.common.InfoEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference) HashSet(java.util.HashSet)

Aggregations

GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)125 FixedTarget (mage.target.targetpointer.FixedTarget)96 Permanent (mage.game.permanent.Permanent)93 ContinuousEffect (mage.abilities.effects.ContinuousEffect)76 Player (mage.players.Player)76 Card (mage.cards.Card)42 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)28 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)22 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)21 UUID (java.util.UUID)18 BoostTargetEffect (mage.abilities.effects.common.continuous.BoostTargetEffect)17 Effect (mage.abilities.effects.Effect)16 OneShotEffect (mage.abilities.effects.OneShotEffect)15 FilterCard (mage.filter.FilterCard)15 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)15 TargetPermanent (mage.target.TargetPermanent)15 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)14 SacrificeTargetEffect (mage.abilities.effects.common.SacrificeTargetEffect)13 FilterCreatureCard (mage.filter.common.FilterCreatureCard)12 FixedTargets (mage.target.targetpointer.FixedTargets)12