示例#1
0
          @Override
          public boolean perform(Game game, Event event, java.util.Map<Parameter, Set> parameters) {
            Set cards = new Set();

            for (Player player : parameters.get(Parameter.PLAYER).getAll(Player.class))
              cards.addAll(player.getHand(game.actualState).objects);

            java.util.Map<Parameter, Set> discardParameters =
                new java.util.HashMap<Parameter, Set>();
            discardParameters.put(EventType.Parameter.CAUSE, parameters.get(Parameter.CAUSE));
            discardParameters.put(EventType.Parameter.CARD, cards);
            Event discardEvent =
                createEvent(
                    game,
                    "Each player discards his or her hand",
                    EventType.DISCARD_CARDS,
                    discardParameters);
            discardEvent.perform(event, true);

            java.util.Map<Parameter, Set> drawParameters = new java.util.HashMap<Parameter, Set>();
            drawParameters.put(EventType.Parameter.CAUSE, parameters.get(Parameter.CAUSE));
            drawParameters.put(EventType.Parameter.PLAYER, parameters.get(Parameter.PLAYER));
            drawParameters.put(EventType.Parameter.NUMBER, new Set(4));
            Event drawEvent =
                createEvent(game, "and draws four cards.", EventType.DRAW_CARDS, drawParameters);
            drawEvent.perform(event, true);

            event.setResult(Empty.set);

            return true;
          }
示例#2
0
 @Override
 protected void update(GameState state, Event event) {
   Set objects = event.getResult(state);
   for (GameObject o : objects.getAll(GameObject.class)) {
     int controllerID = o.getController(state).ID;
     if (this.counts.containsKey(controllerID))
       this.counts.put(controllerID, this.counts.get(controllerID) + 1);
     else this.counts.put(controllerID, 1);
   }
 }
示例#3
0
  @Override
  public Set evaluate(GameState state, Identified thisObject) {
    Set ret = new Set();

    for (GameObject object : state.getAllObjects())
      for (Class<? extends Keyword> c : this.abilities) if (object.hasAbility(c)) ret.add(object);

    for (Player player : state.players)
      for (Class<? extends Keyword> c : this.abilities) if (player.hasAbility(c)) ret.add(player);

    return ret;
  }
示例#4
0
  @Override
  public Set evaluate(GameState state, Identified thisObject) {
    Set players = this.players.evaluate(state, thisObject);
    java.util.Map<Integer, Integer> flag = state.getTracker(this.tracker).getValue(state);
    int count = 0;

    for (Player player : players.getAll(Player.class))
      if (flag.containsKey(player.ID)) {
        int value = flag.get(player.ID);
        if (value > count) count = value;
      }
    return new Set(count);
  }
示例#5
0
    @Override
    public DamageAssignment.Batch match(Event context, DamageAssignment.Batch damageAssignments) {
      DamageAssignment.Batch ret = new DamageAssignment.Batch();

      Set valid =
          CREATURES_YOU_CONTROL.evaluate(context.state, this.getSourceObject(context.state));

      for (DamageAssignment damage : damageAssignments)
        if (!damage.isCombatDamage && valid.contains(context.state.get(damage.takerID)))
          ret.add(damage);

      return ret;
    }
示例#6
0
 public static Set get() {
   if (set == null) {
     Set ret = new Set();
     for (Class<? extends Card> card : org.rnd.jmagic.CardLoader.getAllCards()) {
       Name name = card.getAnnotation(Name.class);
       if (name != null)
         // when naming cards for meddling mage, you name one
         // side of a split card, not both sides.
         java.util.Arrays.stream(name.value().split(" // ")).forEach(n -> ret.add(n));
     }
     set = new Set.Unmodifiable(ret);
   }
   return set;
 }
