Exemplo n.º 1
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
      if (controller.getLibrary().size() > 0) {
        Card card = controller.getLibrary().getFromTop(game);
        if (card == null) {
          return false;
        }
        controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
        if (card.getCardType().contains(CardType.CREATURE)) {
          FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
          boolean found = false;
          for (Permanent permanent :
              game.getBattlefield().getAllActivePermanents(filter, controller.getId(), game)) {
            if (CardUtil.shareSubtypes(card, permanent, game)) {
              found = true;
              break;
            }
          }
          if (found) {
            game.informPlayers(
                sourceObject.getLogName()
                    + ": Found a creature that shares a creature type with the revealed card.");
            if (controller.chooseUse(Outcome.Benefit, "Cast the card?", source, game)) {
              controller.cast(card.getSpellAbility(), game, true);
            } else {
              game.informPlayers(
                  sourceObject.getLogName()
                      + ": "
                      + controller.getLogName()
                      + " canceled casting the card.");
              controller.getLibrary().putOnBottom(card, game);
            }
          } else {
            game.informPlayers(
                sourceObject.getLogName()
                    + ": No creature that shares a creature type with the revealed card.");
            controller.getLibrary().putOnBottom(card, game);
          }
        } else {
          game.informPlayers(
              sourceObject.getLogName() + ": Put " + card.getLogName() + " on the bottom.");
          controller.getLibrary().putOnBottom(card, game);
        }

        return true;
      }
    }
    return false;
  }
Exemplo n.º 2
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   MageObject sourceObject = game.getObject(source.getSourceId());
   if (player != null) {
     Choice typeChoice = new ChoiceImpl(true);
     typeChoice.setMessage("Choose a creature type:");
     typeChoice.setChoices(CardRepository.instance.getCreatureTypes());
     while (!player.choose(outcome, typeChoice, game)) {
       if (!player.canRespond()) {
         return false;
       }
     }
     if (typeChoice.getChoice() != null) {
       game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice());
     }
     FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent();
     filterCreaturePermanent.add(new SubtypePredicate(typeChoice.getChoice()));
     for (Permanent creature :
         game.getBattlefield()
             .getActivePermanents(filterCreaturePermanent, source.getSourceId(), game)) {
       creature.untap(game);
     }
     return true;
   }
   return false;
 }
Exemplo n.º 3
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(targetPointer.getFirst(game, source));
   MageObject mageObject = game.getObject(source.getSourceId());
   if (player != null && mageObject != null) {
     String message = userMessage;
     if (message == null) {
       message =
           getCostText()
               + " to prevent "
               + executingEffect.getText(source.getModes().getMode())
               + "?";
     }
     message = CardUtil.replaceSourceName(message, mageObject.getLogName());
     cost.clearPaid();
     if (cost.canPay(source, source.getSourceId(), player.getId(), game)
         && player.chooseUse(executingEffect.getOutcome(), message, source, game)) {
       cost.pay(source, game, source.getSourceId(), player.getId(), false, null);
     }
     if (!cost.isPaid()) {
       executingEffect.setTargetPointer(this.targetPointer);
       return executingEffect.apply(game, source);
     }
     return true;
   }
   return false;
 }
Exemplo n.º 4
0
 @Override
 public String getInfoMessage(Ability source, GameEvent event, Game game) {
   MageObject mageObject = game.getObject(source.getSourceId());
   if (mageObject != null) {
     return "You can't cast a card with that name (" + mageObject.getLogName() + " in play).";
   }
   return null;
 }
Exemplo n.º 5
0
 @Override
 public String getGameLogMessage(Game game) {
   if (game.isSimulation()) {
     return "";
   }
   MageObject object = game.getObject(this.sourceId);
   if (object == null) { // e.g. sacrificed token
     logger.warn("Could get no object: " + this.toString());
   }
   return new StringBuilder(" activates: ")
       .append(
           object != null
               ? this.formatRule(getModes().getText(), object.getLogName())
               : getModes().getText())
       .append(" from ")
       .append(getMessageText(game))
       .toString();
 }
 @Override
 public boolean apply(Game game, Ability source) {
   Card sourceCard = game.getCard(source.getSourceId());
   MageObject sourceObject = game.getObject(source.getSourceId());
   if (sourceCard != null) {
     Player player = game.getPlayer(sourceCard.getOwnerId());
     if (player != null) {
       Zone fromZone = game.getState().getZone(sourceCard.getId());
       Cards cards = new CardsImpl();
       cards.add(sourceCard);
       player.revealCards(sourceObject.getLogName(), cards, game);
       player.moveCardToLibraryWithInfo(
           sourceCard, source.getSourceId(), game, fromZone, true, true);
       player.shuffleLibrary(game);
       return true;
     }
   }
   return false;
 }
