use of mage.MageItem in project mage by magefree.
the class WillScholarOfFrostEffect 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(targetPointer.getTargets(game, source));
Map<UUID, Integer> playerMap = cards.getCards(game).stream().filter(Objects::nonNull).map(MageItem::getId).map(game::getControllerId).filter(Objects::nonNull).collect(Collectors.toMap(Function.identity(), x -> 1, Integer::sum));
player.moveCards(cards, Zone.EXILED, source, game);
for (Map.Entry<UUID, Integer> entry : playerMap.entrySet()) {
new Elemental44Token().putOntoBattlefield(entry.getValue(), game, source, entry.getKey());
}
return true;
}
use of mage.MageItem in project mage by magefree.
the class OrvarTheAllFormEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Spell spell = (Spell) this.getValue("spellCast");
if (player == null || spell == null) {
return false;
}
List<Predicate<Permanent>> predicates = spell.getSpellAbility().getModes().values().stream().map(Mode::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).map(game::getPermanent).filter(Objects::nonNull).map(MageItem::getId).map(PermanentIdPredicate::new).collect(Collectors.toList());
if (predicates.isEmpty()) {
return false;
}
FilterPermanent filter = new FilterControlledPermanent("a permanent you control targeted by that spell");
filter.add(Predicates.or(predicates));
filter.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(source))));
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
return new CreateTokenCopyTargetEffect().setTargetPointer(new FixedTarget(target.getFirstTarget(), game)).apply(game, source);
}
use of mage.MageItem in project mage by magefree.
the class RitesOfSpringEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int numDiscarded = controller.discard(0, Integer.MAX_VALUE, false, source, game).size();
if (numDiscarded == 0) {
return true;
}
TargetCardInLibrary target = new TargetCardInLibrary(numDiscarded, StaticFilters.FILTER_CARD_BASIC_LAND);
controller.searchLibrary(target, source, game);
Cards cards = new CardsImpl();
controller.getLibrary().getCards(game).stream().filter(Objects::nonNull).map(MageItem::getId).filter(target.getTargets()::contains).forEach(cards::add);
controller.revealCards(source, cards, game);
controller.moveCards(cards, Zone.HAND, source, game);
controller.shuffleLibrary(source, game);
return true;
}
use of mage.MageItem in project mage by magefree.
the class RampantRejuvenatorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = source.getSourcePermanentOrLKI(game);
if (player == null || permanent == null) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary(0, permanent.getPower().getValue(), StaticFilters.FILTER_CARD_BASIC_LANDS);
player.searchLibrary(target, source, game);
Cards cards = new CardsImpl();
player.getLibrary().getCards(game).stream().map(MageItem::getId).filter(target.getTargets()::contains).forEach(cards::add);
player.moveCards(cards, Zone.BATTLEFIELD, source, game);
player.shuffleLibrary(source, game);
return true;
}
use of mage.MageItem in project mage by magefree.
the class IlluminatedFolioTarget method possibleTargets.
@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
if (this.getTargets().size() == 1) {
Card card = game.getCard(this.getTargets().get(0));
possibleTargets.removeIf(uuid -> !game.getCard(uuid).getColor(game).shares(card.getColor(game)));
return possibleTargets;
}
if (possibleTargets.size() < 2) {
possibleTargets.clear();
return possibleTargets;
}
Set<Card> allTargets = possibleTargets.stream().map(game::getCard).collect(Collectors.toSet());
possibleTargets.clear();
for (ObjectColor color : ObjectColor.getAllColors()) {
Set<Card> inColor = allTargets.stream().filter(card -> card.getColor(game).shares(color)).collect(Collectors.toSet());
if (inColor.size() > 1) {
inColor.stream().map(MageItem::getId).forEach(possibleTargets::add);
}
if (possibleTargets.size() == allTargets.size()) {
break;
}
}
return possibleTargets;
}
Aggregations