use of mage.filter.FilterPermanent in project mage by magefree.
the class ComputerPlayer method findBestPermanentTargets.
protected void findBestPermanentTargets(Outcome outcome, UUID abilityControllerId, UUID sourceId, FilterPermanent filter, Game game, Target target, List<Permanent> goodList, List<Permanent> badList, List<Permanent> allList) {
// searching for most valuable/powerfull permanents
goodList.clear();
badList.clear();
allList.clear();
List<UUID> usedTargets = target.getTargets();
// search all
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, abilityControllerId, sourceId, game)) {
if (usedTargets.contains(permanent.getId())) {
continue;
}
if (outcome.isGood()) {
// good effect
if (permanent.isControlledBy(abilityControllerId)) {
goodList.add(permanent);
} else {
badList.add(permanent);
}
} else {
// bad effect
if (permanent.isControlledBy(abilityControllerId)) {
badList.add(permanent);
} else {
goodList.add(permanent);
}
}
}
// sort from tiny to big (more valuable)
PermanentComparator comparator = new PermanentComparator(game);
goodList.sort(comparator);
badList.sort(comparator);
// most valueable goes first in good list
Collections.reverse(goodList);
// most weakest goes first in bad list (no need to reverse)
// Collections.reverse(badList);
allList.addAll(goodList);
allList.addAll(badList);
// "can target all mode" don't need your/opponent lists -- all targets goes with same value
if (outcome.isCanTargetAll()) {
// bad sort
allList.sort(comparator);
if (outcome.isGood()) {
// good sort
Collections.reverse(allList);
}
goodList.clear();
goodList.addAll(allList);
badList.clear();
badList.addAll(allList);
}
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class BeamsplitterMageApplier method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Spell spell = (Spell) getValue("spellCast");
if (player == null || spell == null) {
return false;
}
FilterPermanent filter = new FilterControlledCreaturePermanent("a creature you control that can be targeted by " + spell.getName());
filter.add(AnotherPredicate.instance);
filter.add(new BeamsplitterMagePredicate(spell));
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null) {
return false;
}
spell.createCopyOnStack(game, source, player.getId(), false, 1, new BeamsplitterMageApplier(permanent, game));
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class ChaosLordEffect method checkInterveningIfClause.
@Override
public boolean checkInterveningIfClause(Game game) {
Condition condition = new ControlsPermanentsComparedToOpponentsCondition(ComparisonType.EQUAL_TO, new FilterPermanent());
Player controller = game.getPlayer(controllerId);
if (controller != null && condition.apply(game, this)) {
return super.checkInterveningIfClause(game);
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class DispersalEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Set<PermanentIdPredicate> permsToReturn = new HashSet<>();
for (UUID opponentId : game.getOpponents(player.getId())) {
Player opponent = game.getPlayer(opponentId);
if (opponent == null) {
continue;
}
int highestCMC = 0;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponentId)) {
if (permanent != null) {
highestCMC = Math.max(highestCMC, permanent.getManaValue());
}
}
FilterPermanent filter = new FilterNonlandPermanent("permanent you control with mana value " + highestCMC);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, highestCMC));
filter.add(new ControllerIdPredicate(opponentId));
Target target = new TargetPermanent(1, 1, filter, true);
if (opponent.choose(outcome, target, source.getSourceId(), game)) {
if (target.getFirstTarget() == null) {
continue;
}
permsToReturn.add(new PermanentIdPredicate(target.getFirstTarget()));
}
}
FilterPermanent filter = new FilterPermanent();
filter.add(Predicates.or(permsToReturn));
new ReturnToHandFromBattlefieldAllEffect(filter).apply(game, source);
new DiscardEachPlayerEffect(StaticValue.get(1), false, TargetController.OPPONENT).apply(game, source);
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class JuxtaposeEffect method getPermanentsWithTheHighestCMC.
private List<Permanent> getPermanentsWithTheHighestCMC(Game game, UUID playerId, FilterPermanent filter) {
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(filter, playerId, game);
int highestCMC = -1;
for (Permanent permanent : permanents) {
if (highestCMC < permanent.getManaValue()) {
highestCMC = permanent.getManaValue();
}
}
List<Permanent> result = new ArrayList<>();
for (Permanent permanent : permanents) {
if (permanent.getManaValue() == highestCMC) {
result.add(permanent);
}
}
return result;
}
Aggregations