示例#7
0
    public EntwineAdditionalCost(GameState state, CostCollection costs, String costName) {
      super(
          state,
          "If you choose all the modes of this spell, you pay an additional " + costName + ".");

      this.costCollection = costs;
      this.costName = costName;

      Set newCosts = Set.fromCollection(costs.manaCost);
      newCosts.addAll(costs.events);

      ContinuousEffect.Part part = new ContinuousEffect.Part(ContinuousEffectType.COST_ADDITION);
      part.parameters.put(ContinuousEffectType.Parameter.OBJECT, This.instance());
      part.parameters.put(ContinuousEffectType.Parameter.COST, Identity.fromCollection(newCosts));
      this.addEffectPart(part);

      // This only applies if you've chosen all of its modes
      this.canApply =
          Not.instance(
              RelativeComplement.instance(
                  ModesOf.instance(This.instance()), SelectedModesOf.instance(This.instance())));
    }
示例#8
0
  @Override
  public boolean perform(Game game, Event event, java.util.Map<Parameter, Set> parameters) {
    boolean allDiscarded = event.allChoicesMade;
    Set cause = parameters.get(Parameter.CAUSE);
    Set result = new Set();

    for (Player player : parameters.get(Parameter.PLAYER).getAll(Player.class)) {
      Set discardThese = event.getChoices(player);

      java.util.Map<Parameter, Set> discardParameters = new java.util.HashMap<Parameter, Set>();
      discardParameters.put(Parameter.CAUSE, cause);
      discardParameters.put(Parameter.CARD, discardThese);
      Event discard =
          createEvent(
              game, player + " discards " + discardThese + ".", DISCARD_CARDS, discardParameters);
      if (!discard.perform(event, false)) allDiscarded = false;
      result.addAll(discard.getResult());
    }

    event.setResult(Identity.instance(result));
    return allDiscarded;
  }
 @Override
 public boolean match(GameState state, Identified object, Set set) {
   Set newSet = Set.fromCollection(set);
   for (ZoneChange change : set.getAll(ZoneChange.class)) {
     newSet.add(state.get(change.oldObjectID));
     // If we're evaluating this pattern to determine whether a look-back
     // trigger should trigger, the new object might not actually exist
     // yet.
     if (state.containsIdentified(change.newObjectID)) newSet.add(state.get(change.newObjectID));
     newSet.remove(change);
   }
   return super.match(state, object, newSet);
 }
示例#10
0
 @Override
 public org.rnd.jmagic.engine.Set evaluate(GameState state, Identified thisObject) {
   Set ret = new Set();
   for (int ID : state.getTracker(Tracker.class).getValue(state)) ret.add(state.get(ID));
   return ret;
 }
