use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class FeastOfWormsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentOrLKIBattlefield(id);
Player targetPlayer = null;
if (permanent != null) {
targetPlayer = game.getPlayer(permanent.getControllerId());
}
if (targetPlayer != null && permanent != null && (permanent.isLegendary())) {
FilterControlledPermanent filter = new FilterControlledLandPermanent("land to sacrifice");
filter.add(new ControllerIdPredicate(targetPlayer.getId()));
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, false);
if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
targetPlayer.chooseTarget(Outcome.Sacrifice, target, source, game);
Permanent land = game.getPermanent(target.getFirstTarget());
if (land != null) {
land.sacrifice(source, game);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class GargantuanGorillaFightEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourcePermanent != null) {
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
SacrificeTargetCost cost = new SacrificeTargetCost(target);
if (!controller.chooseUse(Outcome.Benefit, "Sacrifice a Forest?", source, game) || !cost.canPay(source, source, source.getControllerId(), game) || !cost.pay(source, game, source, source.getControllerId(), true)) {
sourcePermanent.sacrifice(source, game);
controller.damage(7, sourcePermanent.getId(), source, game);
} else if (cost.isPaid()) {
for (Permanent permanent : cost.getPermanents()) {
if (filterSnow.match(permanent, game)) {
game.addEffect(new GainAbilitySourceEffect(TrampleAbility.getInstance(), Duration.EndOfTurn), source);
break;
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class GlobalRuinDestroyLandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Set<UUID> lands = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
for (SubType landName : Arrays.stream(SubType.values()).filter(p -> p.getSubTypeSet() == SubTypeSet.BasicLandType).collect(Collectors.toSet())) {
FilterControlledLandPermanent filter = new FilterControlledLandPermanent(landName + " you control");
filter.add(landName.getPredicate());
Target target = new TargetControlledPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(outcome, target, source, game);
lands.add(target.getFirstTarget());
}
}
}
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_LAND, game)) {
if (!lands.contains(permanent.getId())) {
permanent.sacrifice(source, game);
}
}
return true;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class GuardDogsEffect method init.
@Override
public void init(Ability source, Game game) {
this.controlledTarget = new TargetControlledPermanent();
this.controlledTarget.setNotTarget(true);
this.controlledTarget.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
super.init(source, game);
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class RunEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getTargets().getFirstTarget());
if (targetPlayer != null) {
FilterControlledPermanent filter = new FilterControlledPermanent("artifact or creature");
filter.add(Predicates.or(CardType.ARTIFACT.getPredicate(), CardType.CREATURE.getPredicate()));
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
targetPlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
int damage = permanent.getManaValue();
if (damage > 0) {
targetPlayer.damage(damage, source.getSourceId(), source, game);
}
}
}
}
return true;
}
Aggregations