@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;
 }
示例#2
0
文件: Rethink.java 项目: poixen/mage
 @Override
 public boolean apply(Game game, Ability source) {
   StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
   if (spell != null) {
     Player player = game.getPlayer(spell.getControllerId());
     if (player != null) {
       GenericManaCost cost = new GenericManaCost(spell.getConvertedManaCost());
       if (!cost.pay(source, game, source.getSourceId(), player.getId(), false)) {
         game.getStack().counter(spell.getId(), source.getSourceId(), game);
       }
       return true;
     }
   }
   return false;
 }
示例#3
0
  @Override
  public boolean apply(Game game, Ability source) {

    List<Spell> spellsToCounter = new LinkedList<Spell>();
    for (StackObject stackObject : game.getStack()) {
      if (stackObject instanceof Spell
          && !stackObject.getControllerId().equals(source.getControllerId())) {
        spellsToCounter.add((Spell) stackObject);
      }
    }
    for (Spell spell : spellsToCounter) {
      game.getStack().counter(spell.getId(), source.getSourceId(), game);
    }
    return true;
  }
示例#4
0
 @Override
 public boolean apply(Game game, Ability source) {
   boolean countered = false;
   StackObject stackObject = game.getStack().getStackObject(targetPointer.getFirst(game, source));
   if (game.getStack().counter(source.getFirstTarget(), source.getSourceId(), game)) {
     countered = true;
   }
   if (stackObject != null) {
     Player controller = game.getPlayer(stackObject.getControllerId());
     if (controller != null) {
       controller.moveCards(
           controller.getLibrary().getTopCards(game, 2), Zone.GRAVEYARD, source, game);
     }
   }
   return countered;
 }
示例#5
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player you = game.getPlayer(source.getControllerId());
   if (you != null) {
     Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
     if (spell != null) {
       ObjectColor color1 =
           new ObjectColor((String) game.getState().getValue(source.getSourceId() + "_color1"));
       ObjectColor color2 =
           new ObjectColor((String) game.getState().getValue(source.getSourceId() + "_color2"));
       int amount = 0;
       if (spell.getColor(game).contains(color1)) {
         ++amount;
       }
       if (spell.getColor(game).contains(color2)) {
         ++amount;
       }
       if (amount > 0) {
         you.gainLife(amount, game);
         return true;
       }
     }
   }
   return false;
 }
示例#6
0
 @Override
 public boolean triggerAbility(TriggeredAbility source, Game game) {
   if (source != null && source.canChooseTarget(game)) {
     Ability ability;
     List<Ability> options = getPlayableOptions(source, game);
     if (options.isEmpty()) {
       ability = source;
     } else {
       if (options.size() == 1) ability = options.get(0);
       else ability = options.get(rnd.nextInt(options.size()));
     }
     if (ability.isUsesStack()) {
       game.getStack().push(new StackAbility(ability, playerId));
       if (ability.activate(game, false)) {
         actionCount++;
         return true;
       }
     } else {
       if (ability.activate(game, false)) {
         ability.resolve(game);
         actionCount++;
         return true;
       }
     }
   }
   return false;
 }
示例#7
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   Spell spell = game.getStack().getSpell(event.getTargetId());
   if (spell != null && spell.getCardType().contains(CardType.CREATURE)) {
     return true;
   }
   return false;
 }
示例#8
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   StackObject spell = game.getStack().getStackObject(event.getSourceId());
   if (spell != null && spell.getControllerId().equals(source.getControllerId())) {
     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 copy = spell.copySpell(source.getControllerId());
     ;
     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);
     }
     game.informPlayers(player.getLogName() + " copies " + activateMessage);
     return true;
   }
   return false;
 }
示例#10
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   Spell spell = game.getStack().getSpell(event.getTargetId());
   if (spell != null && spell.getCardType().contains(CardType.ARTIFACT)) {
     this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getPlayerId()));
     return true;
   }
   return false;
 }
示例#11
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;
         }
       }
     }
   }
 }
示例#12
0
 protected void simulateStep(Game game, Step step) {
   if (ALLOW_INTERRUPT && Thread.interrupted()) {
     Thread.currentThread().interrupt();
     logger.debug("interrupted");
     return;
   }
   if (!game.gameOver(null)) {
     game.getPhase().setStep(step);
     if (!step.skipStep(game, game.getActivePlayerId())) {
       step.beginStep(game, game.getActivePlayerId());
       game.checkStateAndTriggered();
       while (!game.getStack().isEmpty()) {
         game.getStack().resolve(game);
         game.applyEffects();
       }
       step.endStep(game, game.getActivePlayerId());
     }
   }
 }
