@Override
 protected Tracker clone() {
   Tracker ret = (Tracker) super.clone();
   ret.values = new java.util.HashSet<Integer>(this.values);
   ret.unmodifiable = java.util.Collections.unmodifiableSet(ret.values);
   return ret;
 }
Esempio n. 2
0
 @SuppressWarnings("unchecked")
 @Override
 public GameObjectsThisTurnCounter clone() {
   GameObjectsThisTurnCounter ret = (GameObjectsThisTurnCounter) super.clone();
   ret.counts = (java.util.HashMap<Integer, Integer>) (this.counts.clone());
   ret.unmodifiable = java.util.Collections.unmodifiableMap(ret.counts);
   return ret;
 }
Esempio n. 3
0
  /** keys are player IDs, values are the number of spells the player cast in the previous turn */
  public static final class Tracker
      extends org.rnd.jmagic.engine.Tracker<java.util.Map<Integer, Integer>> {
    private java.util.HashMap<Integer, Integer> thisTurn =
        new java.util.HashMap<Integer, Integer>();
    private java.util.HashMap<Integer, Integer> previousTurn =
        new java.util.HashMap<Integer, Integer>();
    private java.util.Map<Integer, Integer> unmodifiable =
        java.util.Collections.unmodifiableMap(this.previousTurn);

    @SuppressWarnings("unchecked")
    @Override
    public Tracker clone() {
      Tracker ret = (Tracker) super.clone();
      ret.thisTurn = (java.util.HashMap<Integer, Integer>) this.thisTurn.clone();
      ret.previousTurn = (java.util.HashMap<Integer, Integer>) this.previousTurn.clone();
      ret.unmodifiable = java.util.Collections.unmodifiableMap(ret.previousTurn);
      return ret;
    }

    @Override
    protected boolean match(GameState state, Event event) {
      if (event.type == EventType.CAST_SPELL_OR_ACTIVATE_ABILITY) {
        if (event.getResult(state).getOne(GameObject.class).isSpell()) return true;
      } else if (event.type == EventType.BEGIN_TURN) return true;
      return false;
    }

    @Override
    protected java.util.Map<Integer, Integer> getValueInternal() {
      return this.unmodifiable;
    }

    @Override
    protected void update(GameState state, Event event) {
      if (event.type == EventType.CAST_SPELL_OR_ACTIVATE_ABILITY) {
        Player caster =
            event
                .parameters
                .get(EventType.Parameter.PLAYER)
                .evaluate(state, null)
                .getOne(Player.class);
        if (this.thisTurn.containsKey(caster.ID))
          this.thisTurn.put(caster.ID, this.thisTurn.get(caster.ID) + 1);
        else this.thisTurn.put(caster.ID, 1);
      } else
      // it's a turn change
      {
        this.previousTurn.clear();
        this.previousTurn.putAll(this.thisTurn);
        this.thisTurn.clear();
      }
    }

    @Override
    protected void reset() {
      // This is an actively resetting tracker.
    }
  }
Esempio n. 4
0
 @SuppressWarnings("unchecked")
 @Override
 public Tracker clone() {
   Tracker ret = (Tracker) super.clone();
   ret.thisTurn = (java.util.HashMap<Integer, Integer>) this.thisTurn.clone();
   ret.previousTurn = (java.util.HashMap<Integer, Integer>) this.previousTurn.clone();
   ret.unmodifiable = java.util.Collections.unmodifiableMap(ret.previousTurn);
   return ret;
 }
    public static final class Tracker
        extends org.rnd.jmagic.engine.Tracker<java.util.Collection<Integer>> {
      private java.util.Set<Integer> values = new java.util.HashSet<Integer>();
      private java.util.Set<Integer> unmodifiable =
          java.util.Collections.unmodifiableSet(this.values);

      @Override
      protected Tracker clone() {
        Tracker ret = (Tracker) super.clone();
        ret.values = new java.util.HashSet<Integer>(this.values);
        ret.unmodifiable = java.util.Collections.unmodifiableSet(ret.values);
        return ret;
      }

      @Override
      protected java.util.Collection<Integer> getValueInternal() {
        return this.unmodifiable;
      }

      @Override
      protected void reset() {
        this.values.clear();
      }

      @Override
      protected boolean match(GameState state, Event event) {
        return event.type == EventType.BECOMES_TARGET;
      }

      @Override
      protected void update(GameState state, Event event) {
        Identified target =
            event
                .parameters
                .get(EventType.Parameter.TARGET)
                .evaluate(state, event.getSource())
                .getOne(Identified.class);
        this.values.add(target.ID);
      }
    }
Esempio n. 6
0
  /**
   * Track the number of {@link GameObject} instances in the result of any matching event. Keys are
   * controller IDs, values are the number of GameObject instances controlled by that player (or
   * owned if those objects are not on the battlefield or the stack) in the result of any matches
   * this turn.
   */
  public abstract static class GameObjectsThisTurnCounter
      extends Tracker<java.util.Map<Integer, Integer>> {
    protected java.util.HashMap<Integer, Integer> counts =
        new java.util.HashMap<Integer, Integer>();
    private java.util.Map<Integer, Integer> unmodifiable =
        java.util.Collections.unmodifiableMap(this.counts);

    @SuppressWarnings("unchecked")
    @Override
    public GameObjectsThisTurnCounter clone() {
      GameObjectsThisTurnCounter ret = (GameObjectsThisTurnCounter) super.clone();
      ret.counts = (java.util.HashMap<Integer, Integer>) (this.counts.clone());
      ret.unmodifiable = java.util.Collections.unmodifiableMap(ret.counts);
      return ret;
    }

    @Override
    protected java.util.Map<Integer, Integer> getValueInternal() {
      return this.unmodifiable;
    }

    @Override
    protected void reset() {
      this.counts.clear();
    }

    @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);
      }
    }
  }
Esempio n. 7
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;
  }