Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.l2jfrozen.gameserver.model.actor.instance;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import com.l2jfrozen.gameserver.cache.HtmCache;
- import com.l2jfrozen.gameserver.model.L2Skill;
- import com.l2jfrozen.gameserver.model.entity.olympiad.Olympiad;
- import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
- import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
- import com.l2jfrozen.gameserver.network.serverpackets.PlaySound;
- import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
- import com.l2jfrozen.gameserver.templates.StatsSet;
- import com.l2jfrozen.util.database.L2DatabaseFactory;
- public class L2ResetClassInstance extends L2NpcInstance
- {
- public L2ResetClassInstance(int objectId, L2NpcTemplate template)
- {
- super(objectId, template);
- }
- @Override
- public void showChatWindow(L2PcInstance playerInstance, int val)
- {
- if (playerInstance == null)
- return;
- String htmContent = HtmCache.getInstance().getHtm("data/html/ResetClass/ResetClass.htm");
- if (val > 0)
- {
- htmContent = HtmCache.getInstance().getHtm("data/html/ResetClass/ResetClass-" + val + ".htm");
- }
- if (htmContent != null)
- {
- NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(getObjectId());
- npcHtmlMessage.setHtml(htmContent);
- npcHtmlMessage.replace("%objectId%", String.valueOf(getObjectId()));
- playerInstance.sendPacket(npcHtmlMessage);
- }
- playerInstance.sendPacket(ActionFailed.STATIC_PACKET);
- }
- @Override
- public void onBypassFeedback(L2PcInstance player, String command)
- {
- if ((player.getLevel() < 76) && (player.getLevel() <= 80))
- {
- player.sendMessage("Usted No tiene El LvL Necesario.");
- return;
- }
- if (!(player.getClassId().level() == 3))
- {
- player.sendMessage("Necesitas la tercera Class.");
- return;
- }
- if (!(player.getInventory().getInventoryItemCount(57, 0) >= 10))
- {
- player.sendMessage("No tienes 3 Subs.");
- return;
- }
- if (player.isAio())
- {
- player.sendMessage("You may not add a new subclass.");
- return;
- }
- if (command.startsWith("HumanoF1"))
- {
- player.setClassId(0);
- player.setBaseClass(0);
- Finish(player);
- return;
- }
- if (command.startsWith("HumanoM1"))
- {
- player.setClassId(10);
- player.setBaseClass(10);
- Finish(player);
- return;
- }
- if (command.startsWith("ElfoBF1"))
- {
- player.setClassId(18);
- player.setBaseClass(18);
- Finish(player);
- return;
- }
- if (command.startsWith("ElfoBM1"))
- {
- player.setClassId(25);
- player.setBaseClass(25);
- Finish(player);
- return;
- }
- if (command.startsWith("ElfoNF1"))
- {
- player.setClassId(31);
- player.setBaseClass(31);
- Finish(player);
- return;
- }
- if (command.startsWith("ElfoNM1"))
- {
- player.setClassId(38);
- player.setBaseClass(38);
- Finish(player);
- return;
- }
- if (command.startsWith("OrcF1"))
- {
- player.setClassId(44);
- player.setBaseClass(44);
- Finish(player);
- return;
- }
- if (command.startsWith("OrcoM1"))
- {
- player.setClassId(49);
- player.setBaseClass(49);
- Finish(player);
- return;
- }
- if (command.startsWith("Enano1"))
- {
- player.setClassId(53);
- player.setBaseClass(53);
- Finish(player);
- return;
- }
- super.onBypassFeedback(player, command);
- }
- //fixed subclass
- static String RESTORE_SKILLS_FOR_CHAR_ALT_SUBCLASS = "DELETE FROM character_skills WHERE char_obj_id=?";
- static String RESTORE_SKILLS_FOR_CHAR = "DELETE FROM character_skills WHERE char_obj_id=?";
- static String INSERT_DATA = "REPLACE INTO olympiad_nobles (char_id, class_id, olympiad_points) VALUES (?,?,?)";
- static String OLYMPIAD_UPDATE = "UPDATE olympiad_nobles SET class_id=?, olympiad_points=?, competitions_done=?, competitions_won=?, competitions_lost=?, competitions_drawn=? WHERE char_Id=?";
- static String DELETE_CHAR_HERO = "DELETE FROM heroes WHERE char_id=?";
- static String DELETE_CHAR_HENNAS = "DELETE FROM character_hennas WHERE char_obj_id=? AND class_index=?";
- static String DELETE_CHAR_SUBCLASS = "DELETE FROM character_subclasses WHERE char_obj_id=?";
- public static void DeleteSkillsSub(L2PcInstance player)
- {
- try (Connection con = L2DatabaseFactory.getInstance().getConnection(false))
- {
- PreparedStatement statement = con.prepareStatement(RESTORE_SKILLS_FOR_CHAR_ALT_SUBCLASS);
- statement.setInt(1, player.getObjectId());
- statement.execute();
- statement.close();
- con.close();
- }
- catch (Exception e)
- {
- LOGGER.warn("could not clear char Skills Acumulativas2: " + e);
- }
- }
- public static void DeleteSkills(L2PcInstance player)
- {
- try (Connection con = L2DatabaseFactory.getInstance().getConnection(false))
- {
- PreparedStatement statement = con.prepareStatement(RESTORE_SKILLS_FOR_CHAR);
- statement.setInt(1, player.getObjectId());
- statement.execute();
- statement.close();
- con.close();
- }
- catch (Exception e)
- {
- LOGGER.warn("could not clear char Skills Acumulativas: " + e);
- }
- }
- public static void DeleteHero(L2PcInstance player)
- {
- try (Connection con = L2DatabaseFactory.getInstance().getConnection(false))
- {
- PreparedStatement statement = con.prepareStatement(DELETE_CHAR_HERO);
- statement.setInt(1, player.getObjectId());
- statement.execute();
- statement.close();
- con.close();
- }
- catch (Exception e)
- {
- LOGGER.warn("could not clear char Hero: " + e);
- }
- }
- public static void DeleteSubClasses(L2PcInstance player)
- {
- try (Connection con = L2DatabaseFactory.getInstance().getConnection(false))
- {
- PreparedStatement statement = con.prepareStatement(DELETE_CHAR_SUBCLASS);
- statement.setInt(1, player.getObjectId());
- statement.execute();
- statement.close();
- con.close();
- }
- catch (Exception e)
- {
- LOGGER.warn("could not clear char Subclasses: " + e);
- }
- }
- public static void updateClasse(L2PcInstance player)
- {
- if (player == null)
- return;
- try (Connection con = L2DatabaseFactory.getInstance().getConnection(false))
- {
- PreparedStatement stmt = con.prepareStatement(INSERT_DATA);
- stmt.setInt(1, player.getObjectId());
- stmt.setInt(2, player.getClassId().getId());
- stmt.setInt(3, 18);
- stmt.execute();
- stmt.close();
- con.close();
- }
- catch (Exception e)
- {
- LOGGER.warn("Class Card: Could not clear char Olympiad Points: " + e);
- }
- }
- private static void Finish(L2PcInstance activeChar)
- {
- String newclass = activeChar.getTemplate().getClassName();
- for (final L2Skill skill : activeChar.getAllSkills())
- {
- activeChar.removeSkill(skill);
- }
- DeleteHenna(activeChar, 0);
- DeleteSubClasses(activeChar);
- DeleteSkills(activeChar);
- DeleteSkillsSub(activeChar);
- activeChar.sendMessage(activeChar.getName() + " is now a " + newclass + ".");
- activeChar.refreshOverloaded();
- activeChar.store();
- activeChar.broadcastUserInfo();
- activeChar.sendSkillList();
- activeChar.sendPacket(new PlaySound("ItemSound.quest_finish"));
- if (activeChar.isNoble())
- {
- StatsSet playerStat = Olympiad.getNobleStats(activeChar.getObjectId());
- if (!(playerStat == null))
- {
- updateClasse(activeChar);
- DeleteHero(activeChar);
- activeChar.sendMessage("You now has " + Olympiad.getInstance().getNoblePoints(activeChar.getObjectId()) + " Olympiad points.");
- }
- }
- activeChar.sendMessage("You will be disconnected for security reasons.");
- waitSecs(5);
- activeChar.getClient().closeNow();
- }
- public static void waitSecs(int i)
- {
- try
- {
- Thread.sleep(i * 1000);
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- }
- public static void DeleteHenna(L2PcInstance player, int classIndex)
- {
- try (Connection con = L2DatabaseFactory.getInstance().getConnection(false))
- {
- // Remove all henna info stored for this sub-class.
- PreparedStatement statement = con.prepareStatement(DELETE_CHAR_HENNAS);
- statement.setInt(1, player.getObjectId());
- statement.setInt(2, classIndex);
- statement.execute();
- statement.close();
- con.close();
- }
- catch (Exception e)
- {
- LOGGER.warn("could not clear Hennas Dyes: " + e);
- }
- }
- }
Add Comment
Please, Sign In to add comment