示例#13
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getType() == GameEvent.EventType.SPELL_CAST) {
     Spell spell = game.getStack().getSpell(event.getTargetId());
     if (spell != null && spell.getColor().contains(ObjectColor.GREEN)) {
       return true;
     }
   }
   return false;
 }
 private UUID getSourceControllerId(UUID sourceId, Game game) {
   StackObject source = game.getStack().getStackObject(sourceId);
   if (source != null) {
     return source.getControllerId();
   }
   Permanent permanent = game.getBattlefield().getPermanent(sourceId);
   if (permanent != null) {
     return permanent.getControllerId();
   }
   return null;
 }
示例#15
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     UUID targetId = targetPointer.getFirst(game, source);
     StackObject stackObject = game.getStack().getStackObject(targetId);
     if (stackObject != null
         && game.getStack()
             .counter(targetId, source.getSourceId(), game, Zone.EXILED, false, false)) {
       Card card = ((Spell) stackObject).getCard();
       if (card != null) {
         ContinuousEffect effect = new SpelljackCastFromExileEffect();
         effect.setTargetPointer(
             new FixedTarget(card.getId(), game.getState().getZoneChangeCounter(card.getId())));
         game.addEffect(effect, source);
       }
     }
     return true;
   }
   return false;
 }
示例#16
0
 @Override
 public boolean replaceEvent(GameEvent event, Ability source, Game game) {
   UUID eventObject = ((ZoneChangeEvent) event).getTargetId();
   StackObject card = game.getStack().getStackObject(eventObject);
   Player controller = game.getPlayer(source.getControllerId());
   if (card != null && controller != null) {
     if (card instanceof Card) {
       return controller.moveCards((Card) card, Zone.EXILED, source, game);
     }
   }
   return false;
 }
示例#17
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) {
     if (event.getSourceId().equals(this.getSourceId())) {
       StackObject object = game.getStack().getStackObject(event.getSourceId());
       if (object != null && object.getStackAbility() instanceof CyclingAbility) {
         return true;
       }
     }
   }
   return false;
 }
示例#18
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getType() == GameEvent.EventType.SPELL_CAST) {
     Spell spell = game.getStack().getSpell(event.getTargetId());
     if (spell != null && spell.getConvertedManaCost() <= 3) {
       for (Effect effect : this.getEffects()) {
         effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
       }
       return true;
     }
   }
   return false;
 }
示例#19
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;
     }
   }
 }
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   BoseijuWhoSheltersAllWatcher watcher =
       (BoseijuWhoSheltersAllWatcher)
           game.getState().getWatchers().get("ManaPaidFromBoseijuWhoSheltersAllWatcher");
   Spell spell = game.getStack().getSpell(event.getTargetId());
   if (spell != null && watcher.spells.contains(spell.getId())) {
     if (filter.match(spell.getCard(), game)) {
       return true;
     }
   }
   return false;
 }
示例#21
0
 @Override
 public boolean apply(Game game, Ability source) {
   StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
   MageObject sourceObject = game.getObject(source.getSourceId());
   if (sourceObject != null && spell != null) {
     Player player = game.getPlayer(spell.getControllerId());
     Player controller = game.getPlayer(source.getControllerId());
     if (player != null && controller != null) {
       int amount =
           game.getBattlefield()
               .countAll(new FilterArtifactPermanent(), source.getControllerId(), game);
       if (amount > 0) {
         GenericManaCost cost = new GenericManaCost(amount);
         if (!cost.pay(source, game, spell.getControllerId(), spell.getControllerId(), false)) {
           game.informPlayers(
               sourceObject.getLogName() + ": cost wasn't payed - countering target spell.");
           return game.getStack().counter(source.getFirstTarget(), source.getSourceId(), game);
         }
       }
       return true;
     }
   }
   return false;
 }
 @Override
 public boolean apply(MageObject input, Game game) {
   Spell spell = game.getStack().getSpell(input.getId());
   if (spell != null) {
     Targets spellTargets = spell.getSpellAbility().getTargets();
     int numberOfTargets = 0;
     for (Target target : spellTargets) {
       numberOfTargets += target.getTargets().size();
     }
     if (numberOfTargets == targets) {
       return true;
     }
   }
   return false;
 }
示例#23
0
文件: Vex.java 项目: nigelzor/mage
 @Override
 public boolean apply(Game game, Ability source) {
   UUID targetId = source.getFirstTarget();
   Player controller = null;
   boolean countered = false;
   if (targetId != null) {
     controller = game.getPlayer(game.getControllerId(targetId));
   }
   if (targetId != null && game.getStack().counter(targetId, source.getSourceId(), game)) {
     countered = true;
   }
   if (controller != null) {
     controller.drawCards(1, game);
   }
   return countered;
 }
