示例#1
0
 @Override
 public MagicSet evaluate(GameState state, Identified thisObject) {
   MagicSet ret = new MagicSet();
   for (Identified i : this.what.evaluate(state, thisObject).getAll(Identified.class))
     ret.add(i.getName());
   return ret;
 }
示例#2
0
    @Override
    protected void update(GameState state, Event event) {
      MagicSet movements = event.getResult(state);
      for (ZoneChange zc : movements.getAll(ZoneChange.class)) {

        int ownerID = state.<GameObject>get(zc.oldObjectID).ownerID;
        if (this.counts.containsKey(ownerID))
          this.counts.put(ownerID, this.counts.get(ownerID) + 1);
        else this.counts.put(ownerID, 1);
      }
    }
示例#3
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;
        }
示例#4
0
        @Override
        public boolean perform(Game game, Event event, Map<Parameter, MagicSet> parameters) {
          event.setResult(Empty.set);

          MagicSet cause = parameters.get(Parameter.CAUSE);
          Player you = parameters.get(Parameter.PLAYER).getOne(Player.class);
          Zone library = you.getLibrary(game.actualState);

          Map<Parameter, MagicSet> zombieParameters = new HashMap<Parameter, MagicSet>();
          zombieParameters.put(Parameter.CAUSE, cause);
          zombieParameters.put(Parameter.PLAYER, new MagicSet(you));
          zombieParameters.put(Parameter.NUMBER, ONE);
          zombieParameters.put(Parameter.CARD, new MagicSet(library));
          zombieParameters.put(Parameter.TYPE, new MagicSet(HasSubType.instance(SubType.ZOMBIE)));
          Event zombieSearch =
              createEvent(game, "Search your library for a Zombie card", SEARCH, zombieParameters);
          zombieSearch.perform(event, false);

          Map<Parameter, MagicSet> swampParameters =
              new HashMap<Parameter, MagicSet>(zombieParameters);
          swampParameters.put(Parameter.TYPE, new MagicSet(HasSubType.instance(SubType.SWAMP)));
          Event swampSearch =
              createEvent(game, "Search your library for a Swamp card", SEARCH, swampParameters);
          swampSearch.perform(event, false);

          MagicSet thoseCards = new MagicSet();
          thoseCards.addAll(zombieSearch.getResult());
          thoseCards.addAll(swampSearch.getResult());

          Map<Parameter, MagicSet> moveParameters = new HashMap<Parameter, MagicSet>();
          moveParameters.put(Parameter.CAUSE, cause);
          moveParameters.put(Parameter.TO, new MagicSet(you.getHand(game.actualState)));
          moveParameters.put(Parameter.OBJECT, thoseCards);
          Event move =
              createEvent(game, "Put those cards into your hand", MOVE_OBJECTS, moveParameters);
          move.perform(event, true);

          Map<Parameter, MagicSet> shuffleParameters = new HashMap<Parameter, MagicSet>();
          shuffleParameters.put(Parameter.CAUSE, cause);
          shuffleParameters.put(Parameter.PLAYER, new MagicSet(you));
          Event shuffle =
              createEvent(game, "Shuffle your library", SHUFFLE_LIBRARY, shuffleParameters);
          shuffle.perform(event, true);

          return true;
        }
示例#5
0
  @Override
  public boolean attempt(Game game, Event event, Map<Parameter, MagicSet> parameters) {
    int lifeGain = Sum.get(parameters.get(Parameter.NUMBER));
    if (lifeGain <= 0) return true;

    MagicSet players = parameters.get(Parameter.PLAYER);
    for (Player player : players.getAll(Player.class)) {
      HashMap<Parameter, MagicSet> newParameters = new HashMap<Parameter, MagicSet>(parameters);
      newParameters.put(Parameter.PLAYER, new MagicSet(player));
      Event gainLifeOnePlayer =
          createEvent(
              game, player + " loses " + lifeGain + " life", GAIN_LIFE_ONE_PLAYER, newParameters);
      if (!gainLifeOnePlayer.attempt(event)) return false;
    }

    return true;
  }
示例#6
0
  @Override
  public MagicSet evaluate(GameState state, Identified thisObject) {
    MagicSet allAttackers = Attacking.get(state);
    if (this.what == null) return allAttackers;

    Set<Integer> beingAttackedIDs = new HashSet<Integer>();
    MagicSet evaluateWhat = this.what.evaluate(state, thisObject);
    for (GameObject o : evaluateWhat.getAll(GameObject.class))
      if (o.getTypes().contains(Type.PLANESWALKER)) beingAttackedIDs.add(o.ID);
    for (Player p : evaluateWhat.getAll(Player.class)) beingAttackedIDs.add(p.ID);

    Set<GameObject> attackingThisPlayer = allAttackers.getAll(GameObject.class);
    Iterator<GameObject> objectIterator = attackingThisPlayer.iterator();
    while (objectIterator.hasNext()) {
      GameObject attacker = objectIterator.next();
      if (!beingAttackedIDs.contains(attacker.getAttackingID())) objectIterator.remove();
    }

    return new MagicSet(attackingThisPlayer);
  }
示例#7
0
  @Override
  public MagicSet evaluate(GameState state, Identified thisObject) {
    MagicSet ret = new MagicSet();
    MagicSet what = this.what.evaluate(state, thisObject);
    auras:
    for (GameObject aura : state.getAllObjects()) {
      if (!aura.getSubTypes().contains(SubType.AURA)) continue;

      for (Keyword ability : aura.getKeywordAbilities())
        if (ability.isEnchant()) {
          Enchant e = (Enchant) ability;
          MagicSet intermediate = new MagicSet(what);
          intermediate.retainAll(e.filter.evaluate(state, aura));
          for (GameObject o : intermediate.getAll(GameObject.class))
            if (!o.cantBeAttachedBy().match(state, thisObject, new MagicSet(aura))) {
              ret.add(aura);
              continue auras;
            }
        }
    }
    return ret;
  }
示例#8
0
  @Override
  public boolean perform(Game game, Event event, Map<Parameter, MagicSet> parameters) {
    int lifeGain = Sum.get(parameters.get(Parameter.NUMBER));
    if (lifeGain <= 0) {
      event.setResult(Empty.set);
      return true;
    }

    MagicSet result = new MagicSet();
    MagicSet players = parameters.get(Parameter.PLAYER);
    for (Player player : players.getAll(Player.class)) {
      HashMap<Parameter, MagicSet> newParameters = new HashMap<Parameter, MagicSet>(parameters);
      newParameters.put(Parameter.PLAYER, new MagicSet(player));
      Event gain =
          createEvent(
              game, player + " gains " + lifeGain + " life", GAIN_LIFE_ONE_PLAYER, newParameters);
      gain.perform(event, false);
      result.addAll(gain.getResult());
    }

    event.setResult(result);
    return true;
  }
示例#9
0
 public static MagicSet get(GameState state) {
   MagicSet ret = new MagicSet();
   for (GameObject o : state.battlefield()) if (-1 != o.getAttackingID()) ret.add(o);
   return ret;
 }