Search in sources :

Example 46 with GainControlTargetEffect

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

the class HeraldOfLeshracLeavesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        if (playerId.equals(source.getControllerId())) {
            continue;
        }
        FilterPermanent filter = new FilterLandPermanent();
        filter.add(new OwnerIdPredicate(playerId));
        filter.add(new ControllerIdPredicate(source.getControllerId()));
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, playerId);
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 47 with GainControlTargetEffect

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

the class KaronaFalseGodEffect 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)) {
        sourcePermanent.untap(game);
        game.informPlayers(newController.getLogName() + " untaps " + sourceObject.getIdName());
        // 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("KaronaFalseGodSourceId");
                UUID controllerId = (UUID) effect.getValue("KaronaFalseGodControllerId");
                if (source.getSourceId().equals(checkId) && newController.getId().equals(controllerId)) {
                    effect.discard();
                }
            }
        }
        ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, newController.getId());
        effect.setValue("KaronaFalseGodSourceId", source.getSourceId());
        effect.setValue("KaronaFalseGodControllerId", 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) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObject(mage.MageObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 48 with GainControlTargetEffect

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

the class PreacherEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    Permanent targetPermanent = game.getPermanent(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && sourcePermanent != null && targetPermanent != null) {
        SourceTappedCondition sourceTappedCondition = SourceTappedCondition.TAPPED;
        ConditionalContinuousEffect effect = new ConditionalContinuousEffect(new GainControlTargetEffect(Duration.Custom), sourceTappedCondition, "Gain control of target creature of an opponent's choice that they control for as long as {this} remains tapped");
        effect.setTargetPointer(new FixedTarget(targetPermanent.getId(), game));
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetOpponentsChoicePermanent(mage.target.common.TargetOpponentsChoicePermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) SourceTappedCondition(mage.abilities.condition.common.SourceTappedCondition) ConditionalContinuousEffect(mage.abilities.decorator.ConditionalContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 49 with GainControlTargetEffect

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

the class SokenzanRenegadeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        int max = Integer.MIN_VALUE;
        Player newController = null;
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                if (player.getHand().size() > max) {
                    max = player.getHand().size();
                    newController = player;
                }
            }
        }
        if (newController != null) {
            ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, newController.getId());
            effect.setTargetPointer(new FixedTarget(sourcePermanent.getId(), game));
            game.addEffect(effect, source);
            if (!source.isControlledBy(newController.getId())) {
                game.informPlayers(newController.getLogName() + " got control of " + sourcePermanent.getLogName());
            }
            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)

Example 50 with GainControlTargetEffect

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

the class TheWretchedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent theWretched = source.getSourcePermanentIfItStillExists(game);
    if (theWretched == null || theWretched.isRemovedFromCombat() || !theWretched.isAttacking() || !source.isControlledBy(theWretched.getControllerId())) {
        return false;
    }
    // Check if control of source has changed since ability triggered????? (does it work is it neccessary???)
    for (CombatGroup combatGroup : game.getCombat().getGroups()) {
        if (!combatGroup.getAttackers().contains(source.getSourceId())) {
            continue;
        }
        for (UUID creatureId : combatGroup.getBlockers()) {
            Permanent blocker = game.getPermanent(creatureId);
            if (blocker == null || blocker.getBlocking() <= 0) {
                continue;
            }
            ContinuousEffect effect = new GainControlTargetEffect(Duration.WhileControlled, source.getControllerId());
            effect.setTargetPointer(new FixedTarget(blocker.getId(), game));
            game.addEffect(effect, source);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) CombatGroup(mage.game.combat.CombatGroup)

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