use of mage.filter.FilterPermanent in project mage by magefree.
the class ExpropriateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
// Outcome.Detriment - AI will gain control all the time (Money choice)
// TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
TwoChoiceVote vote = new TwoChoiceVote("Time (extra turn)", "Money (gain control)", Outcome.Detriment);
vote.doVotes(source, game);
// extra turn
int timeCount = vote.getVoteCount(true);
for (int i = 0; i < timeCount; i++) {
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false));
}
// gain control
if (vote.getVoteCount(false) < 1) {
return true;
}
List<Permanent> toSteal = new ArrayList<>();
for (UUID playerId : vote.getVotedFor(false)) {
int moneyCount = vote.getVotes(playerId).stream().mapToInt(x -> x ? 0 : 1).sum();
FilterPermanent filter = new FilterPermanent();
filter.add(new ControllerIdPredicate(playerId));
moneyCount = Math.min(game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game), moneyCount);
if (moneyCount == 0) {
continue;
}
TargetPermanent target = new TargetPermanent(moneyCount, filter);
target.setNotTarget(true);
player.choose(Outcome.GainControl, target, source.getSourceId(), game);
target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).forEach(toSteal::add);
}
game.addEffect(new GainControlTargetEffect(Duration.Custom, true, source.getControllerId()).setTargetPointer(new FixedTargets(toSteal, game)), source);
return true;
}
use of mage.filter.FilterPermanent 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.filter.FilterPermanent in project mage by magefree.
the class NettlevineBlightEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent nettlevineBlight = game.getPermanent(source.getSourceId());
Player newController = null;
if (controller != null && nettlevineBlight != null) {
Permanent enchantedPermanent = game.getPermanent(nettlevineBlight.getAttachedTo());
if (enchantedPermanent != null) {
newController = game.getPlayer(enchantedPermanent.getControllerId());
enchantedPermanent.sacrifice(source, game);
}
if (newController != null) {
FilterPermanent filter = new FilterPermanent("creature or land permanent you control");
filter.add(Predicates.or(CardType.CREATURE.getPredicate(), CardType.LAND.getPredicate()));
filter.add(new ControllerIdPredicate(newController.getId()));
filter.add(new CanBeEnchantedByPredicate(nettlevineBlight));
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), newController.getId(), game) && newController.choose(outcome, target, source.getSourceId(), game)) {
Permanent chosenPermanent = game.getPermanent(target.getFirstTarget());
if (chosenPermanent != null) {
Card nettlevineBlightCard = game.getCard(source.getSourceId());
if (nettlevineBlightCard != null) {
game.getState().setValue("attachTo:" + nettlevineBlight.getId(), chosenPermanent);
chosenPermanent.addAttachment(nettlevineBlight.getId(), source, game);
return true;
}
}
}
}
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class QuarryColossusReturnLibraryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (permanent != null && controller != null) {
Player owner = game.getPlayer(permanent.getOwnerId());
if (owner != null) {
int plains = game.getBattlefield().countAll(new FilterPermanent(SubType.PLAINS, "Plains you control"), source.getControllerId(), game);
controller.putCardOnTopXOfLibrary(permanent, game, source, plains, true);
return true;
}
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class DeadlyVanityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
TargetPermanent target = new TargetCreatureOrPlaneswalker();
target.setNotTarget(true);
controller.choose(outcome, target, source.getId(), game);
FilterPermanent filter = new FilterCreatureOrPlaneswalkerPermanent();
UUID targetId = target.getFirstTarget();
if (targetId != null) {
filter.add(Predicates.not(new PermanentIdPredicate(targetId)));
}
return new DestroyAllEffect(filter).apply(game, source);
}
Aggregations