Search in sources :

Example 1 with SharesCreatureTypePredicate

use of mage.filter.predicate.mageobject.SharesCreatureTypePredicate in project mage by magefree.

the class TajuruParagonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 6));
    player.revealCards(source, cards, game);
    Permanent permanent = source.getSourcePermanentOrLKI(game);
    if (permanent != null) {
        FilterCard filter = new FilterCard("card that shares a creature type with " + permanent.getName());
        filter.add(new SharesCreatureTypePredicate(permanent));
        TargetCard target = new TargetCardInLibrary(0, 1, filter);
        player.choose(outcome, cards, target, game);
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            player.moveCards(card, Zone.HAND, source, game);
            cards.remove(card);
        }
    }
    player.putCardsOnBottomOfLibrary(cards, game, source, false);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 2 with SharesCreatureTypePredicate

use of mage.filter.predicate.mageobject.SharesCreatureTypePredicate in project mage by magefree.

the class PyreOfHeroesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sacrificedPermanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
            if (!sacrificeCost.getPermanents().isEmpty()) {
                sacrificedPermanent = sacrificeCost.getPermanents().get(0);
            }
            break;
        }
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (sacrificedPermanent == null || controller == null) {
        return false;
    }
    int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
    FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
    filter.add(CardType.CREATURE.getPredicate());
    filter.add(new SharesCreatureTypePredicate(sacrificedPermanent));
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 3 with SharesCreatureTypePredicate

use of mage.filter.predicate.mageobject.SharesCreatureTypePredicate in project mage by magefree.

the class SharedAnimosityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (permanent == null) {
        return false;
    }
    FilterPermanent filter = new FilterAttackingCreature();
    filter.add(new SharesCreatureTypePredicate(permanent));
    filter.add(AnotherPredicate.instance);
    int count = game.getBattlefield().count(filter, permanent.getId(), source.getControllerId(), game);
    if (count > 0) {
        game.addEffect(new BoostTargetEffect(count, 0, Duration.EndOfTurn).setTargetPointer(new FixedTarget(permanent, game)), source);
    }
    return true;
}
Also used : FilterAttackingCreature(mage.filter.common.FilterAttackingCreature) FixedTarget(mage.target.targetpointer.FixedTarget) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate) BoostTargetEffect(mage.abilities.effects.common.continuous.BoostTargetEffect)

Example 4 with SharesCreatureTypePredicate

use of mage.filter.predicate.mageobject.SharesCreatureTypePredicate in project mage by magefree.

the class ReinsOfTheVinesteedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card aura = game.getCard(source.getSourceId());
    if (aura != null && game.getState().getZone(aura.getId()) == Zone.GRAVEYARD) {
        Player controller = game.getPlayer(source.getControllerId());
        Permanent lastStateAura = (Permanent) game.getLastKnownInformation(aura.getId(), Zone.BATTLEFIELD);
        Permanent lastStateCreature = game.getPermanentOrLKIBattlefield(lastStateAura.getAttachedTo());
        if (lastStateCreature == null) {
            return false;
        }
        FilterPermanent FILTER = new FilterCreaturePermanent("creature that shares a creature type with " + lastStateCreature.getName());
        FILTER.add(new SharesCreatureTypePredicate(lastStateCreature));
        TargetPermanent target = new TargetPermanent(FILTER);
        target.setNotTarget(true);
        if (controller != null && controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
            Permanent targetPermanent = game.getPermanent(target.getFirstTarget());
            if (!targetPermanent.cantBeAttachedBy(aura, source, game, false)) {
                game.getState().setValue("attachTo:" + aura.getId(), targetPermanent);
                controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
                return targetPermanent.addAttachment(aura.getId(), source, game);
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate) TargetPermanent(mage.target.TargetPermanent) Card(mage.cards.Card)

Example 5 with SharesCreatureTypePredicate

use of mage.filter.predicate.mageobject.SharesCreatureTypePredicate in project mage by magefree.

the class WeightOfConscienceTarget method canTarget.

@Override
public boolean canTarget(UUID id, Ability source, Game game) {
    if (!super.canTarget(id, game)) {
        return false;
    }
    Permanent targetPermanent = game.getPermanent(id);
    if (targetPermanent == null) {
        return false;
    }
    if (this.getTargets().isEmpty()) {
        List<Permanent> permanentList = game.getBattlefield().getActivePermanents(filterUntapped, source.getControllerId(), source.getSourceId(), game);
        if (permanentList.size() < 2) {
            return false;
        }
        for (Permanent permanent : permanentList) {
            if (permanent.isAllCreatureTypes(game)) {
                return true;
            }
            FilterPermanent filter = filterUntapped.copy();
            filter.add(new SharesCreatureTypePredicate(permanent));
            if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 1) {
                return true;
            }
        }
    } else {
        Permanent firstTarget = game.getPermanent(this.getTargets().get(0));
        return firstTarget != null && firstTarget.shareCreatureTypes(game, targetPermanent);
    }
    return false;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate)

Aggregations

SharesCreatureTypePredicate (mage.filter.predicate.mageobject.SharesCreatureTypePredicate)8 Permanent (mage.game.permanent.Permanent)8 Player (mage.players.Player)6 FilterPermanent (mage.filter.FilterPermanent)4 TargetPermanent (mage.target.TargetPermanent)4 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)4 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)4 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)3 Cost (mage.abilities.costs.Cost)2 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)2 Card (mage.cards.Card)2 FilterCard (mage.filter.FilterCard)2 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)2 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)2 TargetCard (mage.target.TargetCard)2 TapSourceCost (mage.abilities.costs.common.TapSourceCost)1 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)1 DestroyAllEffect (mage.abilities.effects.common.DestroyAllEffect)1 BoostTargetEffect (mage.abilities.effects.common.continuous.BoostTargetEffect)1 FilterAttackingCreature (mage.filter.common.FilterAttackingCreature)1