use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class ReignOfThePitEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int totalPowerSacrificed = 0;
List<UUID> perms = new ArrayList<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent(1, 1, new FilterControlledCreaturePermanent(), true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
while (!target.isChosen() && player.canRespond()) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
}
perms.addAll(target.getTargets());
}
}
}
for (UUID permID : perms) {
Permanent permanent = game.getPermanent(permID);
if (permanent != null) {
int power = permanent.getPower().getValue();
if (permanent.sacrifice(source, game)) {
totalPowerSacrificed += power;
}
}
}
new CreateTokenEffect(new DemonFlyingToken(totalPowerSacrificed)).apply(game, source);
return true;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class BolsterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (amount.calculate(game, source, this) <= 0) {
return true;
}
int leastToughness = Integer.MAX_VALUE;
Permanent selectedCreature = null;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game)) {
if (leastToughness > permanent.getToughness().getValue()) {
leastToughness = permanent.getToughness().getValue();
selectedCreature = permanent;
} else if (leastToughness == permanent.getToughness().getValue()) {
leastToughness = permanent.getToughness().getValue();
selectedCreature = null;
}
}
if (leastToughness != Integer.MAX_VALUE) {
if (selectedCreature == null) {
FilterPermanent filter = new FilterControlledCreaturePermanent("creature you control with toughness " + leastToughness);
filter.add(new ToughnessPredicate(ComparisonType.EQUAL_TO, leastToughness));
Target target = new TargetPermanent(1, 1, filter, true);
if (controller.chooseTarget(outcome, target, source, game)) {
selectedCreature = game.getPermanent(target.getFirstTarget());
}
}
if (selectedCreature != null) {
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(amount.calculate(game, source, this)));
effect.setTargetPointer(new FixedTarget(selectedCreature, game));
return effect.apply(game, source);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class DivineReckoningEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Card> chosen = new ArrayList<>();
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
Target target = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Benefit, target, source, game);
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
chosen.add(permanent);
}
}
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), source.getSourceId(), game)) {
if (!chosen.contains(permanent)) {
permanent.destroy(source, game, false);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class FrayingOmnipotenceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
// Each player loses half of their life,
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
int lifeToLose = (int) Math.ceil(player.getLife() / 2.0);
player.loseLife(lifeToLose, game, source, false);
}
// then discards half of the cards in their hand,
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
int cardsToDiscard = (int) Math.ceil(player.getHand().size() / 2.0);
if (cardsToDiscard > 0) {
player.discard(cardsToDiscard, false, false, source, game);
}
}
// then sacrifices half of the creatures they control,
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
int creaturesToSacrifice = (int) Math.ceil(game.getBattlefield().count(filter, source.getSourceId(), player.getId(), game) / 2.0);
if (creaturesToSacrifice == 0) {
continue;
}
Target target = new TargetControlledCreaturePermanent(creaturesToSacrifice, creaturesToSacrifice, filter, true);
target.chooseTarget(Outcome.Sacrifice, playerId, source, game);
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
}
return true;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class PulseOfTheTangleReturnToHandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
FilterControlledCreaturePermanent controllerFilter = new FilterControlledCreaturePermanent();
PermanentsOnBattlefieldCount controllerCount = new PermanentsOnBattlefieldCount(controllerFilter);
int controllerAmount = controllerCount.calculate(game, source, this);
boolean check = false;
if (controller != null) {
for (UUID opponentID : game.getOpponents(controller.getId())) {
if (opponentID != null) {
FilterCreaturePermanent opponentFilter = new FilterCreaturePermanent();
opponentFilter.add(new ControllerIdPredicate(opponentID));
PermanentsOnBattlefieldCount opponentCreatureCount = new PermanentsOnBattlefieldCount(opponentFilter);
check = opponentCreatureCount.calculate(game, source, this) > controllerAmount;
if (check) {
break;
}
}
}
if (check) {
Card card = game.getCard(source.getSourceId());
controller.moveCards(card, Zone.HAND, source, game);
return true;
}
}
return false;
}
Aggregations