use of mage.target.common.TargetControlledCreaturePermanent 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.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class MagneticMountainEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (player != null && sourcePermanent != null) {
int countBattlefield = game.getBattlefield().getAllActivePermanents(filter2, game.getActivePlayerId(), game).size();
while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.Benefit, "Pay {4} and untap a tapped blue creature under your control?", source, game)) {
Target tappedCreatureTarget = new TargetControlledCreaturePermanent(1, 1, filter2, true);
if (player.choose(Outcome.Untap, tappedCreatureTarget, source.getSourceId(), game)) {
Cost cost = ManaUtil.createManaCost(4, false);
Permanent tappedCreature = game.getPermanent(tappedCreatureTarget.getFirstTarget());
if (tappedCreature != null && cost.pay(source, game, source, player.getId(), false)) {
tappedCreature.untap(game);
} else {
break;
}
} else {
break;
}
countBattlefield = game.getBattlefield().getAllActivePermanents(filter2, game.getActivePlayerId(), game).size();
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledCreaturePermanent 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.TargetControlledCreaturePermanent 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;
}
use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class ScarscaleRitualCost method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Player controller = game.getPlayer(ability.getControllerId());
if (controller != null) {
Target target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
controller.chooseTarget(Outcome.UnboostCreature, target, ability, game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.addCounters(CounterType.M1M1.createInstance(), controllerId, ability, game);
game.informPlayers(controller.getLogName() + " puts a -1/-1 counter on " + permanent.getLogName());
this.paid = true;
}
}
return paid;
}
Aggregations