Exemple #1
0
  /**
   * @param State.<br>
   *     0 - not decided yet<br>
   *     1 - independent<br>
   *     2 - contracted with castle<br>
   *     <br>
   * @param CastleId.<br>
   *     set Castle Id for contracted fort
   */
  public final void setFortState(int state, int castleId) {
    if (_castleId != 0) {
      Castle castle = CastleManager.getInstance().getCastleById(_castleId);
      if (castle != null) castle.removeContractFort(getFortId());
    }
    if (state == 2 && castleId != 0) {
      Castle castle = CastleManager.getInstance().getCastleById(castleId);
      if (castle != null) castle.addContractFort(getFortId());
    }
    _state = state;
    _castleId = castleId;
    Connection con = null;
    try {
      con = L2DatabaseFactory.getInstance().getConnection();
      PreparedStatement statement;

      statement = con.prepareStatement("UPDATE fort SET state=?, castleId=? WHERE id = ?");
      statement.setInt(1, getFortState());
      statement.setInt(2, getCastleId());
      statement.setInt(3, getFortId());
      statement.execute();
      statement.close();
    } catch (Exception e) {
      _log.warn("Exception: updateOwnerInDB(L2Clan clan): " + e.getMessage(), e);
    } finally {
      try {
        if (con != null) con.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }
Exemple #2
0
  private void load() {
    Connection con = null;
    try {
      PreparedStatement statement;
      ResultSet rs;

      con = L2DatabaseFactory.getInstance().getConnection(con);

      statement = con.prepareStatement("SELECT * FROM fort WHERE id = ?");
      statement.setInt(1, getFortId());
      rs = statement.executeQuery();

      while (rs.next()) {
        _name = rs.getString("name");
        _siegeDate = Calendar.getInstance();
        _siegeDate.setTimeInMillis(rs.getLong("siegeDate"));
        _lastOwnedTime = rs.getLong("lastOwnedTime");
        _ownerId = rs.getInt("owner");
        _fortType = rs.getInt("fortType");
        _state = rs.getInt("state");
        _castleId = rs.getInt("castleId");
      }

      rs.close();
      statement.close();

      if (_ownerId > 0) {
        L2Clan clan = ClanTable.getInstance().getClan(_ownerId); // Try to find clan instance
        if (clan != null) {
          setOwnerClan(clan);
          clan.setHasFort(getFortId());
          ThreadPoolManager.getInstance()
              .scheduleGeneral(
                  new FortUpdater(clan, 1), 3600000); // Schedule owner tasks to start running
        } else setOwnerClan(null);
      } else setOwnerClan(null);

      if (_state == 2 && _castleId != 0) {
        Castle castle = CastleManager.getInstance().getCastleById(_castleId);
        if (castle != null) castle.addContractFort(getFortId());
      }
    } catch (Exception e) {
      _log.warn("Exception: loadFortData(): " + e.getMessage(), e);
    } finally {
      try {
        if (con != null) con.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }