use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class MudslideEffect 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(filter, game.getActivePlayerId(), game).size();
while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.Benefit, "Pay {2} and untap a tapped creature without flying under your control?", source, game)) {
Target tappedCreatureTarget = new TargetControlledCreaturePermanent(1, 1, filter, true);
if (player.choose(Outcome.Untap, tappedCreatureTarget, source.getSourceId(), game)) {
Cost cost = ManaUtil.createManaCost(2, 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(filter, game.getActivePlayerId(), game).size();
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class MultipleChoiceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int xValue = source.getManaCostsToPay().getX();
if (xValue == 1 || xValue >= 4) {
controller.scry(1, source, game);
controller.drawCards(1, source, game);
}
if (xValue == 3 || xValue >= 4) {
new Elemental44Token().putOntoBattlefield(1, game, source, source.getControllerId());
}
if (xValue != 2 && xValue < 4) {
return true;
}
TargetPlayer targetPlayer = new TargetPlayer(0, 1, true);
controller.choose(Outcome.Detriment, targetPlayer, source.getSourceId(), game);
Player player = game.getPlayer(targetPlayer.getFirstTarget());
if (player == null || game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getSourceId(), player.getId(), game) <= 0) {
return true;
}
TargetPermanent targetPermanent = new TargetControlledCreaturePermanent();
targetPermanent.setNotTarget(true);
player.choose(Outcome.ReturnToHand, targetPermanent, source.getSourceId(), game);
Permanent permanent = game.getPermanent(targetPermanent.getFirstTarget());
return permanent == null || player.moveCards(permanent, Zone.HAND, source, game);
}
use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class PrimalEmpathyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int highestPower = game.getBattlefield().getActivePermanents(source.getControllerId(), game).stream().filter(permanent1 -> permanent1.isCreature(game)).map(Permanent::getPower).mapToInt(MageInt::getValue).max().orElse(0);
boolean flag = game.getBattlefield().getAllActivePermanents(source.getControllerId()).stream().filter(permanent1 -> permanent1.isCreature(game)).map(Permanent::getPower).mapToInt(MageInt::getValue).anyMatch(i -> i >= highestPower);
if (flag) {
return player.drawCards(1, source, game) > 0;
}
Target target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (!player.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
return permanent != null && permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
}
use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class RaidingPartyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourcePermanent != null) {
Set<UUID> plainsToSave = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int countBattlefield = game.getBattlefield().getAllActivePermanents(filter, game.getActivePlayerId(), game).size();
int tappedCount = 0;
Target untappedCreatureTarget = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, filter, true);
if (player.choose(Outcome.Benefit, untappedCreatureTarget, source.getSourceId(), game)) {
tappedCount = untappedCreatureTarget.getTargets().size();
for (UUID creatureId : untappedCreatureTarget.getTargets()) {
Permanent creature = game.getPermanentOrLKIBattlefield(creatureId);
if (creature != null) {
creature.tap(source, game);
}
}
}
if (tappedCount > 0) {
Target plainsToSaveTarget = new TargetPermanent(0, tappedCount * 2, filter2, true);
if (player.choose(Outcome.Benefit, plainsToSaveTarget, source.getSourceId(), game)) {
for (UUID plainsId : plainsToSaveTarget.getTargets()) {
plainsToSave.add(plainsId);
Permanent plains = game.getPermanent(plainsId);
if (plains != null) {
game.informPlayers(player.getLogName() + " chose " + plains.getLogName() + " to not be destroyed by " + sourcePermanent.getLogName());
}
}
}
}
}
}
for (Permanent plains : game.getBattlefield().getActivePermanents(filter2, source.getControllerId(), source.getSourceId(), game)) {
if (!plainsToSave.contains(plains.getId())) {
plains.destroy(source, game, false);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledCreaturePermanent in project mage by magefree.
the class SavraSacrificeGreenCreatureAbility method apply.
@Override
public boolean apply(Game game, Ability source) {
List<UUID> perms = new ArrayList<>();
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null && !playerId.equals(source.getControllerId())) {
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Sacrifice, target, source, game);
perms.addAll(target.getTargets());
}
}
}
for (UUID permID : perms) {
Permanent permanent = game.getPermanent(permID);
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
return true;
}
return false;
}
Aggregations