Package mage.game.events

Examples of mage.game.events.GameEvent


      game.getTurn().setPhase(new CombatPhase());
      if (game.getPhase().beginPhase(game, game.getActivePlayerId())) {
        simulateStep(game, new BeginCombatStep());
        game.getPhase().setStep(new DeclareAttackersStep());
        if (!game.getStep().skipStep(game, game.getActivePlayerId())) {
          game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_PRE, null, null, game.getActivePlayerId()));
          if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_ATTACKERS, game.getActivePlayerId(), game.getActivePlayerId()))) {
            val = simulateAttackers(game, node, game.getActivePlayerId(), depth, alpha, beta, counter);
          }
        }
        else if (!counter) {
          simulateToEnd(game);
          val = simulatePostCombatMain(game, node, depth, alpha, beta);
        }
      }
    }
    else {
      if (!game.getStep().skipStep(game, game.getActivePlayerId())) {
        game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_PRE, null, null, game.getActivePlayerId()));
        if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_BLOCKERS, game.getActivePlayerId(), game.getActivePlayerId()))) {
          //only suitable for two player games - only simulates blocks for 1st defender
          val = simulateBlockers(game, node, game.getCombat().getDefenders().iterator().next(), depth, alpha, beta, counter);
        }
      }
View Full Code Here


            game.getPhase().setStep(new UntapStep());
          }
      }
      if (!game.getStep().skipStep(game, game.getActivePlayerId())) {
        if (game.getTurn().getStepType() == PhaseStep.DECLARE_ATTACKERS) {
          game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_PRE, null, null, activePlayerId));
          if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_ATTACKERS, activePlayerId, activePlayerId))) {
            for (Combat engagement: ((SimulatedPlayer)game.getPlayer(activePlayerId)).addAttackers(game)) {
              Game sim = game.copy();
              UUID defenderId = game.getOpponents(playerId).iterator().next();
              for (CombatGroup group: engagement.getGroups()) {
                for (UUID attackerId: group.getAttackers()) {
                  sim.getPlayer(activePlayerId).declareAttacker(attackerId, defenderId, sim);
                }
              }
              sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, playerId, playerId));
              SimulationNode newNode = new SimulationNode(sim, node.getDepth()-1, activePlayerId);
              logger.fine("simulating -- node #:" + SimulationNode.getCount() + " declare attakers");
              newNode.setCombat(sim.getCombat());
              node.children.add(newNode);
            }
          }
        }
        else if (game.getTurn().getStepType() == PhaseStep.DECLARE_BLOCKERS) {
          game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_PRE, null, null, activePlayerId));
          if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_BLOCKERS, activePlayerId, activePlayerId))) {
            for (UUID defenderId: game.getCombat().getDefenders()) {
              //check if defender is being attacked
              if (game.getCombat().isAttacked(defenderId, game)) {
                for (Combat engagement: ((SimulatedPlayer)game.getPlayer(defenderId)).addBlockers(game)) {
View Full Code Here

    }

    @Override
    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
      boolean retValue = false;
      GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), event.getAmount(), false);
      int damage = event.getAmount();
      if (!game.replaceEvent(preventEvent)) {
        event.setAmount(0);
        game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage));
        retValue = true;
