Search in sources :

Example 1 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.

the class HumanPlayer method selectBlockers.

@Override
public void selectBlockers(Ability source, Game game, UUID defendingPlayerId) {
    if (gameInCheckPlayableState(game)) {
        return;
    }
    FilterCreatureForCombatBlock filter = filterCreatureForCombatBlock.copy();
    filter.add(new ControllerIdPredicate(defendingPlayerId));
    // stop skip on any/zero permanents available
    int possibleBlockersCount = game.getBattlefield().count(filter, null, playerId, game);
    boolean canStopOnAny = possibleBlockersCount != 0 && getControllingPlayersUserData(game).getUserSkipPrioritySteps().isStopOnDeclareBlockersWithAnyPermanents();
    boolean canStopOnZero = possibleBlockersCount == 0 && getControllingPlayersUserData(game).getUserSkipPrioritySteps().isStopOnDeclareBlockersWithZeroPermanents();
    // skip declare blocker step
    // as opposed to declare attacker - it can be skipped by ANY skip button TODO: make same for declare attackers and rework skip buttons (normal and forced)
    boolean skipButtonActivated = passedAllTurns || passedUntilEndStepBeforeMyTurn || passedTurn || passedUntilEndOfTurn || passedUntilNextMain;
    if (skipButtonActivated && !canStopOnAny && !canStopOnZero) {
        return;
    }
    while (canRespond()) {
        updateGameStatePriority("selectBlockers", game);
        prepareForResponse(game);
        if (!isExecutingMacro()) {
            Map<String, Serializable> options = new HashMap<>();
            java.util.List<UUID> possibleBlockers = game.getBattlefield().getActivePermanents(filter, playerId, game).stream().map(p -> p.getId()).collect(Collectors.toList());
            options.put(Constants.Option.POSSIBLE_BLOCKERS, (Serializable) possibleBlockers);
            game.fireSelectEvent(playerId, "Select blockers", options);
        }
        waitForResponse(game);
        UUID responseId = getFixedResponseUUID(game);
        if (response.getBoolean() != null) {
            return;
        } else if (response.getInteger() != null) {
            return;
        } else if (responseId != null) {
            Permanent blocker = game.getPermanent(responseId);
            if (blocker != null) {
                boolean removeBlocker = false;
                // does not block yet and can block or can block more attackers
                if (filter.match(blocker, null, playerId, game)) {
                    selectCombatGroup(defendingPlayerId, blocker.getId(), game);
                } else if (filterBlock.match(blocker, null, playerId, game) && game.getStack().isEmpty()) {
                    removeBlocker = true;
                }
                if (removeBlocker) {
                    game.getCombat().removeBlocker(blocker.getId(), game);
                }
            }
        }
    }
}
Also used : RequirementEffect(mage.abilities.effects.RequirementEffect) FilterBlockingCreature(mage.filter.common.FilterBlockingCreature) Match(mage.game.match.Match) REQUEST_AUTO_ANSWER_RESET_ALL(mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_RESET_ALL) Logger(org.apache.log4j.Logger) TapSourceCost(mage.abilities.costs.common.TapSourceCost) ManaCost(mage.abilities.costs.mana.ManaCost) mage.constants(mage.constants) Draft(mage.game.draft.Draft) mage.abilities(mage.abilities) Choice(mage.choices.Choice) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) StaticFilters(mage.filter.StaticFilters) GameLog(mage.util.GameLog) TargetAnyTarget(mage.target.common.TargetAnyTarget) mage.cards(mage.cards) FilterCreatureForCombatBlock(mage.filter.common.FilterCreatureForCombatBlock) CardUtil(mage.util.CardUtil) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) FilterCreatureForCombat(mage.filter.common.FilterCreatureForCombat) TargetDefender(mage.target.common.TargetDefender) List(java.util.List) Permanent(mage.game.permanent.Permanent) TargetAmount(mage.target.TargetAmount) Tournament(mage.game.tournament.Tournament) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Target(mage.target.Target) java.util(java.util) PlayerImpl(mage.players.PlayerImpl) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PlayerList(mage.players.PlayerList) DeclareAttackerEvent(mage.game.events.DeclareAttackerEvent) Player(mage.players.Player) ManaUtil(mage.util.ManaUtil) TargetCard(mage.target.TargetCard) FilterAttackingCreature(mage.filter.common.FilterAttackingCreature) MageObject(mage.MageObject) CombatGroup(mage.game.combat.CombatGroup) Spell(mage.game.stack.Spell) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) Deck(mage.cards.decks.Deck) TRIGGER_AUTO_ORDER_RESET_ALL(mage.constants.PlayerAction.TRIGGER_AUTO_ORDER_RESET_ALL) TargetAttackingCreature(mage.target.common.TargetAttackingCreature) java.awt(java.awt) VariableCost(mage.abilities.costs.VariableCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Game(mage.game.Game) ManaAbility(mage.abilities.mana.ManaAbility) ChoiceImpl(mage.choices.ChoiceImpl) GameImpl(mage.game.GameImpl) MessageToClient(mage.util.MessageToClient) HintUtils(mage.abilities.hint.HintUtils) TargetPermanent(mage.target.TargetPermanent) Serializable(java.io.Serializable) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FilterCreatureForCombatBlock(mage.filter.common.FilterCreatureForCombatBlock) java.util(java.util) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate)

