use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class GodsendRuleModifyingEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent equipment = game.getPermanentOrLKIBattlefield((this.getSourceId()));
if (equipment != null && equipment.getAttachedTo() != null) {
Permanent equippedPermanent = game.getPermanentOrLKIBattlefield((equipment.getAttachedTo()));
if (equippedPermanent != null) {
possibleTargets.clear();
String targetName = "";
if (equippedPermanent.isAttacking()) {
for (CombatGroup group : game.getCombat().getGroups()) {
if (group.getAttackers().contains(equippedPermanent.getId())) {
possibleTargets.addAll(group.getBlockers());
}
}
targetName = "a creature blocking attacker ";
} else if (equippedPermanent.getBlocking() > 0) {
for (CombatGroup group : game.getCombat().getGroups()) {
if (group.getBlockers().contains(equippedPermanent.getId())) {
possibleTargets.addAll(group.getAttackers());
}
}
targetName = "a creature blocked by creature ";
}
if (!possibleTargets.isEmpty()) {
this.getTargets().clear();
if (possibleTargets.size() == 1) {
this.getEffects().get(0).setTargetPointer(new FixedTarget(possibleTargets.iterator().next(), game));
} else {
this.getEffects().get(0).setTargetPointer(new FirstTargetPointer());
targetName = targetName + " equipped by " + equipment.getName();
FilterCreaturePermanent filter = new FilterCreaturePermanent(targetName);
List<PermanentIdPredicate> uuidPredicates = new ArrayList<>();
for (UUID creatureId : possibleTargets) {
uuidPredicates.add(new PermanentIdPredicate(creatureId));
}
filter.add(Predicates.or(uuidPredicates));
this.getTargets().add(new TargetCreaturePermanent(filter));
}
return true;
}
}
}
return false;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class SasayasEssenceManaEffect method produceMana.
/**
* RULINGS 6/1/2005 If Sasaya’s Essence’s controller has four Forests and
* taps one of them for Green, the Essence will add GreenGreenGreen to that
* player’s mana pool for a total of GreenGreenGreenGreen.
*
* 6/1/2005 If Sasaya’s Essence’s controller has four Mossfire Valley and
* taps one of them for RedGreen, the Essence will add three mana (one for
* each other Mossfire Valley) of any combination of Red and/or Green to
* that player’s mana pool.
*
* 6/1/2005 If Sasaya’s Essence’s controller has two Brushlands and taps one
* of them for White, Sasaya’s Essence adds another White to that player’s
* mana pool. It won’t produce Green or Colorless unless the land was tapped
* for Green or Colorless instead.
*/
@Override
public Mana produceMana(Game game, Ability source) {
Mana newMana = new Mana();
if (game == null) {
return newMana;
}
Player controller = game.getPlayer(source.getControllerId());
Mana mana = (Mana) this.getValue("mana");
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (controller != null && mana != 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) {
Choice choice = new ChoiceColor(true);
choice.getChoices().clear();
choice.setMessage("Pick the type of mana to produce");
if (mana.getBlack() > 0) {
choice.getChoices().add("Black");
}
if (mana.getRed() > 0) {
choice.getChoices().add("Red");
}
if (mana.getBlue() > 0) {
choice.getChoices().add("Blue");
}
if (mana.getGreen() > 0) {
choice.getChoices().add("Green");
}
if (mana.getWhite() > 0) {
choice.getChoices().add("White");
}
if (mana.getColorless() > 0) {
choice.getChoices().add("Colorless");
}
if (!choice.getChoices().isEmpty()) {
for (int i = 0; i < count; i++) {
choice.clearChoice();
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!controller.choose(outcome, choice, game)) {
return newMana;
}
}
switch(choice.getChoice()) {
case "Black":
newMana.increaseBlack();
break;
case "Blue":
newMana.increaseBlue();
break;
case "Red":
newMana.increaseRed();
break;
case "Green":
newMana.increaseGreen();
break;
case "White":
newMana.increaseWhite();
break;
case "Colorless":
newMana.increaseColorless();
break;
}
}
}
}
}
return newMana;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class GauntletsOfLightEffect method apply.
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null || permanent.getAttachedTo() == null) {
return false;
}
Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
if (attachedTo == null || !attachedTo.getAbilities().containsKey(VigilanceAbility.getInstance().getId())) {
return false;
}
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new PermanentIdPredicate(permanent.getAttachedTo()));
game.getCombat().setUseToughnessForDamage(true);
game.getCombat().addUseToughnessForDamageFilter(filter);
return true;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class CallOfTheDeathDwellerTarget method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Cards cards = new CardsImpl(source.getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).collect(Collectors.toSet()));
if (player == null || cards.isEmpty() || !player.moveCards(cards, Zone.BATTLEFIELD, source, game)) {
return false;
}
List<PermanentIdPredicate> predicates = cards.stream().map(game::getPermanent).filter(Objects::nonNull).map(MageItem::getId).map(PermanentIdPredicate::new).collect(Collectors.toList());
if (predicates.isEmpty()) {
return false;
}
FilterPermanent filter = new FilterPermanent("creature to put a deathtouch counter on");
filter.add(Predicates.or(predicates));
Target target = new TargetPermanent(0, 1, filter, true);
if (player.choose(outcome, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.addCounters(CounterType.DEATHTOUCH.createInstance(), source.getControllerId(), source, game);
}
}
filter.setMessage("creature to put a menace counter on");
target = new TargetPermanent(0, 1, filter, true);
if (player.choose(outcome, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.addCounters(CounterType.MENACE.createInstance(), source.getControllerId(), source, game);
}
}
return true;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class DescentIntoMadnessEffect method selectCards.
private void selectCards(Player player, List<UUID> selectedObjects, int count, Ability source, Game game) {
int amount = Math.min(count, player.getHand().size() + game.getBattlefield().getAllActivePermanents(player.getId()).size());
int cardsFromHand = 0;
while (player.canRespond() && amount > 0) {
Target target;
do {
FilterControlledPermanent filter = new FilterControlledPermanent();
filter.setMessage("permanent you control (" + amount + " left in total)");
List<PermanentIdPredicate> uuidPredicates = new ArrayList<>();
for (UUID uuid : selectedObjects) {
uuidPredicates.add(new PermanentIdPredicate(uuid));
}
filter.add(Predicates.not(Predicates.or(uuidPredicates)));
target = new TargetControlledPermanent(0, 1, filter, true);
if (target.canChoose(source.getSourceId(), player.getId(), game) && player.choose(Outcome.Exile, target, source.getSourceId(), game)) {
for (UUID targetId : target.getTargets()) {
if (!selectedObjects.contains(targetId)) {
Permanent chosen = game.getPermanent(targetId);
if (chosen != null) {
amount--;
game.informPlayers(player.getLogName() + " selects " + chosen.getLogName() + " from battlefield");
selectedObjects.add(targetId);
}
}
}
}
} while (amount > 0 && !target.getTargets().isEmpty() && player.canRespond());
if (amount > 0) {
TargetCard targetInHand;
do {
FilterCard filterInHand = new FilterCard();
filterInHand.setMessage("card from your hand (" + amount + " left in total)");
targetInHand = new TargetCard(0, 1, Zone.HAND, filterInHand);
List<CardIdPredicate> uuidPredicates = new ArrayList<>();
for (UUID uuid : selectedObjects) {
uuidPredicates.add(new CardIdPredicate(uuid));
}
filterInHand.add(Predicates.not(Predicates.or(uuidPredicates)));
if (targetInHand.canChoose(source.getSourceId(), player.getId(), game) && player.choose(Outcome.Exile, player.getHand(), targetInHand, game)) {
Card card = player.getHand().get(targetInHand.getFirstTarget(), game);
if (card != null) {
selectedObjects.add(targetInHand.getFirstTarget());
amount--;
cardsFromHand++;
}
}
} while (amount > 0 && !targetInHand.getTargets().isEmpty() && player.canRespond());
}
}
if (cardsFromHand > 0) {
game.informPlayers(player.getLogName() + " selects " + cardsFromHand + (cardsFromHand == 1 ? " card" : " cards") + " from their hand");
}
}
Aggregations