use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class DebtToTheKamiExileEnchantmentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
if (player == null) {
return false;
}
Target target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null) {
return false;
}
return player.moveCards(permanent, Zone.EXILED, source, game);
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class DevourFleshSacrificeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player == null) {
return false;
}
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
int realCount = game.getBattlefield().countAll(filter, player.getId(), game);
if (realCount > 0) {
Target target = new TargetControlledPermanent(1, 1, filter, true);
while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Sacrifice, target, source, game);
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
int gainLife = permanent.getToughness().getValue();
permanent.sacrifice(source, game);
game.getState().processAction(game);
player.gainLife(gainLife, game, source);
} else {
return false;
}
}
return true;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class DevoutInvocationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
TargetPermanent target = new TargetControlledPermanent(0, Integer.MAX_VALUE, DevoutInvocation.filter, true);
controller.choose(outcome, target, source.getSourceId(), game);
if (target.getTargets().isEmpty()) {
return false;
}
int tappedAmount = 0;
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null && permanent.tap(source, game)) {
tappedAmount++;
}
}
if (tappedAmount > 0) {
AngelToken angelToken = new AngelToken();
angelToken.putOntoBattlefield(tappedAmount, game, source, source.getControllerId());
}
return true;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class GraveExchangeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getTargets().get(1).getFirstTarget());
if (player == null) {
return false;
}
Target target = new TargetControlledPermanent(new FilterControlledCreaturePermanent());
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) {
return permanent.sacrifice(source, game);
}
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class KathrilAspectWarperEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null || game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game) == 0) {
return false;
}
Set<CounterType> counterSet = player.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game).stream().map(Card::getAbilities).flatMap(Collection::stream).map(this::checkAbility).collect(Collectors.toSet());
if (counterSet == null || counterSet.size() == 0) {
return false;
}
int countersAdded = 0;
for (CounterType counterType : counterSet) {
if (counterType == null) {
continue;
}
FilterControlledPermanent filter = new FilterControlledCreaturePermanent("creature to give a " + counterType + " counter");
Target target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (!player.choose(outcome, target, source.getSourceId(), game)) {
continue;
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null) {
continue;
}
if (permanent.addCounters(counterType.createInstance(), source.getControllerId(), source, game)) {
countersAdded++;
}
}
if (countersAdded == 0) {
return false;
}
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
return true;
}
permanent.addCounters(CounterType.P1P1.createInstance(countersAdded), source.getControllerId(), source, game);
return true;
}
Aggregations