コード例 #1
0
ファイル: DoublingSeason.java プロジェクト: poixen/mage
 @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;
 }
コード例 #2
0
 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;
 }
コード例 #3
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;
 }
コード例 #4
0
ファイル: Counterflux.java プロジェクト: Nick456/mage
  @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;
  }
コード例 #5
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;
 }
コード例 #6
0
ファイル: PsychicStrike.java プロジェクト: poixen/mage
 @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;
 }
コード例 #7
0
ファイル: RealitySmasher.java プロジェクト: marthinwurer/mage
 @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;
 }
コード例 #8
0
ファイル: CobraTrap.java プロジェクト: gitter-badger/mage
 @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;
         }
       }
     }
   }
 }
コード例 #9
0
ファイル: GameState.java プロジェクト: sucramnosslin/mage
  public String getValue(boolean useHidden) {
    StringBuilder sb = new StringBuilder(1024);

    sb.append(turnNum)
        .append(turn.getPhaseType())
        .append(turn.getStepType())
        .append(activePlayerId)
        .append(priorityPlayerId);

    for (Player player : players.values()) {
      sb.append("player").append(player.getLife()).append("hand");
      if (useHidden) {
        sb.append(player.getHand());
      } else {
        sb.append(player.getHand().size());
      }
      sb.append("library")
          .append(player.getLibrary().size())
          .append("graveyard")
          .append(player.getGraveyard());
    }

    sb.append("permanents");
    for (Permanent permanent : battlefield.getAllPermanents()) {
      sb.append(permanent.getValue());
    }

    sb.append("spells");
    for (StackObject spell : stack) {
      sb.append(spell.getControllerId()).append(spell.getName());
    }

    for (ExileZone zone : exile.getExileZones()) {
      sb.append("exile").append(zone.getName()).append(zone);
    }

    sb.append("combat");
    for (CombatGroup group : combat.getGroups()) {
      sb.append(group.getDefenderId()).append(group.getAttackers()).append(group.getBlockers());
    }

    return sb.toString();
  }
コード例 #10
0
ファイル: SummoningTrap.java プロジェクト: eliahhecht/mage
 @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;
     }
   }
 }
コード例 #11
0
ファイル: OverrideCard.java プロジェクト: nigelzor/mage
 @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;
 }
コード例 #12
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;
 }
コード例 #13
0
ファイル: GameView.java プロジェクト: bradens/mage
  public GameView(GameState state, Game game) {
    for (Player player : state.getPlayers().values()) {
      players.add(new PlayerView(player, state, game));
    }
    for (StackObject stackObject : state.getStack()) {
      if (stackObject instanceof StackAbility) {
        MageObject object = game.getObject(stackObject.getSourceId());
        Card card = game.getCard(stackObject.getSourceId());
        if (card != null) {
          if (object != null) {
            stack.put(
                stackObject.getId(),
                new StackAbilityView(
                    game, (StackAbility) stackObject, card.getName(), new CardView(card)));
          } else {
            stack.put(
                stackObject.getId(),
                new StackAbilityView(game, (StackAbility) stackObject, "", new CardView(card)));
          }
          if (card.canTransform()) {
            updateLatestCardView(game, card, stackObject.getId());
          }
          checkPaid(stackObject.getId(), (StackAbility) stackObject);
        } else if (object != null) {
          if (object instanceof PermanentToken) {
            PermanentToken token = (PermanentToken) object;
            stack.put(stackObject.getId(), new CardView(token));
            checkPaid(stackObject.getId(), (StackAbility) stackObject);
          } else {
            StackAbility stackAbility = ((StackAbility) object);
            stackAbility.newId();
            MageObject emblem = game.getEmblem(stackAbility.getSourceId());
            if (emblem != null) {
              Card sourceCard = game.getCard(((CommandObject) emblem).getSourceId());
              if (sourceCard != null) {
                stackAbility.setName("Emblem " + sourceCard.getName());
                stackAbility.setExpansionSetCode(sourceCard.getExpansionSetCode());
              }
            }

            stack.put(stackObject.getId(), new CardView(stackAbility));
            checkPaid(stackObject.getId(), stackAbility);
          }
        }
      } else {
        stack.put(stackObject.getId(), new CardView((Spell) stackObject));
        checkPaid(stackObject.getId(), (Spell) stackObject);
      }
      // stackOrder.add(stackObject.getId());
    }
    // Collections.reverse(stackOrder);
    for (ExileZone exileZone : state.getExile().getExileZones()) {
      exiles.add(new ExileView(exileZone, game));
    }
    for (String name : state.getRevealed().keySet()) {
      revealed.add(new RevealedView(name, state.getRevealed().get(name), game));
    }
    this.phase = state.getTurn().getPhaseType();
    this.step = state.getTurn().getStepType();
    this.turn = state.getTurnNum();
    if (state.getActivePlayerId() != null)
      this.activePlayerName = state.getPlayer(state.getActivePlayerId()).getName();
    else this.activePlayerName = "";
    if (state.getPriorityPlayerId() != null)
      this.priorityPlayerName = state.getPlayer(state.getPriorityPlayerId()).getName();
    else this.priorityPlayerName = "";
    for (CombatGroup combatGroup : state.getCombat().getGroups()) {
      combat.add(new CombatGroupView(combatGroup, game));
    }
    this.special =
        state.getSpecialActions().getControlledBy(state.getPriorityPlayerId()).size() > 0;
  }
コード例 #14
0
ファイル: GameState.java プロジェクト: sucramnosslin/mage
  public String getValue(boolean useHidden, Game game) {
    StringBuilder sb = new StringBuilder(1024);

    sb.append(turnNum)
        .append(turn.getPhaseType())
        .append(turn.getStepType())
        .append(activePlayerId)
        .append(priorityPlayerId);

    for (Player player : players.values()) {
      sb.append("player").append(player.isPassed()).append(player.getLife()).append("hand");
      if (useHidden) {
        sb.append(player.getHand());
      } else {
        sb.append(player.getHand().size());
      }
      sb.append("library").append(player.getLibrary().size());
      sb.append("graveyard");
      for (Card card : player.getGraveyard().getCards(game)) {
        sb.append(card.getName());
      }
    }

    sb.append("permanents");
    List<String> perms = new ArrayList<String>();
    for (Permanent permanent : battlefield.getAllPermanents()) {
      perms.add(permanent.getValue());
    }
    Collections.sort(perms);
    sb.append(perms);

    sb.append("spells");
    for (StackObject spell : stack) {
      sb.append(spell.getControllerId()).append(spell.getName());
      sb.append(spell.getStackAbility().toString());
      for (Mode mode : spell.getStackAbility().getModes().values()) {
        if (!mode.getTargets().isEmpty()) {
          sb.append("targets");
          for (Target target : mode.getTargets()) {
            sb.append(target.getTargets());
          }
        }
        if (!mode.getChoices().isEmpty()) {
          sb.append("choices");
          for (Choice choice : mode.getChoices()) {
            sb.append(choice.getChoice());
          }
        }
      }
    }

    for (ExileZone zone : exile.getExileZones()) {
      sb.append("exile").append(zone.getName()).append(zone);
    }

    sb.append("combat");
    for (CombatGroup group : combat.getGroups()) {
      sb.append(group.getDefenderId()).append(group.getAttackers()).append(group.getBlockers());
    }

    return sb.toString();
  }