Пример #1
0
  public void select(Player player) {
    long curTime = System.currentTimeMillis();

    Connection con = null;
    PreparedStatement statement = null;
    ResultSet rset = null;
    try {
      con = DatabaseFactory.getInstance().getConnection();
      statement = con.prepareStatement(SELECT_SQL_QUERY);
      statement.setInt(1, player.getObjectId());
      rset = statement.executeQuery();
      while (rset.next()) {
        int group = rset.getInt("reuse_group");
        int item_id = rset.getInt("item_id");
        long endTime = rset.getLong("end_time");
        long reuse = rset.getLong("reuse");

        if (endTime - curTime > 500) {
          TimeStamp stamp = new TimeStamp(item_id, endTime, reuse);
          player.addSharedGroupReuse(group, stamp);
        }
      }
      DbUtils.close(statement);

      statement = con.prepareStatement(DELETE_SQL_QUERY);
      statement.setInt(1, player.getObjectId());
      statement.execute();
    } catch (Exception e) {
      _log.error("CharacterGroupReuseDAO.select(L2Player):", e);
    } finally {
      DbUtils.closeQuietly(con, statement, rset);
    }
  }
Пример #2
0
  public Map<Integer, Friend> select(Player owner) {
    Map<Integer, Friend> map = new HashMap<Integer, Friend>();
    Connection con = null;
    PreparedStatement statement = null;
    ResultSet rset = null;
    try {
      con = DatabaseFactory.getInstance().getConnection();
      statement =
          con.prepareStatement(
              "SELECT f.friend_id, c.char_name, s.class_id, s.level FROM character_friends f LEFT JOIN characters c ON f.friend_id = c.obj_Id LEFT JOIN character_subclasses s ON ( f.friend_id = s.char_obj_id AND s.active =1 ) WHERE f.char_id = ?");
      statement.setInt(1, owner.getObjectId());
      rset = statement.executeQuery();
      while (rset.next()) {
        int objectId = rset.getInt("f.friend_id");
        String name = rset.getString("c.char_name");
        int classId = rset.getInt("s.class_id");
        int level = rset.getInt("s.level");

        map.put(objectId, new Friend(objectId, name, level, classId));
      }
    } catch (Exception e) {
      _log.error("CharacterFriendDAO.load(L2Player): " + e, e);
    } finally {
      DbUtils.closeQuietly(con, statement, rset);
    }
    return map;
  }
Пример #3
0
  /** Сбрасывает информацию о ноблесах, сохраняя очки за предыдущий период */
  public static synchronized void cleanupNobles() {
    _log.info("Olympiad: Calculating last period...");
    Connection con = null;
    PreparedStatement statement = null;
    try {
      con = DatabaseFactory.getInstance().getConnection();
      statement = con.prepareStatement(OlympiadNobleDAO.OLYMPIAD_CALCULATE_LAST_PERIOD);
      statement.setInt(1, Config.OLYMPIAD_BATTLES_FOR_REWARD);
      statement.execute();
      DbUtils.close(statement);

      statement = con.prepareStatement(OlympiadNobleDAO.OLYMPIAD_CLEANUP_NOBLES);
      statement.setInt(1, Config.OLYMPIAD_POINTS_DEFAULT);
      statement.execute();
    } catch (Exception e) {
      _log.error("Olympiad System: Couldn't calculate last period!", e);
    } finally {
      DbUtils.closeQuietly(con, statement);
    }

    for (Integer nobleId : Olympiad._nobles.keySet()) {
      StatsSet nobleInfo = Olympiad._nobles.get(nobleId);
      int points = nobleInfo.getInteger(Olympiad.POINTS);
      int compDone = nobleInfo.getInteger(Olympiad.COMP_DONE);
      nobleInfo.set(Olympiad.POINTS, Config.OLYMPIAD_POINTS_DEFAULT);
      if (compDone >= Config.OLYMPIAD_BATTLES_FOR_REWARD) {
        nobleInfo.set(Olympiad.POINTS_PAST, points);
        nobleInfo.set(Olympiad.POINTS_PAST_STATIC, points);
      } else {
        nobleInfo.set(Olympiad.POINTS_PAST, 0);
        nobleInfo.set(Olympiad.POINTS_PAST_STATIC, 0);
      }
      nobleInfo.set(Olympiad.COMP_DONE, 0);
      nobleInfo.set(Olympiad.COMP_WIN, 0);
      nobleInfo.set(Olympiad.COMP_LOOSE, 0);
      nobleInfo.set(Olympiad.GAME_CLASSES_COUNT, 0);
      nobleInfo.set(Olympiad.GAME_NOCLASSES_COUNT, 0);
    }
  }
