private void processHeros(PreparedStatement ps, int charId, StatsSet hero) throws SQLException { ps.setInt(1, charId); try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { int clanId = rs.getInt("clanid"); int allyId = rs.getInt("allyId"); String clanName = ""; String allyName = ""; int clanCrest = 0; int allyCrest = 0; if (clanId > 0) { clanName = ClanTable.getInstance().getClan(clanId).getName(); clanCrest = ClanTable.getInstance().getClan(clanId).getCrestId(); if (allyId > 0) { allyName = ClanTable.getInstance().getClan(clanId).getAllyName(); allyCrest = ClanTable.getInstance().getClan(clanId).getAllyCrestId(); } } hero.set(CLAN_CREST, clanCrest); hero.set(CLAN_NAME, clanName); hero.set(ALLY_CREST, allyCrest); hero.set(ALLY_NAME, allyName); } ps.clearParameters(); } }
private static final void dissolveClan(L2PcInstance player, int clanId) { if (!player.isClanLeader()) { player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT)); return; } final L2Clan clan = player.getClan(); if (clan.getAllyId() != 0) { player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISPERSE_THE_CLANS_IN_ALLY)); return; } if (clan.isAtWar()) { player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISSOLVE_WHILE_IN_WAR)); return; } if (clan.getHasCastle() != 0 || clan.getHasHideout() != 0 || clan.getHasFort() != 0) { player.sendPacket( new SystemMessage(SystemMessageId.CANNOT_DISSOLVE_WHILE_OWNING_CLAN_HALL_OR_CASTLE)); return; } for (Castle castle : CastleManager.getInstance().getCastles()) { if (SiegeManager.getInstance().checkIsRegistered(clan, castle.getCastleId())) { player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISSOLVE_WHILE_IN_SIEGE)); return; } } for (Fort fort : FortManager.getInstance().getForts()) { if (FortSiegeManager.getInstance().checkIsRegistered(clan, fort.getFortId())) { player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISSOLVE_WHILE_IN_SIEGE)); return; } } if (player.isInsideZone(L2PcInstance.ZONE_SIEGE)) { player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISSOLVE_WHILE_IN_SIEGE)); return; } if (clan.getDissolvingExpiryTime() > System.currentTimeMillis()) { player.sendPacket(new SystemMessage(SystemMessageId.DISSOLUTION_IN_PROGRESS)); return; } clan.setDissolvingExpiryTime( System.currentTimeMillis() + Config.ALT_CLAN_DISSOLVE_DAYS * 86400000L); // 24*60*60*1000 = 86400000 clan.updateClanInDB(); ClanTable.getInstance().scheduleRemoveClan(clan.getClanId()); // The clan leader should take the XP penalty of a full death. player.deathPenalty(false, false, false); }
public void convertOldPedgeFiles() { File dir = new File(Config.DATAPACK_ROOT, "data/crests/"); File[] files = dir.listFiles(new OldPledgeFilter()); for (File file : files) { int clanId = Integer.parseInt(file.getName().substring(7, file.getName().length() - 4)); _log.info("Found old crest file \"" + file.getName() + "\" for clanId " + clanId); int newId = IdFactory.getInstance().getNextId(); L2Clan clan = ClanTable.getInstance().getClan(clanId); if (clan != null) { removeOldPledgeCrest(clan.getCrestId()); file.renameTo(new File(Config.DATAPACK_ROOT, "data/crests/Crest_" + newId + ".bmp")); _log.info("Renamed Clan crest to new format: Crest_" + newId + ".bmp"); Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?"); statement.setInt(1, newId); statement.setInt(2, clan.getClanId()); statement.executeUpdate(); statement.close(); } catch (SQLException e) { _log.log(Level.WARNING, "Could not update the crest id:" + e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } clan.setCrestId(newId); } else { _log.info("Clan Id: " + clanId + " does not exist in table.. deleting."); file.delete(); } } }
public void updateHeroes(boolean setDefault) { try (Connection con = L2DatabaseFactory.getInstance().getConnection()) { if (setDefault) { try (PreparedStatement update_all = con.prepareStatement(UPDATE_ALL)) { update_all.execute(); } } else { StatsSet hero; int heroId; for (Entry<Integer, StatsSet> entry : _heroes.entrySet()) { hero = entry.getValue(); heroId = entry.getKey(); if (_completeHeroes.isEmpty() || !_completeHeroes.containsKey(heroId)) { try (PreparedStatement insert = con.prepareStatement(INSERT_HERO)) { insert.setInt(1, heroId); insert.setInt(2, hero.getInt(Olympiad.CLASS_ID)); insert.setInt(3, hero.getInt(COUNT)); insert.setInt(4, hero.getInt(PLAYED)); insert.setString(5, String.valueOf(hero.getBoolean(CLAIMED))); insert.execute(); insert.close(); } try (PreparedStatement statement = con.prepareStatement(GET_CLAN_ALLY)) { statement.setInt(1, heroId); try (ResultSet rset = statement.executeQuery()) { if (rset.next()) { int clanId = rset.getInt("clanid"); int allyId = rset.getInt("allyId"); String clanName = ""; String allyName = ""; int clanCrest = 0; int allyCrest = 0; if (clanId > 0) { clanName = ClanTable.getInstance().getClan(clanId).getName(); clanCrest = ClanTable.getInstance().getClan(clanId).getCrestId(); if (allyId > 0) { allyName = ClanTable.getInstance().getClan(clanId).getAllyName(); allyCrest = ClanTable.getInstance().getClan(clanId).getAllyCrestId(); } } hero.set(CLAN_CREST, clanCrest); hero.set(CLAN_NAME, clanName); hero.set(ALLY_CREST, allyCrest); hero.set(ALLY_NAME, allyName); } } } _heroes.remove(heroId); _heroes.put(heroId, hero); _completeHeroes.put(heroId, hero); } else { try (PreparedStatement statement = con.prepareStatement(UPDATE_HERO)) { statement.setInt(1, hero.getInt(COUNT)); statement.setInt(2, hero.getInt(PLAYED)); statement.setString(3, String.valueOf(hero.getBoolean(CLAIMED))); statement.setInt(4, heroId); statement.execute(); } } } } } catch (SQLException e) { _log.log(Level.WARNING, "Hero System: Couldnt update Heroes", e); } }
@Override public void onBypassFeedback(L2PcInstance player, String command) { String[] commandStr = command.split(" "); String actualCommand = commandStr[0]; // Get actual command String cmdParams = ""; String cmdParams2 = ""; if (commandStr.length >= 2) cmdParams = commandStr[1]; if (commandStr.length >= 3) cmdParams2 = commandStr[2]; if (actualCommand.equalsIgnoreCase("create_clan")) { if (cmdParams.isEmpty()) return; ClanTable.getInstance().createClan(player, cmdParams); } else if (actualCommand.equalsIgnoreCase("create_academy")) { if (cmdParams.isEmpty()) return; createSubPledge(player, cmdParams, null, L2Clan.SUBUNIT_ACADEMY, 5); } else if (actualCommand.equalsIgnoreCase("rename_pledge")) { if (cmdParams.isEmpty() || cmdParams2.isEmpty()) return; renameSubPledge(player, Integer.valueOf(cmdParams), cmdParams2); } else if (actualCommand.equalsIgnoreCase("create_royal")) { if (cmdParams.isEmpty()) return; createSubPledge(player, cmdParams, cmdParams2, L2Clan.SUBUNIT_ROYAL1, 6); } else if (actualCommand.equalsIgnoreCase("create_knight")) { if (cmdParams.isEmpty()) return; createSubPledge(player, cmdParams, cmdParams2, L2Clan.SUBUNIT_KNIGHT1, 7); } else if (actualCommand.equalsIgnoreCase("assign_subpl_leader")) { if (cmdParams.isEmpty()) return; assignSubPledgeLeader(player, cmdParams, cmdParams2); } else if (actualCommand.equalsIgnoreCase("create_ally")) { if (cmdParams.isEmpty()) return; if (player.getClan() == null) player.sendPacket(new SystemMessage(SystemMessageId.ONLY_CLAN_LEADER_CREATE_ALLIANCE)); else player.getClan().createAlly(player, cmdParams); } else if (actualCommand.equalsIgnoreCase("dissolve_ally")) { player.getClan().dissolveAlly(player); } else if (actualCommand.equalsIgnoreCase("dissolve_clan")) { dissolveClan(player, player.getClanId()); } else if (actualCommand.equalsIgnoreCase("change_clan_leader")) { if (cmdParams.isEmpty()) return; changeClanLeader(player, cmdParams); } else if (actualCommand.equalsIgnoreCase("recover_clan")) { recoverClan(player, player.getClanId()); } else if (actualCommand.equalsIgnoreCase("increase_clan_level")) { if (player.getClan().levelUpClan(player)) { player.broadcastPacket(new MagicSkillUse(player, 5103, 1, 0, 0)); player.broadcastPacket(new MagicSkillLaunched(player, 5103, 1)); } } else if (actualCommand.equalsIgnoreCase("learn_clan_skills")) { showPledgeSkillList(player); } else if (command.startsWith("Subclass")) { // Subclasses may not be changed while a skill is in use. if (player.isCastingNow() || player.isAllSkillsDisabled()) { player.sendPacket( new SystemMessage(SystemMessageId.SUBCLASS_NO_CHANGE_OR_CREATE_WHILE_SKILL_IN_USE)); return; } NpcHtmlMessage html = new NpcHtmlMessage(getObjectId()); if (player.getTransformation() != null) { html.setFile(player.getHtmlPrefix(), "data/html/villagemaster/SubClass_NoTransformed.htm"); player.sendPacket(html); return; } int cmdChoice = 0; int paramOne = 0; int paramTwo = 0; try { cmdChoice = Integer.parseInt(command.substring(9, 10).trim()); int endIndex = command.indexOf(' ', 11); if (endIndex == -1) endIndex = command.length(); paramOne = Integer.parseInt(command.substring(11, endIndex).trim()); if (command.length() > endIndex) paramTwo = Integer.parseInt(command.substring(endIndex).trim()); } catch (Exception NumberFormatException) { } switch (cmdChoice) { case 0: // Subclass change menu html.setFile(player.getHtmlPrefix(), getSubClassMenu(player.getRace())); break; case 1: // Add Subclass - Initial // Avoid giving player an option to add a new sub class, if they have three already. if (player.getTotalSubClasses() >= Config.MAX_SUBCLASS) { html.setFile(player.getHtmlPrefix(), getSubClassFail()); break; } html.setFile(player.getHtmlPrefix(), "data/html/villagemaster/SubClass_Add.htm"); final StringBuilder content1 = StringUtil.startAppend(200); Set<PlayerClass> subsAvailable = getAvailableSubClasses(player); if (subsAvailable != null && !subsAvailable.isEmpty()) { for (PlayerClass subClass : subsAvailable) { StringUtil.append( content1, "<a action=\"bypass -h npc_%objectId%_Subclass 4 ", String.valueOf(subClass.ordinal()), "\" msg=\"1268;", formatClassForDisplay(subClass), "\">", formatClassForDisplay(subClass), "</a><br>"); } } else { // TODO: Retail message player.sendMessage("There are no sub classes available at this time."); return; } html.replace("%list%", content1.toString()); break; case 2: // Change Class - Initial if (player.getSubClasses().isEmpty()) html.setFile(player.getHtmlPrefix(), "data/html/villagemaster/SubClass_ChangeNo.htm"); else { final StringBuilder content2 = StringUtil.startAppend(200); if (checkVillageMaster(player.getBaseClass())) { StringUtil.append( content2, "<a action=\"bypass -h npc_%objectId%_Subclass 5 0\">", CharTemplateTable.getInstance().getClassNameById(player.getBaseClass()), "</a><br>"); } for (Iterator<SubClass> subList = iterSubClasses(player); subList.hasNext(); ) { SubClass subClass = subList.next(); if (checkVillageMaster(subClass.getClassDefinition())) { StringUtil.append( content2, "<a action=\"bypass -h npc_%objectId%_Subclass 5 ", String.valueOf(subClass.getClassIndex()), "\">", formatClassForDisplay(subClass.getClassDefinition()), "</a><br>"); } } if (content2.length() > 0) { html.setFile(player.getHtmlPrefix(), "data/html/villagemaster/SubClass_Change.htm"); html.replace("%list%", content2.toString()); } else html.setFile( player.getHtmlPrefix(), "data/html/villagemaster/SubClass_ChangeNotFound.htm"); } break; case 3: // Change/Cancel Subclass - Initial if (player.getSubClasses() == null || player.getSubClasses().isEmpty()) { html.setFile( player.getHtmlPrefix(), "data/html/villagemaster/SubClass_ModifyEmpty.htm"); break; } // custom value if (player.getTotalSubClasses() > 3) { html.setFile( player.getHtmlPrefix(), "data/html/villagemaster/SubClass_ModifyCustom.htm"); final StringBuilder content3 = StringUtil.startAppend(200); int classIndex = 1; for (Iterator<SubClass> subList = iterSubClasses(player); subList.hasNext(); ) { SubClass subClass = subList.next(); StringUtil.append( content3, "Sub-class ", String.valueOf(classIndex++), "<br>", "<a action=\"bypass -h npc_%objectId%_Subclass 6 ", String.valueOf(subClass.getClassIndex()), "\">", CharTemplateTable.getInstance().getClassNameById(subClass.getClassId()), "</a><br>"); } html.replace("%list%", content3.toString()); } else { // retail html contain only 3 subclasses html.setFile(player.getHtmlPrefix(), "data/html/villagemaster/SubClass_Modify.htm"); if (player.getSubClasses().containsKey(1)) html.replace( "%sub1%", CharTemplateTable.getInstance() .getClassNameById(player.getSubClasses().get(1).getClassId())); else html.replace( "<a action=\"bypass -h npc_%objectId%_Subclass 6 1\">%sub1%</a><br>", ""); if (player.getSubClasses().containsKey(2)) html.replace( "%sub2%", CharTemplateTable.getInstance() .getClassNameById(player.getSubClasses().get(2).getClassId())); else html.replace( "<a action=\"bypass -h npc_%objectId%_Subclass 6 2\">%sub2%</a><br>", ""); if (player.getSubClasses().containsKey(3)) html.replace( "%sub3%", CharTemplateTable.getInstance() .getClassNameById(player.getSubClasses().get(3).getClassId())); else html.replace( "<a action=\"bypass -h npc_%objectId%_Subclass 6 3\">%sub3%</a><br>", ""); } break; case 4: // Add Subclass - Action (Subclass 4 x[x]) /* * If the character is less than level 75 on any of their previously chosen * classes then disallow them to change to their most recently added sub-class choice. */ if (!player.getFloodProtectors().getSubclass().tryPerformAction("add subclass")) { _log.warning( "Player " + player.getName() + " has performed a subclass change too fast"); return; } boolean allowAddition = true; if (player.getTotalSubClasses() >= Config.MAX_SUBCLASS) allowAddition = false; if (player.getLevel() < 75) allowAddition = false; if (allowAddition) { if (!player.getSubClasses().isEmpty()) { for (Iterator<SubClass> subList = iterSubClasses(player); subList.hasNext(); ) { SubClass subClass = subList.next(); if (subClass.getLevel() < 75) { allowAddition = false; break; } } } } /* * If quest checking is enabled, verify if the character has completed the Mimir's Elixir (Path to Subclass) * and Fate's Whisper (A Grade Weapon) quests by checking for instances of their unique reward items. * * If they both exist, remove both unique items and continue with adding the sub-class. */ if (allowAddition && !Config.ALT_GAME_SUBCLASS_WITHOUT_QUESTS) allowAddition = checkQuests(player); if (allowAddition && isValidNewSubClass(player, paramOne)) { if (!player.addSubClass(paramOne, player.getTotalSubClasses() + 1)) return; player.setActiveClass(player.getTotalSubClasses()); html.setFile(player.getHtmlPrefix(), "data/html/villagemaster/SubClass_AddOk.htm"); player.sendPacket( new SystemMessage(SystemMessageId.ADD_NEW_SUBCLASS)); // Subclass added. } else html.setFile(player.getHtmlPrefix(), getSubClassFail()); break; case 5: // Change Class - Action /* * If the character is less than level 75 on any of their previously chosen * classes then disallow them to change to their most recently added sub-class choice. * * Note: paramOne = classIndex */ if (!player.getFloodProtectors().getSubclass().tryPerformAction("change class")) { _log.warning( "Player " + player.getName() + " has performed a subclass change too fast"); return; } if (player.getClassIndex() == paramOne) { html.setFile(player.getHtmlPrefix(), "data/html/villagemaster/SubClass_Current.htm"); break; } if (paramOne == 0) { if (!checkVillageMaster(player.getBaseClass())) return; } else { try { if (!checkVillageMaster(player.getSubClasses().get(paramOne).getClassDefinition())) return; } catch (NullPointerException e) { return; } } player.setActiveClass(paramOne); player.sendPacket( new SystemMessage( SystemMessageId.SUBCLASS_TRANSFER_COMPLETED)); // Transfer completed. return; case 6: // Change/Cancel Subclass - Choice // validity check if (paramOne < 1 || paramOne > Config.MAX_SUBCLASS) return; subsAvailable = getAvailableSubClasses(player); // another validity check if (subsAvailable == null || subsAvailable.isEmpty()) { // TODO: Retail message player.sendMessage("There are no sub classes available at this time."); return; } final StringBuilder content6 = StringUtil.startAppend(200); for (PlayerClass subClass : subsAvailable) { StringUtil.append( content6, "<a action=\"bypass -h npc_%objectId%_Subclass 7 ", String.valueOf(paramOne), " ", String.valueOf(subClass.ordinal()), "\" msg=\"1445;", "\">", formatClassForDisplay(subClass), "</a><br>"); } switch (paramOne) { case 1: html.setFile( player.getHtmlPrefix(), "data/html/villagemaster/SubClass_ModifyChoice1.htm"); break; case 2: html.setFile( player.getHtmlPrefix(), "data/html/villagemaster/SubClass_ModifyChoice2.htm"); break; case 3: html.setFile( player.getHtmlPrefix(), "data/html/villagemaster/SubClass_ModifyChoice3.htm"); break; default: html.setFile( player.getHtmlPrefix(), "data/html/villagemaster/SubClass_ModifyChoice.htm"); } html.replace("%list%", content6.toString()); break; case 7: // Change Subclass - Action /* * Warning: the information about this subclass will be removed from the * subclass list even if false! */ if (!player.getFloodProtectors().getSubclass().tryPerformAction("change class")) { _log.warning( "Player " + player.getName() + " has performed a subclass change too fast"); return; } if (!isValidNewSubClass(player, paramTwo)) return; if (player.modifySubClass(paramOne, paramTwo)) { player.abortCast(); player .stopAllEffectsExceptThoseThatLastThroughDeath(); // all effects from old subclass // stopped! player.stopCubics(); player.setActiveClass(paramOne); html.setFile(player.getHtmlPrefix(), "data/html/villagemaster/SubClass_ModifyOk.htm"); html.replace("%name%", CharTemplateTable.getInstance().getClassNameById(paramTwo)); player.sendPacket( new SystemMessage(SystemMessageId.ADD_NEW_SUBCLASS)); // Subclass added. } else { /* * This isn't good! modifySubClass() removed subclass from memory * we must update _classIndex! Else IndexOutOfBoundsException can turn * up some place down the line along with other seemingly unrelated * problems. */ player.setActiveClass( 0); // Also updates _classIndex plus switching _classid to baseclass. player.sendMessage( "The sub class could not be added, you have been reverted to your base class."); return; } break; } html.replace("%objectId%", String.valueOf(getObjectId())); player.sendPacket(html); } else { // this class dont know any other commands, let forward // the command to the parent class super.onBypassFeedback(player, command); } }
private static final void createSubPledge( L2PcInstance player, String clanName, String leaderName, int pledgeType, int minClanLvl) { if (!player.isClanLeader()) { player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT)); return; } final L2Clan clan = player.getClan(); if (clan.getLevel() < minClanLvl) { if (pledgeType == L2Clan.SUBUNIT_ACADEMY) player.sendPacket( new SystemMessage( SystemMessageId.YOU_DO_NOT_MEET_CRITERIA_IN_ORDER_TO_CREATE_A_CLAN_ACADEMY)); else player.sendPacket( new SystemMessage( SystemMessageId.YOU_DO_NOT_MEET_CRITERIA_IN_ORDER_TO_CREATE_A_MILITARY_UNIT)); return; } if (!Util.isAlphaNumeric(clanName) || 2 > clanName.length()) { player.sendPacket(new SystemMessage(SystemMessageId.CLAN_NAME_INCORRECT)); return; } if (clanName.length() > 16) { player.sendPacket(new SystemMessage(SystemMessageId.CLAN_NAME_TOO_LONG)); return; } for (L2Clan tempClan : ClanTable.getInstance().getClans()) { if (tempClan.getSubPledge(clanName) != null) { if (pledgeType == L2Clan.SUBUNIT_ACADEMY) { SystemMessage sm = new SystemMessage(SystemMessageId.S1_ALREADY_EXISTS); sm.addString(clanName); player.sendPacket(sm); sm = null; } else player.sendPacket( new SystemMessage(SystemMessageId.ANOTHER_MILITARY_UNIT_IS_ALREADY_USING_THAT_NAME)); return; } } if (pledgeType != L2Clan.SUBUNIT_ACADEMY) { if (clan.getClanMember(leaderName) == null || clan.getClanMember(leaderName).getPledgeType() != 0) { if (pledgeType >= L2Clan.SUBUNIT_KNIGHT1) player.sendPacket( new SystemMessage(SystemMessageId.CAPTAIN_OF_ORDER_OF_KNIGHTS_CANNOT_BE_APPOINTED)); else if (pledgeType >= L2Clan.SUBUNIT_ROYAL1) player.sendPacket( new SystemMessage(SystemMessageId.CAPTAIN_OF_ROYAL_GUARD_CANNOT_BE_APPOINTED)); return; } } final int leaderId = pledgeType != L2Clan.SUBUNIT_ACADEMY ? clan.getClanMember(leaderName).getObjectId() : 0; if (clan.createSubPledge(player, pledgeType, leaderId, clanName) == null) return; SystemMessage sm; if (pledgeType == L2Clan.SUBUNIT_ACADEMY) { sm = new SystemMessage(SystemMessageId.THE_S1S_CLAN_ACADEMY_HAS_BEEN_CREATED); sm.addString(player.getClan().getName()); } else if (pledgeType >= L2Clan.SUBUNIT_KNIGHT1) { sm = new SystemMessage(SystemMessageId.THE_KNIGHTS_OF_S1_HAVE_BEEN_CREATED); sm.addString(player.getClan().getName()); } else if (pledgeType >= L2Clan.SUBUNIT_ROYAL1) { sm = new SystemMessage(SystemMessageId.THE_ROYAL_GUARD_OF_S1_HAVE_BEEN_CREATED); sm.addString(player.getClan().getName()); } else sm = new SystemMessage(SystemMessageId.CLAN_CREATED); player.sendPacket(sm); if (pledgeType != L2Clan.SUBUNIT_ACADEMY) { final L2ClanMember leaderSubPledge = clan.getClanMember(leaderName); final L2PcInstance leaderPlayer = leaderSubPledge.getPlayerInstance(); if (leaderPlayer != null) { leaderPlayer.setPledgeClass(leaderSubPledge.calculatePledgeClass(leaderPlayer)); leaderPlayer.sendPacket(new UserInfo(leaderPlayer)); leaderPlayer.sendPacket(new ExBrExtraUserInfo(leaderPlayer)); } } }