Esempio n. 1
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);
      }
    }
Esempio n. 2
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);
  }
Esempio n. 3
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;
  }
Esempio n. 4
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;
  }
Esempio n. 5
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;
  }