Search in sources :

Example 31 with FixedTarget

use of mage.target.targetpointer.FixedTarget in project mage by magefree.

the class LoxodonPeacekeeperEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent sourcePermanent = game.getPermanent(source.getSourceId());
        if (sourcePermanent != null) {
            int lowLife = Integer.MAX_VALUE;
            Set<UUID> tiedPlayers = new HashSet<>();
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    if (player.getLife() < lowLife) {
                        lowLife = player.getLife();
                    }
                }
            }
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    if (player.getLife() == lowLife) {
                        tiedPlayers.add(playerId);
                    }
                }
            }
            if (tiedPlayers.size() > 0) {
                UUID newControllerId = null;
                if (tiedPlayers.size() > 1) {
                    FilterPlayer filter = new FilterPlayer("a player tied for lowest life total");
                    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                        if (!tiedPlayers.contains(playerId)) {
                            filter.add(Predicates.not(new PlayerIdPredicate(playerId)));
                        }
                    }
                    TargetPlayer target = new TargetPlayer(1, 1, true, filter);
                    if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
                        while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
                            controller.chooseTarget(outcome, target, source, game);
                        }
                    } else {
                        return false;
                    }
                    newControllerId = game.getPlayer(target.getFirstTarget()).getId();
                } else {
                    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                        if (tiedPlayers.contains(playerId)) {
                            newControllerId = playerId;
                            break;
                        }
                    }
                }
                if (newControllerId != null) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, newControllerId);
                    effect.setTargetPointer(new FixedTarget(sourcePermanent, game));
                    game.addEffect(effect, source);
                    game.informPlayers(game.getPlayer(newControllerId).getLogName() + " has gained control of " + sourcePermanent.getLogName());
                    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) PlayerIdPredicate(mage.filter.predicate.other.PlayerIdPredicate) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) TargetPlayer(mage.target.TargetPlayer) HashSet(java.util.HashSet)

Example 32 with FixedTarget

use of mage.target.targetpointer.FixedTarget in project mage by magefree.

the class MurderousSpoilsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent target = game.getPermanent(source.getFirstTarget());
    if (target != null) {
        List<Permanent> attachments = new ArrayList<>();
        for (UUID uuid : target.getAttachments()) {
            Permanent attached = game.getBattlefield().getPermanent(uuid);
            if (attached.hasSubtype(SubType.EQUIPMENT, game)) {
                attachments.add(attached);
            }
        }
        for (Permanent p : attachments) {
            ContinuousEffect gainControl = new GainControlTargetEffect(Duration.Custom);
            gainControl.setTargetPointer(new FixedTarget(p, game));
            game.addEffect(gainControl, source);
        }
        target.destroy(source, game, true);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ArrayList(java.util.ArrayList) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 33 with FixedTarget

use of mage.target.targetpointer.FixedTarget in project mage by magefree.

the class AwakenElementalToken method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID targetId = null;
    for (Target target : source.getTargets()) {
        targetId = target.getFirstTarget();
    }
    if (targetId != null) {
        FixedTarget fixedTarget = new FixedTarget(targetId, game);
        ContinuousEffect continuousEffect = new BecomesCreatureTargetEffect(new AwakenElementalToken(), false, true, Duration.EndOfGame);
        continuousEffect.setTargetPointer(fixedTarget);
        game.addEffect(continuousEffect, source);
        Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(3));
        effect.setTargetPointer(fixedTarget);
        return effect.apply(game, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) BecomesCreatureTargetEffect(mage.abilities.effects.common.continuous.BecomesCreatureTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) BecomesCreatureTargetEffect(mage.abilities.effects.common.continuous.BecomesCreatureTargetEffect) Effect(mage.abilities.effects.Effect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 34 with FixedTarget

use of mage.target.targetpointer.FixedTarget in project mage by magefree.

the class NullstoneGargoyleTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Spell spell = game.getSpell(event.getTargetId());
    if (spell.isCreature(game)) {
        return false;
    }
    SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
    if (watcher != null && watcher.getNumberOfNonCreatureSpells() == 1) {
        for (Effect effect : getEffects()) {
            effect.setTargetPointer(new FixedTarget(event.getTargetId()));
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) CounterTargetEffect(mage.abilities.effects.common.CounterTargetEffect) Effect(mage.abilities.effects.Effect) Spell(mage.game.stack.Spell)

Example 35 with FixedTarget

use of mage.target.targetpointer.FixedTarget in project mage by magefree.

the class NorrittDelayedDestroyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    DestroyTargetEffect effect = new DestroyTargetEffect();
    effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
    AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect, TargetController.ANY, new InvertCondition(TargetAttackedThisTurnCondition.instance));
    delayedAbility.getDuration();
    delayedAbility.getTargets().addAll(source.getTargets());
    game.addDelayedTriggeredAbility(delayedAbility, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) InvertCondition(mage.abilities.condition.InvertCondition)

Aggregations

FixedTarget (mage.target.targetpointer.FixedTarget)746 Permanent (mage.game.permanent.Permanent)491 Player (mage.players.Player)385 ContinuousEffect (mage.abilities.effects.ContinuousEffect)248 Effect (mage.abilities.effects.Effect)222 OneShotEffect (mage.abilities.effects.OneShotEffect)185 UUID (java.util.UUID)178 Card (mage.cards.Card)174 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)116 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)109 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)101 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)87 TargetPermanent (mage.target.TargetPermanent)84 FilterPermanent (mage.filter.FilterPermanent)71 MageObject (mage.MageObject)68 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)63 BoostTargetEffect (mage.abilities.effects.common.continuous.BoostTargetEffect)53 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)53 CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)50 FilterCard (mage.filter.FilterCard)46