コード例 #1
0
ファイル: Hero.java プロジェクト: LucusAngel/L2J_Server_BETA
  /**
   * Claims the hero status for the given player.
   *
   * @param player the player to become hero
   */
  public void claimHero(L2PcInstance player) {
    _heroes.get(player.getObjectId()).set(CLAIMED, true);

    final L2Clan clan = player.getClan();
    if ((clan != null) && (clan.getLevel() >= 5)) {
      clan.addReputationScore(Config.HERO_POINTS, true);
      final SystemMessage sm =
          SystemMessage.getSystemMessage(
              SystemMessageId.CLAN_MEMBER_C1_BECAME_HERO_AND_GAINED_S2_REPUTATION_POINTS);
      sm.addString(CharNameTable.getInstance().getNameById(player.getObjectId()));
      sm.addInt(Config.HERO_POINTS);
      clan.broadcastToOnlineMembers(sm);
    }

    player.setHero(true);
    player.broadcastPacket(new SocialAction(player.getObjectId(), 20016)); // Hero Animation
    player.sendPacket(new UserInfo(player));
    player.sendPacket(new ExBrExtraUserInfo(player));
    player.broadcastUserInfo();
    // Set Gained hero and reload data
    setHeroGained(player.getObjectId());
    loadFights(player.getObjectId());
    loadDiary(player.getObjectId());
    _heroMessage.put(player.getObjectId(), "");

    updateHeroes(false);
  }
コード例 #2
0
  final void onAuctionFinished(final ItemAuction auction) {
    auction.broadcastToAllBiddersInternal(
        new SystemMessage(SystemMessageId.S1_AUCTION_ENDED).addNumber(auction.getAuctionId()));

    final ItemAuctionBid bid = auction.getHighestBid();
    if (bid != null) {
      final L2ItemInstance item = auction.createNewItemInstance();
      final L2PcInstance player = bid.getPlayer();
      if (player != null) {
        player.getWarehouse().addItem("ItemAuction", item, null, null);
        player.sendPacket(
            new SystemMessage(SystemMessageId.WON_BID_ITEM_CAN_BE_FOUND_IN_WAREHOUSE));

        _log.log(
            Level.INFO,
            "L2ItemAuctionInstance: Auction "
                + auction.getAuctionId()
                + " has finished. Highest bid by "
                + player.getName()
                + " for instance "
                + _instanceId);
      } else {
        item.setOwnerId(bid.getPlayerObjId());
        item.setLocation(ItemLocation.WAREHOUSE);
        item.updateDatabase();
        L2World.getInstance().removeObject(item);

        _log.log(
            Level.INFO,
            "L2ItemAuctionInstance: Auction "
                + auction.getAuctionId()
                + " has finished. Highest bid by "
                + CharNameTable.getInstance().getNameById(bid.getPlayerObjId())
                + " for instance "
                + _instanceId);
      }

      // Clean all canceled bids
      auction.clearCanceledBids();
    } else {
      _log.log(
          Level.INFO,
          "L2ItemAuctionInstance: Auction "
              + auction.getAuctionId()
              + " has finished. There have not been any bid for instance "
              + _instanceId);
    }
  }
コード例 #3
0
ファイル: Hero.java プロジェクト: LucusAngel/L2J_Server_BETA
  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);
    }
  }
