use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.
the class CallToArmsStateTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent permanent = game.getPermanent(getSourceId());
UUID playerId = (UUID) game.getState().getValue(getSourceId() + ChooseOpponentEffect.VALUE_KEY);
if (permanent != null) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
Condition condition = new MostCommonColorCondition(color, true, new ControllerIdPredicate(playerId));
return !condition.apply(game, this);
}
}
return false;
}
use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.
the class FelineSovereignTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.DAMAGED_PLAYER) {
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
Permanent p = game.getPermanent(event.getSourceId());
if (damageEvent.isCombatDamage() && p != null && p.isControlledBy(this.getControllerId()) && filter.match(p, getSourceId(), getControllerId(), game) && !damagedPlayerIds.contains(event.getPlayerId())) {
damagedPlayerIds.add(event.getPlayerId());
this.getTargets().clear();
FilterArtifactOrEnchantmentPermanent filter = new FilterArtifactOrEnchantmentPermanent();
filter.add(new ControllerIdPredicate(event.getPlayerId()));
this.addTarget(new TargetPermanent(0, 1, filter, false));
return true;
}
}
if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_PRIORITY || (event.getType() == GameEvent.EventType.ZONE_CHANGE && event.getTargetId().equals(getSourceId()))) {
damagedPlayerIds.clear();
}
return false;
}
use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.
the class HighcliffFelidarEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Set<UUID> toDestroy = new HashSet();
game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).forEachOrdered(opponent -> {
int maxPower = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game).stream().map(Permanent::getPower).mapToInt(MageInt::getValue).max().orElse(Integer.MIN_VALUE);
if (maxPower > Integer.MIN_VALUE) {
FilterPermanent filter = new FilterCreaturePermanent("creature with the greatest power controlled by " + opponent.getName());
filter.add(new ControllerIdPredicate(opponent.getId()));
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, maxPower));
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
if (controller.choose(outcome, target, source.getSourceId(), game)) {
toDestroy.add(target.getFirstTarget());
}
}
});
toDestroy.stream().map(game::getPermanent).filter(Objects::nonNull).forEachOrdered(permanent -> permanent.destroy(source, game, false));
return true;
}
use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.
the class MistbladeShinobiTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (((DamagedPlayerEvent) event).isCombatDamage() && event.getSourceId().equals(sourceId)) {
Player opponent = game.getPlayer(event.getPlayerId());
if (opponent != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
filter.add(new ControllerIdPredicate(opponent.getId()));
this.getTargets().clear();
this.addTarget(new TargetCreaturePermanent(filter));
return true;
}
}
return false;
}
use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.
the class MythosOfSnapdaxEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
boolean conditionMet = condition.apply(game, source);
List<Player> playerList = game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).filter(Objects::nonNull).collect(Collectors.toList());
Set<UUID> toKeep = new HashSet();
for (Player player : playerList) {
for (CardType cardType : cardTypes) {
String message = cardType.toString().equals("Artifact") ? "an " : "a ";
message += cardType.toString().toLowerCase(Locale.ENGLISH);
message += (conditionMet && player != controller) ? " controlled by " + player.getName() : " you control";
FilterPermanent filter = new FilterNonlandPermanent(message);
filter.add(cardType.getPredicate());
filter.add(new ControllerIdPredicate(player.getId()));
if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0) {
continue;
}
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
if (conditionMet) {
controller.choose(outcome, target, source.getSourceId(), game);
} else {
player.choose(outcome, target, source.getSourceId(), game);
}
toKeep.add(target.getFirstTarget());
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_NON_LAND, source.getControllerId(), game)) {
if (permanent == null || toKeep.contains(permanent.getId())) {
continue;
}
permanent.sacrifice(source, game);
}
return true;
}
Aggregations