Exemple #1
0
 public static boolean isPowerOrThoughnessGreater(
     Permanent sourceCreature, Permanent newCreature) {
   if (newCreature.getPower().getValue() > sourceCreature.getPower().getValue()) {
     return true;
   }
   return newCreature.getToughness().getValue() > sourceCreature.getToughness().getValue();
 }
Exemple #2
0
 @Override
 public boolean apply(Game game, Ability source) {
   Permanent creature1 = game.getPermanent(source.getSourceId());
   Permanent creature2 = game.getPermanent(source.getFirstTarget());
   // 20110930 - 701.10
   if (creature1 != null && creature2 != null) {
     if (creature1.getCardType().contains(CardType.CREATURE)
         && creature2.getCardType().contains(CardType.CREATURE)) {
       creature1.damage(creature2.getPower().getValue(), creature2.getId(), game, true, false);
       creature2.damage(creature1.getPower().getValue(), creature1.getId(), game, true, false);
       return true;
     }
   }
   return false;
 }
 @Override
 public int calculate(Game game, Ability sourceAbility, Effect effect) {
   int value = 0;
   for (Permanent creature :
       game.getBattlefield()
           .getActivePermanents(
               new FilterControlledCreaturePermanent(), sourceAbility.getControllerId(), game)) {
     if (creature != null
         && creature.getPower().getValue() > value
         && !sourceAbility.getSourceId().equals(creature.getId())) {
       value = creature.getPower().getValue();
     }
   }
   return value;
 }
Exemple #4
0
  @Override
  public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null) {
      if (permanent.getImprinted().size() > 0) {
        Card card = game.getCard(permanent.getImprinted().get(0));
        if (card != null && card.getCardType().contains(CardType.CREATURE)) {
          switch (layer) {
            case TypeChangingEffects_4:
              if (sublayer == SubLayer.NA) {
                permanent.getSubtype().addAll(card.getSubtype());
              }

              break;
            case PTChangingEffects_7:
              if (sublayer == SubLayer.SetPT_7b) {
                permanent.getPower().setValue(card.getPower().getValue());
                permanent.getToughness().setValue(card.getToughness().getValue());
              }
          }
          return true;
        }
      }
    }
    return false;
  }
Exemple #5
0
 /**
  * There are effects that let creatures assigns combat damage equal to its toughness rather than
  * its power. So this method takes this into account to get the value of damage a creature will
  * assign
  *
  * @param permanent
  * @param game
  * @return
  */
 private int getDamageValueFromPermanent(Permanent permanent, Game game) {
   if (game.getCombat().useToughnessForDamage()) {
     return permanent.getToughness().getValue();
   } else {
     return permanent.getPower().getValue();
   }
 }
Exemple #6
0
  @Test
  public void testEnteringWithCounters() {
    addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 5);
    addCard(Constants.Zone.GRAVEYARD, playerA, "Dearly Departed");
    addCard(Constants.Zone.BATTLEFIELD, playerA, "Thraben Doomsayer");

    activateAbility(
        2,
        Constants.PhaseStep.PRECOMBAT_MAIN,
        playerA,
        "{T}: Put a 1/1 white Human creature token onto the battlefield.");

    setStopAt(2, Constants.PhaseStep.BEGIN_COMBAT);
    execute();

    assertLife(playerA, 20);
    assertLife(playerB, 20);

    assertPermanentCount(playerA, "Human", 1);

    // check that the +1/+1 counter was added to the token
    Permanent humanToken = getPermanent("Human", playerA.getId());
    Assert.assertEquals(2, humanToken.getPower().getValue());
    Assert.assertEquals(2, humanToken.getToughness().getValue());
  }
  @Override
  public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    switch (layer) {
      case TypeChangingEffects_4:
        if (sublayer == SubLayer.NA) {
          affectedObjectList.clear();
          for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
            if (permanent != null) {
              affectedObjectList.add(new MageObjectReference(permanent, game));
              permanent.getCardType().add(CardType.CREATURE);
            }
          }
        }
        break;

      case PTChangingEffects_7:
        if (sublayer == SubLayer.SetPT_7b) {
          for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) {
            Permanent permanent = it.next().getPermanent(game);
            if (permanent != null) {
              int manaCost = permanent.getConvertedManaCost();
              permanent.getPower().setValue(manaCost);
              permanent.getToughness().setValue(manaCost);
            }
          }
        }
    }
    return true;
  }
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller == null) {
     return false;
   }
   int totalPowerSacrificed = 0;
   List<UUID> perms = new ArrayList<>();
   for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
     Player player = game.getPlayer(playerId);
     if (player != null) {
       TargetControlledCreaturePermanent target =
           new TargetControlledCreaturePermanent(
               1, 1, new FilterControlledCreaturePermanent(), true);
       if (target.canChoose(player.getId(), game)) {
         while (!target.isChosen() && player.canRespond()) {
           player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
         }
         perms.addAll(target.getTargets());
       }
     }
   }
   for (UUID permID : perms) {
     Permanent permanent = game.getPermanent(permID);
     if (permanent != null) {
       int power = permanent.getPower().getValue();
       if (permanent.sacrifice(source.getSourceId(), game)) {
         totalPowerSacrificed += power;
       }
     }
   }
   new CreateTokenEffect(new ReignOfThePitToken(totalPowerSacrificed)).apply(game, source);
   return true;
 }
