use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class HarmonyOfNatureEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
TargetPermanent target = new TargetControlledPermanent(0, Integer.MAX_VALUE, HarmonyOfNature.filter, true);
controller.choose(outcome, target, source.getSourceId(), game);
if (target.getTargets().isEmpty()) {
return false;
}
int tappedAmount = 0;
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null && permanent.tap(source, game)) {
tappedAmount++;
}
}
if (tappedAmount > 0) {
controller.gainLife(tappedAmount * 4, game, source);
}
return true;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class HungryHungryHeiferEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game);
if (sourceObject != null && controller != null) {
if (controller.chooseUse(outcome, "Remove a counter from a permanent you control?", source, game)) {
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
RemoveCounterCost cost = new RemoveCounterCost(target);
if (cost.pay(null, game, source, controller.getId(), true)) {
return true;
}
}
sourceObject.sacrifice(source, game);
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class LinessaZephyrMageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (targetPlayer != null) {
// Target player returns a creature they control to its owner's hand,
Target target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
targetPlayer.moveCards(permanent, Zone.HAND, source, game);
}
}
// then repeats this process for an artifact,
FilterControlledPermanent filter = new FilterControlledPermanent("artifact you control");
filter.add(CardType.ARTIFACT.getPredicate());
target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
targetPlayer.moveCards(permanent, Zone.HAND, source, game);
}
}
// an enchantment,
filter = new FilterControlledPermanent("enchantment you control");
filter.add(CardType.ENCHANTMENT.getPredicate());
target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
targetPlayer.moveCards(permanent, Zone.HAND, source, game);
}
}
// and a land.
filter = new FilterControlledPermanent("land you control");
filter.add(CardType.LAND.getPredicate());
target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
targetPlayer.moveCards(permanent, Zone.HAND, source, game);
}
}
return true;
}
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class MarshalingTheTroopsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
TargetPermanent target = new TargetControlledPermanent(0, Integer.MAX_VALUE, MarshalingTheTroops.filter, true);
controller.choose(outcome, target, source.getSourceId(), game);
if (target.getTargets().isEmpty()) {
return false;
}
int tappedAmount = 0;
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null && permanent.tap(source, game)) {
tappedAmount++;
}
}
if (tappedAmount > 0) {
controller.gainLife(tappedAmount * 4, game, source);
}
return true;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class SerendibDjinnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetControlledPermanent(1, 1, new FilterControlledLandPermanent(), true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
if (permanent.hasSubtype(SubType.ISLAND, game)) {
controller.damage(3, source.getSourceId(), source, game);
}
}
}
return true;
}
return false;
}
Aggregations