use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ArchfiendOfDepravityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
if (opponent != null) {
List<Permanent> creaturesToSacrifice = new ArrayList<>();
TargetControlledPermanent target = new TargetControlledPermanent(0, 2, new FilterControlledCreaturePermanent("creatures to keep"), true);
if (opponent.chooseTarget(outcome, target, source, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), opponent.getId(), source.getSourceId(), game)) {
if (permanent != null && !target.getTargets().contains(permanent.getId())) {
creaturesToSacrifice.add(permanent);
}
}
}
for (Permanent creature : creaturesToSacrifice) {
creature.sacrifice(source, game);
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ReleaseSacrificeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<UUID> chosen = new ArrayList<>();
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
Target target1 = new TargetControlledPermanent(1, 1, new FilterControlledArtifactPermanent(), true);
Target target2 = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
Target target3 = new TargetControlledPermanent(1, 1, new FilterControlledEnchantmentPermanent(), true);
Target target4 = new TargetControlledPermanent(1, 1, new FilterControlledLandPermanent(), true);
Target target5 = new TargetControlledPermanent(1, 1, new FilterControlledPlaneswalkerPermanent(), true);
if (target1.canChoose(source.getSourceId(), player.getId(), game)) {
while (player.canRespond() && !target1.isChosen() && target1.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Benefit, target1, source, game);
}
Permanent artifact = game.getPermanent(target1.getFirstTarget());
if (artifact != null) {
chosen.add(artifact.getId());
}
target1.clearChosen();
}
if (target2.canChoose(source.getSourceId(), player.getId(), game)) {
while (player.canRespond() && !target2.isChosen() && target2.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Benefit, target2, source, game);
}
Permanent creature = game.getPermanent(target2.getFirstTarget());
if (creature != null) {
chosen.add(creature.getId());
}
target2.clearChosen();
}
if (target3.canChoose(source.getSourceId(), player.getId(), game)) {
while (player.canRespond() && !target3.isChosen() && target3.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Benefit, target3, source, game);
}
Permanent enchantment = game.getPermanent(target3.getFirstTarget());
if (enchantment != null) {
chosen.add(enchantment.getId());
}
target3.clearChosen();
}
if (target4.canChoose(source.getSourceId(), player.getId(), game)) {
while (player.canRespond() && !target4.isChosen() && target4.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Benefit, target4, source, game);
}
Permanent land = game.getPermanent(target4.getFirstTarget());
if (land != null) {
chosen.add(land.getId());
}
target4.clearChosen();
}
if (target5.canChoose(source.getSourceId(), player.getId(), game)) {
while (player.canRespond() && !target5.isChosen() && target5.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Benefit, target5, source, game);
}
Permanent planeswalker = game.getPermanent(target5.getFirstTarget());
if (planeswalker != null) {
chosen.add(planeswalker.getId());
}
target5.clearChosen();
}
}
for (UUID uuid : chosen) {
Permanent permanent = game.getPermanent(uuid);
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
return true;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ClambassadorsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetControlledPermanent(1, 1, filter, 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);
}
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (permanent != null && opponent != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
game.informPlayers(opponent.getLogName() + " has gained control of " + permanent.getLogName());
return true;
}
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ClarionUltimatumTarget method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int permCount = game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT, source.getSourceId(), source.getControllerId(), game);
TargetPermanent targetPermanent = new TargetControlledPermanent(Math.max(permCount, 5));
targetPermanent.setNotTarget(true);
player.choose(outcome, targetPermanent, source.getSourceId(), game);
Set<String> names = targetPermanent.getTargets().stream().map(game::getCard).filter(Objects::nonNull).map(MageObject::getName).collect(Collectors.toSet());
TargetCardInLibrary targetCardInLibrary = new ClarionUltimatumTarget(names);
player.searchLibrary(targetCardInLibrary, source, game);
Cards cards = new CardsImpl(targetCardInLibrary.getTargets());
player.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
player.shuffleLibrary(source, game);
return true;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ClackbridgeTrollEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
boolean flag = false;
for (UUID opponentId : game.getOpponents(controller.getId())) {
Player opponent = game.getPlayer(opponentId);
if (opponent == null) {
continue;
}
TargetControlledPermanent target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (!target.canChoose(source.getSourceId(), opponent.getId(), game) || !opponent.chooseUse(Outcome.AIDontUseIt, "Sacrifice a creature?", source, game) || !opponent.choose(Outcome.Sacrifice, target, source.getSourceId(), game)) {
continue;
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null || !permanent.sacrifice(source, game)) {
continue;
}
flag = true;
}
if (flag) {
Permanent sourcePerm = source.getSourcePermanentIfItStillExists(game);
if (sourcePerm != null) {
sourcePerm.tap(source, game);
}
controller.gainLife(3, game, source);
controller.drawCards(1, source, game);
}
return true;
}
Aggregations