Example #1
0
        @Override
        public boolean perform(Game game, Event event, Map<Parameter, MagicSet> parameters) {
          MagicSet cause = parameters.get(Parameter.CAUSE);
          event.setResult(Empty.set);

          Set<Color> choices = parameters.get(Parameter.CHOICE).getAll(Color.class);
          Player player = parameters.get(Parameter.PLAYER).getOne(Player.class);

          PlayerInterface.ChooseParameters<Color> chooseParameters =
              new PlayerInterface.ChooseParameters<Color>(
                  1,
                  1,
                  new LinkedList<Color>(choices),
                  PlayerInterface.ChoiceType.COLOR,
                  PlayerInterface.ChooseReason.CHOOSE_COLOR);
          chooseParameters.thisID = cause.getOne(GameObject.class).ID;
          List<Color> chosenList = player.choose(chooseParameters);
          if (chosenList.isEmpty()) return false;

          Color color = chosenList.get(0);

          Class<? extends Protection> ability = Protection.from(color);

          ContinuousEffect.Part part =
              new ContinuousEffect.Part(ContinuousEffectType.ADD_ABILITY_TO_OBJECT);
          part.parameters.put(
              ContinuousEffectType.Parameter.OBJECT,
              Intersect.instance(
                  HasColor.instance(Color.WHITE),
                  Intersect.instance(
                      HasType.instance(Type.CREATURE), ControlledBy.instance(You.instance()))));
          part.parameters.put(
              ContinuousEffectType.Parameter.ABILITY,
              Identity.instance(new SimpleAbilityFactory(ability)));

          Map<Parameter, MagicSet> fceParameters = new HashMap<Parameter, MagicSet>();
          fceParameters.put(Parameter.CAUSE, cause);
          fceParameters.put(Parameter.EFFECT, new MagicSet(part));
          Event protection =
              createEvent(
                  game,
                  "White creatures you control gain protection from the chosen color until end of turn.",
                  EventType.CREATE_FLOATING_CONTINUOUS_EFFECT,
                  fceParameters);
          protection.perform(event, false);

          return true;
        }