Search in sources :

Example 46 with TargetOpponent

use of mage.target.common.TargetOpponent in project mage by magefree.

the class EntersBattlefieldUnderControlOfOpponentOfChoiceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Target target = new TargetOpponent();
    target.setNotTarget(true);
    if (!controller.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
        return false;
    }
    Player opponent = game.getPlayer(target.getFirstTarget());
    if (opponent == null) {
        return false;
    }
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (permanent != null) {
        // permanent was controlled by this player since the existance of this object so original controller has to be set to the first controller
        permanent.setOriginalControllerId(opponent.getId());
        // neccessary to set already here because spell caster never controlled the permanent (important for rule 800.4a)
        permanent.setControllerId(opponent.getId());
        game.informPlayers(permanent.getLogName() + " enters the battlefield under the control of " + opponent.getLogName());
    }
    ContinuousEffect continuousEffect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
    continuousEffect.setTargetPointer(new FixedTarget(source.getSourceId(), source.getSourceObjectZoneChangeCounter()));
    game.addEffect(continuousEffect, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 47 with TargetOpponent

use of mage.target.common.TargetOpponent in project mage by magefree.

the class TributeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentEntering(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        UUID opponentId;
        if (game.getOpponents(controller.getId()).size() == 1) {
            opponentId = game.getOpponents(controller.getId()).iterator().next();
        } else {
            Target target = new TargetOpponent();
            controller.choose(outcome, target, source.getSourceId(), game);
            opponentId = target.getFirstTarget();
        }
        if (opponentId != null) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null) {
                StringBuilder sb = new StringBuilder("Pay tribute to ");
                sb.append(sourcePermanent.getName());
                sb.append(" (add ").append(CardUtil.numberToText(tributeValue)).append(" +1/+1 counter");
                sb.append(tributeValue > 1 ? "s" : "").append(" to it)?");
                if (opponent.chooseUse(outcome, sb.toString(), source, game)) {
                    if (!game.isSimulation()) {
                        game.informPlayers(opponent.getLogName() + " pays tribute to " + sourcePermanent.getLogName());
                    }
                    game.getState().setValue("tributeValue" + source.getSourceId(), "yes");
                    return sourcePermanent.addCounters(CounterType.P1P1.createInstance(tributeValue), opponent.getId(), source, game);
                } else {
                    if (!game.isSimulation()) {
                        game.informPlayers(opponent.getLogName() + " does not pay tribute to " + sourcePermanent.getLogName());
                    }
                    game.getState().setValue("tributeValue" + source.getSourceId(), "no");
                }
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID)

Example 48 with TargetOpponent

use of mage.target.common.TargetOpponent in project mage by magefree.

the class FickleEfreetGainControlEffect 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) {
        if (!controller.flipCoin(source, game, true)) {
            if (sourcePermanent != null) {
                Target target = new TargetOpponent(true);
                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);
                    }
                }
                Player chosenOpponent = game.getPlayer(target.getFirstTarget());
                if (chosenOpponent != null) {
                    ContinuousEffect effect = new FickleEfreetGainControlEffect(Duration.Custom, target.getFirstTarget());
                    effect.setTargetPointer(new FixedTarget(sourcePermanent.getId(), game));
                    game.addEffect(effect, source);
                    game.informPlayers(chosenOpponent.getLogName() + " has gained control of " + sourcePermanent.getLogName());
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 49 with TargetOpponent

use of mage.target.common.TargetOpponent in project mage by magefree.

the class FerventMasteryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (!AlternativeCostSourceAbility.getActivatedStatus(game, source, this.alternativeCostOriginalID, false)) {
        return false;
    }
    Player player = game.getPlayer(source.getControllerId());
    TargetOpponent targetOpponent = new TargetOpponent(true);
    if (!player.chooseTarget(Outcome.DrawCard, targetOpponent, source, game)) {
        return false;
    }
    Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
    if (opponent == null) {
        return false;
    }
    int discarded = opponent.discard(0, Integer.MAX_VALUE, false, source, game).size();
    opponent.drawCards(discarded, source, game);
    return true;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent)

Example 50 with TargetOpponent

use of mage.target.common.TargetOpponent in project mage by magefree.

the class GoblinFestivalGainControlEffect 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) {
        if (!controller.flipCoin(source, game, true)) {
            if (sourcePermanent != null) {
                Target target = new TargetOpponent(true);
                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);
                    }
                }
                Player chosenOpponent = game.getPlayer(target.getFirstTarget());
                if (chosenOpponent != null) {
                    ContinuousEffect effect = new GoblinFestivalGainControlEffect(Duration.Custom, chosenOpponent.getId());
                    effect.setTargetPointer(new FixedTarget(sourcePermanent.getId(), game));
                    game.addEffect(effect, source);
                    game.informPlayers(chosenOpponent.getLogName() + " has gained control of " + sourcePermanent.getLogName());
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Target(mage.target.Target) TargetAnyTarget(mage.target.common.TargetAnyTarget) FixedTarget(mage.target.targetpointer.FixedTarget) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Aggregations

Player (mage.players.Player)67 TargetOpponent (mage.target.common.TargetOpponent)67 Target (mage.target.Target)35 UUID (java.util.UUID)25 MageObject (mage.MageObject)22 TargetCard (mage.target.TargetCard)22 FilterCard (mage.filter.FilterCard)21 Permanent (mage.game.permanent.Permanent)20 Card (mage.cards.Card)13 FixedTarget (mage.target.targetpointer.FixedTarget)12 ArrayList (java.util.ArrayList)8 CardsImpl (mage.cards.CardsImpl)8 ContinuousEffect (mage.abilities.effects.ContinuousEffect)7 Cards (mage.cards.Cards)7 Zone (mage.constants.Zone)6 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)6 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)5 Effect (mage.abilities.effects.Effect)4 OneShotEffect (mage.abilities.effects.OneShotEffect)4 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)4