Exemplo n.º 1
0
 void updateCounters(Card c) {
   set(TrackableProperty.Counters, c.getCounters());
   CardStateView state = getCurrentState();
   state.updatePower(c);
   state.updateToughness(c);
   state.updateLoyalty(c);
 }
Exemplo n.º 2
0
  void updateState(Card c) {
    updateName(c);

    boolean isSplitCard = c.isSplitCard();
    set(TrackableProperty.Cloned, c.isCloned());
    set(TrackableProperty.SplitCard, isSplitCard);
    set(TrackableProperty.FlipCard, c.isFlipCard());

    CardStateView cloner = CardView.getState(c, CardStateName.Cloner);
    set(
        TrackableProperty.Cloner,
        cloner == null ? null : cloner.getName() + " (" + cloner.getId() + ")");

    CardState currentState = c.getCurrentState();
    if (isSplitCard) {
      if (c.getCurrentStateName() != CardStateName.LeftSplit
          && c.getCurrentStateName() != CardStateName.RightSplit) {
        currentState = c.getState(CardStateName.LeftSplit);
      }
    }

    CardStateView currentStateView = currentState.getView();
    if (getCurrentState() != currentStateView) {
      set(TrackableProperty.CurrentState, currentStateView);
      currentStateView.updatePower(
          c); // ensure power, toughness, and loyalty updated when current state changes
      currentStateView.updateToughness(c);
      currentStateView.updateLoyalty(c);

      // update the color only while in Game
      if (c.getGame() != null) {
        currentStateView.updateColors(currentState);
      }
    }
    currentState
        .getView()
        .updateKeywords(c, currentState); // update keywords even if state doesn't change

    CardState alternateState =
        isSplitCard ? c.getState(CardStateName.RightSplit) : c.getAlternateState();
    if (alternateState == null) {
      set(TrackableProperty.AlternateState, null);
    } else {
      CardStateView alternateStateView = alternateState.getView();
      if (getAlternateState() != alternateStateView) {
        set(TrackableProperty.AlternateState, alternateStateView);
        alternateStateView.updatePower(
            c); // ensure power, toughness, and loyalty updated when current state changes
        alternateStateView.updateToughness(c);
        alternateStateView.updateLoyalty(c);

        // update the color only while in Game
        if (c.getGame() != null) {
          alternateStateView.updateColors(alternateState);
        }
      }
      alternateState.getView().updateKeywords(c, alternateState);
    }
  }
Exemplo n.º 3
0
  public String getText(CardStateView state) {
    final StringBuilder sb = new StringBuilder();
    // final boolean isSplitCard = (state.getState() == CardStateName.LeftSplit);

    if (getId() < 0) {
      if (isSplitCard()) {
        sb.append("(").append(state.getName()).append(") ");
        sb.append(state.getOracleText());
        sb.append("\r\n\r\n");
        sb.append("(").append(getAlternateState().getName()).append(") ");
        sb.append(getAlternateState().getOracleText());
        return sb.toString().trim();
      } else {
        return state.getOracleText();
      }
    }

    final String rulesText = state.getRulesText();
    if (!rulesText.isEmpty()) {
      sb.append(rulesText).append("\r\n\r\n");
    }
    if (isCommander()) {
      sb.append(getOwner()).append("'s Commander\r\n");
      sb.append(getOwner().getCommanderInfo()).append("\r\n");
    }

    if (isSplitCard()) {
      CardStateView view =
          state.getState() == CardStateName.LeftSplit ? state : getAlternateState();
      if (getZone() != ZoneType.Stack) {
        sb.append("(");
        sb.append(view.getName());
        sb.append(") ");
      }
      sb.append(view.getAbilityText());
    } else {
      sb.append(state.getAbilityText());
    }

    if (isSplitCard() && getZone() != ZoneType.Stack) {
      // ensure ability text for right half of split card is included unless spell is on stack
      sb.append("\r\n\r\n")
          .append("(")
          .append(getAlternateState().getName())
          .append(") ")
          .append(getAlternateState().getOracleText());
    }

    String nonAbilityText = get(TrackableProperty.NonAbilityText);
    int blockAdditional = state.getBlockAdditional();
    if (blockAdditional > 1) {
      final StringBuilder ab = new StringBuilder();
      ab.append("CARDNAME can block an additional ");
      ab.append(blockAdditional);
      ab.append(" creatures.");
      nonAbilityText =
          nonAbilityText.replaceFirst("CARDNAME can block an additional creature.", ab.toString());
      nonAbilityText = nonAbilityText.replaceAll("CARDNAME can block an additional creature.", "");
      nonAbilityText = nonAbilityText.replaceAll("\r\n\r\n\r\n", "");
    }
    if (!nonAbilityText.isEmpty()) {
      sb.append("\r\n \r\nNon ability features: \r\n");
      sb.append(nonAbilityText.replaceAll("CARDNAME", getName()));
    }

    sb.append(getRemembered());

    PlayerView chosenPlayer = getChosenPlayer();
    if (chosenPlayer != null) {
      sb.append("\r\n[Chosen player: ");
      sb.append(chosenPlayer);
      sb.append("]\r\n");
    }

    Direction chosenDirection = getChosenDirection();
    if (chosenDirection != null) {
      sb.append("\r\n[Chosen direction: ");
      sb.append(chosenDirection);
      sb.append("]\r\n");
    }

    Iterable<CardView> hauntedBy = getHauntedBy();
    if (hauntedBy != null) {
      sb.append("Haunted by: ");
      boolean needDelim = false;
      for (final CardView c : hauntedBy) {
        if (needDelim) {
          sb.append(",");
        } else {
          needDelim = false;
        }
        sb.append(c);
      }
      sb.append("\r\n");
    }

    CardView haunting = getHaunting();
    if (haunting != null) {
      sb.append("Haunting: ").append(haunting);
      sb.append("\r\n");
    }

    CardView pairedWith = getPairedWith();
    if (pairedWith != null) {
      sb.append("\r\n \r\nPaired With: ").append(pairedWith);
      sb.append("\r\n");
    }

    String cloner = get(TrackableProperty.Cloner);
    if (!cloner.isEmpty()) {
      sb.append("\r\nCloned by: ").append(cloner);
    }

    return sb.toString().trim();
  }