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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations