Search in sources :

Example 21 with GainControlTargetEffect

use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.

the class ExpropriateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    // Outcome.Detriment - AI will gain control all the time (Money choice)
    // TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
    TwoChoiceVote vote = new TwoChoiceVote("Time (extra turn)", "Money (gain control)", Outcome.Detriment);
    vote.doVotes(source, game);
    // extra turn
    int timeCount = vote.getVoteCount(true);
    for (int i = 0; i < timeCount; i++) {
        game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false));
    }
    // gain control
    if (vote.getVoteCount(false) < 1) {
        return true;
    }
    List<Permanent> toSteal = new ArrayList<>();
    for (UUID playerId : vote.getVotedFor(false)) {
        int moneyCount = vote.getVotes(playerId).stream().mapToInt(x -> x ? 0 : 1).sum();
        FilterPermanent filter = new FilterPermanent();
        filter.add(new ControllerIdPredicate(playerId));
        moneyCount = Math.min(game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game), moneyCount);
        if (moneyCount == 0) {
            continue;
        }
        TargetPermanent target = new TargetPermanent(moneyCount, filter);
        target.setNotTarget(true);
        player.choose(Outcome.GainControl, target, source.getSourceId(), game);
        target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).forEach(toSteal::add);
    }
    game.addEffect(new GainControlTargetEffect(Duration.Custom, true, source.getControllerId()).setTargetPointer(new FixedTargets(toSteal, game)), source);
    return true;
}
Also used : GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) ArrayList(java.util.ArrayList) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Duration(mage.constants.Duration) ExileSpellEffect(mage.abilities.effects.common.ExileSpellEffect) TwoChoiceVote(mage.choices.TwoChoiceVote) Game(mage.game.Game) List(java.util.List) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) FixedTargets(mage.target.targetpointer.FixedTargets) TurnMod(mage.game.turn.TurnMod) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FixedTargets(mage.target.targetpointer.FixedTargets) ArrayList(java.util.ArrayList) TurnMod(mage.game.turn.TurnMod) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) TwoChoiceVote(mage.choices.TwoChoiceVote) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 22 with GainControlTargetEffect

use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.

the class ExertInfluenceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller != null && sourceObject != null) {
        int colors = new ColorsOfManaSpentToCastCount().calculate(game, source, this);
        if (targetCreature.getPower().getValue() <= colors) {
            game.addEffect(new GainControlTargetEffect(Duration.Custom, true), source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) MageObject(mage.MageObject) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) ColorsOfManaSpentToCastCount(mage.abilities.dynamicvalue.common.ColorsOfManaSpentToCastCount)

Example 23 with GainControlTargetEffect

use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.

the class InsurrectionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean result = false;
    ContinuousEffect gainControl = new GainControlTargetEffect(Duration.EndOfTurn);
    ContinuousEffect gainHaste = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
    for (Permanent creature : game.getBattlefield().getAllActivePermanents(CardType.CREATURE, game)) {
        creature.untap(game);
        gainControl.setTargetPointer(new FixedTarget(creature.getId(), game));
        gainHaste.setTargetPointer(new FixedTarget(creature.getId(), game));
        game.addEffect(gainControl, source);
        game.addEffect(gainHaste, source);
        result = true;
    }
    return result;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 24 with GainControlTargetEffect

use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.

the class ChangeCreatureTypeTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
        ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true);
        effect.setTargetPointer(new FixedTarget(targetPermanent, game));
        game.addEffect(effect, source);
        effect = new ChangeCreatureTypeTargetEffect(null, SubType.VAMPIRE, Duration.Custom);
        effect.setTargetPointer(new FixedTarget(targetPermanent, game));
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 25 with GainControlTargetEffect

use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.

the class ConfiscationCoupEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        new GetEnergyCountersControllerEffect(4).apply(game, source);
        Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (targetPermanent != null) {
            Cost cost = new PayEnergyCost(targetPermanent.getManaCost().manaValue());
            if (cost.canPay(source, source, source.getControllerId(), game)) {
                int manaValue = targetPermanent.getManaCost().manaValue();
                StringBuilder energy = new StringBuilder(manaValue);
                for (int i = 0; i < manaValue; i++) {
                    energy.append("{E}");
                }
                if (controller.chooseUse(outcome, "Pay " + energy + " to get control of " + targetPermanent.getLogName() + '?', source, game)) {
                    if (cost.pay(source, game, source, source.getControllerId(), true)) {
                        ContinuousEffect controllEffect = new GainControlTargetEffect(Duration.Custom);
                        controllEffect.setTargetPointer(new FixedTarget(targetPermanent, game));
                        game.addEffect(controllEffect, source);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) GetEnergyCountersControllerEffect(mage.abilities.effects.common.counter.GetEnergyCountersControllerEffect) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) PayEnergyCost(mage.abilities.costs.common.PayEnergyCost) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cost(mage.abilities.costs.Cost) PayEnergyCost(mage.abilities.costs.common.PayEnergyCost) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Aggregations

GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)57 FixedTarget (mage.target.targetpointer.FixedTarget)52 Permanent (mage.game.permanent.Permanent)48 ContinuousEffect (mage.abilities.effects.ContinuousEffect)42 Player (mage.players.Player)40 UUID (java.util.UUID)22 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)15 TargetPermanent (mage.target.TargetPermanent)13 FilterPermanent (mage.filter.FilterPermanent)12 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)12 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)9 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)9 Target (mage.target.Target)8 TargetPlayer (mage.target.TargetPlayer)7 MageObject (mage.MageObject)5 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)5 OneShotEffect (mage.abilities.effects.OneShotEffect)4 TargetOpponent (mage.target.common.TargetOpponent)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3