Search in sources :

Example 96 with Ability

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

the class MindleecherLookEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    game.getOpponents(controller.getId()).stream().map(game::getPlayer).map(Player::getLibrary).map(library -> library.getFromTop(game)).forEach(cards::add);
    if (cards.isEmpty()) {
        return false;
    }
    controller.moveCards(cards, Zone.EXILED, source, game);
    cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
    if (cards.isEmpty()) {
        return false;
    }
    cards.getCards(game).stream().forEach(card -> card.setFaceDown(true, game));
    for (Card card : cards.getCards(game)) {
        game.addEffect(new MindleecherCastFromExileEffect(controller.getId()).setTargetPointer(new FixedTarget(card, game)), source);
        game.addEffect(new MindleecherLookEffect(controller.getId()).setTargetPointer(new FixedTarget(card, game)), source);
    }
    return true;
}
Also used : mage.cards(mage.cards) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) MutateAbility(mage.abilities.keyword.MutateAbility) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) Game(mage.game.Game) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl) MutatesSourceTriggeredAbility(mage.abilities.common.MutatesSourceTriggeredAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) mage.constants(mage.constants) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) mage.cards(mage.cards)

Example 97 with Ability

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

the class PakoArcaneRetrieverWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    PakoArcaneRetrieverWatcher watcher = game.getState().getWatcher(PakoArcaneRetrieverWatcher.class);
    if (controller == null || watcher == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    game.getState().getPlayersInRange(controller.getId(), game).stream().map(game::getPlayer).map(Player::getLibrary).map(library -> library.getFromTop(game)).forEach(cards::add);
    controller.moveCards(cards, Zone.EXILED, source, game);
    cards.removeIf(cardId -> game.getState().getZone(cardId) != Zone.EXILED);
    int counters = cards.count(StaticFilters.FILTER_CARD_NON_CREATURE, game);
    if (cards.isEmpty()) {
        return true;
    }
    cards.getCards(game).stream().filter(card -> card.addCounters(CounterType.FETCH.createInstance(), source.getControllerId(), source, game)).filter(card -> !card.isCreature(game)).forEach(card -> watcher.addCard(controller.getId(), card, game));
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null || counters == 0) {
        return true;
    }
    return permanent.addCounters(CounterType.P1P1.createInstance(counters), source.getControllerId(), source, game);
}
Also used : StaticFilters(mage.filter.StaticFilters) java.util(java.util) PartnerWithAbility(mage.abilities.keyword.PartnerWithAbility) mage.cards(mage.cards) AttacksTriggeredAbility(mage.abilities.common.AttacksTriggeredAbility) HasteAbility(mage.abilities.keyword.HasteAbility) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) MageInt(mage.MageInt) Player(mage.players.Player) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) Permanent(mage.game.permanent.Permanent) mage.constants(mage.constants) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) Player(mage.players.Player) mage.cards(mage.cards) Permanent(mage.game.permanent.Permanent)

Example 98 with Ability

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

the class QuickSilverElementalBlueManaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    Permanent creature = game.getPermanent(source.getTargets().getFirstTarget());
    if (permanent != null && creature != null) {
        for (ActivatedAbility ability : creature.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD)) {
            Ability newAbility = ability.copy();
            newAbility.newOriginalId();
            game.addEffect(new GainAbilitySourceEffect(newAbility, Duration.EndOfTurn), source);
        }
        return true;
    }
    return false;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) ActivatedAbility(mage.abilities.ActivatedAbility)

Example 99 with Ability

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

the class RetetherEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Map<Card, Permanent> auraMap = new HashMap<>();
        auraCardsInGraveyard: for (Card aura : controller.getGraveyard().getCards(filterAura, source.getSourceId(), source.getControllerId(), game)) {
            if (aura != null) {
                FilterCreaturePermanent filter = new FilterCreaturePermanent("creature to enchant (" + aura.getLogName() + ')');
                filter.add(new CanBeEnchantedByPredicate(aura));
                Target target = null;
                auraLegalitySearch: for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, playerId, game)) {
                        if (permanent != null) {
                            for (Ability ability : aura.getAbilities()) {
                                if (ability instanceof SpellAbility) {
                                    for (Target abilityTarget : ability.getTargets()) {
                                        if (abilityTarget.possibleTargets(controller.getId(), game).contains(permanent.getId())) {
                                            target = abilityTarget.copy();
                                            break auraLegalitySearch;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (target != null) {
                    target.getFilter().add(CardType.CREATURE.getPredicate());
                    target.setNotTarget(true);
                    if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
                        target.setTargetName("creature to enchant (" + aura.getLogName() + ')');
                        if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
                            Permanent permanent = game.getPermanent(target.getFirstTarget());
                            if (permanent != null && !permanent.cantBeAttachedBy(aura, source, game, true)) {
                                auraMap.put(aura, permanent);
                                game.getState().setValue("attachTo:" + aura.getId(), permanent);
                                continue auraCardsInGraveyard;
                            }
                        }
                    }
                }
                game.informPlayers("No valid creature targets for " + aura.getLogName());
            }
        }
        controller.moveCards(auraMap.keySet(), Zone.BATTLEFIELD, source, game);
        for (Entry<Card, Permanent> entry : auraMap.entrySet()) {
            Card aura = entry.getKey();
            Permanent permanent = entry.getValue();
            if (aura != null && permanent != null) {
                permanent.addAttachment(aura.getId(), source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) HashMap(java.util.HashMap) SpellAbility(mage.abilities.SpellAbility) CanBeEnchantedByPredicate(mage.filter.predicate.permanent.CanBeEnchantedByPredicate) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 100 with Ability

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

the class SerpentsSoulJarWatcher method addPlayable.

static void addPlayable(Ability source, Game game) {
    MageObjectReference mor = new MageObjectReference(source);
    game.getState().getWatcher(SerpentsSoulJarWatcher.class).morMap.computeIfAbsent(mor, m -> new HashMap<>()).compute(source.getControllerId(), CardUtil::setOrIncrementValue);
}
Also used : DiesCreatureTriggeredAbility(mage.abilities.common.DiesCreatureTriggeredAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) PayLifeCost(mage.abilities.costs.common.PayLifeCost) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) HashMap(java.util.HashMap) UUID(java.util.UUID) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) Watcher(mage.watchers.Watcher) TapSourceCost(mage.abilities.costs.common.TapSourceCost) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) ExileZone(mage.game.ExileZone) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) Map(java.util.Map) Card(mage.cards.Card) mage.constants(mage.constants) Ability(mage.abilities.Ability) HashMap(java.util.HashMap) MageObjectReference(mage.MageObjectReference) CardUtil(mage.util.CardUtil)

Aggregations

Ability (mage.abilities.Ability)359 Player (mage.players.Player)173 Permanent (mage.game.permanent.Permanent)134 UUID (java.util.UUID)126 Game (mage.game.Game)123 OneShotEffect (mage.abilities.effects.OneShotEffect)98 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)87 CardSetInfo (mage.cards.CardSetInfo)87 CardImpl (mage.cards.CardImpl)85 CardType (mage.constants.CardType)78 Outcome (mage.constants.Outcome)76 Card (mage.cards.Card)72 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)64 MageObject (mage.MageObject)57 MageInt (mage.MageInt)47 SpellAbility (mage.abilities.SpellAbility)43 Objects (java.util.Objects)38 Zone (mage.constants.Zone)38 mage.constants (mage.constants)37 FilterCard (mage.filter.FilterCard)35