Esempio n. 1
0
 @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);
 }
Esempio n. 2
0
  public RuneflareTrap(GameState state) {
    super(state);

    // If an opponent drew three or more cards this turn, you may pay (R)
    // rather than pay Runeflare Trap's mana cost.
    state.ensureTracker(new CardsDrawn());
    SetGenerator opponents = OpponentsOf.instance(You.instance());
    SetGenerator cardsDrawn = MaximumPerPlayer.instance(CardsDrawn.class, opponents);
    SetGenerator trapCondition = Intersect.instance(cardsDrawn, Between.instance(3, null));
    this.addAbility(
        new Trap(
            state,
            this.getName(),
            trapCondition,
            "If an opponent drew three or more cards this turn",
            "(R)"));

    // Runeflare Trap deals damage to target player equal to the number of
    // cards in that player's hand.
    Target target = this.addTarget(Players.instance(), "target player");

    SetGenerator amount = Count.instance(InZone.instance(HandOf.instance(targetedBy(target))));
    this.addEffect(
        spellDealDamage(
            amount,
            targetedBy(target),
            "Runeflare Trap deals damage to target player equal to the number of cards in that player's hand."));
  }
Esempio n. 3
0
  public PermafrostTrap(GameState state) {
    super(state);

    // If an opponent had a green creature enter the battlefield under his
    // or her control this turn, you may pay (U) rather than pay Permafrost
    // Trap's mana cost.
    state.ensureTracker(new GreenCreaturesPutOntoTheBattlefieldThisTurnCounter());
    SetGenerator opponents = OpponentsOf.instance(You.instance());
    SetGenerator maxPerOpponent =
        MaximumPerPlayer.instance(
            GreenCreaturesPutOntoTheBattlefieldThisTurnCounter.class, opponents);
    SetGenerator trapCondition = Intersect.instance(Between.instance(2, null), maxPerOpponent);
    this.addAbility(
        new org.rnd.jmagic.abilities.Trap(
            state,
            this.getName(),
            trapCondition,
            "If an opponent had a green creature enter the battlefield under his or her control this turn",
            "(U)"));

    Target target = this.addTarget(CreaturePermanents.instance(), "up to two target creatures");
    target.setNumber(0, 2);

    // Tap up to two target creatures. Those creatures don't untap during
    // their controller's next untap step.
    EventFactory tap =
        new EventFactory(
            EventType.TAP_HARD,
            "Tap up to two target creatures. Those creatures don't untap during their controller's next untap step.");
    tap.parameters.put(EventType.Parameter.CAUSE, This.instance());
    tap.parameters.put(EventType.Parameter.OBJECT, targetedBy(target));
    this.addEffect(tap);
  }
Esempio n. 4
0
    @Override
    public Set evaluate(GameState state, Identified thisObject) {
      Tracker tracker = state.getTracker(Tracker.class);

      // if "a player" cast two or more spells this turn -- a single value
      // in the map must be >= 2
      for (int spellCount : tracker.getValue(state).values())
        if (spellCount >= 2) return NonEmpty.set;
      return Empty.set;
    }
Esempio n. 5
0
  public Monstrosity(GameState state, String manaCost, int N) {
    super(state, manaCost + ": Monstrosity " + N + ".");
    this.manaCost = manaCost;
    this.N = N;

    this.setManaCost(new ManaPool(manaCost));

    state.ensureTracker(new org.rnd.jmagic.engine.eventTypes.Monstrosity.MonstrousTracker());
    EventFactory monstrosity = monstrosity(N);
    this.addEffect(monstrosity);
  }
Esempio n. 6
0
    @Override
    protected boolean match(GameState state, Event event) {
      if (event.type != EventType.MOVE_BATCH) return false;

      for (ZoneChange change :
          event
              .parametersNow
              .get(EventType.Parameter.TARGET)
              .evaluate(state, null)
              .getAll(ZoneChange.class)) {
        if (state.battlefield().ID != change.destinationZoneID) continue;

        GameObject object = state.get(change.newObjectID);
        if (!object.getColors().contains(Color.GREEN) || !object.getTypes().contains(Type.CREATURE))
          continue;

        return true;
      }
      return false;
    }
Esempio n. 7
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. 8
0
    public MarduWarshriekerAbility0(GameState state) {
      super(
          state,
          "When Mardu Warshrieker enters the battlefield, if you attacked with a creature this turn, add (R)(W)(B) to your mana pool.");
      this.addPattern(whenThisEntersTheBattlefield());

      state.ensureTracker(new org.rnd.jmagic.engine.trackers.AttackTracker());
      this.interveningIf = Raid.instance();

      this.addEffect(addManaToYourManaPoolFromAbility("(R)(W)(B)"));
    }
Esempio n. 9
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;
  }
Esempio n. 10
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);
  }
Esempio n. 11
0
    @Override
    public boolean checkSpecialRestrictions(GameState state, List<Target> choices) {
      if (choices.isEmpty()) return true;

      List<Integer> controllers = new LinkedList<Integer>();
      for (Target choice : choices) {
        int controller = state.<GameObject>get(choice.targetID).controllerID;
        if (controllers.contains(controller)) return false;
        controllers.add(controller);
      }

      return true;
    }
Esempio n. 12
0
    public BecomeHuman(GameState state, String cardName) {
      super(
          state,
          "At the beginning of each upkeep, if a player cast two or more spells last turn, transform "
              + cardName
              + ".");
      this.cardName = cardName;

      this.addPattern(atTheBeginningOfEachUpkeep());

      state.ensureTracker(new Tracker());
      this.interveningIf = NewMoon.instance();

      this.addEffect(transformThis(cardName));
    }
Esempio n. 13
0
    public BecomeFuzzy(GameState state, String cardName) {
      super(
          state,
          "At the beginning of each upkeep, if no spells were cast last turn, transform "
              + cardName
              + ".");
      this.cardName = cardName;

      this.addPattern(atTheBeginningOfEachUpkeep());

      state.ensureTracker(new Tracker());
      this.interveningIf = FullMoon.instance();

      this.addEffect(transformThis(cardName));
    }
Esempio n. 14
0
    public Glass(GameState state) {
      super(
          state,
          "Whenever this creature becomes the target of a spell or ability for the first time in a turn, counter that spell or ability.");

      SimpleEventPattern pattern = new SimpleEventPattern(EventType.BECOMES_TARGET);
      pattern.put(
          EventType.Parameter.TARGET,
          RelativeComplement.instance(ABILITY_SOURCE_OF_THIS, TargetedThisTurn.instance()));
      state.ensureTracker(new TargetedThisTurn.Tracker());

      SetGenerator thatSpell =
          EventParameter.instance(
              TriggerEvent.instance(This.instance()), EventType.Parameter.OBJECT);
      this.addEffect(counter(thatSpell, "Counter that spell or ability."));
    }
Esempio n. 15
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. 16
0
 public static MagicSet get(GameState state) {
   MagicSet ret = new MagicSet();
   for (GameObject o : state.battlefield()) if (-1 != o.getAttackingID()) ret.add(o);
   return ret;
 }
Esempio n. 17
0
 @Override
 public Set evaluate(GameState state, Identified thisObject) {
   Tracker tracker = state.getTracker(Tracker.class);
   if (tracker.getValue(state).isEmpty()) return NonEmpty.set;
   return Empty.set;
 }
Esempio n. 18
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;
 }