Пример #4
0
  public static synchronized void sortHerosToBe() {
    if (Olympiad._period != 1) {
      return;
    }

    Olympiad._heroesToBe = new ArrayList<StatsSet>();

    Connection con = null;
    PreparedStatement statement = null;
    ResultSet rset = null;
    try {
      con = DatabaseFactory.getInstance().getConnection();
      StatsSet hero;

      for (ClassId id : ClassId.VALUES) {
        if (id.getId() > 138) {
          statement = con.prepareStatement(OlympiadNobleDAO.OLYMPIAD_GET_HEROS);
          statement.setInt(1, id.getId());
          statement.setInt(2, Config.OLYMPIAD_BATTLES_FOR_REWARD);
          rset = statement.executeQuery();

          if (rset.next()) {
            hero = new StatsSet();
            hero.set(Olympiad.CLASS_ID, id.getId());
            hero.set(Olympiad.CHAR_ID, rset.getInt(Olympiad.CHAR_ID));
            hero.set(Olympiad.CHAR_NAME, rset.getString(Olympiad.CHAR_NAME));

            Olympiad._heroesToBe.add(hero);
          }
          DbUtils.close(statement, rset);
        }
      }
    } catch (Exception e) {
      _log.error("Olympiad System: Couldnt heros from db!", e);
    } finally {
      DbUtils.closeQuietly(con, statement, rset);
    }
  }
Пример #5
0
  public static synchronized void loadNoblesRank() {
    Olympiad._noblesRank = new ConcurrentHashMap<Integer, Integer>();
    Map<Integer, Integer> tmpPlace = new HashMap<Integer, Integer>();

    Connection con = null;
    PreparedStatement statement = null;
    ResultSet rset = null;
    try {
      con = DatabaseFactory.getInstance().getConnection();
      statement = con.prepareStatement(OlympiadNobleDAO.GET_ALL_CLASSIFIED_NOBLESS);
      rset = statement.executeQuery();
      int place = 1;
      while (rset.next()) {
        tmpPlace.put(rset.getInt(Olympiad.CHAR_ID), place++);
      }

    } catch (Exception e) {
      _log.error("Olympiad System: Error!", e);
    } finally {
      DbUtils.closeQuietly(con, statement, rset);
    }

    int rank1 = (int) Math.round(tmpPlace.size() * 0.01);
    int rank2 = (int) Math.round(tmpPlace.size() * 0.10);
    int rank3 = (int) Math.round(tmpPlace.size() * 0.25);
    int rank4 = (int) Math.round(tmpPlace.size() * 0.50);

    if (rank1 == 0) {
      rank1 = 1;
      rank2++;
      rank3++;
      rank4++;
    }

    for (int charId : tmpPlace.keySet()) {
      if (tmpPlace.get(charId) <= rank1) {
        Olympiad._noblesRank.put(charId, 1);
      } else if (tmpPlace.get(charId) <= rank2) {
        Olympiad._noblesRank.put(charId, 2);
      } else if (tmpPlace.get(charId) <= rank3) {
        Olympiad._noblesRank.put(charId, 3);
      } else if (tmpPlace.get(charId) <= rank4) {
        Olympiad._noblesRank.put(charId, 4);
      } else {
        Olympiad._noblesRank.put(charId, 5);
      }
    }
  }
Пример #6
0
 public void insert(Player owner, Player friend) {
   Connection con = null;
   PreparedStatement statement = null;
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement =
         con.prepareStatement("INSERT INTO character_friends (char_id,friend_id) VALUES(?,?)");
     statement.setInt(1, owner.getObjectId());
     statement.setInt(2, friend.getObjectId());
     statement.execute();
   } catch (Exception e) {
     _log.warn(
         owner.getFriendList() + " could not add friend objectid: " + friend.getObjectId(), e);
   } finally {
     DbUtils.closeQuietly(con, statement);
   }
 }
