コード例 #1
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (player != null && permanent != null) {
      String colors;
      ChoiceColor colorChoice = new ChoiceColor();
      colorChoice.setMessage("Choose the first color");
      while (!player.choose(Outcome.GainLife, colorChoice, game)) {
        if (!player.canRespond()) {
          return false;
        }
      }
      game.getState().setValue(permanent.getId() + "_color1", colorChoice.getColor().toString());
      colors = colorChoice.getChoice().toLowerCase() + " and ";

      colorChoice.getChoices().remove(colorChoice.getChoice());
      colorChoice.setMessage("Choose the second color");
      while (!player.choose(Outcome.GainLife, colorChoice, game) && player.canRespond()) {
        game.debugMessage("player canceled choosing type. retrying.");
      }
      game.getState().setValue(permanent.getId() + "_color2", colorChoice.getColor().toString());
      colors = colors + colorChoice.getChoice().toLowerCase();
      game.informPlayers(
          permanent.getName() + ": " + player.getLogName() + " has chosen " + colors);
    }
    return false;
  }
コード例 #2
0
  @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;
  }
コード例 #3
0
 private void defenderDamage(Permanent attacker, int amount, Game game) {
   if (this.defenderIsPlaneswalker) {
     Permanent defender = game.getPermanent(defenderId);
     if (defender != null) {
       defender.markDamage(amount, attacker.getId(), game, true, true);
     }
   } else {
     Player defender = game.getPlayer(defenderId);
     defender.damage(amount, attacker.getId(), game, true, true);
   }
 }
コード例 #4
0
 @Override
 public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
   Set<UUID> possibleTargets = new HashSet<UUID>();
   for (Permanent permanent :
       game.getBattlefield().getActivePermanents(filter, sourceControllerId, game)) {
     if (!targets.containsKey(permanent.getId())) {
       possibleTargets.add(permanent.getId());
     }
   }
   return possibleTargets;
 }
コード例 #5
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   if (super.applies(event, source, game) && event instanceof DamageEvent) {
     Permanent targetPermanent = game.getPermanent(this.getTargetPointer().getFirst(game, source));
     if (targetPermanent != null
         && (event.getSourceId().equals(targetPermanent.getId())
             || event.getTargetId().equals(targetPermanent.getId()))) {
       return true;
     }
   }
   return false;
 }
コード例 #6
0
 @Override
 public boolean apply(Game game, Ability source) {
   for (Permanent perm :
       game.getBattlefield()
           .getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
     if (!this.affectedObjectsSet || objects.contains(perm.getId())) {
       if (!(excludeSource && perm.getId().equals(source.getSourceId()))) {
         perm.addAbility(ability, source.getSourceId(), game);
       }
     }
   }
   return true;
 }
コード例 #7
0
 @Override
 public void init(Ability source, Game game) {
   super.init(source, game);
   if (this.affectedObjectsSet) {
     for (Permanent perm :
         game.getBattlefield()
             .getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
       if (!(excludeSource && perm.getId().equals(source.getSourceId()))) {
         objects.add(perm.getId());
       }
     }
   }
 }
コード例 #8
0
 @Override
 public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
   Set<UUID> possibleTargets = new HashSet<UUID>();
   MageObject targetSource = game.getObject(sourceId);
   for (Permanent permanent :
       game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
     if (!targets.containsKey(permanent.getId())
         && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
       possibleTargets.add(permanent.getId());
     }
   }
   return possibleTargets;
 }
コード例 #9
0
ファイル: NightfallPredator.java プロジェクト: xdaft/mage
 @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;
 }
コード例 #10
0
 @Override
 public boolean apply(Game game, Ability source) {
   Permanent permanent = game.getPermanent(source.getSourceId());
   Permanent targetCreature =
       game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
   if (targetCreature != null && permanent != null) {
     Permanent blueprintPermanent =
         game.copyPermanent(
             Duration.Custom,
             targetCreature,
             permanent.getId(),
             source,
             new EmptyApplyToPermanent());
     blueprintPermanent.addAbility(
         new EntersBattlefieldAllTriggeredAbility(
             Zone.BATTLEFIELD,
             new UnstableShapeshifterEffect(),
             filterAnotherCreature,
             false,
             SetTargetPointer.PERMANENT,
             ""),
         game);
     return true;
   }
   return false;
 }
