use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class DismantleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (controller != null) {
if (permanent != null) {
int counterCount = 0;
counterCount = permanent.getCounters(game).values().stream().map((counter) -> counter.getCount()).reduce(counterCount, Integer::sum);
permanent.destroy(source, game, false);
if (counterCount > 0) {
Target target = new TargetControlledPermanent(1, 1, new FilterControlledArtifactPermanent("an artifact you control"), true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.chooseTarget(Outcome.Benefit, target, source, game);
Permanent artifact = game.getPermanent(target.getFirstTarget());
Counter counter;
if (controller.chooseUse(Outcome.BoostCreature, "Choose which kind of counters to add", null, "+1/+1 counters", "Charge counters", source, game)) {
counter = CounterType.P1P1.createInstance(counterCount);
} else {
counter = CounterType.CHARGE.createInstance(counterCount);
}
if (artifact != null) {
artifact.addCounters(counter, source.getControllerId(), source, game);
}
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class DroughtAdditionalCostEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
int blackSymbols = abilityToModify.getManaCosts().getMana().getBlack();
TargetControlledPermanent target = new TargetControlledPermanent(blackSymbols, blackSymbols, filter, true);
target.setRequired(false);
abilityToModify.addCost(new SacrificeTargetCost(target));
return true;
}
use of mage.target.common.TargetControlledPermanent 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.target.common.TargetControlledPermanent 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.target.common.TargetControlledPermanent in project mage by magefree.
the class RaziasPurificationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Card> chosen = new ArrayList<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
Target target1 = new TargetControlledPermanent(1, 1, new FilterControlledPermanent(), true);
if (player != null && target1.canChoose(source.getSourceId(), player.getId(), game)) {
int chosenPermanents = 0;
while (player.canRespond() && !target1.isChosen() && target1.canChoose(source.getSourceId(), player.getId(), game) && chosenPermanents < 3) {
player.chooseTarget(Outcome.Benefit, target1, source, game);
for (UUID targetId : target1.getTargets()) {
Permanent p = game.getPermanent(targetId);
if (p != null) {
chosen.add(p);
chosenPermanents++;
}
}
target1.clearChosen();
}
}
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
if (!chosen.contains(permanent)) {
permanent.sacrifice(source, game);
}
}
return true;
}
Aggregations