Exemple #9
0
  public static void transform(Permanent permanent, Card sourceCard, Game game) {

    if (sourceCard == null) {
      return;
    }

    permanent.setName(sourceCard.getName());
    permanent.getColor().setColor(sourceCard.getColor());
    permanent.getManaCost().clear();
    permanent.getManaCost().add(sourceCard.getManaCost());
    permanent.getCardType().clear();
    for (CardType type : sourceCard.getCardType()) {
      permanent.getCardType().add(type);
    }
    permanent.getSubtype().clear();
    for (String type : sourceCard.getSubtype()) {
      permanent.getSubtype().add(type);
    }
    permanent.getSupertype().clear();
    for (String type : sourceCard.getSupertype()) {
      permanent.getSupertype().add(type);
    }
    permanent.setExpansionSetCode(sourceCard.getExpansionSetCode());
    permanent.getAbilities().clear();
    for (Ability ability : sourceCard.getAbilities()) {
      permanent.addAbility(ability, game);
    }
    permanent.getPower().setValue(sourceCard.getPower().getValue());
    permanent.getToughness().setValue(sourceCard.getToughness().getValue());
  }
  @Override
  public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (sourcePermanent == null) {
      sourcePermanent =
          (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    }
    if (sourcePermanent == null) {
      return false;
    }

    int damage = sourcePermanent.getPower().getValue();

    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent != null) {
      permanent.damage(damage, sourcePermanent.getId(), game, false, true);
      return true;
    }
    Player player = game.getPlayer(source.getFirstTarget());
    if (player != null) {
      player.damage(damage, sourcePermanent.getId(), game, false, true);
      return true;
    }
    return false;
  }