コード例 #11
0
ファイル: TritonTactics.java プロジェクト: poixen/mage
 @Override
 public boolean apply(Game game, Ability source) {
   Set<String> targets = new HashSet<>();
   for (UUID target : targetPointer.getTargets(game, source)) {
     Permanent permanent = game.getPermanent(target);
     if (permanent != null) {
       permanent.untap(game);
       targets.add(CardUtil.getCardZoneString("", permanent.getId(), game));
     }
   }
   if (!targets.isEmpty()) {
     // save the targets for the watcher in a map with zone change counter (as the card is recast
     // during combat it's neccessary to save with zone change counter)
     Map<Integer, Set<String>> targetMap;
     Object object = game.getState().getValue("targets" + source.getSourceId());
     if (object != null && object instanceof Map) {
       targetMap = (Map<Integer, Set<String>>) object;
     } else {
       targetMap = new HashMap<>();
     }
     targetMap.put(game.getCard(source.getSourceId()).getZoneChangeCounter(game), targets);
     if (object == null) {
       game.getState().setValue("targets" + source.getSourceId().toString(), targetMap);
     }
   }
   return true;
 }
コード例 #12
0
ファイル: StromkirkNoble.java プロジェクト: xdaft/mage
 @Override
 public boolean applies(Permanent permanent, Ability source, Game game) {
   if (permanent.getId().equals(source.getSourceId())) {
     return true;
   }
   return false;
 }
コード例 #13
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);
      }
    }
  }
コード例 #14
0
ファイル: GameState.java プロジェクト: sucramnosslin/mage
 public Permanent getPermanent(UUID permanentId) {
   if (permanentId != null && battlefield.containsPermanent(permanentId)) {
     Permanent permanent = battlefield.getPermanent(permanentId);
     setZone(permanent.getId(), Zone.BATTLEFIELD); // shouldn't this be set anyway? (LevelX2)
     return permanent;
   }
   return null;
 }
コード例 #15
0
ファイル: RockBasilisk.java プロジェクト: TumbleMagnet/mage
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   Permanent blocker = game.getPermanent(event.getSourceId());
   Permanent blocked = game.getPermanent(event.getTargetId());
   Permanent rockBasilisk = game.getPermanent(sourceId);
   if (blocker != null
       && blocker != rockBasilisk
       && !blocker.getSubtype().contains("Wall")
       && blocked == rockBasilisk) {
     this.getEffects().get(0).setTargetPointer(new FixedTarget(blocker.getId()));
     return true;
   }
   if (blocker != null && blocker == rockBasilisk && !blocked.getSubtype().contains("Wall")) {
     this.getEffects().get(0).setTargetPointer(new FixedTarget(blocked.getId()));
     return true;
   }
   return false;
 }
コード例 #16
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);
       }
     }
   }
 }
コード例 #17
0
ファイル: GlacialCrasher.java プロジェクト: jjmarcel/mage-1
 @Override
 public boolean applies(Permanent permanent, Ability source, Game game) {
   if (permanent.getId().equals(source.getSourceId())) {
     if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game)
         < 1) {
       return true;
     }
   }
   return false;
 }
コード例 #18
0
ファイル: Disarm.java プロジェクト: royk/mage
    @java.lang.Override
    public boolean apply(Game game, Ability source) {
      Permanent creature = game.getPermanent(targetPointer.getFirst(game, source));
      if (creature != null) {
        FilterPermanent creatureFilter = new FilterPermanent();
        creatureFilter.add(new PermanentIdPredicate(creature.getId()));

        FilterPermanent equipmentFilter = new FilterPermanent();
        equipmentFilter.add(new AttachedToPredicate(creatureFilter));
        equipmentFilter.add(new SubtypePredicate("Equipment"));

        for (Permanent equipment :
            game.getBattlefield().getAllActivePermanents(equipmentFilter, game)) {
          creature.removeAttachment(equipment.getId(), game);
        }
        return true;
      }
      return false;
    }
コード例 #19
0
 /**
  * Damages attacking creatures by a creature that blocked several ones Damages only attackers as
  * blocker was damage in {@link #singleBlockerDamage}.
  *
  * <p>Handles abilities like "{this} an block any number of creatures.".
  *
  * @param first
  * @param game
  */
 private void singleAttackerDamage(boolean first, Game game) {
   Permanent blocker = game.getPermanent(blockers.get(0));
   Permanent attacker = game.getPermanent(attackers.get(0));
   if (blocker != null && attacker != null) {
     if (canDamage(blocker, first)) {
       int damage = getDamageValueFromPermanent(blocker, game);
       attacker.markDamage(damage, blocker.getId(), game, true, true);
     }
   }
 }
コード例 #20
0
ファイル: Invisibility.java プロジェクト: jjmarcel/mage-1
 @Override
 public boolean applies(Permanent permanent, Ability source, Game game) {
   Permanent enchantment = game.getPermanent(source.getSourceId());
   if (enchantment != null && enchantment.getAttachedTo() != null) {
     if (permanent.getId().equals(enchantment.getAttachedTo())) {
       return true;
     }
   }
   return false;
 }
