Beispiel #1
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;
 }
Beispiel #2
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.
    }
  }
Beispiel #3
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;
 }
Beispiel #4
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);
      }
    }
  }