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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations