use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class HeraldOfLeshracLeavesEffect method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Target target = new TargetPermanent(filter);
if (target.choose(Outcome.GainControl, controllerId, source.getSourceId(), game)) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame);
effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
game.addEffect(effect, ability);
game.getState().processAction(game);
paid = true;
}
return paid;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class WildDogsEffect 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 lowLife = Integer.MIN_VALUE;
boolean tie = false;
for (UUID playerID : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerID);
if (player != null) {
if (player.getLife() > lowLife) {
lowLife = player.getLife();
newController = player;
tie = false;
} else if (player.getLife() == lowLife) {
tie = true;
}
}
}
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 InfernalDenizenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent creature = game.getPermanent(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
DynamicValue swamps = new PermanentsOnBattlefieldCount(filter);
boolean canSac = swamps.calculate(game, source, this) > 1;
Effect effect = new SacrificeControllerEffect(filter, 2, "Sacrifice two Swamps");
effect.apply(game, source);
if (!canSac) {
if (creature != null) {
creature.tap(source, game);
}
TargetOpponent targetOpp = new TargetOpponent(true);
if (targetOpp.canChoose(source.getSourceId(), player.getId(), game) && targetOpp.choose(Outcome.Detriment, player.getId(), source.getSourceId(), game)) {
Player opponent = game.getPlayer(targetOpp.getFirstTarget());
if (opponent != null) {
FilterCreaturePermanent filter2 = new FilterCreaturePermanent("creature controlled by " + player.getLogName());
filter2.add(new ControllerIdPredicate(player.getId()));
TargetCreaturePermanent targetCreature = new TargetCreaturePermanent(1, 1, filter2, true);
targetCreature.setTargetController(opponent.getId());
if (targetCreature.canChoose(source.getSourceId(), id, game) && opponent.chooseUse(Outcome.GainControl, "Gain control of a creature?", source, game) && opponent.chooseTarget(Outcome.GainControl, targetCreature, source, game)) {
ConditionalContinuousEffect giveEffect = new ConditionalContinuousEffect(new GainControlTargetEffect(Duration.Custom, true, opponent.getId()), SourceOnBattlefieldCondition.instance, "");
giveEffect.setTargetPointer(new FixedTarget(targetCreature.getFirstTarget(), game));
game.addEffect(giveEffect, source);
return true;
}
}
}
}
}
return false;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class NihiloorLoseLifeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player opponent = game.getPlayer(playerId);
if (opponent == null) {
continue;
}
TargetPermanent target = new TargetPermanent(0, 1, filter, true);
target.withChooseHint("tapping a creature controlled by " + opponent.getName());
controller.choose(outcome, target, source.getControllerId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null || !permanent.tap(source, game)) {
continue;
}
FilterPermanent filter2 = new FilterPermanent("creature controlled by " + opponent.getName() + " with power " + permanent.getPower().getValue() + " or less");
filter2.add(new NihiloorPredicate(permanent, playerId));
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new GainControlTargetEffect(Duration.Custom, true), false, "gain control of target creature that player controls with " + "power less than or equal to the tapped creature's power for as long as you control {this}");
ability.addTarget(new TargetPermanent(filter2));
game.fireReflexiveTriggeredAbility(ability, source);
}
return true;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class ReinsOfPowerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID opponentId = this.getTargetPointer().getFirst(game, source);
if (opponentId != null) {
// Untap all creatures you control and all creatures target opponent controls.
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(Predicates.or(new ControllerIdPredicate(source.getControllerId()), new ControllerIdPredicate(opponentId)));
new UntapAllEffect(filter).apply(game, source);
// You and that opponent each gain control of all creatures the other controls until end of turn.
Set<UUID> yourCreatures = new HashSet<>();
Set<UUID> opponentCreatures = new HashSet<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), source.getControllerId(), source.getSourceId(), game)) {
yourCreatures.add(permanent.getId());
}
FilterCreaturePermanent filterOpponent = new FilterCreaturePermanent();
filterOpponent.add(new ControllerIdPredicate(opponentId));
for (Permanent permanent : game.getBattlefield().getActivePermanents(filterOpponent, source.getControllerId(), source.getSourceId(), game)) {
opponentCreatures.add(permanent.getId());
}
for (UUID creatureId : yourCreatures) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn, opponentId);
effect.setTargetPointer(new FixedTarget(creatureId, game));
game.addEffect(effect, source);
}
for (UUID creatureId : opponentCreatures) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(creatureId, game));
game.addEffect(effect, source);
}
// Those creatures gain haste until end of turn.
game.addEffect(new GainAbilityAllEffect(HasteAbility.getInstance(), Duration.EndOfTurn, filter), source);
return true;
}
return false;
}
Aggregations