示例#24
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   if (event.getZone() == Zone.HAND) {
     Spell spell = game.getStack().getSpell(event.getTargetId());
     if (spell != null
         && !spell.isCopy()
         && (spell.getCardType().contains(CardType.INSTANT)
             || spell.getCardType().contains(CardType.SORCERY))) {
       for (Effect effect : this.getEffects()) {
         effect.setTargetPointer(new FixedTarget(event.getTargetId()));
       }
       return true;
     }
   }
   return false;
 }
示例#25
0
 @Override
 public boolean checkTrigger(GameEvent event, Game game) {
   StackObject spell = game.getStack().getStackObject(event.getSourceId());
   if (spell == null || !(spell instanceof Spell)) {
     return false;
   } else {
     if (event.getTargetId().equals(this.getSourceId())
         && game.getOpponents(this.controllerId).contains(event.getPlayerId())
         && spellCard.match(spell, getSourceId(), getControllerId(), game)) {
       for (Effect effect : getEffects()) {
         effect.setTargetPointer(new FixedTarget(spell.getId()));
       }
       return true;
     }
   }
   return false;
 }
示例#26
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   Card targetCard = game.getCard(event.getTargetId());
   StackObject stackObject = (StackObject) game.getStack().getStackObject(event.getSourceId());
   if (targetCard != null
       && stackObject != null
       && targetCard.getId().equals(source.getSourceId())) {
     if (stackObject.getColor(game).contains(ObjectColor.BLACK)
         || stackObject.getColor(game).contains(ObjectColor.RED)) {
       if (!stackObject.getControllerId().equals(source.getControllerId())
               && stackObject.getCardType().contains(CardType.INSTANT)
           || stackObject.getCardType().contains(CardType.SORCERY)) {
         return true;
       }
     }
   }
   return false;
 }
 @Override
 public boolean applies(Ability abilityToModify, Ability source, Game game) {
   if (abilityToModify instanceof SpellAbility) {
     if (abilityToModify.getControllerId().equals(source.getControllerId())) {
       Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
       if (spell != null) {
         return this.filter.match(spell, source.getSourceId(), source.getControllerId(), game);
       } else {
         // used at least for flashback ability because Flashback ability doesn't use stack or for
         // getPlayables where spell is not cast yet
         Card sourceCard = game.getCard(abilityToModify.getSourceId());
         return sourceCard != null
             && this.filter.match(
                 sourceCard, source.getSourceId(), source.getControllerId(), game);
       }
     }
   }
   return false;
 }
示例#28
0
  @Override
  public boolean moveToExile(
      UUID exileId, String name, UUID sourceId, Game game, ArrayList<UUID> appliedEffects) {
    ZoneChangeEvent event =
        new ZoneChangeEvent(
            this.getId(), sourceId, this.getOwnerId(), Zone.STACK, Zone.EXILED, appliedEffects);
    if (!game.replaceEvent(event)) {
      game.getStack().remove(this);
      game.rememberLKI(this.getId(), event.getFromZone(), this);

      if (exileId == null) {
        game.getExile().getPermanentExile().add(this.card);
      } else {
        game.getExile().createZone(exileId, name).add(this.card);
      }
      game.setZone(this.card.getId(), event.getToZone());
      game.fireEvent(event);
      return event.getToZone() == Zone.EXILED;
    }
    return false;
  }
示例#29
0
 protected void addAbilityNode(SimulationNode parent, Ability ability, Game game) {
   Game sim = game.copy();
   sim.getStack().push(new StackAbility(ability, playerId));
   ability.activate(sim, false);
   sim.applyEffects();
   SimulationNode newNode = new SimulationNode(parent, sim, playerId);
   logger.debug(
       indent(newNode.getDepth())
           + "simulating -- node #:"
           + SimulationNode.getCount()
           + " triggered ability option");
   for (Target target : ability.getTargets()) {
     for (UUID targetId : target.getTargets()) {
       newNode.getTargets().add(targetId);
     }
   }
   for (Choice choice : ability.getChoices()) {
     newNode.getChoices().add(choice.getChoice());
   }
   parent.children.add(newNode);
 }
示例#30
0
 @Override
 public boolean triggerAbility(TriggeredAbility source, Game game) {
   Ability ability = source.copy();
   List<Ability> options = getPlayableOptions(ability, game);
   if (options.isEmpty()) {
     if (logger.isDebugEnabled()) logger.debug("simulating -- triggered ability:" + ability);
     game.getStack().push(new StackAbility(ability, playerId));
     ability.activate(game, false);
     game.applyEffects();
     game.getPlayers().resetPassed();
   } else {
     SimulationNode parent = (SimulationNode) game.getCustomData();
     if (parent.getDepth() == maxDepth) return true;
     logger.debug(
         indent(parent.getDepth())
             + "simulating -- triggered ability - adding children:"
             + options.size());
     for (Ability option : options) {
       addAbilityNode(parent, option, game);
     }
   }
   return true;
 }