예제 #1
0
  public void loadDiary(int charId) {
    final List<StatsSet> _diary = new FastList<>();
    int diaryentries = 0;
    try (Connection con = L2DatabaseFactory.getInstance().getConnection();
        PreparedStatement statement =
            con.prepareStatement("SELECT * FROM  heroes_diary WHERE charId=? ORDER BY time ASC")) {
      statement.setInt(1, charId);
      try (ResultSet rset = statement.executeQuery()) {
        while (rset.next()) {
          StatsSet _diaryentry = new StatsSet();

          long time = rset.getLong("time");
          int action = rset.getInt("action");
          int param = rset.getInt("param");

          String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(time));
          _diaryentry.set("date", date);

          if (action == ACTION_RAID_KILLED) {
            L2NpcTemplate template = NpcData.getInstance().getTemplate(param);
            if (template != null) {
              _diaryentry.set("action", template.getName() + " was defeated");
            }
          } else if (action == ACTION_HERO_GAINED) {
            _diaryentry.set("action", "Gained Hero status");
          } else if (action == ACTION_CASTLE_TAKEN) {
            Castle castle = CastleManager.getInstance().getCastleById(param);
            if (castle != null) {
              _diaryentry.set("action", castle.getName() + " Castle was successfuly taken");
            }
          }
          _diary.add(_diaryentry);
          diaryentries++;
        }
      }
      _herodiary.put(charId, _diary);

      _log.info(
          "Hero System: Loaded "
              + diaryentries
              + " diary entries for Hero: "
              + CharNameTable.getInstance().getNameById(charId));
    } catch (SQLException e) {
      _log.log(Level.WARNING, "Hero System: Couldnt load Hero Diary for CharId: " + charId, e);
    }
  }
예제 #2
0
  public void setCastleTaken(int charId, int castleId) {
    setDiaryData(charId, ACTION_CASTLE_TAKEN, castleId);

    Castle castle = CastleManager.getInstance().getCastleById(castleId);
    if ((castle != null) && _herodiary.containsKey(charId)) {
      // Get Data
      List<StatsSet> _list = _herodiary.get(charId);
      // Clear old data
      _herodiary.remove(charId);
      // Prepare new data
      StatsSet _diaryentry = new StatsSet();
      String date =
          (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(System.currentTimeMillis()));
      _diaryentry.set("date", date);
      _diaryentry.set("action", castle.getName() + " Castle was successfuly taken");
      // Add to old list
      _list.add(_diaryentry);
      // Put new list into diary
      _herodiary.put(charId, _list);
    }
  }