コード例 #21
0
 @Override
 public boolean apply(Permanent input, Game game) {
   for (CombatGroup combatGroup : game.getCombat().getGroups()) {
     if (combatGroup.getBlockers().contains(input.getId())
         && combatGroup.getAttackers().contains(attackerId)) {
       return true;
     }
   }
   return false;
 }
コード例 #22
0
ファイル: MyrGalvanizer.java プロジェクト: gitter-badger/mage
 @Override
 public boolean apply(Game game, Ability source) {
   for (Permanent permanent :
       game.getBattlefield()
           .getActivePermanents(MyrGalvanizer.filter, source.getControllerId(), game)) {
     if (!permanent.getId().equals(source.getSourceId())) {
       permanent.untap(game);
     }
   }
   return true;
 }
コード例 #23
0
ファイル: Spiritualize.java プロジェクト: nigelzor/mage
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   Permanent target = game.getPermanent(this.getFirstTarget());
   if (target != null && event.getSourceId().equals(target.getId())) {
     for (Effect effect : this.getEffects()) {
       effect.setValue("damage", event.getAmount());
     }
     return true;
   }
   return false;
 }
コード例 #24
0
ファイル: Sunforger.java プロジェクト: jjmarcel/mage-1
 @Override
 public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) {
   Permanent attachment = game.getPermanent(sourceId);
   Permanent permanent = game.getPermanent(attachment.getAttachedTo());
   if (permanent != null) {
     paid = permanent.removeAttachment(attachment.getId(), game);
     if (paid) {
       game.fireEvent(
           GameEvent.getEvent(GameEvent.EventType.UNATTACHED, sourceId, sourceId, controllerId));
     }
   }
   return paid;
 }
コード例 #25
0
 @Override
 public boolean applies(Permanent permanent, Ability source, Game game) {
   Permanent rustTick = game.getPermanent(source.getSourceId());
   if (rustTick != null && rustTick.isTapped()) {
     if (rustTick.getConnectedCards("DesertersQuarters").size() > 0) {
       UUID target = rustTick.getConnectedCards("DesertersQuarters").get(0);
       if (target != null && target.equals(permanent.getId())) {
         return true;
       }
     }
   }
   return false;
 }
コード例 #26
0
ファイル: InfiltrationLens.java プロジェクト: xdaft/mage
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getType() == GameEvent.EventType.CREATURE_BLOCKED) {
     Permanent equipment = game.getPermanent(sourceId);
     if (equipment != null && equipment.getAttachedTo() != null) {
       Permanent equipped = game.getPermanent(equipment.getAttachedTo());
       if (equipped.getId().equals(event.getTargetId())) {
         return true;
       }
     }
   }
   return false;
 }
コード例 #27
0
ファイル: MassMutiny.java プロジェクト: TumbleMagnet/mage
  @Override
  public boolean apply(Game game, Ability source) {
    boolean result = false;
    for (Target target : source.getTargets()) {
      if (target instanceof TargetCreaturePermanent) {
        Permanent targetCreature = game.getPermanent(target.getFirstTarget());
        if (targetCreature != null) {
          ContinuousEffect effect1 = new GainControlTargetEffect(Duration.EndOfTurn);
          effect1.setTargetPointer(new FixedTarget(targetCreature.getId()));
          game.addEffect(effect1, source);

          ContinuousEffect effect2 =
              new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
          effect2.setTargetPointer(new FixedTarget(targetCreature.getId()));
          game.addEffect(effect2, source);

          targetCreature.untap(game);
          result = true;
        }
      }
    }
    return result;
  }
コード例 #28
0
ファイル: JoragaInvocation.java プロジェクト: poixen/mage
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     for (Permanent permanent :
         game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), game)) {
       ContinuousEffect effect = new MustBeBlockedByAtLeastOneTargetEffect();
       effect.setTargetPointer(new FixedTarget(permanent.getId()));
       game.addEffect(effect, source);
     }
     return true;
   }
   return false;
 }
コード例 #29
0
 @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;
 }
コード例 #30
0
ファイル: RockBasilisk.java プロジェクト: TumbleMagnet/mage
 @Override
 public boolean apply(Game game, Ability source) {
   Permanent targetCreature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
   if (targetCreature != null) {
     AtTheEndOfCombatDelayedTriggeredAbility delayedAbility =
         new AtTheEndOfCombatDelayedTriggeredAbility(new DestroyTargetEffect());
     delayedAbility.setSourceId(source.getSourceId());
     delayedAbility.setControllerId(source.getControllerId());
     delayedAbility.setSourceObject(source.getSourceObject(game), game);
     delayedAbility.getEffects().get(0).setTargetPointer(new FixedTarget(targetCreature.getId()));
     game.addDelayedTriggeredAbility(delayedAbility);
     return true;
   }
   return false;
 }