use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class DistantMelodyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Choice typeChoice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
if (controller != null && controller.choose(Outcome.BoostCreature, typeChoice, game)) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
return new DrawCardSourceControllerEffect(new PermanentsOnBattlefieldCount(filter)).apply(game, source);
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class LastDitchEffortEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
Target target = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, new FilterControlledCreaturePermanent(), true);
player.chooseTarget(Outcome.Sacrifice, target, source, game);
int numSacrificed = 0;
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
if (permanent.sacrifice(source, game)) {
numSacrificed++;
}
}
}
if (numSacrificed > 0) {
int damage = numSacrificed;
UUID uuid = this.getTargetPointer().getFirst(game, source);
Permanent permanent = game.getPermanent(uuid);
Player opponent = game.getPlayer(uuid);
if (permanent != null) {
permanent.damage(damage, source.getSourceId(), source, game, false, true);
}
if (opponent != null) {
opponent.damage(damage, source.getSourceId(), source, game);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class PoxEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// Each player loses a third of their life,
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int lifeToLose = (int) Math.ceil(player.getLife() / 3.0);
player.loseLife(lifeToLose, game, source, false);
}
}
// then discards a third of the cards in their hand,
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int cardsToDiscard = (int) Math.ceil(player.getHand().size() / 3.0);
if (cardsToDiscard > 0) {
player.discard(cardsToDiscard, false, false, source, game);
}
}
}
// then sacrifices a third of the creatures they control,
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
int creaturesToSacrifice = (int) Math.ceil(game.getBattlefield().count(filter, source.getSourceId(), player.getId(), game) / 3.0);
if (creaturesToSacrifice > 0) {
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);
}
}
}
}
}
// then sacrifices a third of the lands they control.
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
FilterControlledLandPermanent filter = new FilterControlledLandPermanent();
int landsToSacrifice = (int) Math.ceil(game.getBattlefield().count(filter, source.getSourceId(), player.getId(), game) / 3.0);
if (landsToSacrifice > 0) {
Target target = new TargetControlledPermanent(landsToSacrifice, landsToSacrifice, 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;
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class ProwlingPangolinEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
boolean costPaid = false;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(2, 2, new FilterControlledCreaturePermanent("two creatures"), true));
Player player = game.getPlayer(playerId);
if (player != null && cost.canPay(source, source, playerId, game) && player.chooseUse(Outcome.Sacrifice, "Sacrifice two creatures?", source, game) && cost.pay(source, game, source, playerId, true, null)) {
costPaid = true;
}
}
if (costPaid) {
Permanent sourceObject = game.getPermanent(source.getSourceId());
if (sourceObject != null) {
sourceObject.sacrifice(source, game);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class RuptureEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
int power = 0;
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent(1, 1, new FilterControlledCreaturePermanent("creature to sacrifice"), true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
while (!target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game) && player.canRespond()) {
player.chooseTarget(Outcome.Sacrifice, target, source, game);
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
power = permanent.getPower().getValue();
permanent.sacrifice(source, game);
}
}
if (power > 0) {
new DamageEverythingEffect(power, filter).apply(game, source);
}
return true;
}
return false;
}
Aggregations