use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ShimatsuTheBloodcloakedEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
Player controller = game.getPlayer(source.getControllerId());
if (creature != null && controller != null) {
Target target = new TargetControlledPermanent(0, Integer.MAX_VALUE, new FilterControlledPermanent(), true);
if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
return false;
}
controller.chooseTarget(Outcome.Detriment, target, source, game);
if (!target.getTargets().isEmpty()) {
int sacrificedCreatures = target.getTargets().size();
game.informPlayers(controller.getLogName() + " sacrifices " + sacrificedCreatures + " creatures for " + creature.getLogName());
for (UUID targetId : target.getTargets()) {
Permanent targetCreature = game.getPermanent(targetId);
if (targetCreature == null || !targetCreature.sacrifice(source, game)) {
return false;
}
}
creature.addCounters(CounterType.P1P1.createInstance(sacrificedCreatures), source.getControllerId(), source, game);
}
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class SmokestackEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player activePlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (activePlayer != null && sourcePermanent != null) {
int count = sourcePermanent.getCounters(game).getCount(CounterType.SOOT);
if (count > 0) {
int amount = Math.min(count, game.getBattlefield().countAll(new FilterControlledPermanent(), activePlayer.getId(), game));
Target target = new TargetControlledPermanent(amount, amount, new FilterControlledPermanent(), true);
// had, if thats the case this ability should fizzle.
if (target.canChoose(source.getSourceId(), activePlayer.getId(), game)) {
while (!target.isChosen() && target.canChoose(source.getSourceId(), activePlayer.getId(), game) && activePlayer.canRespond()) {
activePlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
}
for (int idx = 0; idx < target.getTargets().size(); idx++) {
Permanent permanent = game.getPermanent(target.getTargets().get(idx));
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class TwistedJusticeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getTargets().getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
FilterControlledPermanent filter = new FilterControlledPermanent("creature");
filter.add(CardType.CREATURE.getPredicate());
filter.add(TargetController.YOU.getControllerPredicate());
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
// had, if thats the case this ability should fizzle.
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
controller.drawCards(permanent.getPower().getValue(), source, game);
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class DevourEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
Player controller = game.getPlayer(source.getControllerId());
if (creature == null || controller == null) {
return false;
}
Target target = new TargetControlledPermanent(1, Integer.MAX_VALUE, devourFactor.getFilter(), true);
target.setRequired(false);
if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
return false;
}
if (!controller.chooseUse(Outcome.Detriment, "Devour " + devourFactor.getCardType().toString().toLowerCase() + "s?", source, game)) {
return false;
}
controller.chooseTarget(Outcome.Detriment, target, source, game);
if (target.getTargets().isEmpty()) {
return false;
}
List<Permanent> creaturesDevoured = new ArrayList<>();
int devouredCreatures = 0;
for (UUID targetId : target.getTargets()) {
Permanent targetCreature = game.getPermanent(targetId);
if (targetCreature != null && targetCreature.sacrifice(source, game)) {
creaturesDevoured.add(targetCreature);
devouredCreatures++;
}
}
if (!game.isSimulation()) {
game.informPlayers(creature.getLogName() + " devours " + devouredCreatures + " " + devourFactor.getCardType().toString().toLowerCase() + "s");
}
// need for multistep effects
game.getState().processAction(game);
int amountCounters;
if (devourFactor == DevourFactor.DevourX) {
amountCounters = devouredCreatures * devouredCreatures;
} else {
amountCounters = devouredCreatures * devourFactor.getFactor();
}
creature.addCounters(CounterType.P1P1.createInstance(amountCounters), source.getControllerId(), source, game);
game.getState().setValue(creature.getId().toString() + "devoured", creaturesDevoured);
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class JalumGrifterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getTargets().get(0).getFirstTarget());
if (controller != null && opponent != null) {
List<Card> shellGamePile = new ArrayList<>();
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard != null) {
sourceCard = sourceCard.copy();
sourceCard.setFaceDown(true, game);
shellGamePile.add(sourceCard);
game.informPlayers(controller.getLogName() + " turns " + sourceCard.getLogName() + " face down");
}
Target target = new TargetControlledPermanent(2, 2, new FilterControlledLandPermanent(), true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
controller.chooseTarget(outcome, target, source, game);
}
}
for (UUID cardId : target.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
card = card.copy();
card.setFaceDown(true, game);
shellGamePile.add(card);
game.informPlayers(controller.getLogName() + " turns " + card.getLogName() + " face down");
}
}
if (shellGamePile.isEmpty()) {
return true;
}
Collections.shuffle(shellGamePile);
game.informPlayers(controller.getLogName() + " shuffles the face-down pile");
TargetCard targetCard = new TargetCard(Zone.HAND, new FilterCard());
CardsImpl cards = new CardsImpl();
cards.addAll(shellGamePile);
if (opponent.choose(Outcome.Sacrifice, cards, targetCard, game)) {
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
card.setFaceDown(false, game);
game.informPlayers(opponent.getLogName() + " reveals " + card.getLogName());
if (card.getId().equals(sourceCard.getId())) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
sourcePermanent.sacrifice(source, game);
}
} else {
Permanent permanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (permanent != null) {
permanent.destroy(source, game, false);
}
}
}
}
return true;
}
return false;
}
Aggregations