use of mage.target.TargetPermanent in project mage by magefree.
the class MistOfStagnationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player activePlayer = game.getPlayer(game.getActivePlayerId());
if (activePlayer != null) {
int cardsInGrave = activePlayer.getGraveyard().size();
if (cardsInGrave > 0) {
TargetPermanent target = new TargetPermanent(cardsInGrave, cardsInGrave, new FilterPermanent("permanents to untap"), true);
activePlayer.chooseTarget(outcome, target, source, game);
for (UUID oneTarget : target.getTargets()) {
Permanent p = game.getPermanent(oneTarget);
if (p != null) {
p.untap(game);
}
}
}
return true;
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class NahirisLithoformingSacrificeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null || source.getManaCostsToPay().getX() == 0) {
return false;
}
int landCount = game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_LAND_SHORT_TEXT, source.getSourceId(), source.getControllerId(), game);
landCount = Math.min(source.getManaCostsToPay().getX(), landCount);
TargetPermanent target = new TargetPermanent(landCount, landCount, StaticFilters.FILTER_CONTROLLED_LAND_SHORT_TEXT, true);
player.choose(outcome, target, source.getSourceId(), game);
int counter = 0;
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null && permanent.sacrifice(source, game)) {
counter++;
}
}
player.drawCards(counter, source, game);
game.addEffect(new PlayAdditionalLandsControllerEffect(source.getManaCostsToPay().getX(), Duration.EndOfTurn), source);
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class MythosOfSnapdaxEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
boolean conditionMet = condition.apply(game, source);
List<Player> playerList = game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).filter(Objects::nonNull).collect(Collectors.toList());
Set<UUID> toKeep = new HashSet();
for (Player player : playerList) {
for (CardType cardType : cardTypes) {
String message = cardType.toString().equals("Artifact") ? "an " : "a ";
message += cardType.toString().toLowerCase(Locale.ENGLISH);
message += (conditionMet && player != controller) ? " controlled by " + player.getName() : " you control";
FilterPermanent filter = new FilterNonlandPermanent(message);
filter.add(cardType.getPredicate());
filter.add(new ControllerIdPredicate(player.getId()));
if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0) {
continue;
}
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
if (conditionMet) {
controller.choose(outcome, target, source.getSourceId(), game);
} else {
player.choose(outcome, target, source.getSourceId(), game);
}
toKeep.add(target.getFirstTarget());
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_NON_LAND, source.getControllerId(), game)) {
if (permanent == null || toKeep.contains(permanent.getId())) {
continue;
}
permanent.sacrifice(source, game);
}
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class OldGrowthTrollContinuousEffect method apply.
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
if (game.getState().getZoneChangeCounter(source.getSourceId()) > zoneChangeCounter) {
discard();
return false;
}
Permanent sourceObject = game.getPermanent(source.getSourceId());
if (sourceObject == null) {
sourceObject = game.getPermanentEntering(source.getSourceId());
}
if (sourceObject == null) {
return false;
}
Permanent troll = sourceObject;
switch(layer) {
case TypeChangingEffects_4:
troll.removeAllCardTypes(game);
troll.addCardType(game, CardType.ENCHANTMENT);
troll.removeAllSubTypes(game);
troll.addSubType(game, SubType.AURA);
break;
case AbilityAddingRemovingEffects_6:
// Spell Ability can be null with clone effects (ex. Moritte)
if (troll.getSpellAbility() == null) {
troll.addAbility(new SpellAbility(null, null), source.getSourceId(), game);
}
troll.getSpellAbility().getTargets().clear();
troll.getSpellAbility().getEffects().clear();
TargetPermanent auraTarget = new TargetPermanent(filter);
troll.getSpellAbility().addTarget(auraTarget);
troll.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature));
troll.addAbility(new EnchantAbility(auraTarget.getTargetName()), source.getSourceId(), game);
// add the activated ability
troll.addAbility(makeAbility(), source.getSourceId(), game);
}
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class RavenousRotbellyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
TargetPermanent target = new TargetPermanent(0, 3, filter, true);
player.choose(outcome, target, source.getSourceId(), game);
int amount = 0;
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null && permanent.sacrifice(source, game)) {
amount++;
}
}
if (amount < 1) {
return false;
}
game.fireReflexiveTriggeredAbility(new ReflexiveTriggeredAbility(new SacrificeOpponentsEffect(amount, StaticFilters.FILTER_PERMANENT_CREATURES), false, "each opponent sacrifices that many creatures"), source);
return true;
}
Aggregations