Exemple #11
0
 @Override
 public boolean apply(Game game, Ability source) {
   MageObject mageObject = source.getSourceObject(game);
   Permanent permanent = game.getPermanent(source.getSourceId());
   if (permanent != null
       && mageObject == null
       && new MageObjectReference(permanent, game).refersTo(mageObject, game)) {
     discard();
     return false;
   }
   UUID exileId =
       CardUtil.getExileZoneId(
           game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
   if (exileId != null) {
     ExileZone exileZone = game.getExile().getExileZone(exileId);
     if (exileZone == null) {
       return false;
     }
     Card exiledCard = null;
     for (Card card : exileZone.getCards(game)) {
       exiledCard = card;
       break;
     }
     if (exiledCard != null) {
       int value = exiledCard.getManaCost().convertedManaCost();
       permanent.getPower().setValue(value);
       permanent.getToughness().setValue(value);
     }
   }
   return true;
 }
Exemple #12
0
 @Override
 public boolean apply(Game game, Ability source) {
   Permanent token = game.getPermanent(source.getSourceId());
   if (token != null) {
     Player controller = game.getPlayer(source.getControllerId());
     if (controller != null) {
       token.getPower().setValue(controller.getLife());
       token.getToughness().setValue(controller.getLife());
       return true;
     }
   }
   return false;
 }
Exemple #13
0
  @Override
  public boolean apply(Game game, Ability source) {
    Card card = game.getCard(source.getFirstTarget());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (card == null || permanent == null) {
      return false;
    }
    card.moveToExile(null, "Dimir Doppelganger", source.getSourceId(), game);
    Card cardToCopy = card.copy();
    cardToCopy.assignNewId();
    permanent.setName(cardToCopy.getName());
    permanent.getPower().setValue(cardToCopy.getPower().getValue());
    permanent.getToughness().setValue(cardToCopy.getToughness().getValue());
    permanent.getColor(game).setColor(cardToCopy.getColor(game));
    permanent.getManaCost().clear();
    permanent.getManaCost().add(cardToCopy.getManaCost());
    permanent.getCardType().clear();
    for (CardType type : cardToCopy.getCardType()) {
      if (!permanent.getCardType().contains(type)) {
        permanent.getCardType().add(type);
      }
    }
    permanent.getSubtype(game).clear();
    for (String type : cardToCopy.getSubtype(game)) {
      if (!permanent.getSubtype(game).contains(type)) {
        permanent.getSubtype(game).add(type);
      }
    }
    permanent.getSupertype().clear();
    for (String type : cardToCopy.getSupertype()) {
      if (!permanent.getSupertype().contains(type)) {
        permanent.getSupertype().add(type);
      }
    }
    permanent.removeAllAbilities(source.getSourceId(), game);
    // gains ability of Dimir Doppelganger
    Ability dimirDoppelgangerAbility =
        new SimpleActivatedAbility(
            Zone.BATTLEFIELD, new DimirDoppelgangerEffect(), new ManaCostsImpl("{1}{U}{B}"));
    dimirDoppelgangerAbility.addTarget(
        new TargetCardInGraveyard(new FilterCreatureCard("creature card in a graveyard")));
    permanent.addAbility(dimirDoppelgangerAbility, source.getSourceId(), game);

    for (Ability ability : cardToCopy.getAbilities()) {
      if (!permanent.getAbilities().contains(ability)) {
        permanent.addAbility(ability, source.getSourceId(), game);
      }
    }
    return true;
  }
Exemple #14
0
 @Override
 public boolean apply(Game game, Ability source) {
   Permanent permanent =
       game.getPermanentOrLKIBattlefield(this.getTargetPointer().getFirst(game, source));
   if (permanent != null) {
     Player controller = game.getPlayer(permanent.getControllerId());
     if (controller != null) {
       int amount = permanent.getPower().getValue();
       controller.damage(amount, source.getSourceId(), game, false, true);
       return true;
     }
   }
   return false;
 }
  @Override
  public boolean apply(Game game, Ability source) {
    Set<UUID> controllers = new HashSet<>();
    Integer maxPower = null;

    List<Permanent> permanents =
        game.getBattlefield()
            .getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
    for (Permanent permanent : permanents) {
      if (permanent == null) {
        continue;
      }

      int power = permanent.getPower().getValue();
      if (maxPower == null || power > maxPower) {
        maxPower = permanent.getPower().getValue();
        controllers.clear();
      }
      if (power == maxPower) {
        controllers.add(permanent.getControllerId());
      }
    }
    return controllers.contains(source.getControllerId());
  }
Exemple #16
0
    @Override
    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
      Permanent permanent = ((EntersTheBattlefieldEvent) event).getTarget();
      if (permanent != null) {
        Choice choice = new ChoiceImpl(true);
        choice.setMessage("Choose what " + permanent.getIdName() + " becomes to");
        choice.getChoices().add(choice33);
        choice.getChoices().add(choice22);
        choice.getChoices().add(choice16);
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
          while (!choice.isChosen()) {
            controller.choose(Outcome.Neutral, choice, game);
            if (!controller.canRespond()) {
              return false;
            }
          }
        }
        int power = 0;
        int toughness = 0;
        switch (choice.getChoice()) {
          case choice33:
            power = 3;
            toughness = 3;
            break;
          case choice22:
            power = 2;
            toughness = 2;
            game.addEffect(
                new GainAbilitySourceEffect(FlyingAbility.getInstance(), Duration.Custom), source);
            break;
          case choice16:
            power = 1;
            toughness = 6;
            game.addEffect(
                new GainAbilitySourceEffect(DefenderAbility.getInstance(), Duration.Custom),
                source);
            break;
        }
        permanent.getPower().modifyBaseValue(power);
        permanent.getToughness().modifyBaseValue(toughness);
        // game.addEffect(new SetPowerToughnessSourceEffect(power, toughness, Duration.Custom,
        // SubLayer.SetPT_7b), source);

      }
      return false;
    }
