use of mage.filter.predicate.permanent.BlockedByIdPredicate in project mage by magefree.
the class WallOfVaporEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game) && event instanceof DamageEvent && event.getAmount() > 0) {
DamageEvent damageEvent = (DamageEvent) event;
if (event.getTargetId().equals(source.getSourceId())) {
Permanent permanent = game.getPermanentOrLKIBattlefield(damageEvent.getSourceId());
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new BlockedByIdPredicate(source.getSourceId()));
if (permanent != null && filter.match(permanent, game)) {
return true;
}
}
}
return false;
}
use of mage.filter.predicate.permanent.BlockedByIdPredicate 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);
}
use of mage.filter.predicate.permanent.BlockedByIdPredicate in project mage by magefree.
the class GreaterWerewolfEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourcePermanent != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(Predicates.or(new BlockedByIdPredicate(sourcePermanent.getId()), new BlockingAttackerIdPredicate(sourcePermanent.getId())));
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
Effect effect = new AddCountersTargetEffect(CounterType.M0M2.createInstance(), Outcome.UnboostCreature);
effect.setTargetPointer(new FixedTarget(permanent, game));
effect.apply(game, source);
}
return true;
}
return false;
}
use of mage.filter.predicate.permanent.BlockedByIdPredicate in project mage by magefree.
the class SpittingSlugEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourcePermanent != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(Predicates.or(new BlockedByIdPredicate(sourcePermanent.getId()), new BlockingAttackerIdPredicate(sourcePermanent.getId())));
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
ContinuousEffect effect = new GainAbilityTargetEffect(FirstStrikeAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
return true;
}
return false;
}
use of mage.filter.predicate.permanent.BlockedByIdPredicate in project mage by magefree.
the class SereneMasterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourceCreature = game.getPermanent(source.getSourceId());
if (controller != null && sourceCreature != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature it's blocking");
filter.add(new BlockedByIdPredicate((source.getSourceId())));
Target target = new TargetCreaturePermanent(filter);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
if (controller.chooseTarget(outcome, target, source, game)) {
Permanent attackingCreature = game.getPermanent(target.getFirstTarget());
if (attackingCreature != null) {
int newSourcePower = attackingCreature.getPower().getValue();
int newAttackerPower = sourceCreature.getPower().getValue();
ContinuousEffect effect = new SetPowerToughnessTargetEffect(newSourcePower, sourceCreature.getToughness().getValue(), Duration.EndOfCombat);
effect.setTargetPointer(new FixedTarget(source.getSourceId(), game));
game.addEffect(effect, source);
effect = new SetPowerToughnessTargetEffect(newAttackerPower, attackingCreature.getToughness().getValue(), Duration.EndOfCombat);
effect.setTargetPointer(new FixedTarget(attackingCreature.getId(), game));
game.addEffect(effect, source);
return true;
}
}
}
}
return false;
}
Aggregations