Esempio n. 1
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   return event.getPlayerId().equals(this.getControllerId())
       && game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD)
           .getCardType()
           .contains(CardType.CREATURE);
 }
Esempio n. 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;
  }
Esempio n. 3
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   Permanent permanent = (Permanent) game.getLastKnownInformation(target, Zone.BATTLEFIELD);
   if (permanent != null && controller != null) {
     Player player = game.getPlayer(permanent.getOwnerId());
     if (player != null) {
       FilterCreatureCard filter =
           new FilterCreatureCard(
               new StringBuilder("a creature card from ")
                   .append(player.getLogName())
                   .append("'s graveyard")
                   .toString());
       filter.add(new OwnerIdPredicate(player.getId()));
       Target targetCreature = new TargetCardInGraveyard(filter);
       if (targetCreature.canChoose(source.getSourceId(), controller.getId(), game)
           && controller.chooseTarget(outcome, targetCreature, source, game)) {
         Card card = game.getCard(targetCreature.getFirstTarget());
         if (card != null && game.getState().getZone(card.getId()).equals(Zone.GRAVEYARD)) {
           return card.putOntoBattlefield(
               game, Zone.GRAVEYARD, source.getSourceId(), player.getId());
         }
       }
       return true;
     }
   }
   return false;
 }
 @Override
 public boolean apply(Game game, Ability source) {
   Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
   if (spell == null) {
     spell =
         (Spell) game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.STACK);
   }
   if (spell != null) {
     Spell copy = spell.copySpell();
     copy.setControllerId(source.getControllerId());
     copy.setCopiedSpell(true);
     game.getStack().push(copy);
     copy.chooseNewTargets(game, source.getControllerId());
     Player player = game.getPlayer(source.getControllerId());
     String activateMessage = copy.getActivatedMessage(game);
     if (activateMessage.startsWith(" casts ")) {
       activateMessage = activateMessage.substring(6);
     }
     if (!game.isSimulation()) {
       game.informPlayers(player.getLogName() + activateMessage);
     }
     return true;
   }
   return false;
 }
Esempio n. 5
0
 @Override
 public boolean apply(Game game, Ability source) {
   Permanent sourcePermanent =
       (Permanent)
           game.getLastKnownInformation(
               targetPointer.getFirst(game, source), Constants.Zone.BATTLEFIELD);
   if (sourcePermanent == null) {
     return false;
   }
   Player controller = game.getPlayer(source.getControllerId());
   if (controller == null) {
     return false;
   }
   Cards revealed = new CardsImpl();
   Card artifactCard = null;
   Cards nonArtifactCards = new CardsImpl();
   Player player = game.getPlayer(sourcePermanent.getControllerId());
   while (artifactCard == null && player.getLibrary().size() > 0) {
     Card card = player.getLibrary().removeFromTop(game);
     revealed.add(card);
     if (card.getCardType().contains(CardType.ARTIFACT)) artifactCard = card;
     else nonArtifactCards.add(card);
   }
   player.revealCards("Shape Anew", revealed, game);
   if (artifactCard != null) {
     artifactCard.putOntoBattlefield(
         game, Constants.Zone.LIBRARY, source.getId(), player.getId());
   }
   player.getLibrary().addAll(nonArtifactCards.getCards(game), game);
   player.shuffleLibrary(game);
   return true;
 }
Esempio n. 6
0
 private MageObject getMageObject(GameEvent event, Game game, TriggeredAbility ability) {
   MageObject object = game.getPermanent(ability.getSourceId());
   if (object == null) {
     object = game.getLastKnownInformation(ability.getSourceId(), event.getZone());
     if (object == null) {
       object = game.getObject(ability.getSourceId());
     }
   }
   return object;
 }
Esempio n. 7
0
 @Override
 public boolean apply(Game game, Ability source) {
   Permanent permanent =
       (Permanent) game.getLastKnownInformation(source.getFirstTarget(), Zone.BATTLEFIELD);
   if (permanent != null && !permanent.getSupertype().contains("Basic")) {
     Player player = game.getPlayer(permanent.getControllerId());
     if (player != null) {
       player.damage(2, source.getSourceId(), game, false, true);
       return true;
     }
   }
   return false;
 }
