Search in sources :

Example 6 with FilterPlayer

use of mage.filter.FilterPlayer in project mage by magefree.

the class BurningCinderFuryOfCrimsonChaosFireWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player tappingPlayer = game.getPlayer(firstControllerId);
    Permanent permanentToControl = game.getPermanent(this.getTargetPointer().getFirst(game, source));
    if (tappingPlayer != null && permanentToControl != null) {
        // Create opponent filter list manually because otherwise opponent check prevents controller of this to be valid
        FilterPlayer filter = new FilterPlayer("opponent to control " + permanentToControl.getIdName());
        List<PlayerIdPredicate> opponentPredicates = new ArrayList<>();
        for (UUID opponentId : game.getOpponents(firstControllerId)) {
            opponentPredicates.add(new PlayerIdPredicate(opponentId));
        }
        filter.add(Predicates.or(opponentPredicates));
        Target target = new TargetPlayer(1, 1, true, filter);
        target.setTargetController(firstControllerId);
        target.setAbilityController(source.getControllerId());
        if (tappingPlayer.chooseTarget(outcome, target, source, game)) {
            Player chosenOpponent = game.getPlayer(target.getFirstTarget());
            if (chosenOpponent != null) {
                game.informPlayers(tappingPlayer.getLogName() + " chose " + chosenOpponent.getLogName() + " to gain control of " + permanentToControl.getLogName() + " at the beginning of the next end step");
                ContinuousEffect effect = new BurningCinderFuryOfCrimsonChaosFireCreatureGainControlEffect(Duration.Custom, chosenOpponent.getId());
                effect.setTargetPointer(new FixedTarget(permanentToControl.getId(), game));
                game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPlayer(mage.filter.FilterPlayer) Permanent(mage.game.permanent.Permanent) FilterPlayer(mage.filter.FilterPlayer) TargetPlayer(mage.target.TargetPlayer) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) PlayerIdPredicate(mage.filter.predicate.other.PlayerIdPredicate) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Aggregations

FilterPlayer (mage.filter.FilterPlayer)6 PlayerIdPredicate (mage.filter.predicate.other.PlayerIdPredicate)6 Player (mage.players.Player)5 Permanent (mage.game.permanent.Permanent)4 TargetPlayer (mage.target.TargetPlayer)4 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 Target (mage.target.Target)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 Ability (mage.abilities.Ability)1 EntersBattlefieldTriggeredAbility (mage.abilities.common.EntersBattlefieldTriggeredAbility)1 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)1 ConditionalInterveningIfTriggeredAbility (mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility)1 GainAbilityControlledEffect (mage.abilities.effects.common.continuous.GainAbilityControlledEffect)1 GainAbilityControllerEffect (mage.abilities.effects.common.continuous.GainAbilityControllerEffect)1 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)1 FlyingAbility (mage.abilities.keyword.FlyingAbility)1 ProtectionAbility (mage.abilities.keyword.ProtectionAbility)1 FilterPermanent (mage.filter.FilterPermanent)1