use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class TeveshSzatDoomOfFoolsCommanderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
// gain control of all commanders
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
game.addEffect(new GainControlTargetEffect(Duration.Custom, true).setTargetPointer(new FixedTarget(permanent, game)), source);
}
// put all commanders to battlefield under control
// TODO: doesn't support range of influence (e.g. take control of all commanders)
Set<Card> commandersToPut = new HashSet<>();
game.getPlayerList().stream().map(game::getPlayer).filter(Objects::nonNull).forEach(player -> {
commandersToPut.addAll(game.getCommanderCardsFromCommandZone(player, CommanderCardType.COMMANDER_OR_OATHBREAKER));
});
controller.moveCards(new CardsImpl(commandersToPut), Zone.BATTLEFIELD, source, game);
return true;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class TwistAllegianceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetOpponent = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
// only creatures of controller & target opponent
if (permanent.isControlledBy(source.getControllerId()) || permanent.isControlledBy(targetOpponent.getId())) {
UUID newController = permanent.isControlledBy(source.getControllerId()) ? targetOpponent.getId() : source.getControllerId();
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn, true, newController);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
permanent.untap(game);
effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class WishclawTalismanEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
effect.apply(game, source);
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
TargetPlayer target = new TargetOpponent();
target.setNotTarget(true);
if (!player.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
ContinuousEffect continuousEffect = new GainControlTargetEffect(Duration.Custom, true, target.getFirstTarget());
continuousEffect.setTargetPointer(new FixedTarget(source.getSourceId(), game));
game.addEffect(continuousEffect, source);
return true;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect 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.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class DomineeringWillEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (targetPlayer != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn, targetPlayer.getId());
effect.setTargetPointer(new SecondTargetPointer());
effect.setText("Target player gains control of up to three target nonattacking creatures until end of turn");
game.addEffect(effect, source);
Effect effect2 = new UntapTargetEffect();
effect2.setTargetPointer(new SecondTargetPointer());
effect2.setText("Untap those creatures");
effect2.apply(game, source);
RequirementEffect effect3 = new BlocksIfAbleTargetEffect(Duration.EndOfTurn);
effect3.setTargetPointer(new SecondTargetPointer());
effect3.setText("They block this turn if able");
game.addEffect(effect3, source);
return true;
}
return false;
}
Aggregations