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

    SetGenerator trapCondition =
        Intersect.instance(Between.instance(4, null), Count.instance(Attacking.instance()));
    this.addAbility(
        new org.rnd.jmagic.abilities.Trap(
            state,
            this.getName(),
            trapCondition,
            "If four or more creatures are attacking",
            "(1)(W)"));

    Target target = this.addTarget(Attacking.instance(), "up to five target attacking creatures");
    target.setNumber(1, 5);

    this.setDivision(Union.instance(numberGenerator(5), Identity.instance("damage")));
    EventType.ParameterMap damageParameters = new EventType.ParameterMap();
    damageParameters.put(EventType.Parameter.SOURCE, This.instance());
    damageParameters.put(
        EventType.Parameter.TAKER,
        ChosenTargetsFor.instance(Identity.instance(target), This.instance()));
    this.addEffect(
        new EventFactory(
            EventType.DISTRIBUTE_DAMAGE,
            damageParameters,
            "Arrow Volley Trap deals 5 damage divided as you choose among any number of target attacking creatures."));
  }
Esempio n. 3
0
    public TentacleRape(GameState state) {
      super(
          state,
          "Whenever Lorthos, the Tidemaker attacks, you may pay (8). If you do, tap up to eight target permanents. Those permanents don't untap during their controllers' next untap steps.");
      this.addPattern(whenThisAttacks());

      Target target = this.addTarget(Permanents.instance(), "up to eight target permanents");
      target.setNumber(0, 8);

      EventFactory mayPay8 = new EventFactory(EventType.PLAYER_MAY_PAY_MANA, "You may pay (8)");
      mayPay8.parameters.put(EventType.Parameter.CAUSE, This.instance());
      mayPay8.parameters.put(EventType.Parameter.PLAYER, You.instance());
      mayPay8.parameters.put(
          EventType.Parameter.COST, Identity.fromCollection(new ManaPool("(8)")));

      EventFactory tapHard =
          new EventFactory(
              EventType.TAP_HARD,
              "Tap up to eight target permanents. Those permanents don't untap during their controllers' next untap steps.");
      tapHard.parameters.put(EventType.Parameter.CAUSE, This.instance());
      tapHard.parameters.put(EventType.Parameter.OBJECT, targetedBy(target));

      EventFactory totalEffect =
          new EventFactory(
              EventType.IF_EVENT_THEN_ELSE,
              "You may pay (R). If you do, return Punishing Fire from your graveyard to your hand.");
      totalEffect.parameters.put(EventType.Parameter.IF, Identity.instance(mayPay8));
      totalEffect.parameters.put(EventType.Parameter.THEN, Identity.instance(tapHard));
      this.addEffect(totalEffect);
    }
Esempio n. 4
0
  public Ghostform(GameState state) {
    super(state);

    // Up to two target creatures are unblockable this turn.
    Target target = this.addTarget(CreaturePermanents.instance(), "up to two target creatures");
    target.setNumber(0, 2);
    this.addEffect(
        createFloatingEffect(
            "Up to two target creatures are unblockable this turn.",
            unblockable(targetedBy(target))));
  }
Esempio n. 5
0
  public Switcheroo(GameState state) {
    super(state);

    // Exchange control of two target creatures.
    Target target = this.addTarget(CreaturePermanents.instance(), "two target creatures");
    target.setNumber(2, 2);

    EventFactory factory =
        new EventFactory(EventType.EXCHANGE_CONTROL, "Exchange control of two target creatures.");
    factory.parameters.put(EventType.Parameter.CAUSE, This.instance());
    factory.parameters.put(EventType.Parameter.OBJECT, targetedBy(target));
    this.addEffect(factory);
  }
Esempio n. 6
0
  public BloodFeud(GameState state) {
    super(state);

    // Target creature fights another target creature. (Each deals damage
    // equal to its power to the other.)
    Target target1 = this.addTarget(CreaturePermanents.instance(), "target creature");
    target1.restrictFromLaterTargets = true;
    Target target2 = this.addTarget(CreaturePermanents.instance(), "another target creature");
    this.addEffect(
        fight(
            Union.instance(targetedBy(target1), targetedBy(target2)),
            "Target creature fights another target creature."));
  }
Esempio n. 7
0
    public InfernoTitanAbility1(GameState state) {
      super(
          state,
          "Whenever Inferno Titan enters the battlefield or attacks, it deals 3 damage divided as you choose among one, two, or three target creatures and/or players.");
      this.addPattern(whenThisEntersTheBattlefield());
      this.addPattern(whenThisAttacks());

      Target target =
          this.addTarget(
              CREATURES_AND_PLAYERS, "one, two, or three target creatures and/or players");
      target.setNumber(1, 3);
      this.setDivision(Union.instance(numberGenerator(3), Identity.instance("damage")));

      EventFactory damage =
          new EventFactory(
              EventType.DISTRIBUTE_DAMAGE,
              "It deals 3 damage divided as you choose among one, two, or three target creatures and/or players.");
      damage.parameters.put(EventType.Parameter.SOURCE, ABILITY_SOURCE_OF_THIS);
      damage.parameters.put(
          EventType.Parameter.TAKER,
          ChosenTargetsFor.instance(Identity.instance(target), This.instance()));
      this.addEffect(damage);
    }
