use of mage.target.TargetPlayer in project mage by magefree.
the class AgonizingMemoriesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Player you = game.getPlayer(source.getControllerId());
if (targetPlayer != null && you != null) {
chooseCardInHandAndPutOnTopOfLibrary(game, source, you, targetPlayer);
chooseCardInHandAndPutOnTopOfLibrary(game, source, you, targetPlayer);
return true;
}
return false;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class CloudhoofKirinEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
Player targetPlayer = null;
for (Target target : source.getTargets()) {
if (target instanceof TargetPlayer) {
targetPlayer = game.getPlayer(target.getFirstTarget());
}
}
int cmc = spell.getManaValue();
if (targetPlayer != null && cmc > 0) {
targetPlayer.millCards(cmc, source, game);
return true;
}
}
return false;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class CurseOfLeechesEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
TargetPlayer target = new TargetPlayer();
target.withChooseHint("Player to attach to").setNotTarget(true);
controller.choose(Outcome.Detriment, target, source.getSourceId(), game);
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent == null) {
return false;
}
permanent.addAttachment(target.getFirstTarget(), source, game);
return false;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class CurseOfMisfortunesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent enchantment = game.getPermanent(source.getSourceId());
if (controller != null && enchantment != null && enchantment.getAttachedTo() != null) {
Player targetPlayer = game.getPlayer(enchantment.getAttachedTo());
Player player = game.getPlayer(source.getControllerId());
if (player != null && targetPlayer != null) {
FilterCard filter = new FilterCard("Curse card that doesn't have the same name as a Curse attached to enchanted player");
filter.add(SubType.CURSE.getPredicate());
// get the names of attached Curses
for (UUID attachmentId : targetPlayer.getAttachments()) {
Permanent attachment = game.getPermanent(attachmentId);
if (attachment != null && attachment.hasSubtype(SubType.CURSE, game)) {
filter.add(Predicates.not(new NamePredicate(attachment.getName())));
}
}
TargetCardInLibrary targetCard = new TargetCardInLibrary(filter);
if (player.searchLibrary(targetCard, source, game)) {
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
this.setTargetPointer(new FixedTarget(targetPlayer.getId()));
game.getState().setValue("attachTo:" + card.getId(), targetPlayer.getId());
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
targetPlayer.addAttachment(card.getId(), source, game);
}
}
}
player.shuffleLibrary(source, game);
}
return true;
}
return false;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class CurseOfTheCabalTriggeredAbilityConditionalDelay method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (targetPlayer != null) {
int amount = game.getBattlefield().countAll(StaticFilters.FILTER_CONTROLLED_PERMANENT, targetPlayer.getId(), game) / 2;
if (amount < 1) {
return true;
}
Target target = new TargetControlledPermanent(amount, amount, StaticFilters.FILTER_CONTROLLED_PERMANENT, true);
if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
while (!target.isChosen() && target.canChoose(source.getSourceId(), targetPlayer.getId(), game) && targetPlayer.canRespond()) {
targetPlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
}
// sacrifice all chosen (non null) permanents
target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).forEach(permanent -> permanent.sacrifice(source, game));
}
return true;
}
return false;
}
Aggregations