コード例 #4
0
ファイル: Hero.java プロジェクト: LucusAngel/L2J_Server_BETA
  public void showHeroFights(L2PcInstance activeChar, int heroclass, int charid, int page) {
    final int perpage = 20;
    int _win = 0;
    int _loss = 0;
    int _draw = 0;

    if (_herofights.containsKey(charid)) {
      List<StatsSet> _list = _herofights.get(charid);

      final NpcHtmlMessage FightReply = new NpcHtmlMessage();
      final String htmContent =
          HtmCache.getInstance()
              .getHtm(activeChar.getHtmlPrefix(), "data/html/olympiad/herohistory.htm");
      if (htmContent != null) {
        FightReply.setHtml(htmContent);
        FightReply.replace("%heroname%", CharNameTable.getInstance().getNameById(charid));

        if (!_list.isEmpty()) {
          if (_herocounts.containsKey(charid)) {
            StatsSet _herocount = _herocounts.get(charid);
            _win = _herocount.getInt("victory");
            _loss = _herocount.getInt("loss");
            _draw = _herocount.getInt("draw");
          }

          boolean color = true;
          final StringBuilder fList = new StringBuilder(500);
          int counter = 0;
          int breakat = 0;
          for (int i = ((page - 1) * perpage); i < _list.size(); i++) {
            breakat = i;
            StatsSet fight = _list.get(i);
            StringUtil.append(fList, "<tr><td>");
            if (color) {
              StringUtil.append(fList, "<table width=270 bgcolor=\"131210\">");
            } else {
              StringUtil.append(fList, "<table width=270>");
            }
            StringUtil.append(
                fList,
                "<tr><td width=220><font color=\"LEVEL\">"
                    + fight.getString("start")
                    + "</font>&nbsp;&nbsp;"
                    + fight.getString("result")
                    + "</td><td width=50 align=right>"
                    + (fight.getInt("classed") > 0
                        ? "<font color=\"FFFF99\">cls</font>"
                        : "<font color=\"999999\">non-cls<font>")
                    + "</td></tr>");
            StringUtil.append(
                fList,
                "<tr><td width=220>vs "
                    + fight.getString("oponent")
                    + " ("
                    + fight.getString("oponentclass")
                    + ")</td><td width=50 align=right>("
                    + fight.getString("time")
                    + ")</td></tr>");
            StringUtil.append(fList, "<tr><td colspan=2>&nbsp;</td></tr></table>");
            StringUtil.append(fList, "</td></tr>");
            color = !color;
            counter++;
            if (counter >= perpage) {
              break;
            }
          }

          if (breakat < (_list.size() - 1)) {
            FightReply.replace(
                "%buttprev%",
                "<button value=\"Prev\" action=\"bypass _match?class="
                    + heroclass
                    + "&page="
                    + (page + 1)
                    + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
          } else {
            FightReply.replace("%buttprev%", "");
          }

          if (page > 1) {
            FightReply.replace(
                "%buttnext%",
                "<button value=\"Next\" action=\"bypass _match?class="
                    + heroclass
                    + "&page="
                    + (page - 1)
                    + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
          } else {
            FightReply.replace("%buttnext%", "");
          }

          FightReply.replace("%list%", fList.toString());
        } else {
          FightReply.replace("%list%", "");
          FightReply.replace("%buttprev%", "");
          FightReply.replace("%buttnext%", "");
        }

        FightReply.replace("%win%", String.valueOf(_win));
        FightReply.replace("%draw%", String.valueOf(_draw));
        FightReply.replace("%loos%", String.valueOf(_loss));

        activeChar.sendPacket(FightReply);
      }
    }
  }
コード例 #5
0
ファイル: Hero.java プロジェクト: LucusAngel/L2J_Server_BETA
  public void showHeroDiary(L2PcInstance activeChar, int heroclass, int charid, int page) {
    final int perpage = 10;

    if (_herodiary.containsKey(charid)) {
      List<StatsSet> _mainlist = _herodiary.get(charid);
      final NpcHtmlMessage DiaryReply = new NpcHtmlMessage();
      final String htmContent =
          HtmCache.getInstance()
              .getHtm(activeChar.getHtmlPrefix(), "data/html/olympiad/herodiary.htm");
      if ((htmContent != null) && _heroMessage.containsKey(charid)) {
        DiaryReply.setHtml(htmContent);
        DiaryReply.replace("%heroname%", CharNameTable.getInstance().getNameById(charid));
        DiaryReply.replace("%message%", _heroMessage.get(charid));
        DiaryReply.disableValidation();

        if (!_mainlist.isEmpty()) {
          FastList<StatsSet> _list = FastList.newInstance();
          _list.addAll(_mainlist);
          Collections.reverse(_list);

          boolean color = true;
          final StringBuilder fList = new StringBuilder(500);
          int counter = 0;
          int breakat = 0;
          for (int i = ((page - 1) * perpage); i < _list.size(); i++) {
            breakat = i;
            StatsSet _diaryentry = _list.get(i);
            StringUtil.append(fList, "<tr><td>");
            if (color) {
              StringUtil.append(fList, "<table width=270 bgcolor=\"131210\">");
            } else {
              StringUtil.append(fList, "<table width=270>");
            }
            StringUtil.append(
                fList,
                "<tr><td width=270><font color=\"LEVEL\">"
                    + _diaryentry.getString("date")
                    + ":xx</font></td></tr>");
            StringUtil.append(
                fList, "<tr><td width=270>" + _diaryentry.getString("action") + "</td></tr>");
            StringUtil.append(fList, "<tr><td>&nbsp;</td></tr></table>");
            StringUtil.append(fList, "</td></tr>");
            color = !color;
            counter++;
            if (counter >= perpage) {
              break;
            }
          }

          if (breakat < (_list.size() - 1)) {
            DiaryReply.replace(
                "%buttprev%",
                "<button value=\"Prev\" action=\"bypass _diary?class="
                    + heroclass
                    + "&page="
                    + (page + 1)
                    + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
          } else {
            DiaryReply.replace("%buttprev%", "");
          }

          if (page > 1) {
            DiaryReply.replace(
                "%buttnext%",
                "<button value=\"Next\" action=\"bypass _diary?class="
                    + heroclass
                    + "&page="
                    + (page - 1)
                    + "\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
          } else {
            DiaryReply.replace("%buttnext%", "");
          }

          DiaryReply.replace("%list%", fList.toString());

          FastList.recycle(_list);
        } else {
          DiaryReply.replace("%list%", "");
          DiaryReply.replace("%buttprev%", "");
          DiaryReply.replace("%buttnext%", "");
        }

        activeChar.sendPacket(DiaryReply);
      }
    }
  }
コード例 #6
0
ファイル: Hero.java プロジェクト: LucusAngel/L2J_Server_BETA
  public void loadFights(int charId) {
    final List<StatsSet> _fights = new FastList<>();
    StatsSet _herocountdata = new StatsSet();
    Calendar _data = Calendar.getInstance();
    _data.set(Calendar.DAY_OF_MONTH, 1);
    _data.set(Calendar.HOUR_OF_DAY, 0);
    _data.set(Calendar.MINUTE, 0);
    _data.set(Calendar.MILLISECOND, 0);

    long from = _data.getTimeInMillis();
    int numberoffights = 0;
    int _victorys = 0;
    int _losses = 0;
    int _draws = 0;

    try (Connection con = L2DatabaseFactory.getInstance().getConnection();
        PreparedStatement statement =
            con.prepareStatement(
                "SELECT * FROM olympiad_fights WHERE (charOneId=? OR charTwoId=?) AND start<? ORDER BY start ASC")) {
      statement.setInt(1, charId);
      statement.setInt(2, charId);
      statement.setLong(3, from);
      try (ResultSet rset = statement.executeQuery()) {
        int charOneId;
        int charOneClass;
        int charTwoId;
        int charTwoClass;
        int winner;
        long start;
        int time;
        int classed;
        while (rset.next()) {
          charOneId = rset.getInt("charOneId");
          charOneClass = rset.getInt("charOneClass");
          charTwoId = rset.getInt("charTwoId");
          charTwoClass = rset.getInt("charTwoClass");
          winner = rset.getInt("winner");
          start = rset.getLong("start");
          time = rset.getInt("time");
          classed = rset.getInt("classed");

          if (charId == charOneId) {
            String name = CharNameTable.getInstance().getNameById(charTwoId);
            String cls = ClassListData.getInstance().getClass(charTwoClass).getClientCode();
            if ((name != null) && (cls != null)) {
              StatsSet fight = new StatsSet();
              fight.set("oponent", name);
              fight.set("oponentclass", cls);

              fight.set("time", calcFightTime(time));
              String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(start));
              fight.set("start", date);

              fight.set("classed", classed);
              if (winner == 1) {
                fight.set("result", "<font color=\"00ff00\">victory</font>");
                _victorys++;
              } else if (winner == 2) {
                fight.set("result", "<font color=\"ff0000\">loss</font>");
                _losses++;
              } else if (winner == 0) {
                fight.set("result", "<font color=\"ffff00\">draw</font>");
                _draws++;
              }

              _fights.add(fight);

              numberoffights++;
            }
          } else if (charId == charTwoId) {
            String name = CharNameTable.getInstance().getNameById(charOneId);
            String cls = ClassListData.getInstance().getClass(charOneClass).getClientCode();
            if ((name != null) && (cls != null)) {
              StatsSet fight = new StatsSet();
              fight.set("oponent", name);
              fight.set("oponentclass", cls);

              fight.set("time", calcFightTime(time));
              String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(start));
              fight.set("start", date);

              fight.set("classed", classed);
              if (winner == 1) {
                fight.set("result", "<font color=\"ff0000\">loss</font>");
                _losses++;
              } else if (winner == 2) {
                fight.set("result", "<font color=\"00ff00\">victory</font>");
                _victorys++;
              } else if (winner == 0) {
                fight.set("result", "<font color=\"ffff00\">draw</font>");
                _draws++;
              }

              _fights.add(fight);

              numberoffights++;
            }
          }
        }
      }

      _herocountdata.set("victory", _victorys);
      _herocountdata.set("draw", _draws);
      _herocountdata.set("loss", _losses);

      _herocounts.put(charId, _herocountdata);
      _herofights.put(charId, _fights);

      _log.info(
          "Hero System: Loaded "
              + numberoffights
              + " fights for Hero: "
              + CharNameTable.getInstance().getNameById(charId));
    } catch (SQLException e) {
      _log.log(
          Level.WARNING, "Hero System: Couldnt load Hero fights history for CharId: " + charId, e);
    }
  }
コード例 #7
0
  @Override
  protected void runImpl() {
    // Last Verified: May 30, 2009 - Gracia Final - Players are able to create characters with names
    // consisting of as little as 1,2,3 letter/number combinations.
    if ((_name.length() < 1) || (_name.length() > 16)) {
      if (Config.DEBUG)
        _log.fine(
            "Character Creation Failure: Character name "
                + _name
                + " is invalid. Message generated: Your title cannot exceed 16 characters in length. Please try again.");

      sendPacket(new CharCreateFail(CharCreateFail.REASON_16_ENG_CHARS));
      return;
    }

    if (Config.FORBIDDEN_NAMES.length > 1) {
      for (String st : Config.FORBIDDEN_NAMES) {
        if (_name.toLowerCase().contains(st.toLowerCase())) {
          sendPacket(new CharCreateFail(CharCreateFail.REASON_INCORRECT_NAME));
          return;
        }
      }
    }

    // Last Verified: May 30, 2009 - Gracia Final
    if (!Util.isAlphaNumeric(_name) || !isValidName(_name)) {
      if (Config.DEBUG)
        _log.fine(
            "Character Creation Failure: Character name "
                + _name
                + " is invalid. Message generated: Incorrect name. Please try again.");

      sendPacket(new CharCreateFail(CharCreateFail.REASON_INCORRECT_NAME));
      return;
    }

    if (_face > 2 || _face < 0) {
      _log.warning(
          "Character Creation Failure: Character face "
              + _face
              + " is invalid. Possible client hack. "
              + getClient());

      sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
      return;
    }

    if (_hairStyle < 0 || (_sex == 0 && _hairStyle > 4) || (_sex != 0 && _hairStyle > 6)) {
      _log.warning(
          "Character Creation Failure: Character hair style "
              + _hairStyle
              + " is invalid. Possible client hack. "
              + getClient());

      sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
      return;
    }

    if (_hairColor > 3 || _hairColor < 0) {
      _log.warning(
          "Character Creation Failure: Character hair color "
              + _hairColor
              + " is invalid. Possible client hack. "
              + getClient());

      sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
      return;
    }

    L2PcInstance newChar = null;
    L2PcTemplate template = null;

    /*
     * DrHouse: Since checks for duplicate names are done using SQL, lock must be held until data is written to DB as well.
     */
    synchronized (CharNameTable.getInstance()) {
      if (CharNameTable.getInstance().accountCharNumber(getClient().getAccountName())
              >= Config.MAX_CHARACTERS_NUMBER_PER_ACCOUNT
          && Config.MAX_CHARACTERS_NUMBER_PER_ACCOUNT != 0) {
        if (Config.DEBUG) _log.fine("Max number of characters reached. Creation failed.");

        sendPacket(new CharCreateFail(CharCreateFail.REASON_TOO_MANY_CHARACTERS));
        return;
      } else if (CharNameTable.getInstance().doesCharNameExist(_name)) {
        if (Config.DEBUG)
          _log.fine(
              "Character Creation Failure: Message generated: You cannot create another character. Please delete the existing character and try again.");

        sendPacket(new CharCreateFail(CharCreateFail.REASON_NAME_ALREADY_EXISTS));
        return;
      }

      template = CharTemplateTable.getInstance().getTemplate(_classId);

      if (template == null || template.classBaseLevel > 1) {
        if (Config.DEBUG)
          _log.fine(
              "Character Creation Failure: "
                  + _name
                  + " classId: "
                  + _classId
                  + " Template: "
                  + template
                  + " Message generated: Your character creation has failed.");

        sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
        return;
      }

      int objectId = IdFactory.getInstance().getNextId();
      newChar =
          L2PcInstance.create(
              objectId,
              template,
              getClient().getAccountName(),
              _name,
              _hairStyle,
              _hairColor,
              _face,
              _sex != 0);
    }

    newChar.setCurrentHp(template.baseHpMax);
    newChar.setCurrentCp(template.baseCpMax);
    newChar.setCurrentMp(template.baseMpMax);
    // newChar.setMaxLoad(template.baseLoad);

    CharCreateOk cco = new CharCreateOk();
    sendPacket(cco);

    initNewChar(getClient(), newChar);

    LogRecord record = new LogRecord(Level.INFO, "Created new character");
    record.setParameters(new Object[] {newChar, this.getClient()});
    _logAccounting.log(record);
  }