use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class OverwhelmingStampedeInitEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int maxPower = 0;
for (Permanent perm : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
if (perm.getPower().getValue() > maxPower) {
maxPower = perm.getPower().getValue();
}
}
ContinuousEffect effect = new GainAbilityControlledEffect(TrampleAbility.getInstance(), Duration.EndOfTurn, new FilterCreaturePermanent());
game.addEffect(effect, source);
if (maxPower != 0) {
effect = new BoostControlledEffect(maxPower, maxPower, Duration.EndOfTurn);
game.addEffect(effect, source);
}
return true;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class RetetherEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Map<Card, Permanent> auraMap = new HashMap<>();
auraCardsInGraveyard: for (Card aura : controller.getGraveyard().getCards(filterAura, source.getSourceId(), source.getControllerId(), game)) {
if (aura != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature to enchant (" + aura.getLogName() + ')');
filter.add(new CanBeEnchantedByPredicate(aura));
Target target = null;
auraLegalitySearch: for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, playerId, game)) {
if (permanent != null) {
for (Ability ability : aura.getAbilities()) {
if (ability instanceof SpellAbility) {
for (Target abilityTarget : ability.getTargets()) {
if (abilityTarget.possibleTargets(controller.getId(), game).contains(permanent.getId())) {
target = abilityTarget.copy();
break auraLegalitySearch;
}
}
}
}
}
}
}
if (target != null) {
target.getFilter().add(CardType.CREATURE.getPredicate());
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
target.setTargetName("creature to enchant (" + aura.getLogName() + ')');
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null && !permanent.cantBeAttachedBy(aura, source, game, true)) {
auraMap.put(aura, permanent);
game.getState().setValue("attachTo:" + aura.getId(), permanent);
continue auraCardsInGraveyard;
}
}
}
}
game.informPlayers("No valid creature targets for " + aura.getLogName());
}
}
controller.moveCards(auraMap.keySet(), Zone.BATTLEFIELD, source, game);
for (Entry<Card, Permanent> entry : auraMap.entrySet()) {
Card aura = entry.getKey();
Permanent permanent = entry.getValue();
if (aura != null && permanent != null) {
permanent.addAttachment(aura.getId(), source, game);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class SomnophoreTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.getSourceId())) {
Player opponent = game.getPlayer(event.getPlayerId());
if (opponent != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
filter.add(new ControllerIdPredicate(opponent.getId()));
this.getTargets().clear();
this.addTarget(new TargetCreaturePermanent(filter));
return true;
}
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class WalkingDesecrationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (player != null) {
if (sourceObject != null) {
Choice typeChoice = new ChoiceCreatureType(sourceObject);
if (player.choose(outcome, typeChoice, game)) {
game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice());
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
RequirementEffect effect = new AttacksIfAbleAllEffect(filter, Duration.EndOfTurn);
game.addEffect(effect, source);
return true;
}
}
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class WallOfShadowsEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!super.applies(event, source, game) || !(event instanceof DamageEvent) || event.getAmount() <= 0) {
return false;
}
DamageEvent damageEvent = (DamageEvent) event;
if (!event.getTargetId().equals(source.getSourceId())) {
return false;
}
Permanent permanent = game.getPermanentOrLKIBattlefield(damageEvent.getSourceId());
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new BlockedByIdPredicate(source.getSourceId()));
return permanent != null && filter.match(permanent, game);
}
Aggregations