use of mage.choices.ChooseFriendsAndFoes in project mage by magefree.
the class KhorvathsFuryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
choice.chooseFriendOrFoe(controller, source, game);
Map<UUID, Integer> cardsToDraw = new HashMap<>();
for (Player player : choice.getFriends()) {
if (player != null) {
int cardsInHand = player.getHand().size();
player.discard(cardsInHand, false, false, source, game);
if (cardsInHand > 0) {
cardsToDraw.put(player.getId(), cardsInHand);
}
}
}
for (Player player : choice.getFriends()) {
if (player != null) {
player.drawCards(cardsToDraw.get(player.getId()) + 1, source, game);
}
}
for (Player player : choice.getFoes()) {
if (player != null) {
player.damage(player.getHand().size(), source.getSourceId(), source, game);
}
}
return true;
}
use of mage.choices.ChooseFriendsAndFoes in project mage by magefree.
the class ZndrspltsJudgmentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
choice.chooseFriendOrFoe(controller, source, game);
for (Player player : choice.getFriends()) {
if (player == null) {
continue;
}
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
filter.add(new ControllerIdPredicate(player.getId()));
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
if (!player.choose(Outcome.Copy, target, source.getSourceId(), game)) {
continue;
}
Effect effect = new CreateTokenCopyTargetEffect(player.getId());
effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
effect.apply(game, source);
}
for (Player player : choice.getFoes()) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
filter.add(new ControllerIdPredicate(player.getId()));
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
if (!player.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
continue;
}
Effect effect = new ReturnToHandTargetEffect();
effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
effect.apply(game, source);
}
return true;
}
use of mage.choices.ChooseFriendsAndFoes in project mage by magefree.
the class PirsWhimEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
if (controller != null && !choice.chooseFriendOrFoe(controller, source, game)) {
return false;
}
for (Player player : choice.getFriends()) {
if (player != null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_LAND);
if (player.searchLibrary(target, source, game)) {
player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, true, null);
player.shuffleLibrary(source, game);
}
}
}
for (Player player : choice.getFoes()) {
if (player != null) {
Effect effect = new SacrificeEffect(StaticFilters.FILTER_PERMANENT_ARTIFACT_OR_ENCHANTMENT, 1, "");
effect.setTargetPointer(new FixedTarget(player.getId(), game));
effect.apply(game, source);
}
}
return true;
}
use of mage.choices.ChooseFriendsAndFoes in project mage by magefree.
the class RegnasSanctionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
if (!choice.chooseFriendOrFoe(controller, source, game)) {
return false;
}
FilterPermanent filterToTap = new FilterCreaturePermanent();
for (Player player : choice.getFoes()) {
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
if (game.getBattlefield().contains(filter, source, game, 1) && player.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
filterToTap.add(Predicates.not(new PermanentIdPredicate(target.getFirstTarget())));
}
}
choice.getFriends().stream().map(MageItem::getId).map(ControllerIdPredicate::new).map(Predicates::not).forEach(filterToTap::add);
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
if (choice.getFriends().stream().map(MageItem::getId).anyMatch(permanent::isControlledBy)) {
permanent.addCounters(CounterType.P1P1.createInstance(), source, game);
}
}
return new TapAllEffect(filterToTap).apply(game, source);
}
use of mage.choices.ChooseFriendsAndFoes in project mage by magefree.
the class VirtussManeuverEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
if (controller != null && !choice.chooseFriendOrFoe(controller, source, game)) {
return false;
}
Map<UUID, Card> getBackMap = new HashMap<>();
for (Player player : choice.getFriends()) {
if (player == null) {
continue;
}
FilterCard filter = new FilterCreatureCard("creature card in your graveyard");
filter.add(new OwnerIdPredicate(player.getId()));
TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
getBackMap.put(player.getId(), null);
if (player.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
getBackMap.put(player.getId(), game.getCard(target.getFirstTarget()));
}
}
for (Player player : choice.getFriends()) {
if (player == null) {
continue;
}
Card card = getBackMap.getOrDefault(player.getId(), null);
if (card == null) {
continue;
}
player.moveCards(card, Zone.HAND, source, game);
}
List<UUID> perms = new ArrayList<>();
for (Player player : choice.getFoes()) {
if (player == null) {
continue;
}
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, StaticFilters.FILTER_CONTROLLED_A_CREATURE, true);
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
perms.addAll(target.getTargets());
}
for (UUID permID : perms) {
Permanent permanent = game.getPermanent(permID);
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
return true;
}
Aggregations