Exemplo n.º 7
0
  private void updateTargets(Game game, StackAbility ability) {
    List<String> names = new ArrayList<>();
    for (UUID modeId : ability.getModes().getSelectedModes()) {
      ability.getModes().setMode(ability.getModes().get(modeId));
      if (ability.getTargets().size() > 0) {
        setTargets(ability.getTargets());
      } else {
        List<UUID> targetList = new ArrayList<>();
        for (Effect effect : ability.getEffects()) {
          TargetPointer targetPointer = effect.getTargetPointer();
          if (targetPointer instanceof FixedTarget) {
            targetList.add(((FixedTarget) targetPointer).getTarget());
          }
        }
        if (targetList.size() > 0) {
          overrideTargets(targetList);

          for (UUID uuid : targetList) {
            MageObject mageObject = game.getObject(uuid);
            if (mageObject != null) {
              names.add(mageObject.getLogName());
            }
          }
        }
      }
    }
    if (!names.isEmpty()) {
      getRules().add("<i>Targets: " + names.toString() + "</i>");
    }
    // show for modal ability, which mode was choosen
    if (ability.isModal()) {
      Modes modes = ability.getModes();
      for (UUID modeId : modes.getSelectedModes()) {
        modes.setMode(modes.get(modeId));
        this.rules.add(
            "<span color='green'><i>Chosen mode: "
                + ability.getEffects().getText(modes.get(modeId))
                + "</i></span>");
      }
    }
  }
 @Override
 public void init(Ability source, Game game) {
   super.init(source, game);
   MageObject sourceObject = game.getObject(source.getSourceId());
   Player controller = game.getPlayer(source.getControllerId());
   if (sourceObject != null && controller != null) {
     choice.clearChoice();
     while (!choice.isChosen()) {
       controller.choose(Outcome.Protect, choice, game);
       if (!controller.canRespond()) {
         return;
       }
     }
     if (choice.isChosen() && !game.isSimulation()) {
       game.informPlayers(
           sourceObject.getLogName()
               + ": "
               + controller.getLogName()
               + " has chosen protection from "
               + choice.getChoice());
     }
   }
 }
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   MageObject sourceObject = source.getSourceObject(game);
   if (sourceObject != null && controller != null) {
     ChoiceImpl choices = new ChoiceImpl(true);
     choices.setMessage("Choose token type");
     choices.getChoices().add("White Citizen");
     choices.getChoices().add("Blue Camarid");
     choices.getChoices().add("Black Thrull");
     choices.getChoices().add("Red Goblin");
     choices.getChoices().add("Green Saproling");
     if (controller.choose(Outcome.Neutral, choices, game)) {
       game.informPlayers(
           sourceObject.getLogName() + ": chosen token type is " + choices.getChoice());
       game.getState()
           .setValue(
               source.getSourceId().toString() + "_SarpadianEmpiresVolVii", choices.getChoice());
       return true;
     }
   }
   return false;
 }
Exemplo n.º 10
0
 @Override
 public boolean apply(Game game, Ability source) {
   StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
   MageObject sourceObject = game.getObject(source.getSourceId());
   if (sourceObject != null && spell != null) {
     Player player = game.getPlayer(spell.getControllerId());
     Player controller = game.getPlayer(source.getControllerId());
     if (player != null && controller != null) {
       int amount =
           game.getBattlefield()
               .countAll(new FilterArtifactPermanent(), source.getControllerId(), game);
       if (amount > 0) {
         GenericManaCost cost = new GenericManaCost(amount);
         if (!cost.pay(source, game, spell.getControllerId(), spell.getControllerId(), false)) {
           game.informPlayers(
               sourceObject.getLogName() + ": cost wasn't payed - countering target spell.");
           return game.getStack().counter(source.getFirstTarget(), source.getSourceId(), game);
         }
       }
       return true;
     }
   }
   return false;
 }