Search in sources :

Example 1 with UntapAllEffect

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;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) UntapAllEffect(mage.abilities.effects.common.UntapAllEffect) GainAbilityAllEffect(mage.abilities.effects.common.continuous.GainAbilityAllEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 UntapAllEffect (mage.abilities.effects.common.UntapAllEffect)1 GainAbilityAllEffect (mage.abilities.effects.common.continuous.GainAbilityAllEffect)1 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)1 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)1 Permanent (mage.game.permanent.Permanent)1 FixedTarget (mage.target.targetpointer.FixedTarget)1