use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class ShelteringAncientCost 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) {
Target target = new TargetCreaturePermanent(1, 1, filter, true);
if (target.choose(Outcome.BoostCreature, controllerId, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.addCounters(CounterType.P1P1.createInstance(), controllerId, ability, game);
this.paid = true;
return true;
}
}
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class DuneblastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetCreaturePermanent(0, 1, new FilterCreaturePermanent("creature to keep"), true);
target.setRequired(true);
Permanent creatureToKeep = null;
if (controller.choose(outcome, target, source.getSourceId(), game)) {
creatureToKeep = game.getPermanent(target.getFirstTarget());
}
for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), source.getSourceId(), game)) {
if (!Objects.equals(creature, creatureToKeep)) {
creature.destroy(source, game, false);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class InfernalDenizenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent creature = game.getPermanent(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
DynamicValue swamps = new PermanentsOnBattlefieldCount(filter);
boolean canSac = swamps.calculate(game, source, this) > 1;
Effect effect = new SacrificeControllerEffect(filter, 2, "Sacrifice two Swamps");
effect.apply(game, source);
if (!canSac) {
if (creature != null) {
creature.tap(source, game);
}
TargetOpponent targetOpp = new TargetOpponent(true);
if (targetOpp.canChoose(source.getSourceId(), player.getId(), game) && targetOpp.choose(Outcome.Detriment, player.getId(), source.getSourceId(), game)) {
Player opponent = game.getPlayer(targetOpp.getFirstTarget());
if (opponent != null) {
FilterCreaturePermanent filter2 = new FilterCreaturePermanent("creature controlled by " + player.getLogName());
filter2.add(new ControllerIdPredicate(player.getId()));
TargetCreaturePermanent targetCreature = new TargetCreaturePermanent(1, 1, filter2, true);
targetCreature.setTargetController(opponent.getId());
if (targetCreature.canChoose(source.getSourceId(), id, game) && opponent.chooseUse(Outcome.GainControl, "Gain control of a creature?", source, game) && opponent.chooseTarget(Outcome.GainControl, targetCreature, source, game)) {
ConditionalContinuousEffect giveEffect = new ConditionalContinuousEffect(new GainControlTargetEffect(Duration.Custom, true, opponent.getId()), SourceOnBattlefieldCondition.instance, "");
giveEffect.setTargetPointer(new FixedTarget(targetCreature.getFirstTarget(), game));
game.addEffect(giveEffect, source);
return true;
}
}
}
}
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class PolymorphousRushCopyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetCreaturePermanent(new FilterCreaturePermanent(""));
target.setNotTarget(true);
target.setTargetName("a creature on the battlefield (creature to copy)");
if (target.canChoose(source.getId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
Permanent copyFromCreature = game.getPermanent(target.getFirstTarget());
if (copyFromCreature != null) {
for (UUID copyToId : getTargetPointer().getTargets(game, source)) {
Permanent copyToCreature = game.getPermanent(copyToId);
if (copyToCreature != null) {
game.copyPermanent(Duration.EndOfTurn, copyFromCreature, copyToId, source, new EmptyCopyApplier());
}
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class FallOfTheImpostorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
if (controller != null && opponent != null) {
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game);
Integer maxPower = null;
for (Permanent permanent : permanents) {
if (permanent != null) {
int power = permanent.getPower().getValue();
if (maxPower == null || power > maxPower) {
maxPower = power;
}
}
}
if (maxPower != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new ControllerIdPredicate(opponent.getId()));
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, maxPower));
TargetCreaturePermanent target = new TargetCreaturePermanent(1, 1, filter, true);
controller.chooseTarget(outcome, target, source, game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
controller.moveCardsToExile(permanent, source, game, true, null, null);
return true;
}
}
}
return false;
}
Aggregations