use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class WellspringEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (permanent == null) {
return false;
}
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(permanent.getAttachedTo(), game));
game.addEffect(effect, source);
return true;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class OrderOfSuccessionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Map<UUID, UUID> playerCreature = new HashMap<>(2);
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()) && controller.canRespond()) {
playerList.getNext();
}
Player currentPlayer = game.getPlayer(playerList.get());
Player nextPlayer;
UUID firstNextPlayer = null;
while (!getNextPlayerInDirection(left, playerList, game).equals(firstNextPlayer) && controller.canRespond()) {
nextPlayer = game.getPlayer(playerList.get());
if (nextPlayer == null) {
return false;
}
// save first next player to check for iteration stop
if (firstNextPlayer == null) {
firstNextPlayer = nextPlayer.getId();
}
if (!nextPlayer.canRespond()) {
continue;
}
// if player is in range they choose a creature to control
if (currentPlayer != null && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature controlled by " + nextPlayer.getLogName());
filter.add(new ControllerIdPredicate(nextPlayer.getId()));
Target target = new TargetCreaturePermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game)) {
if (currentPlayer.chooseTarget(outcome, target, source, game)) {
playerCreature.put(currentPlayer.getId(), target.getFirstTarget());
}
}
}
currentPlayer = nextPlayer;
}
// change control of targets
for (Map.Entry<UUID, UUID> entry : playerCreature.entrySet()) {
Player player = game.getPlayer(entry.getKey());
if (player != null) {
Permanent creature = game.getPermanent(entry.getValue());
if (creature != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, player.getId());
effect.setTargetPointer(new FixedTarget(creature.getId(), game));
game.addEffect(effect, source);
game.informPlayers(new StringBuilder(player.getLogName()).append(" gains control of ").append(creature.getName()).toString());
}
}
}
return true;
}
return false;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class WildMammothEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
Player newController = null;
int maxCreatures = 0;
boolean tie = false;
FilterPermanent filter = new FilterPermanent();
filter.add(CardType.CREATURE.getPredicate());
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int value = game.getBattlefield().countAll(filter, playerId, game);
if (value > maxCreatures) {
maxCreatures = value;
}
}
}
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int value = game.getBattlefield().countAll(filter, playerId, game);
if (value == maxCreatures) {
if (newController == null) {
newController = player;
} else {
tie = true;
break;
}
}
}
}
if (!controller.equals(newController) && !tie && newController != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, newController.getId());
effect.setTargetPointer(new FixedTarget(sourcePermanent, game));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class RichesEffect 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) {
Cards creaturesToSteal = new CardsImpl();
// For each opponent, get the creature to steal
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (controller.hasOpponent(playerId, game)) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (opponent.choose(Outcome.Detriment, target, source.getSourceId(), game)) {
creaturesToSteal.add(target.getTargets().get(0));
}
}
}
}
// controller depends on another creatures controller.
for (UUID target : creaturesToSteal) {
GainControlTargetEffect eff = new GainControlTargetEffect(Duration.EndOfGame, true);
eff.setTargetPointer(new FixedTarget(target, game));
game.addEffect(eff, source);
}
return true;
}
return false;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class TahngarthFirstMateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(game.getActivePlayerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller == null || player == null || permanent == null) {
return false;
}
TargetPlayerOrPlaneswalker target = new TargetPlayerOrPlaneswalker(filter);
target.setNotTarget(true);
if (!controller.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfCombat, player.getId());
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
game.getState().processAction(game);
return game.getCombat().addAttackerToCombat(permanent.getId(), target.getFirstTarget(), game);
}
Aggregations