示例#11
0
  @Override
  public boolean perform(Game game, Event event, java.util.Map<Parameter, Set> parameters) {
    Set result = new Set();
    Identified producer = parameters.get(Parameter.SOURCE).getOne(Identified.class);
    java.util.Set<Color> colors = parameters.get(Parameter.MANA).getAll(Color.class);
    java.util.Set<ManaSymbol.ManaType> types =
        parameters.get(Parameter.MANA).getAll(ManaSymbol.ManaType.class);
    ManaPool pool = new ManaPool();

    ManaSymbol addition = new ManaSymbol("");
    addition.colors.addAll(colors);
    for (ManaSymbol.ManaType type : types) {
      if (ManaSymbol.ManaType.COLORLESS == type) {
        addition.colorless = 1;
        addition.name += "1";
      } else {
        Color color = type.getColor();
        addition.colors.add(color);
        addition.name += color.getLetter();
      }
    }
    if (!addition.isZero()) pool.add(addition);

    pool.addAll(parameters.get(Parameter.MANA).getAll(ManaSymbol.class));

    int multiply = 1;
    if (parameters.containsKey(Parameter.MULTIPLY))
      multiply = Sum.get(parameters.get(Parameter.MULTIPLY));

    if (multiply != 1) {
      ManaPool newPool = new ManaPool();

      if (multiply > 1) {
        newPool.addAll(pool);
        for (ManaSymbol symbol : pool)
          for (int i = 1; i < multiply; ++i) newPool.add(symbol.create());
      }

      pool = newPool;
    }

    int number = 1;
    if (parameters.containsKey(Parameter.NUMBER))
      number = Sum.get(parameters.get(Parameter.NUMBER));

    boolean snow = false;
    if (producer.isGameObject())
      snow = ((GameObject) producer).getSuperTypes().contains(SuperType.SNOW);
    for (Player actualPlayer : parameters.get(Parameter.PLAYER).getAll(Player.class)) {
      Player physicalPlayer = actualPlayer.getPhysical();
      java.util.Set<CostCollection> choices = pool.explode("Add");
      // TODO : Ticket 430

      ManaPool chosen = null;
      if (choices.isEmpty()) // empty pool to start with
      chosen = pool;
      else if (choices.size() == 1) chosen = choices.iterator().next().manaCost;
      else {
        // if all of the choices are mana of a single color, present
        // it as a color choice
        boolean allSingleColorSymbols = true;
        for (CostCollection choiceCollection : choices) {
          ManaPool choice = choiceCollection.manaCost;
          if (choice.converted() != 1) {
            allSingleColorSymbols = false;
            break;
          }
          ManaSymbol symbol = choice.first();
          if (symbol.colorless != 0) {
            allSingleColorSymbols = false;
            break;
          }
          if (symbol.colors.size() != 1) {
            allSingleColorSymbols = false;
            break;
          }
        }

        if (allSingleColorSymbols) {
          java.util.Set<Color> colorChoices = java.util.EnumSet.noneOf(Color.class);
          for (CostCollection choice : choices)
            colorChoices.add(choice.manaCost.first().colors.iterator().next());
          Color chosenColor = physicalPlayer.chooseColor(colorChoices, producer.ID);

          ManaSymbol s = pool.first().create();
          s.colors = java.util.EnumSet.of(chosenColor);
          s.colorless = 0;
          chosen = new ManaPool(java.util.Collections.singleton(s));
        } else
          chosen =
              physicalPlayer
                  .sanitizeAndChoose(
                      game.actualState,
                      1,
                      choices,
                      PlayerInterface.ChoiceType.MANA_EXPLOSION,
                      PlayerInterface.ChooseReason.HYBRID_MANA)
                  .iterator()
                  .next()
                  .manaCost;
      }

      for (int i = 0; i < number; ++i) {
        // Use the reference mana to create a new mana to
        // add to the pool
        for (ManaSymbol newMana : chosen) {
          newMana = newMana.create();
          newMana.sourceID = producer.ID;
          newMana.isSnow = snow;
          physicalPlayer.pool.add(newMana);
          result.add(newMana);
          if (game.currentAction != null) game.currentAction.manaProduced.add(newMana);
        }
      }
    }

    GameObject source = event.getSource();
    if (source.isActivatedAbility())
      ((ActivatedAbility) source.getPhysical()).addedMana(result.getAll(ManaSymbol.class));

    event.setResult(Identity.instance(result));
    return true;
  }
示例#12
0
 @Override
 public Set evaluate(GameState state, Identified thisObject) {
   return Set.fromCollection(state.voidedObjects);
 }
