/**
   * 取得报酬
   *
   * @return int 报酬
   */
  public static int getPay(final int objid) {
    Connection con = null;
    PreparedStatement pstm1 = null;
    PreparedStatement pstm2 = null;
    ResultSet rs1 = null;
    int pay = 0;

    try {
      con = L1DatabaseFactory.getInstance().getConnection();
      pstm1 = con.prepareStatement("SELECT Pay FROM characters WHERE objid = ? FOR UPDATE");

      pstm1.setInt(1, objid);
      rs1 = pstm1.executeQuery();

      if (rs1.next()) {
        pay = rs1.getInt("Pay");
      }

      pstm2 = con.prepareStatement("UPDATE characters SET Pay = 0 WHERE objid = ?");
      pstm2.setInt(1, objid);
      pstm2.execute();
    } catch (final SQLException e) {
      _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(rs1);
      SQLUtil.close(pstm1);
      SQLUtil.close(pstm2);
      SQLUtil.close(con);
    }

    return pay;
  }
  private static void clearHomeTownID() {
    Connection con = null;
    PreparedStatement pstm = null;

    try {
      con = L1DatabaseFactory.getInstance().getConnection();
      pstm = con.prepareStatement("UPDATE characters SET HomeTownID = 0 WHERE HomeTownID = -1");
      pstm.execute();
    } catch (final SQLException e) {
      _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(pstm);
      SQLUtil.close(con);
    }
  }
示例#3
0
  public void storeLogEnchant(
      final int char_id, final int item_id, final int old_enchantlvl, final int new_enchantlvl) {
    java.sql.Connection con = null;
    PreparedStatement pstm = null;
    try {
      con = L1DatabaseFactory.getInstance().getConnection();
      pstm =
          con.prepareStatement(
              "INSERT INTO log_enchant SET char_id=?, item_id=?, old_enchantlvl=?, new_enchantlvl=?");
      pstm.setInt(1, char_id);
      pstm.setInt(2, item_id);
      pstm.setInt(3, old_enchantlvl);
      pstm.setInt(4, new_enchantlvl);
      pstm.execute();

    } catch (final Exception e) {
      _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(pstm);
      SQLUtil.close(con);
    }
  }
  private static String totalContribution(final int townId) {
    Connection con = null;
    PreparedStatement pstm1 = null;
    ResultSet rs1 = null;
    PreparedStatement pstm2 = null;
    ResultSet rs2 = null;
    PreparedStatement pstm3 = null;
    ResultSet rs3 = null;
    PreparedStatement pstm4 = null;
    PreparedStatement pstm5 = null;

    int leaderId = 0;
    String leaderName = null;

    try {
      con = L1DatabaseFactory.getInstance().getConnection();
      pstm1 =
          con.prepareStatement(
              "SELECT objid, char_name FROM characters WHERE HomeTownID = ? ORDER BY Contribution DESC");

      pstm1.setInt(1, townId);
      rs1 = pstm1.executeQuery();

      if (rs1.next()) {
        leaderId = rs1.getInt("objid");
        leaderName = rs1.getString("char_name");
      }

      double totalContribution = 0;
      pstm2 =
          con.prepareStatement(
              "SELECT SUM(Contribution) AS TotalContribution FROM characters WHERE HomeTownID = ?");
      pstm2.setInt(1, townId);
      rs2 = pstm2.executeQuery();
      if (rs2.next()) {
        totalContribution = rs2.getInt("TotalContribution");
      }

      double townFixTax = 0;
      pstm3 = con.prepareStatement("SELECT town_fix_tax FROM town WHERE town_id = ?");
      pstm3.setInt(1, townId);
      rs3 = pstm3.executeQuery();
      if (rs3.next()) {
        townFixTax = rs3.getInt("town_fix_tax");
      }

      double contributionUnit = 0;
      if (totalContribution != 0) {
        contributionUnit = Math.floor(townFixTax / totalContribution * 100) / 100;
      }
      pstm4 =
          con.prepareStatement(
              "UPDATE characters SET Contribution = 0, Pay = Contribution * ? WHERE HomeTownID = ?");
      pstm4.setDouble(1, contributionUnit);
      pstm4.setInt(2, townId);
      pstm4.execute();

      pstm5 =
          con.prepareStatement(
              "UPDATE town SET leader_id = ?, leader_name = ?, tax_rate = 0, tax_rate_reserved = 0, sales_money = 0, sales_money_yesterday = sales_money, town_tax = 0, town_fix_tax = 0 WHERE town_id = ?");
      pstm5.setInt(1, leaderId);
      pstm5.setString(2, leaderName);
      pstm5.setInt(3, townId);
      pstm5.execute();
    } catch (final SQLException e) {
      _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(rs1);
      SQLUtil.close(rs2);
      SQLUtil.close(rs3);
      SQLUtil.close(pstm1);
      SQLUtil.close(pstm2);
      SQLUtil.close(pstm3);
      SQLUtil.close(pstm4);
      SQLUtil.close(pstm5);
      SQLUtil.close(con);
    }

    return leaderName;
  }
