use of mage.target.TargetPermanent in project mage by magefree.
the class HeavenlyBlademasterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
if (sourcePermanent == null || player == null) {
return false;
}
Target target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
if (!player.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
target.getTargets().stream().map(attachmentId -> game.getPermanent(attachmentId)).filter(attachment -> attachment != null).forEachOrdered((attachment) -> {
if (!sourcePermanent.cantBeAttachedBy(attachment, source, game, true)) {
if (attachment.getAttachedTo() != sourcePermanent.getId()) {
if (attachment.getAttachedTo() != null) {
Permanent fromPermanent = game.getPermanent(attachment.getAttachedTo());
if (fromPermanent != null) {
fromPermanent.removeAttachment(attachment.getId(), source, game);
}
}
}
sourcePermanent.addAttachment(attachment.getId(), source, game);
game.informPlayers(attachment.getLogName() + " was attached to " + sourcePermanent.getLogName());
}
});
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class LumberingBattlementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sourcePerm = source.getSourcePermanentIfItStillExists(game);
if (player == null || sourcePerm == null) {
return false;
}
Target target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
if (!player.choose(Outcome.Neutral, target, source.getSourceId(), game)) {
return false;
}
Set<Card> cards = new HashSet<>();
for (UUID targetId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
cards.add(permanent);
}
}
return player.moveCardsToExile(cards, source, game, true, CardUtil.getCardExileZoneId(game, source), sourcePerm.getIdName());
}
use of mage.target.TargetPermanent in project mage by magefree.
the class MultipleChoiceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int xValue = source.getManaCostsToPay().getX();
if (xValue == 1 || xValue >= 4) {
controller.scry(1, source, game);
controller.drawCards(1, source, game);
}
if (xValue == 3 || xValue >= 4) {
new Elemental44Token().putOntoBattlefield(1, game, source, source.getControllerId());
}
if (xValue != 2 && xValue < 4) {
return true;
}
TargetPlayer targetPlayer = new TargetPlayer(0, 1, true);
controller.choose(Outcome.Detriment, targetPlayer, source.getSourceId(), game);
Player player = game.getPlayer(targetPlayer.getFirstTarget());
if (player == null || game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getSourceId(), player.getId(), game) <= 0) {
return true;
}
TargetPermanent targetPermanent = new TargetControlledCreaturePermanent();
targetPermanent.setNotTarget(true);
player.choose(Outcome.ReturnToHand, targetPermanent, source.getSourceId(), game);
Permanent permanent = game.getPermanent(targetPermanent.getFirstTarget());
return permanent == null || player.moveCards(permanent, Zone.HAND, source, game);
}
use of mage.target.TargetPermanent in project mage by magefree.
the class OKagachiVengefulKamiWatcher method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Player player = game.getPlayer(event.getTargetId());
if (player == null || !((DamagedPlayerEvent) event).isCombatDamage() || !event.getSourceId().equals(getSourceId())) {
return false;
}
this.getEffects().setValue("damagedPlayer", event.getTargetId());
FilterPermanent filter = new FilterNonlandPermanent("nonland permanent controlled by " + player.getName());
filter.add(new ControllerIdPredicate(event.getTargetId()));
this.getTargets().clear();
this.addTarget(new TargetPermanent(filter));
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class PrimordialMistCastFromExileEffect method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
if (target.choose(Outcome.Exile, controllerId, source.getSourceId(), game)) {
Card card = game.getCard(source.getSourceId());
if (card != null) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
Permanent targetPermanent = game.getPermanent(target.getFirstTarget());
Card targetCard = game.getCard(target.getFirstTarget());
if (targetPermanent != null && targetCard != null) {
String exileName = sourcePermanent.getIdName() + " <this card may be played the turn it was exiled>";
controller.moveCardsToExile(targetPermanent, source, game, true, source.getSourceId(), exileName);
targetPermanent.setFaceDown(false, game);
PrimordialMistCastFromExileEffect effect = new PrimordialMistCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(targetCard.getId()));
game.addEffect(effect, ability);
this.setPaid();
}
}
}
this.setPaid();
return true;
}
}
return false;
}
Aggregations