use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class RhonasTheIndomitableRestrictionEffect method applies.
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 3));
filter.add(AnotherPredicate.instance);
if (permanent.getId().equals(source.getSourceId())) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int permanentsOnBattlefield = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
// is this correct?
return permanentsOnBattlefield < 1;
}
return true;
}
// do not apply to other creatures.
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class SigilOfValorCount method calculate.
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
Permanent equipment = game.getPermanent(sourceAbility.getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) {
FilterPermanent filterPermanent = new FilterControlledCreaturePermanent();
filterPermanent.add(Predicates.not(new CardIdPredicate(equipment.getAttachedTo())));
return game.getBattlefield().count(filterPermanent, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
}
return 0;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class TariffEffect method processPlayer.
private void processPlayer(Game game, Ability source, Player player) {
MageObject sourceObject = game.getObject(source.getSourceId());
List<Permanent> creatures = getPermanentsWithTheHighestCMC(game, player.getId(), new FilterControlledCreaturePermanent());
Permanent creatureToPayFor = chooseOnePermanent(game, player, creatures);
if (creatureToPayFor != null && sourceObject != null) {
ManaCosts manaCost = ManaCosts.removeVariableManaCost(creatureToPayFor.getManaCost());
String message = "Pay " + manaCost.getText() + " (otherwise sacrifice " + creatureToPayFor.getName() + ")?";
if (player.chooseUse(Outcome.Benefit, message, source, game)) {
if (manaCost.pay(source, game, source, player.getId(), false, null)) {
game.informPlayers(sourceObject.getName() + ": " + player.getLogName() + " has paid");
return;
}
}
game.informPlayers(sourceObject.getName() + ": " + player.getLogName() + " hasn't paid");
creatureToPayFor.sacrifice(source, game);
}
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class TributeToHungerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(source.getTargets().getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && opponent != null) {
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
if (target.canChoose(source.getSourceId(), opponent.getId(), game)) {
opponent.chooseTarget(Outcome.Sacrifice, target, source, game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
controller.gainLife(permanent.getToughness().getValue(), game, source);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class XathridDemonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent == null) {
sourcePermanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
}
if (controller == null || sourcePermanent == null) {
return false;
}
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature other than " + sourcePermanent.getName());
filter.add(AnotherPredicate.instance);
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
int amount = permanent.getPower().getValue();
permanent.sacrifice(source, game);
if (amount > 0) {
Set<UUID> opponents = game.getOpponents(source.getControllerId());
for (UUID opponentId : opponents) {
Player opponent = game.getPlayer(opponentId);
if (opponent != null) {
opponent.loseLife(amount, game, source, false);
}
}
}
return true;
}
} else {
sourcePermanent.tap(source, game);
controller.loseLife(7, game, source, false);
return true;
}
return false;
}
Aggregations