Exemple #1
0
  /**
   * Damages attacking creatures by a creature that blocked several ones Damages only attackers as
   * blocker was damage in either {@link #singleBlockerDamage} or {@link #multiBlockerDamage}.
   *
   * <p>Handles abilities like "{this} an block any number of creatures.".
   *
   * @param first
   * @param game
   */
  private void multiAttackerDamage(boolean first, Game game) {
    Permanent blocker = game.getPermanent(blockers.get(0));
    if (blocker == null) {
      return;
    }
    Player player = game.getPlayer(blocker.getControllerId());
    int damage = getDamageValueFromPermanent(blocker, game);

    if (canDamage(blocker, first)) {
      Map<UUID, Integer> assigned = new HashMap<>();
      for (UUID attackerId : attackerOrder) {
        Permanent attacker = game.getPermanent(attackerId);
        int lethalDamage;
        if (blocker.getAbilities().containsKey(DeathtouchAbility.getInstance().getId())) {
          lethalDamage = 1;
        } else {
          lethalDamage = attacker.getToughness().getValue() - attacker.getDamage();
        }
        if (lethalDamage >= damage) {
          assigned.put(attackerId, damage);
          break;
        }
        int damageAssigned =
            player.getAmount(
                lethalDamage, damage, "Assign damage to " + attacker.getLogName(), game);
        assigned.put(attackerId, damageAssigned);
        damage -= damageAssigned;
      }

      for (Map.Entry<UUID, Integer> entry : assigned.entrySet()) {
        Permanent attacker = game.getPermanent(entry.getKey());
        attacker.markDamage(entry.getValue(), blocker.getId(), game, true, true);
      }
    }
  }
Exemple #2
0
 private void singleBlockerDamage(boolean first, Game game) {
   // TODO:  handle banding
   Permanent blocker = game.getPermanent(blockers.get(0));
   Permanent attacker = game.getPermanent(attackers.get(0));
   if (blocker != null && attacker != null) {
     int blockerDamage =
         getDamageValueFromPermanent(
             blocker,
             game); // must be set before attacker damage marking because of effects like Test of
                    // Faith
     if (blocked && canDamage(attacker, first)) {
       int damage = getDamageValueFromPermanent(attacker, game);
       if (hasTrample(attacker)) {
         int lethalDamage;
         if (attacker.getAbilities().containsKey(DeathtouchAbility.getInstance().getId())) {
           lethalDamage = 1;
         } else {
           lethalDamage = blocker.getToughness().getValue() - blocker.getDamage();
         }
         if (lethalDamage >= damage) {
           blocker.markDamage(damage, attacker.getId(), game, true, true);
         } else {
           Player player = game.getPlayer(attacker.getControllerId());
           int damageAssigned =
               player.getAmount(
                   lethalDamage, damage, "Assign damage to " + blocker.getLogName(), game);
           blocker.markDamage(damageAssigned, attacker.getId(), game, true, true);
           damage -= damageAssigned;
           if (damage > 0) {
             defenderDamage(attacker, damage, game);
           }
         }
       } else {
         blocker.markDamage(damage, attacker.getId(), game, true, true);
       }
     }
     if (canDamage(blocker, first)) {
       if (blocker.getBlocking()
           == 1) { // blocking several creatures handled separately
         attacker.markDamage(blockerDamage, blocker.getId(), game, true, true);
       }
     }
   }
 }
