use of mage.target.common.TargetOpponent in project mage by magefree.
the class ViashinoBeyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
TargetOpponent targetDefender = new TargetOpponent();
if (controller != null) {
game.getBattlefield().getAllActivePermanents(CardType.CREATURE, game).stream().filter((permanent) -> (filter.match(permanent, source.getSourceId(), source.getControllerId(), game))).forEachOrdered((permanent) -> {
if (game.getOpponents(controller.getId()).size() > 1) {
controller.choose(outcome.Benefit, targetDefender, source.getSourceId(), game);
} else {
targetDefender.add(game.getOpponents(controller.getId()).iterator().next(), game);
}
if (permanent.canAttack(targetDefender.getFirstTarget(), game)) {
controller.declareAttacker(permanent.getId(), targetDefender.getFirstTarget(), game, false);
}
});
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class ChooseSecretOpponentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getPermanentEntering(source.getSourceId());
if (mageObject == null) {
mageObject = game.getObject(source.getSourceId());
}
if (controller == null || mageObject == null) {
return false;
}
TargetOpponent targetOpponent = new TargetOpponent(true);
targetOpponent.setTargetName("opponent (secretly)");
controller.choose(outcome, targetOpponent, source.getSourceId(), game);
if (targetOpponent.getFirstTarget() == null) {
return false;
}
game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has secretly chosen an opponent.");
setChosenPlayer(targetOpponent.getFirstTarget(), source, game);
setSecretOwner(controller.getId(), source, game);
if (!(mageObject instanceof Permanent)) {
return true;
}
((Permanent) mageObject).addInfo(SECRET_OPPONENT, CardUtil.addToolTipMarkTags(controller.getLogName() + " has secretly chosen an opponent."), game);
return true;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class RohgahhOfKherKeepEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player == null) {
return false;
}
Cost cost = new ManaCostsImpl("{R}{R}{R}");
if (!cost.canPay(source, source, player.getId(), game) || !player.chooseUse(Outcome.Benefit, "Pay {R}{R}{R}?", source, game) || !cost.pay(source, game, source, player.getId(), false)) {
TargetOpponent target = new TargetOpponent();
Player opponent = null;
if (target.choose(Outcome.Detriment, player.getId(), source.getSourceId(), game)) {
opponent = game.getPlayer(target.getFirstTarget());
}
new TapAllEffect(filter).apply(game, source);
if (permanent != null) {
permanent.tap(source, game);
}
if (opponent != null) {
new GainControlAllEffect(Duration.Custom, filter, opponent.getId()).apply(game, source);
if (permanent != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class SandstoneOracleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
TargetOpponent target = new TargetOpponent(true);
if (controller.choose(Outcome.DrawCard, target, source.getSourceId(), game)) {
Player opponent = game.getPlayer(target.getFirstTarget());
if (opponent != null) {
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + opponent.getLogName());
int cardsDiff = opponent.getHand().size() - controller.getHand().size();
if (cardsDiff > 0) {
controller.drawCards(cardsDiff, source, game);
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class SkullwinderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
TargetOpponent targetOpponent = new TargetOpponent(true);
if (controller.choose(Outcome.Detriment, targetOpponent, source.getSourceId(), game)) {
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent != null) {
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + opponent.getLogName());
// That player returns a card from their graveyard to their hand
TargetCardInYourGraveyard targetCard = new TargetCardInYourGraveyard(new FilterCard("a card from your graveyard to return to your hand"));
targetCard.setNotTarget(true);
if (opponent.choose(outcome, targetCard, source.getSourceId(), game)) {
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
opponent.moveCards(card, Zone.HAND, source, game);
}
}
}
}
return true;
}
return false;
}
Aggregations