示例#5
0
  /**
   * 储存聊天
   *
   * @param pc
   * @param target
   * @param text
   * @param type
   */
  public void storeChat(
      final L1PcInstance pc, final L1PcInstance target, final String text, final int type) {
    if (!this.isLoggingTarget(type)) {
      return;
    }

    // type
    // 0:一般频道
    // 1:Whisper(密语频道)
    // 2:大喊频道
    // 3:广播频道
    // 4:血盟频道
    // 11:组队频道
    // 13:联盟频道
    // 14:聊天队伍频道
    Connection con = null;
    PreparedStatement pstm = null;
    try {

      con = L1DatabaseFactory.getInstance().getConnection();
      if (target != null) {
        pstm =
            con.prepareStatement(
                "INSERT INTO log_chat (account_name, char_id, name, clan_id, clan_name, locx, locy, mapid, type, target_account_name, target_id, target_name, target_clan_id, target_clan_name, target_locx, target_locy, target_mapid, content, datetime) VALUE (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE())");
        pstm.setString(1, pc.getAccountName());
        pstm.setInt(2, pc.getId());
        pstm.setString(3, pc.isGm() ? "******" : pc.getName());
        pstm.setInt(4, pc.getClanid());
        pstm.setString(5, pc.getClanname());
        pstm.setInt(6, pc.getX());
        pstm.setInt(7, pc.getY());
        pstm.setInt(8, pc.getMapId());
        pstm.setInt(9, type);
        pstm.setString(10, target.getAccountName());
        pstm.setInt(11, target.getId());
        pstm.setString(12, target.getName());
        pstm.setInt(13, target.getClanid());
        pstm.setString(14, target.getClanname());
        pstm.setInt(15, target.getX());
        pstm.setInt(16, target.getY());
        pstm.setInt(17, target.getMapId());
        pstm.setString(18, text);
      } else {
        pstm =
            con.prepareStatement(
                "INSERT INTO log_chat (account_name, char_id, name, clan_id, clan_name, locx, locy, mapid, type, content, datetime) VALUE (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE())");
        pstm.setString(1, pc.getAccountName());
        pstm.setInt(2, pc.getId());
        pstm.setString(3, pc.isGm() ? "******" : pc.getName());
        pstm.setInt(4, pc.getClanid());
        pstm.setString(5, pc.getClanname());
        pstm.setInt(6, pc.getX());
        pstm.setInt(7, pc.getY());
        pstm.setInt(8, pc.getMapId());
        pstm.setInt(9, type);
        pstm.setString(10, text);
      }
      pstm.execute();

    } catch (final SQLException e) {
      _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(pstm);
      SQLUtil.close(con);
    }
  }