use of mage.abilities.effects.common.UntapAllEffect 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