Esempio n. 8
0
 @Override
 public void watch(GameEvent event, Game game) {
   if (condition == true) { // no need to check - condition has already occured
     return;
   }
   if (event.getType() == EventType.COUNTERED) {
     StackObject stackObject = game.getStack().getStackObject(event.getTargetId());
     if (stackObject == null) {
       stackObject = (StackObject) game.getLastKnownInformation(event.getTargetId(), Zone.STACK);
     }
     StackObject counterObject = game.getStack().getStackObject(event.getSourceId());
     if (counterObject == null) {
       counterObject = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
     }
     if (stackObject != null
         && counterObject != null
         && stackObject.getCardType().contains(CardType.CREATURE)
         && game.getOpponents(controllerId).contains(counterObject.getControllerId())) {
       condition = true;
     }
   }
 }
Esempio n. 9
0
 @Override
 public boolean apply(Game game, Ability source) {
   Permanent permanent =
       (Permanent) game.getLastKnownInformation(source.getFirstTarget(), Zone.BATTLEFIELD);
   if (permanent != null) {
     Player player = game.getPlayer(permanent.getControllerId());
     if (player != null) {
       player.gainLife(permanent.getToughness().getValue(), game);
       return true;
     }
   }
   return false;
 }
Esempio n. 10
0
 @Override
 public void watch(GameEvent event, Game game) {
   if (event.getType() == GameEvent.EventType.ZONE_CHANGE
       && ((ZoneChangeEvent) event).isDiesEvent()) {
     Permanent card =
         (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
     if (card != null
         && card.getOwnerId().equals(this.controllerId)
         && card.getCardType().contains(CardType.CREATURE)
         && !(card instanceof PermanentToken)) {
       creaturesCount++;
     }
   }
 }
Esempio n. 11
0
 private void updateLatestCardView(Game game, Card card, UUID stackId) {
   if (!card.canTransform()) {
     return;
   }
   Permanent permanent = game.getPermanent(card.getId());
   if (permanent == null) {
     permanent =
         (Permanent) game.getLastKnownInformation(card.getId(), Constants.Zone.BATTLEFIELD);
   }
   if (permanent != null) {
     if (permanent.isTransformed()) {
       StackAbilityView stackAbilityView = (StackAbilityView) stack.get(stackId);
       stackAbilityView.getSourceCard().setTransformed(true);
     }
   }
 }
Esempio n. 12
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;
 }
Esempio n. 13
0
 @Override
 public void watch(GameEvent event, Game game) {
   if (condition == true) { // no need to check - condition has already occured
     return;
   }
   Player player = game.getPlayer(controllerId);
   if (player != null && event.getType() == EventType.DESTROYED_PERMANENT) {
     Permanent perm =
         (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
     if (perm != null && !perm.getCardType().contains(CardType.CREATURE)) {
       if (game.getStack().size() > 0) {
         StackObject spell = game.getStack().getStackObject(event.getSourceId());
         if (spell != null && game.getOpponents(controllerId).contains(spell.getControllerId())) {
           condition = true;
         }
       }
     }
   }
 }
Esempio n. 14
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     Permanent permanent =
         (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
     if (permanent != null) {
       List<UUID> imprinted = permanent.getImprinted();
       if (imprinted.size() > 0) {
         Card imprintedCard = game.getCard(imprinted.get(0));
         imprintedCard.setFaceDown(false, game);
         if (imprintedCard.getCardType().contains(CardType.CREATURE)) {
           controller.moveCards(imprintedCard, Zone.BATTLEFIELD, source, game);
         }
       }
     }
     return true;
   }
   return false;
 }
Esempio n. 15
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;
 }
Esempio n. 16
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
     ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
     if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() == Zone.GRAVEYARD) {
       Permanent permanent =
           (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
       if (permanent != null) {
         if (permanent.getId().equals(this.getSourceId())) {
           return true;
         } else {
           if (permanent.getCardType().contains(CardType.CREATURE)) {
             return true;
           }
         }
       }
     }
   }
   return false;
 }