use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class LichDamageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetControlledPermanent(amount, amount, filter, true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
if (controller.choose(Outcome.Sacrifice, target, source.getSourceId(), game)) {
for (UUID targetId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
return true;
}
}
controller.lost(game);
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class NicolBolasDragonGodMinus8Effect method apply.
@Override
public boolean apply(Game game, Ability source) {
Boolean applied = false;
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
player.drawCards(1, source, game);
Set<Card> cardsOnBattlefield = new LinkedHashSet<>();
Set<Card> cards = new LinkedHashSet<>();
for (UUID opponentId : game.getState().getPlayersInRange(player.getId(), game)) {
if (!player.hasOpponent(opponentId, game)) {
continue;
}
Player opponent = game.getPlayer(opponentId);
if (opponent == null) {
continue;
}
List<Target> possibleTargetTypes = new ArrayList<>();
// hand
TargetCardInHand targetHand = new TargetCardInHand();
if (!opponent.getHand().isEmpty()) {
possibleTargetTypes.add(targetHand);
}
// permanent
TargetPermanent targetPermanent = new TargetControlledPermanent();
targetPermanent.setNotTarget(true);
targetPermanent.setTargetController(opponentId);
if (!targetPermanent.possibleTargets(opponentId, game).isEmpty()) {
possibleTargetTypes.add(targetPermanent);
}
// choose target type first, AI must use hand first (benefit)
if (possibleTargetTypes.size() > 1 && !opponent.chooseUse(Outcome.Benefit, "Exile a card in your hand or a permanent you control?", null, "Card in hand", "Permanent", source, game)) {
// change order (permanent goes first)
Collections.reverse(possibleTargetTypes);
}
// choose target
for (Target target : possibleTargetTypes) {
// hand
if (target.equals(targetHand)) {
if (opponent.choose(Outcome.Exile, opponent.getHand(), targetHand, game) && game.getCard(targetHand.getFirstTarget()) != null) {
cards.add(game.getCard(targetHand.getFirstTarget()));
break;
}
}
// permanent
if (target.equals(targetPermanent)) {
if (opponent.choose(Outcome.Exile, targetPermanent, source.getSourceId(), game)) {
MageObject mageObject = game.getObject(targetPermanent.getFirstTarget());
if (mageObject instanceof Permanent) {
cardsOnBattlefield.add((Card) mageObject);
break;
}
}
}
}
}
cards.addAll(cardsOnBattlefield);
for (Card card : cards) {
if (card != null) {
Player owner = game.getPlayer(card.getOwnerId());
if (owner != null && owner.moveCards(card, Zone.EXILED, source, game)) {
applied = true;
}
}
}
return applied;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class RenounceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int amount = 0;
TargetControlledPermanent toSacrifice = new TargetControlledPermanent(0, Integer.MAX_VALUE, new FilterControlledPermanent(), true);
if (player.chooseTarget(Outcome.Sacrifice, toSacrifice, source, game)) {
for (UUID uuid : toSacrifice.getTargets()) {
Permanent permanent = game.getPermanent(uuid);
if (permanent != null) {
permanent.sacrifice(source, game);
amount++;
}
}
player.gainLife(amount * 2, game, source);
}
return true;
}
use of mage.target.common.TargetControlledPermanent 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;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class WarrenWeirdingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player == null) {
return false;
}
FilterControlledPermanent filter = new FilterControlledPermanent("creature");
filter.add(CardType.CREATURE.getPredicate());
filter.add(new ControllerIdPredicate(player.getId()));
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
// had, if thats the case this ability should fizzle.
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
if (filterGoblin.match(permanent, game)) {
for (int i = 0; i < 2; i++) {
Token token = new GoblinRogueToken();
Effect effect = new CreateTokenTargetEffect(token);
effect.setTargetPointer(new FixedTarget(player.getId()));
if (effect.apply(game, source)) {
Permanent tokenPermanent = game.getPermanent(token.getLastAddedToken());
if (tokenPermanent != null) {
ContinuousEffect hasteEffect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
hasteEffect.setTargetPointer(new FixedTarget(tokenPermanent.getId()));
game.addEffect(hasteEffect, source);
}
}
}
}
}
return true;
}
return false;
}
Aggregations