use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class NecromancyChangeAbilityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent enchantment = game.getPermanent(source.getSourceId());
Card cardInGraveyard = game.getCard(getTargetPointer().getFirst(game, source));
if (controller != null && enchantment != null && cardInGraveyard != null) {
controller.moveCards(cardInGraveyard, Zone.BATTLEFIELD, source, game);
Permanent enchantedCreature = game.getPermanent(cardInGraveyard.getId());
if (enchantedCreature != null) {
enchantedCreature.addAttachment(enchantment.getId(), source, game);
FilterCreaturePermanent filter = new FilterCreaturePermanent("enchant creature put onto the battlefield with " + enchantment.getIdName());
filter.add(new PermanentIdPredicate(cardInGraveyard.getId()));
Target target = new TargetCreaturePermanent(filter);
target.addTarget(enchantedCreature.getId(), source, game);
game.addEffect(new NecromancyChangeAbilityEffect(target), source);
}
return true;
}
return false;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class SasayasEssenceManaEffect method getNetMana.
@Override
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>();
Player controller = game.getPlayer(source.getControllerId());
Mana producedMana = (Mana) this.getValue("mana");
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (controller != null && producedMana != null && permanent != null) {
FilterPermanent filter = new FilterLandPermanent();
filter.add(Predicates.not(new PermanentIdPredicate(permanent.getId())));
filter.add(new NamePredicate(permanent.getName()));
int count = game.getBattlefield().countAll(filter, controller.getId(), game);
if (count > 0) {
if (producedMana.getBlack() > 0) {
netMana.add(Mana.BlackMana(count));
}
if (producedMana.getRed() > 0) {
netMana.add(Mana.RedMana(count));
}
if (producedMana.getBlue() > 0) {
netMana.add(Mana.BlueMana(count));
}
if (producedMana.getGreen() > 0) {
netMana.add(Mana.GreenMana(count));
}
if (producedMana.getWhite() > 0) {
netMana.add(Mana.WhiteMana(count));
}
if (producedMana.getColorless() > 0) {
netMana.add(Mana.ColorlessMana(count));
}
}
}
return netMana;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class SeverTheBloodlineEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source));
if (controller != null && targetPermanent != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
if (CardUtil.haveEmptyName(targetPermanent)) {
// if no name (face down creature) only the creature itself is selected
filter.add(new PermanentIdPredicate(targetPermanent.getId()));
} else {
filter.add(new NamePredicate(targetPermanent.getName()));
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
controller.moveCardToExileWithInfo(permanent, null, "", source, game, Zone.BATTLEFIELD, true);
}
return true;
}
return false;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class TormentOfVenomEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetCreature != null) {
new AddCountersTargetEffect(CounterType.M1M1.createInstance(3)).apply(game, source);
Player controllingPlayer = game.getPlayer(targetCreature.getControllerId());
if (controllingPlayer != null) {
int permanents = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_NON_LAND, controllingPlayer.getId(), game);
if (permanents > 0 && controllingPlayer.chooseUse(outcome, "Sacrifices a nonland permanent?", "Otherwise you have to discard a card or lose 3 life.", "Sacrifice", "Discard or life loss", source, game)) {
FilterPermanent filter = new FilterControlledPermanent("another nonland permanent");
filter.add(Predicates.not(CardType.LAND.getPredicate()));
filter.add(Predicates.not(new PermanentIdPredicate(targetCreature.getId())));
Target target = new TargetPermanent(filter);
if (controllingPlayer.choose(outcome, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
return true;
}
}
}
if (!controllingPlayer.getHand().isEmpty() && controllingPlayer.chooseUse(outcome, "Discard a card?", "Otherwise you lose 3 life.", "Discard", "Lose 3 life", source, game)) {
controllingPlayer.discardOne(false, false, source, game);
return true;
}
controllingPlayer.loseLife(3, game, source, false);
return true;
}
}
return false;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class CyclopeanTombCounterWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObjectReference mor = new MageObjectReference(source.getSourceId(), source.getSourceObjectZoneChangeCounter(), game);
CyclopeanTombCounterWatcher watcher = game.getState().getWatcher(CyclopeanTombCounterWatcher.class);
if (controller != null && watcher != null) {
Set<MageObjectReference> landRef = watcher.landMiredByCyclopeanTombInstance(mor, game);
if (landRef == null || landRef.isEmpty()) {
// no lands got mire counter from that instance
return true;
}
FilterLandPermanent filter = new FilterLandPermanent("a land with a mire counter added from the Cyclopean Tomb instance (" + landRef.size() + " left)");
Set<PermanentIdPredicate> idPref = new HashSet<>();
for (MageObjectReference ref : landRef) {
Permanent land = ref.getPermanent(game);
if (land != null) {
idPref.add(new PermanentIdPredicate(land.getId()));
}
}
filter.add(Predicates.or(idPref));
TargetLandPermanent target = new TargetLandPermanent(1, 1, filter, true);
/*Player must choose a land each upkeep. Using the message are above the player hand where frequent interactions
* take place is the most logical way to prompt for this scenario. A new constructor added to provide a not optional
* option for any cards like this where the player must choose a target in such the way this card requires.
*/
if (controller.chooseTarget(Outcome.Neutral, target, source, game)) {
Permanent chosenLand = game.getPermanent(target.getFirstTarget());
if (chosenLand != null) {
Effect effect = new RemoveAllCountersTargetEffect(CounterType.MIRE);
effect.setTargetPointer(new FixedTarget(chosenLand, game));
effect.apply(game, source);
landRef.remove(new MageObjectReference(chosenLand, game));
}
}
return true;
}
return false;
}
Aggregations