Search in sources :

Example 56 with GainControlTargetEffect

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

the class CulturalExchangeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player1 = game.getPlayer(targetPointer.getTargets(game, source).get(0));
    Player player2 = game.getPlayer(targetPointer.getTargets(game, source).get(1));
    Player controller = game.getPlayer(source.getControllerId());
    if (player1 == null || player2 == null || controller == null) {
        return false;
    }
    FilterCreaturePermanent filter1 = new FilterCreaturePermanent("creatures " + player1.getLogName() + " controls");
    FilterCreaturePermanent filter2 = new FilterCreaturePermanent("creatures " + player2.getLogName() + " controls");
    filter1.add(new ControllerIdPredicate(player1.getId()));
    filter2.add(new ControllerIdPredicate(player2.getId()));
    int creatureCount1 = game.getBattlefield().count(filter1, source.getSourceId(), source.getControllerId(), game);
    int creatureCount2 = game.getBattlefield().count(filter2, source.getSourceId(), source.getControllerId(), game);
    int creaturesToSwitch = Math.min(creatureCount1, creatureCount2);
    if (creaturesToSwitch == 0) {
        return true;
    }
    TargetCreaturePermanent target1 = new TargetCreaturePermanent(0, creaturesToSwitch, filter1, true);
    if (target1.choose(Outcome.Benefit, controller.getId(), source.getSourceId(), game)) {
        int otherToSwitch = target1.getTargets().size();
        TargetCreaturePermanent target2 = new TargetCreaturePermanent(otherToSwitch, otherToSwitch, filter2, true);
        if (target2.choose(Outcome.Benefit, controller.getId(), source.getSourceId(), game)) {
            for (UUID creatureId : target1.getTargets()) {
                Permanent creature = game.getPermanent(creatureId);
                if (creature != null) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, player2.getId());
                    game.informPlayers(player2.getLogName() + " gains control of " + creature.getLogName());
                    effect.setTargetPointer(new FixedTarget(creature, game));
                    game.addEffect(effect, source);
                }
            }
            for (UUID creatureId : target2.getTargets()) {
                Permanent creature = game.getPermanent(creatureId);
                if (creature != null) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, player1.getId());
                    game.informPlayers(player1.getLogName() + " gains control of " + creature.getLogName());
                    effect.setTargetPointer(new FixedTarget(creature, game));
                    game.addEffect(effect, source);
                }
            }
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) 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) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 57 with GainControlTargetEffect

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

the class CrownOfDoomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player newController = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (controller != null && newController != null && !Objects.equals(controller.getId(), newController.getId())) {
        ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, newController.getId());
        effect.setTargetPointer(new FixedTarget(source.getSourceId(), game));
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) TargetPlayer(mage.target.TargetPlayer) FilterPlayer(mage.filter.FilterPlayer) ContinuousEffect(mage.abilities.effects.ContinuousEffect) 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