use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class MirrorWeaveEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
FilterCreaturePermanent filter = new FilterCreaturePermanent();
if (controller != null) {
Permanent copyFromCreature = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (copyFromCreature != null) {
filter.add(Predicates.not(new PermanentIdPredicate(copyFromCreature.getId())));
for (Permanent copyToCreature : game.getBattlefield().getAllActivePermanents(filter, game)) {
if (copyToCreature != null) {
game.copyPermanent(Duration.EndOfTurn, copyFromCreature, copyToCreature.getId(), source, new EmptyCopyApplier());
}
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class TargetCreatureWithLessPowerPermanent method canChoose.
@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
// get the most powerful controlled creature that can be targeted
int maxPower = Integer.MIN_VALUE;
Card sourceCard = game.getCard(sourceId);
if (sourceCard == null) {
return false;
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, sourceControllerId, game)) {
if (permanent.getPower().getValue() > maxPower && permanent.canBeTargetedBy(sourceCard, sourceControllerId, game)) {
maxPower = permanent.getPower().getValue();
}
}
// now check, if another creature has less power and can be targeted
FilterCreaturePermanent checkFilter = new FilterCreaturePermanent();
checkFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, maxPower));
for (Permanent permanent : game.getBattlefield().getActivePermanents(checkFilter, sourceControllerId, sourceId, game)) {
if (permanent.canBeTargetedBy(sourceCard, sourceControllerId, game)) {
return true;
}
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class NightmareUnmakingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
FilterPermanent filter = new FilterCreaturePermanent();
filter.add(new PowerPredicate(comparisonType, player.getHand().size()));
return new ExileAllEffect(filter).apply(game, source);
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class OrzhovAdvokistEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<UUID> players = new ArrayList<>();
List<UUID> creatures = new ArrayList<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
if (player.chooseUse(outcome, "Put two +1/+1 counters on a creature you control?", source, game)) {
Target target = new TargetControlledCreaturePermanent(new FilterControlledCreaturePermanent("a creature you control (to add two +1/+1 counters on it)"));
if (player.choose(outcome, target, playerId, game)) {
creatures.add(target.getFirstTarget());
players.add(player.getId());
}
}
}
}
for (UUID creatureId : creatures) {
Permanent creature = game.getPermanent(creatureId);
if (creature != null) {
creature.addCounters(CounterType.P1P1.createInstance(2), creature.getControllerId(), source, game);
}
}
for (UUID playerId : players) {
if (!Objects.equals(playerId, source.getControllerId())) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new ControllerIdPredicate(playerId));
game.addEffect(new CantAttackYouAllEffect(Duration.UntilYourNextTurn, filter, true), source);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class PolymorphousRushCopyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetCreaturePermanent(new FilterCreaturePermanent(""));
target.setNotTarget(true);
target.setTargetName("a creature on the battlefield (creature to copy)");
if (target.canChoose(source.getId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
Permanent copyFromCreature = game.getPermanent(target.getFirstTarget());
if (copyFromCreature != null) {
for (UUID copyToId : getTargetPointer().getTargets(game, source)) {
Permanent copyToCreature = game.getPermanent(copyToId);
if (copyToCreature != null) {
game.copyPermanent(Duration.EndOfTurn, copyFromCreature, copyToId, source, new EmptyCopyApplier());
}
}
}
}
return true;
}
return false;
}
Aggregations