Пример #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();
      }
    }
  }