示例#13
0
  @Override
  public boolean perform(Game game, Event event, java.util.Map<Parameter, Set> parameters) {
    GameObject object = parameters.get(Parameter.OBJECT).getOne(GameObject.class);
    Identified newTarget = parameters.get(Parameter.TARGET).getOne(Identified.class);
    java.util.Set<Target> canBeChanged = new java.util.HashSet<Target>();

    java.util.Map<Target, Boolean> wasLegal = new java.util.HashMap<Target, Boolean>();

    java.util.Map<Target, java.util.List<Target>> allChosenTargets =
        new java.util.HashMap<Target, java.util.List<Target>>();
    for (java.util.Map<Target, java.util.List<Target>> chosenTargets : object.getChosenTargets())
      allChosenTargets.putAll(chosenTargets);

    // Introduce this scope because there are two variables named
    // 'restricted'
    {
      java.util.Set<Integer> restricted = new java.util.HashSet<Integer>();
      for (Mode checkMode : object.getSelectedModes()) {
        for (Target checkBaseTarget : checkMode.targets) {
          java.util.Set<Integer> thisBaseTarget = new java.util.HashSet<Integer>();
          for (Target checkTarget : allChosenTargets.get(checkBaseTarget)) {
            Set legalCheck = checkTarget.legalChoicesNow(game, object);
            boolean legal =
                !(restricted.contains(checkTarget.targetID)
                    || !legalCheck.contains(game.actualState.get(checkTarget.targetID)));
            wasLegal.put(checkTarget, legal);
            if (checkTarget.restrictFromLaterTargets) restricted.add(checkTarget.targetID);
            thisBaseTarget.add(checkTarget.targetID);
          }
        }
      }
    }

    for (Mode mode : object.getSelectedModes()) {
      for (Target baseTarget : mode.targets) {
        for (Target target : allChosenTargets.get(baseTarget)) {
          Set targets = target.legalChoicesNow(game, object);
          if (targets.contains(newTarget)) {
            // The target won't "change" if its already set to
            // this target.
            if (target.targetID == newTarget.ID) continue;

            int oldValue = target.targetID;
            target.targetID = newTarget.ID;

            boolean illegal = false;
            java.util.Set<Integer> restricted = new java.util.HashSet<Integer>();
            legalityCheck:
            for (Mode checkMode : object.getSelectedModes()) {
              for (Target checkBaseTarget : checkMode.targets) {
                java.util.Set<Integer> thisBaseTarget = new java.util.HashSet<Integer>();
                for (Target checkTarget : allChosenTargets.get(checkBaseTarget)) {
                  Set legalCheck = checkTarget.legalChoicesNow(game, object);
                  boolean targetWasLegal = wasLegal.get(checkTarget);
                  if (targetWasLegal
                      && (thisBaseTarget.contains(checkTarget.targetID)
                          || restricted.contains(checkTarget.targetID)
                          || !legalCheck.contains(game.actualState.get(checkTarget.targetID)))) {
                    illegal = true;
                    break legalityCheck;
                  }
                  if (checkTarget.restrictFromLaterTargets) restricted.add(checkTarget.targetID);
                  thisBaseTarget.add(checkTarget.targetID);
                }
              }
            }

            target.targetID = oldValue;

            if (!illegal) {
              canBeChanged.add(target);
            }
          }
        }
      }
    }

    Player player = parameters.get(Parameter.PLAYER).getOne(Player.class);
    java.util.List<Target> choice =
        player.sanitizeAndChoose(
            game.actualState,
            1,
            canBeChanged,
            PlayerInterface.ChoiceType.SINGLE_TARGET,
            PlayerInterface.ChooseReason.TARGET);

    if (!choice.isEmpty()) {
      event.setResult(Identity.instance(object));
      Target chosenTarget = choice.get(0);
      chosenTarget.targetID = newTarget.ID;

      // Also set the target on the physical object
      java.util.Map<Target, java.util.List<Target>>[] chosenTargets = object.getChosenTargets();
      setPhysicalTarget:
      for (int sideNumber = 0; sideNumber < object.getChosenTargets().length; ++sideNumber)
        for (java.util.Map.Entry<Target, java.util.List<Target>> entry :
            chosenTargets[sideNumber].entrySet()) {
          for (int targetNumber = 0; targetNumber < entry.getValue().size(); ++targetNumber) {
            if (entry.getValue().get(targetNumber) == chosenTarget) {
              GameObject physical = object.getPhysical();
              physical
                      .getChosenTargets()[sideNumber]
                      .get(entry.getKey())
                      .get(targetNumber)
                      .targetID =
                  newTarget.ID;
              break setPhysicalTarget;
            }
          }
        }
    } else {
      event.setResult(Identity.instance());
    }

    return choice.size() == 1;
  }