use of mage.target.TargetPlayer in project mage by magefree.
the class BitterheartWitchEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (controller != null && targetPlayer != null) {
TargetCardInLibrary targetCard = new TargetCardInLibrary(filter);
if (controller.searchLibrary(targetCard, source, game)) {
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
game.getState().setValue("attachTo:" + card.getId(), targetPlayer.getId());
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
targetPlayer.addAttachment(card.getId(), source, game);
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class CabalTherapistDiscardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (targetPlayer == null || controller == null || sourceObject == null || cardName == null) {
return false;
}
Cards hand = targetPlayer.getHand().copy();
targetPlayer.revealCards(source, hand, game);
hand.removeIf(uuid -> {
Card card = hand.get(uuid, game);
if (card == null) {
return true;
}
return !CardUtil.haveSameNames(card, cardName, game);
});
targetPlayer.discard(hand, false, source, game);
return true;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class CabalTherapyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (targetPlayer == null || controller == null || sourceObject == null || cardName == null) {
return false;
}
Cards hand = targetPlayer.getHand().copy();
targetPlayer.revealCards(source, hand, game);
hand.removeIf(uuid -> {
Card card = hand.get(uuid, game);
if (card == null) {
return true;
}
return !CardUtil.haveSameNames(card, cardName, game);
});
targetPlayer.discard(hand, false, source, game);
return true;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class EssenceHarvestEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (controller != null && targetPlayer != null) {
List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game);
int amount = 0;
for (Permanent creature : creatures) {
int power = creature.getPower().getValue();
if (amount < power) {
amount = power;
}
}
if (amount > 0) {
targetPlayer.loseLife(amount, game, source, false);
controller.gainLife(amount, game, source);
}
return true;
}
return false;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class GhastlyConscriptionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller != null && targetPlayer != null) {
List<Card> cardsToManifest = new ArrayList<>();
for (Card card : targetPlayer.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game)) {
cardsToManifest.add(card);
controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.GRAVEYARD, true);
}
if (cardsToManifest.isEmpty()) {
return true;
}
Collections.shuffle(cardsToManifest);
game.informPlayers(controller.getLogName() + " shuffles the face-down pile");
Ability newSource = source.copy();
newSource.setWorksFaceDown(true);
for (Card card : cardsToManifest) {
ManaCosts manaCosts = null;
if (card.isCreature(game)) {
manaCosts = card.getSpellAbility().getManaCosts();
if (manaCosts == null) {
manaCosts = new ManaCostsImpl("{0}");
}
}
MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource);
}
Set<Card> toBattlefield = new LinkedHashSet();
toBattlefield.addAll(cardsToManifest);
controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, false, true, false, null);
return true;
}
return false;
}
Aggregations