use of mage.target.TargetPermanent in project mage by magefree.
the class HandOfVecnaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null || player.getHand().size() < 1) {
return false;
}
Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
Permanent equipped = game.getPermanent(sourcePermanent != null ? sourcePermanent.getAttachedTo() : null);
List<Permanent> chooseable = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
if (equipped != null) {
chooseable.add(equipped);
}
Permanent toBoost;
switch(chooseable.size()) {
case 0:
return false;
case 1:
toBoost = chooseable.get(0);
break;
default:
FilterPermanent filter = new FilterPermanent("a creature to give +X/+X to");
filter.add(Predicates.or(chooseable.stream().map(permanent -> new MageObjectReferencePredicate(permanent, game)).collect(Collectors.toList())));
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
toBoost = game.getPermanent(target.getFirstTarget());
}
int xValue = player.getHand().size();
game.addEffect(new BoostTargetEffect(xValue, xValue, Duration.EndOfTurn).setTargetPointer(new FixedTarget(toBoost, game)), source);
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class HumiliateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null || game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getSourceId(), source.getControllerId(), game) < 1) {
return false;
}
TargetPermanent target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
target.withChooseHint("+1/+1 counter");
player.choose(outcome, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
return permanent != null && permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
}
use of mage.target.TargetPermanent in project mage by magefree.
the class InnocentTravelerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean flag = false;
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
Player opponent = game.getPlayer(opponentId);
if (opponent == null) {
continue;
}
TargetPermanent target = new TargetPermanent(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) {
return true;
}
Permanent sourcePerm = source.getSourcePermanentIfItStillExists(game);
if (sourcePerm != null) {
sourcePerm.transform(source, game);
}
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class MarshalingTheTroopsEffect 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, MarshalingTheTroops.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) {
controller.gainLife(tappedAmount * 4, game, source);
}
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class RedirectArtifactDamageFromPlayerToSourceEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getTargetId().equals(source.getControllerId()) && game.getPermanentOrLKIBattlefield(event.getSourceId()).isArtifact(game)) {
TargetPermanent target = new TargetPermanent();
target.add(source.getSourceId(), game);
this.redirectTarget = target;
return true;
}
return false;
}
Aggregations