Esempio n. 1
0
  /**
   * Check for events to go off during each turn
   *
   * @param card card to check events for
   */
  public void checkEvents(Card card) {
    List<Event> eventsToRemove = new ArrayList<Event>();
    // System.out.println("-----------ROUND MANAGER: " + card.getName() + "------------");
    // System.out.println("events before = " + events);

    for (Event event : events) {
      final Event tmp = event;
      // checks if the src is still alive
      if (!checkSrcAlive(event.getSrc())) {
        // System.out.println("Src card died, so flushing out event: " + event);
        Event tmpEvent = new Event(event.getEffect(), event.getEffect().getEndType());
        // Perform the animation
        animationManager.queueEventAnimation(
            tmpEvent,
            new Runnable() {
              @Override
              public void run() {
                tmp.getEffect().doEndEffect();
              }
            });
        // Add the end effect to event history
        eventHistory.addLast(tmpEvent);
      }
    }

    for (Event event : events) {
      final Event tmp = event;

      // check if you put in that event
      if (card == event.getSrc()) {
        event.decreaseTurns();
        if (event.effectEnded()) {
          // System.out.println("END EFFECT: " + event);
          Event tmpEvent = new Event(event.getEffect(), event.getEffect().getEndType());
          // Perform the animation
          animationManager.queueEventAnimation(
              tmpEvent,
              new Runnable() {
                @Override
                public void run() {
                  tmp.getEffect().doEndEffect();
                }
              });
          // Add the end effect to event history
          eventHistory.addLast(tmpEvent);
        }
        // If effect is consistent
        // 	and it didn't get its turns decreased for the first time
        // 	(Basically a check that startEffect() and consistentEffect() weren't called on the same
        // turn)
        if (event.getEffect().isConsistent()
            && event.getTurnsLeft() != (event.getEffect().getTurns())) {
          //	System.out.println("CONSISTENT EFFECT: " + event);
          Event tmpEvent = new Event(event.getEffect(), event.getEffect().getConsistentType());
          animationManager.queueEventAnimation(
              tmpEvent,
              new Runnable() {
                @Override
                public void run() {
                  tmp.getEffect().doConsistentEffect();
                }
              });
          eventHistory.addLast(tmpEvent);
        }
      }
      // Flush out all ended effects
      if (event.effectEnded()) {
        eventsToRemove.add(event);
        // System.out.println("Flushing event: " + event);
      }
    }
    for (Event event : eventsToRemove) {
      events.remove(event);
    }
  }
Esempio n. 2
0
 private void emitEvent(Event event) {
   if (socket != null && socket.connected()) {
     socket.emit("newEvent", event.toJSON());
   }
 }