Пример #7
0
  public void insert(Player player) {
    Connection con = null;
    PreparedStatement statement = null;
    try {
      con = DatabaseFactory.getInstance().getConnection();
      statement = con.prepareStatement(DELETE_SQL_QUERY);
      statement.setInt(1, player.getObjectId());
      statement.execute();

      Collection<IntObjectMap.Entry<TimeStamp>> reuses = player.getSharedGroupReuses();
      if (reuses.isEmpty()) {
        return;
      }

      SqlBatch b = new SqlBatch(INSERT_SQL_QUERY);
      synchronized (reuses) {
        for (IntObjectMap.Entry<TimeStamp> entry : reuses) {
          int group = entry.getKey();
          TimeStamp timeStamp = entry.getValue();
          if (timeStamp.hasNotPassed()) {
            StringBuilder sb = new StringBuilder("(");
            sb.append(player.getObjectId()).append(",");
            sb.append(group).append(",");
            sb.append(timeStamp.getId()).append(",");
            sb.append(timeStamp.getEndTime()).append(",");
            sb.append(timeStamp.getReuseBasic()).append(")");
            b.write(sb.toString());
          }
        }
      }
      if (!b.isEmpty()) {
        statement.executeUpdate(b.close());
      }
    } catch (final Exception e) {
      _log.error("CharacterGroupReuseDAO.insert(L2Player):", e);
    } finally {
      DbUtils.closeQuietly(con, statement);
    }
  }
Пример #8
0
  private void load() {
    int npcId = 0;
    int count = 0;
    int id = 0;
    int lvl = 0;
    int minLvl = 0;

    Connection con = null;
    PreparedStatement statement = null;
    ResultSet rset = null;
    try {
      con = DatabaseFactory.getInstance().getConnection();
      statement = con.prepareStatement("SELECT * FROM pets_skills ORDER BY templateId");
      rset = statement.executeQuery();

      while (rset.next()) {
        npcId = rset.getInt("templateId");
        id = rset.getInt("skillId");
        lvl = rset.getInt("skillLvl");
        minLvl = rset.getInt("minLvl");

        List<SkillLearn> list = _skillTrees.get(npcId);
        if (list == null) {
          _skillTrees.put(npcId, (list = new ArrayList<SkillLearn>()));
        }

        SkillLearn skillLearn = new SkillLearn(id, lvl, minLvl, 0, 0, 0, false);
        list.add(skillLearn);
        count++;
      }
    } catch (Exception e) {
      _log.error("Error while creating pet skill tree (Pet ID " + npcId + ")", e);
    } finally {
      DbUtils.closeQuietly(con, statement, rset);
    }

    _log.info("PetSkillsTable: Loaded " + count + " skills.");
  }
Пример #9
0
  public static List<String> getClassLeaderBoard(int classId) {
    List<String> names = new ArrayList<String>();

    Connection con = null;
    PreparedStatement statement = null;
    ResultSet rset = null;

    try {
      con = DatabaseFactory.getInstance().getConnection();
      statement = con.prepareStatement(OlympiadNobleDAO.GET_EACH_CLASS_LEADER);
      statement.setInt(1, classId);
      rset = statement.executeQuery();
      while (rset.next()) {
        names.add(rset.getString(Olympiad.CHAR_NAME));
      }
    } catch (Exception e) {
      _log.error("Olympiad System: Couldnt get heros from db!", e);
    } finally {
      DbUtils.closeQuietly(con, statement, rset);
    }

    return names;
  }
Пример #10
0
 public void delete(Player owner, int friend) {
   Connection con = null;
   PreparedStatement statement = null;
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement =
         con.prepareStatement(
             "DELETE FROM character_friends WHERE (char_id=? AND friend_id=?) OR (char_id=? AND friend_id=?)");
     statement.setInt(1, owner.getObjectId());
     statement.setInt(2, friend);
     statement.setInt(3, friend);
     statement.setInt(4, owner.getObjectId());
     statement.execute();
   } catch (Exception e) {
     _log.warn(
         "FriendList: could not delete friend objectId: "
             + friend
             + " ownerId: "
             + owner.getObjectId(),
         e);
   } finally {
     DbUtils.closeQuietly(con, statement);
   }
 }