View Full Code Here

    return true;
  }

  @Override
  public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), event.getAmount(), false);
    if (!game.replaceEvent(preventEvent)) {
      if (event.getAmount() >= this.amount) {
        int damage = event.getAmount();
        event.setAmount(event.getAmount() - amount);
        this.used = true;
View Full Code Here

        if (!isPaused() && !gameOver(null)) {
            PlayerList players = state.getPlayerList(nextPlayerId);
            Player playerByOrder = getPlayer(players.get());
            while (!isPaused() && !gameOver(null)) {
                playExtraTurns();
                GameEvent event = new GameEvent(GameEvent.EventType.PLAY_TURN, null, null, playerByOrder.getId());
                if (!replaceEvent(event)) {
                    if (!playTurn(playerByOrder)) {
                        break;
                    }
                    state.setTurnNum(state.getTurnNum() + 1);
View Full Code Here

    private void playExtraTurns() {
        //20091005 - 500.7
        TurnMod extraTurn = getNextExtraTurn();
        while (extraTurn != null) {
            GameEvent event = new GameEvent(GameEvent.EventType.PLAY_TURN, null, null, extraTurn.getPlayerId());
            if (!replaceEvent(event)) {
                Player extraPlayer = this.getPlayer(extraTurn.getPlayerId());
                if (extraPlayer != null && extraPlayer.isInGame()) {
                    state.setExtraTurn(true);
                    state.setTurnId(extraTurn.getId());
View Full Code Here

    private TurnMod getNextExtraTurn() {
        boolean checkForExtraTurn = true;
        while(checkForExtraTurn) {
            TurnMod extraTurn = getState().getTurnMods().getNextExtraTurn();
            if (extraTurn != null) {
                GameEvent event = new GameEvent(GameEvent.EventType.EXTRA_TURN, extraTurn.getId(), null, extraTurn.getPlayerId());
                if (!replaceEvent(event)) {
                    return extraTurn;
                }
            } else {
                checkForExtraTurn = false;
View Full Code Here

                    boolean keep = true;
                    while (true) {
                        if (player.getHand().isEmpty()) {
                            break;
                        }
                        GameEvent event = new GameEvent(GameEvent.EventType.CAN_TAKE_MULLIGAN, null, null, playerId);
                        if (!replaceEvent(event)) {
                            fireEvent(event);
                            if (player.chooseMulligan(this)) {
                                keep = false;
                            }
View Full Code Here

                            // handle bestow unattachment
                            Card card = this.getCard(perm.getId());
                            if (card != null && card.getCardType().contains(CardType.CREATURE)) {
                                UUID wasAttachedTo = perm.getAttachedTo();
                                perm.attachTo(null, this);
                                fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, wasAttachedTo, perm.getId(), perm.getControllerId()));
                            } else {
                                if (movePermanentToGraveyardWithInfo(perm)) {
                                    somethingHappened = true;
                                }
                            }
                        }
                        else {
                            Filter auraFilter = perm.getSpellAbility().getTargets().get(0).getFilter();
                            if (auraFilter instanceof FilterControlledCreaturePermanent) {
                                if (!((FilterControlledCreaturePermanent)auraFilter).match(attachedTo, perm.getId(), perm.getControllerId(), this)
                                        || attachedTo.cantBeEnchantedBy(perm, this)) {
                                    if (movePermanentToGraveyardWithInfo(perm)) {
                                        somethingHappened = true;
                                    }
                                }
                            } else {
                                if (!auraFilter.match(attachedTo, this) || attachedTo.cantBeEnchantedBy(perm, this)) {
                                    // handle bestow unattachment
                                    Card card = this.getCard(perm.getId());
                                    if (card != null && card.getCardType().contains(CardType.CREATURE)) {
                                        UUID wasAttachedTo = perm.getAttachedTo();
                                        perm.attachTo(null, this);
                                        fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, wasAttachedTo, perm.getId(), perm.getControllerId()));
                                    } else {
                                        if (movePermanentToGraveyardWithInfo(perm)) {
                                            somethingHappened = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (target instanceof TargetPlayer) {
                        Player attachedToPlayer = getPlayer(perm.getAttachedTo());
                        if (attachedToPlayer == null) {
                            if (movePermanentToGraveyardWithInfo(perm)) {
                                somethingHappened = true;
                            }
                        }
                        else {
                            Filter auraFilter = perm.getSpellAbility().getTargets().get(0).getFilter();
                            if (!auraFilter.match(attachedToPlayer, this) || attachedToPlayer.hasProtectionFrom(perm, this)) {
                                if (movePermanentToGraveyardWithInfo(perm)) {
                                    somethingHappened = true;
                                }
                            }
                        }
                    }
                }
            }
            if (this.getState().isLegendaryRuleActive() && filterLegendary.match(perm, this)) {
                legendary.add(perm);
            }
            if (filterEquipment.match(perm, this)) {
                //20091005 - 704.5p, 702.14d
                if (perm.getAttachedTo() != null) {
                    Permanent creature = getPermanent(perm.getAttachedTo());
                    if (creature == null || !creature.getAttachments().contains(perm.getId())) {
                        UUID wasAttachedTo = perm.getAttachedTo();
                        perm.attachTo(null, this);
                        fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, wasAttachedTo, perm.getId(), perm.getControllerId()));
                    } else if (!creature.getCardType().contains(CardType.CREATURE) || creature.hasProtectionFrom(perm, this)) {
                        if (creature.removeAttachment(perm.getId(), this)) {
                            somethingHappened = true;
                        }
                    }
View Full Code Here

        if (!(event instanceof DamageEvent)) {
            result.setError(true);
            return result;
        }
        DamageEvent damageEvent = (DamageEvent) event;
        GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, damageEvent.getTargetId(), damageEvent.getSourceId(), source.getControllerId(), damageEvent.getAmount(), false);
        if (game.replaceEvent(preventEvent)) {
            result.setReplaced(true);
            return result;
        }
View Full Code Here

TOP

Related Classes of mage.game.events.GameEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.