Search in sources :

Example 41 with GainControlTargetEffect

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

the class RiskyMoveCreatureGainControlEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    Player newController = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (newController != null && controller != null && sourceObject != null && sourceObject.equals(sourcePermanent)) {
        // remove old control effects of the same player
        for (ContinuousEffect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) {
            if (effect instanceof GainControlTargetEffect) {
                UUID checkId = (UUID) effect.getValue("RiskyMoveSourceId");
                UUID controllerId = (UUID) effect.getValue("RiskyMoveControllerId");
                if (source.getSourceId().equals(checkId) && newController.getId().equals(controllerId)) {
                    effect.discard();
                }
            }
        }
        ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, true, newController.getId());
        effect.setValue("RiskyMoveSourceId", source.getSourceId());
        effect.setValue("RiskyMoveControllerId", newController.getId());
        effect.setTargetPointer(new FixedTarget(sourcePermanent.getId(), game));
        effect.setText("and gains control of it");
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) MageObject(mage.MageObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 42 with GainControlTargetEffect

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

the class ScrambleverseEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    PlayerList players = game.getState().getPlayersInRange(source.getControllerId(), game);
    int count = players.size();
    for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), source.getControllerId(), source.getSourceId(), game)) {
        ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, players.get(RandomUtil.nextInt(count)));
        effect.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect, source);
        permanent.untap(game);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Permanent(mage.game.permanent.Permanent) PlayerList(mage.players.PlayerList) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 43 with GainControlTargetEffect

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

the class SuddenSubstitutionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getSpell(source.getTargets().get(0).getFirstTarget());
    Permanent creature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (spell == null || creature == null) {
        return false;
    }
    ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, spell.getControllerId());
    effect.setTargetPointer(new FixedTarget(creature, game));
    spell.setControllerId(creature.getControllerId());
    spell.chooseNewTargets(game, creature.getControllerId());
    game.addEffect(effect, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell)

Example 44 with GainControlTargetEffect

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

the class FrenziedFugueTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    this.getEffects().clear();
    boolean result;
    if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
        result = event.getTargetId().equals(this.getSourceId());
    } else {
        result = event.getPlayerId().equals(this.getControllerId());
    }
    if (result) {
        Permanent enchantment = game.getPermanentOrLKIBattlefield(getSourceId());
        if (enchantment != null && enchantment.getAttachedTo() != null) {
            Effect effect = new GainControlTargetEffect(Duration.EndOfTurn, true);
            effect.setTargetPointer(new FixedTarget(enchantment.getAttachedTo(), game));
            this.getEffects().add(effect);
            effect = new UntapTargetEffect();
            effect.setTargetPointer(new FixedTarget(enchantment.getAttachedTo(), game));
            this.getEffects().add(effect);
            effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(enchantment.getAttachedTo(), game));
            this.getEffects().add(effect);
        } else {
            result = false;
        }
    }
    return result;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) UntapTargetEffect(mage.abilities.effects.common.UntapTargetEffect) Effect(mage.abilities.effects.Effect) AttachEffect(mage.abilities.effects.common.AttachEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) UntapTargetEffect(mage.abilities.effects.common.UntapTargetEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 45 with GainControlTargetEffect

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

the class GhazbanOgreEffect 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) {
            Player newController = null;
            int lowLife = Integer.MIN_VALUE;
            boolean tie = false;
            for (UUID playerID : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player = game.getPlayer(playerID);
                if (player != null) {
                    if (player.getLife() > lowLife) {
                        lowLife = player.getLife();
                        newController = player;
                        tie = false;
                    } else if (player.getLife() == lowLife) {
                        tie = true;
                    }
                }
            }
            if (!controller.equals(newController) && !tie && newController != null) {
                ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, newController.getId());
                effect.setTargetPointer(new FixedTarget(sourcePermanent, game));
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) 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