Esempio n. 8
0
  @Override
  public boolean perform(Game game, Event event, java.util.Map<Parameter, Set> parameters) {
    GameObject object = parameters.get(Parameter.OBJECT).getOne(GameObject.class);
    Identified newTarget = parameters.get(Parameter.TARGET).getOne(Identified.class);
    java.util.Set<Target> canBeChanged = new java.util.HashSet<Target>();

    java.util.Map<Target, Boolean> wasLegal = new java.util.HashMap<Target, Boolean>();

    java.util.Map<Target, java.util.List<Target>> allChosenTargets =
        new java.util.HashMap<Target, java.util.List<Target>>();
    for (java.util.Map<Target, java.util.List<Target>> chosenTargets : object.getChosenTargets())
      allChosenTargets.putAll(chosenTargets);

    // Introduce this scope because there are two variables named
    // 'restricted'
    {
      java.util.Set<Integer> restricted = new java.util.HashSet<Integer>();
      for (Mode checkMode : object.getSelectedModes()) {
        for (Target checkBaseTarget : checkMode.targets) {
          java.util.Set<Integer> thisBaseTarget = new java.util.HashSet<Integer>();
          for (Target checkTarget : allChosenTargets.get(checkBaseTarget)) {
            Set legalCheck = checkTarget.legalChoicesNow(game, object);
            boolean legal =
                !(restricted.contains(checkTarget.targetID)
                    || !legalCheck.contains(game.actualState.get(checkTarget.targetID)));
            wasLegal.put(checkTarget, legal);
            if (checkTarget.restrictFromLaterTargets) restricted.add(checkTarget.targetID);
            thisBaseTarget.add(checkTarget.targetID);
          }
        }
      }
    }

    for (Mode mode : object.getSelectedModes()) {
      for (Target baseTarget : mode.targets) {
        for (Target target : allChosenTargets.get(baseTarget)) {
          Set targets = target.legalChoicesNow(game, object);
          if (targets.contains(newTarget)) {
            // The target won't "change" if its already set to
            // this target.
            if (target.targetID == newTarget.ID) continue;

            int oldValue = target.targetID;
            target.targetID = newTarget.ID;

            boolean illegal = false;
            java.util.Set<Integer> restricted = new java.util.HashSet<Integer>();
            legalityCheck:
            for (Mode checkMode : object.getSelectedModes()) {
              for (Target checkBaseTarget : checkMode.targets) {
                java.util.Set<Integer> thisBaseTarget = new java.util.HashSet<Integer>();
                for (Target checkTarget : allChosenTargets.get(checkBaseTarget)) {
                  Set legalCheck = checkTarget.legalChoicesNow(game, object);
                  boolean targetWasLegal = wasLegal.get(checkTarget);
                  if (targetWasLegal
                      && (thisBaseTarget.contains(checkTarget.targetID)
                          || restricted.contains(checkTarget.targetID)
                          || !legalCheck.contains(game.actualState.get(checkTarget.targetID)))) {
                    illegal = true;
                    break legalityCheck;
                  }
                  if (checkTarget.restrictFromLaterTargets) restricted.add(checkTarget.targetID);
                  thisBaseTarget.add(checkTarget.targetID);
                }
              }
            }

            target.targetID = oldValue;

            if (!illegal) {
              canBeChanged.add(target);
            }
          }
        }
      }
    }

    Player player = parameters.get(Parameter.PLAYER).getOne(Player.class);
    java.util.List<Target> choice =
        player.sanitizeAndChoose(
            game.actualState,
            1,
            canBeChanged,
            PlayerInterface.ChoiceType.SINGLE_TARGET,
            PlayerInterface.ChooseReason.TARGET);

    if (!choice.isEmpty()) {
      event.setResult(Identity.instance(object));
      Target chosenTarget = choice.get(0);
      chosenTarget.targetID = newTarget.ID;

      // Also set the target on the physical object
      java.util.Map<Target, java.util.List<Target>>[] chosenTargets = object.getChosenTargets();
      setPhysicalTarget:
      for (int sideNumber = 0; sideNumber < object.getChosenTargets().length; ++sideNumber)
        for (java.util.Map.Entry<Target, java.util.List<Target>> entry :
            chosenTargets[sideNumber].entrySet()) {
          for (int targetNumber = 0; targetNumber < entry.getValue().size(); ++targetNumber) {
            if (entry.getValue().get(targetNumber) == chosenTarget) {
              GameObject physical = object.getPhysical();
              physical
                      .getChosenTargets()[sideNumber]
                      .get(entry.getKey())
                      .get(targetNumber)
                      .targetID =
                  newTarget.ID;
              break setPhysicalTarget;
            }
          }
        }
    } else {
      event.setResult(Identity.instance());
    }

    return choice.size() == 1;
  }