Exemple #3
0
 private void multiBlockerDamage(boolean first, Game game) {
   // TODO:  handle banding
   Permanent attacker = game.getPermanent(attackers.get(0));
   if (attacker == null) {
     return;
   }
   Player player = game.getPlayer(attacker.getControllerId());
   int damage = getDamageValueFromPermanent(attacker, game);
   if (canDamage(attacker, first)) {
     // must be set before attacker damage marking because of effects like Test of Faith
     Map<UUID, Integer> blockerPower = new HashMap<>();
     for (UUID blockerId : blockerOrder) {
       Permanent blocker = game.getPermanent(blockerId);
       if (canDamage(blocker, first)) {
         if (blocker.getBlocking() == 1) { // blocking several creatures handled separately
           blockerPower.put(blockerId, getDamageValueFromPermanent(blocker, game));
         }
       }
     }
     Map<UUID, Integer> assigned = new HashMap<>();
     if (blocked) {
       for (UUID blockerId : blockerOrder) {
         Permanent blocker = game.getPermanent(blockerId);
         int lethalDamage;
         if (attacker.getAbilities().containsKey(DeathtouchAbility.getInstance().getId())) {
           lethalDamage = 1;
         } else {
           lethalDamage = blocker.getToughness().getValue() - blocker.getDamage();
         }
         if (lethalDamage >= damage) {
           assigned.put(blockerId, damage);
           damage = 0;
           break;
         }
         int damageAssigned =
             player.getAmount(
                 lethalDamage, damage, "Assign damage to " + blocker.getLogName(), game);
         assigned.put(blockerId, damageAssigned);
         damage -= damageAssigned;
       }
       if (damage > 0 && hasTrample(attacker)) {
         defenderDamage(attacker, damage, game);
       }
     }
     for (UUID blockerId : blockerOrder) {
       Integer power = blockerPower.get(blockerId);
       if (power != null) {
         attacker.markDamage(power.intValue(), blockerId, game, true, true);
       }
     }
     for (Map.Entry<UUID, Integer> entry : assigned.entrySet()) {
       Permanent blocker = game.getPermanent(entry.getKey());
       blocker.markDamage(entry.getValue(), attacker.getId(), game, true, true);
     }
   } else {
     for (UUID blockerId : blockerOrder) {
       Permanent blocker = game.getPermanent(blockerId);
       if (canDamage(blocker, first)) {
         attacker.markDamage(
             getDamageValueFromPermanent(blocker, game), blocker.getId(), game, true, true);
       }
     }
   }
 }
  public PermanentView(Permanent permanent, Card card, UUID createdForPlayerId, Game game) {
    super(permanent, game, permanent.getControllerId().equals(createdForPlayerId));
    this.controlled = permanent.getControllerId().equals(createdForPlayerId);
    this.rules = permanent.getRules(game);
    this.tapped = permanent.isTapped();
    this.flipped = permanent.isFlipped();
    this.phasedIn = permanent.isPhasedIn();
    this.summoningSickness = permanent.hasSummoningSickness();
    this.morphed = permanent.isMorphed();
    this.manifested = permanent.isManifested();
    this.damage = permanent.getDamage();
    if (permanent.getAttachments().size() > 0) {
      attachments = new ArrayList<>();
      attachments.addAll(permanent.getAttachments());
    }
    this.attachedTo = permanent.getAttachedTo();
    if (isToken()) {
      original = new CardView(((PermanentToken) permanent).getToken());
      original.expansionSetCode = permanent.getExpansionSetCode();
      tokenSetCode = original.getTokenSetCode();
    } else {
      if (card != null) {
        // original may not be face down
        original = new CardView(card);
      } else {
        original = null;
      }
    }
    this.transformed = permanent.isTransformed();
    this.copy = permanent.isCopy();

    // for fipped, transformed or copied cards, switch the names
    if (original != null && !original.getName().equals(this.getName())) {
      if (permanent.isCopy() && permanent.isFlipCard()) {
        this.alternateName = permanent.getFlipCardName();
        this.originalName = this.getName();
      } else {
        if (controlled // controller may always know
            || (!morphed && !manifested)) { // others don't know for morph or transformed cards
          this.alternateName = original.getName();
          this.originalName = this.getName();
        }
      }
    }
    if (!permanent.getOwnerId().equals(permanent.getControllerId())) {
      Player owner = game.getPlayer(permanent.getOwnerId());
      if (owner != null) {
        this.nameOwner = owner.getName();
      } else {
        this.nameOwner = "";
      }
    } else {
      this.nameOwner = "";
    }

    if (permanent.isFaceDown(game) && card != null) {
      if (controlled) {
        // must be a morphed or manifested card
        for (Ability permanentAbility : permanent.getAbilities()) {
          if (permanentAbility instanceof TurnFaceUpAbility && !permanentAbility.getRuleVisible()) {
            this.rules.add(permanentAbility.getRule(true));
          }
          if (permanentAbility.getWorksFaceDown()) {
            this.rules.add(permanentAbility.getRule());
          }
        }
        this.name = card.getName();
        this.displayName = card.getName();
        this.expansionSetCode = card.getExpansionSetCode();
        this.cardNumber = card.getCardNumber();
      } else {
        if (permanent.isManifested()) {
          this.rules.add(
              "A manifested creature card can be turned face up any time for it's mana cost."
                  + " A face-down card can also be turned face up for its morph cost.");
        } else if (permanent.isMorphed()) {
          this.rules.add(
              "If the controller has priority, he or she may turn this permanent face up."
                  + " This is a special action; it doesn’t use the stack. To do this he or she pays the morph costs,"
                  + " then turns this permanent face up.");
        }
      }
    }
    // determines if shown in it's own column
    if (permanent.getAttachedTo() != null) {
      attachedToPermanent = game.getPermanent(permanent.getAttachedTo()) != null;
    } else {
      attachedToPermanent = false;
    }
  }