Example 2 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.

the class AvalancheTuskerAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.getSourceId())) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
        UUID defenderId = game.getCombat().getDefendingPlayerId(sourceId, game);
        filter.add(new ControllerIdPredicate(defenderId));
        this.getTargets().clear();
        TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
        this.addTarget(target);
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Example 3 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate 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;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ReturnToHandFromBattlefieldAllEffect(mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect) DiscardEachPlayerEffect(mage.abilities.effects.common.discard.DiscardEachPlayerEffect) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Target(mage.target.Target) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) HashSet(java.util.HashSet)

Example 4 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.

the class HeartPiercerBowAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (super.checkTrigger(event, game)) {
        Permanent equipment = game.getPermanent(getSourceId());
        if (equipment != null && equipment.getAttachedTo() != null) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
            UUID defenderId = game.getCombat().getDefendingPlayerId(equipment.getAttachedTo(), game);
            if (defenderId != null) {
                filter.add(new ControllerIdPredicate(defenderId));
                this.getTargets().clear();
                TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
                this.addTarget(target);
                return true;
            }
        }
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Example 5 with ControllerIdPredicate

use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.

the class MutinyFirstTarget method addTarget.

@Override
public void addTarget(UUID id, Ability source, Game game, boolean skipEvent) {
    super.addTarget(id, source, game, skipEvent);
    // Update the second target
    UUID firstController = game.getControllerId(id);
    if (firstController != null && source.getTargets().size() > 1) {
        Player controllingPlayer = game.getPlayer(firstController);
        TargetCreaturePermanent targetCreaturePermanent = (TargetCreaturePermanent) source.getTargets().get(1);
        // Set a new filter to the second target with the needed restrictions
        FilterCreaturePermanent filter = new FilterCreaturePermanent("another creature that player " + controllingPlayer.getName() + " controls");
        filter.add(new ControllerIdPredicate(firstController));
        filter.add(Predicates.not(new PermanentIdPredicate(id)));
        targetCreaturePermanent.replaceFilter(filter);
    }
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Aggregations

ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)153 Player (mage.players.Player)105 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)87 Permanent (mage.game.permanent.Permanent)70 UUID (java.util.UUID)53 TargetPermanent (mage.target.TargetPermanent)53 FilterPermanent (mage.filter.FilterPermanent)51 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)41 Target (mage.target.Target)29 FixedTarget (mage.target.targetpointer.FixedTarget)21 TargetPlayer (mage.target.TargetPlayer)16 ContinuousEffect (mage.abilities.effects.ContinuousEffect)15 Effect (mage.abilities.effects.Effect)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13 FilterLandPermanent (mage.filter.common.FilterLandPermanent)13 DamagedPlayerEvent (mage.game.events.DamagedPlayerEvent)11 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)9 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)9 MageObject (mage.MageObject)8 HashSet (java.util.HashSet)7