Exemple #17
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     Permanent permanent = game.getPermanent(source.getSourceId());
     if (permanent != null
         && new MageObjectReference(source.getSourceObject(game), game)
             .refersTo(permanent, game)) {
       int amount = permanent.getCounters(game).getCount(CounterType.LORE);
       permanent.getPower().setValue(amount);
       permanent.getToughness().setValue(amount);
       return true;
     } else {
       discard();
     }
   }
   return false;
 }
Exemple #18
0
 @Override
 public int calculate(Game game, Ability sourceAbility, Effect effect) {
   Card sourceCard = game.getCard(sourceAbility.getSourceId());
   if (sourceCard != null) {
     for (Object cost : sourceAbility.getCosts()) {
       if (cost instanceof SacrificeTargetCost) {
         Permanent p =
             (Permanent)
                 game.getLastKnownInformation(
                     ((SacrificeTargetCost) cost).getPermanents().get(0).getId(),
                     Zone.BATTLEFIELD);
         if (p != null) {
           return -1 * p.getPower().getValue();
         }
       }
     }
   }
   return 0;
 }
Exemple #19
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD
       && ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
     Permanent permanent =
         (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
     if (permanent != null
         && permanent.getControllerId().equals(this.getControllerId())
         && permanent.getCardType().contains(CardType.CREATURE)) {
       this.getTargets().clear();
       this.addTarget(new TargetControlledCreaturePermanent());
       this.getEffects().clear();
       this.addEffect(
           new AddCountersTargetEffect(
               CounterType.P1P1.createInstance(permanent.getPower().getValue())));
       return true;
     }
   }
   return false;
 }
 @Override
 public boolean apply(Game game, Ability source) {
   for (UUID permanentId : targetPointer.getTargets(game, source)) {
     Permanent permanent = game.getPermanent(permanentId);
     if (permanent != null) {
       Card card = game.getCard(permanent.getId());
       int zoneChangeCounter = card.getZoneChangeCounter();
       if (permanent.destroy(source.getSourceId(), game, false)) {
         if (card != null
             && game.getPlayer(permanent.getOwnerId()).getGraveyard().contains(card.getId())
             && card.getZoneChangeCounter() == zoneChangeCounter) {
           return new CreateTokenEffect(
                   new VampireToken(
                       permanent.getPower().getValue(), permanent.getToughness().getValue()))
               .apply(game, source);
         }
       }
     }
   }
   return false;
 }
Exemple #21
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   if (player != null) {
     List<Permanent> creatures =
         game.getBattlefield()
             .getAllActivePermanents(new FilterCreaturePermanent(), player.getId(), game);
     int amount = 0;
     for (Permanent creature : creatures) {
       int power = creature.getPower().getValue();
       if (amount < power) {
         amount = power;
       }
     }
     OozeToken oozeToken = new OozeToken();
     oozeToken.getPower().initValue(amount);
     oozeToken.getToughness().initValue(amount);
     oozeToken.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId());
     return true;
   }
   return false;
 }
Exemple #22
0
 @Override
 public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
   Permanent permanent = game.getPermanent(source.getSourceId());
   if (permanent != null) {
     switch (layer) {
       case TypeChangingEffects_4:
         if (sublayer == SubLayer.NA) {
           permanent.getCardType().add(CardType.CREATURE);
           permanent.getSubtype().add("Construct");
         }
         break;
       case PTChangingEffects_7:
         if (sublayer == SubLayer.SetPT_7b) {
           int xValue = source.getManaCostsToPay().getX();
           if (xValue != 0) {
             permanent.getPower().setValue(xValue);
             permanent.getToughness().setValue(xValue);
           }
         }
     }
     return true;
   }
   return false;
 }
Exemple #23
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   Permanent permanent = game.getPermanent(getSourceId());
   return permanent != null && permanent.getPower().getValue() >= 7;
 }
Exemple #24
0
 @Override
 public boolean canBeBlocked(Permanent attacker, Permanent blocker, Ability source, Game game) {
   return blocker.getPower().getValue() <= attacker.getPower().getValue();
 }