예제 #1
0
  public void buildComponents(
      String classPath,
      List<HashMap<String, String>> compInfoList,
      HashMap<String, RandomEventComponent> components) {
    if (compInfoList != null) {
      for (HashMap<String, String> compInfo : compInfoList) {
        String className = classPath + compInfo.get("name");
        Class<?> someClass;

        try {
          someClass = Class.forName(className);
          RandomEventComponent perkCompClass;
          perkCompClass = (RandomEventComponent) someClass.newInstance();
          perkCompClass.setName(compInfo.get("name"));

          for (String key : compInfo.keySet()) {
            perkCompClass.setAttribute(key, compInfo.get(key));
          }

          perkCompClass.createComponent(this);
          components.put(perkCompClass.getName(), perkCompClass);
        } catch (InstantiationException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        } catch (ClassNotFoundException e) {
          e.printStackTrace();
        }
      }
    }
  }
예제 #2
0
  public void activate() throws CivException {
    if (this.active) {
      throw new CivException("Event is already active!");
    }

    this.active = true;
    /* Start by processing all of the action components. */
    for (RandomEventComponent comp : this.actions.values()) {
      comp.process();
    }
    this.save();
  }
예제 #3
0
  @Override
  public void load(ResultSet rs)
      throws SQLException, InvalidNameException, InvalidObjectException, CivException {
    this.setId(rs.getInt("id"));
    this.configRandomEvent = CivSettings.randomEvents.get(rs.getString("config_id"));
    if (this.configRandomEvent == null) {
      /* Delete the random event. */
      this.delete();
      throw new CivException("Couldn't find random event config id:" + rs.getString("config_id"));
    }

    this.town = CivGlobal.getTownFromId(rs.getInt("town_id"));
    if (this.town == null) {
      this.delete();
      throw new CivException(
          "Couldn't find town id:" + rs.getInt("town_id") + " while loading random event.");
    }

    this.startDate = new Date(rs.getLong("start_date"));
    this.active = rs.getBoolean("active");

    loadComponentVars(rs.getString("component_vars"));
    loadSavedMessages(rs.getString("saved_messages"));

    /* Re-run the on start to re-enable any listeners. */
    /* Loop through all components for onStart() */
    buildComponents();
    for (RandomEventComponent comp : this.actions.values()) {
      comp.onStart();
    }
    for (RandomEventComponent comp : this.requirements.values()) {
      comp.onStart();
    }
    for (RandomEventComponent comp : this.success.values()) {
      comp.onStart();
    }
    for (RandomEventComponent comp : this.failure.values()) {
      comp.onStart();
    }

    RandomEventSweeper.register(this);
  }
예제 #4
0
  public void cleanup() {
    /* Loop through all components for cleanup */
    for (RandomEventComponent comp : this.actions.values()) {
      comp.onCleanup();
    }
    for (RandomEventComponent comp : this.requirements.values()) {
      comp.onCleanup();
    }
    for (RandomEventComponent comp : this.success.values()) {
      comp.onCleanup();
    }
    for (RandomEventComponent comp : this.failure.values()) {
      comp.onCleanup();
    }

    town.setActiveEvent(null);
    try {
      this.delete();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
예제 #5
0
  /*
   * Private for now, since we only allow random events on towns atm.
   */
  private void start() {

    /* Loop through all components for onStart() */
    for (RandomEventComponent comp : this.actions.values()) {
      comp.onStart();
    }
    for (RandomEventComponent comp : this.requirements.values()) {
      comp.onStart();
    }
    for (RandomEventComponent comp : this.success.values()) {
      comp.onStart();
    }
    for (RandomEventComponent comp : this.failure.values()) {
      comp.onStart();
    }

    /* Start by processing all of the action components. */
    boolean requireActivation = false;
    for (RandomEventComponent comp : this.actions.values()) {
      if (!comp.requiresActivation()) {
        comp.process();
      } else {
        requireActivation = true;
        CivMessage.sendTown(
            this.town,
            CivColor.Yellow
                + "This event requires activation! use '/town event activate' to activate it.");
      }
    }

    if (!requireActivation) {
      this.active = true;
    }

    /* Register this random event with the sweeper until complete. */
    RandomEventSweeper.register(this);

    /* Setup start date. */
    this.startDate = new Date();

    this.save();
  }