use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class BlimComedicGeniusEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
game.addEffect(new GainControlTargetEffect(Duration.Custom, true, targetPointer.getFirst(game, source)).setTargetPointer(new FixedTarget(source.getFirstTarget(), game)), source);
game.getState().processAction(game);
Map<UUID, Cards> cardsMap = new HashMap<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
int count = game.getBattlefield().count(filter, source.getSourceId(), playerId, game);
if (count < 1) {
continue;
}
player.loseLife(count, game, source, true);
TargetDiscard target = new TargetDiscard(StaticFilters.FILTER_CARD, playerId);
player.choose(outcome, target, source.getSourceId(), game);
cardsMap.put(playerId, new CardsImpl(target.getTargets()));
}
for (Map.Entry<UUID, Cards> entry : cardsMap.entrySet()) {
Player player = game.getPlayer(entry.getKey());
if (player == null) {
continue;
}
player.discard(entry.getValue(), false, source, game);
}
return true;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class AminatouUltimateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice choice = new ChoiceLeftOrRight();
if (!controller.choose(Outcome.Neutral, choice, game)) {
return false;
}
boolean left = choice.getChoice().equals("Left");
PlayerList playerList = game.getState().getPlayerList().copy();
// set playerlist to controller
while (!playerList.get().equals(source.getControllerId())) {
playerList.getNext();
}
UUID currentPlayer = playerList.get();
UUID nextPlayer;
UUID firstNextPlayer = null;
while (!getNextPlayerInDirection(left, playerList, game).equals(firstNextPlayer)) {
nextPlayer = playerList.get();
if (nextPlayer == null) {
return false;
}
// skip players out of range
if (!game.getState().getPlayersInRange(controller.getId(), game).contains(nextPlayer)) {
continue;
}
// save first next player to check for iteration stop
if (firstNextPlayer == null) {
firstNextPlayer = nextPlayer;
}
FilterNonlandPermanent nextPlayerNonlandPermanentsFilter = new FilterNonlandPermanent();
nextPlayerNonlandPermanentsFilter.add(new ControllerIdPredicate(nextPlayer));
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(nextPlayerNonlandPermanentsFilter, game)) {
if (permanent.getId().equals(source.getSourceId())) {
continue;
}
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, currentPlayer);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
currentPlayer = nextPlayer;
}
return true;
}
return false;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class AuraThiefDiesTriggeredEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean ret = false;
for (Permanent enchantment : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_ENCHANTMENT, source.getControllerId(), source.getControllerId(), game)) {
ContinuousEffect gainControl = new GainControlTargetEffect(Duration.EndOfGame);
gainControl.setTargetPointer(new FixedTarget(enchantment.getId(), game));
game.addEffect(gainControl, source);
ret = true;
}
return ret;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class CaptivatingGlanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
final boolean clashResult;
Player controller = game.getPlayer(source.getControllerId());
Permanent captivatingGlance = game.getPermanent(source.getSourceId());
if (controller != null && captivatingGlance != null) {
Permanent enchantedCreature = game.getPermanent(captivatingGlance.getAttachedTo());
clashResult = ClashEffect.getInstance().apply(game, source);
if (enchantedCreature != null) {
if (clashResult) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, false, controller.getId());
effect.setTargetPointer(new FixedTarget(enchantedCreature.getId(), game));
game.addEffect(effect, source);
} else {
Player opponentWhomControllerClashedWith = game.getPlayer(targetPointer.getFirst(game, source));
if (opponentWhomControllerClashedWith != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, false, opponentWhomControllerClashedWith.getId());
effect.setTargetPointer(new FixedTarget(enchantedCreature.getId(), game));
game.addEffect(effect, source);
}
}
return true;
}
}
return false;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class ClambassadorsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetControlledPermanent(1, 1, filter, 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);
}
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (permanent != null && opponent != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
game.informPlayers(opponent.getLogName() + " has gained control of " + permanent.getLogName());
return true;
}
}
return false;
}
Aggregations