@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;
 }
Exemple #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.
    }
  }
Exemple #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;
 }
    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);
      }
    }