Sarada-L2

ResetClass Frozen Teste 2

Jun 21st, 2021
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.10 KB | None | 0 0
  1. package com.l2jfrozen.gameserver.model.actor.instance;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5.  
  6. import com.l2jfrozen.gameserver.cache.HtmCache;
  7. import com.l2jfrozen.gameserver.model.L2Skill;
  8. import com.l2jfrozen.gameserver.model.entity.olympiad.Olympiad;
  9. import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
  10. import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
  11. import com.l2jfrozen.gameserver.network.serverpackets.PlaySound;
  12. import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
  13. import com.l2jfrozen.gameserver.templates.StatsSet;
  14. import com.l2jfrozen.util.database.L2DatabaseFactory;
  15.  
  16. public class L2ResetClassInstance extends L2NpcInstance
  17. {
  18. public L2ResetClassInstance(int objectId, L2NpcTemplate template)
  19. {
  20. super(objectId, template);
  21. }
  22.  
  23. @Override
  24. public void showChatWindow(L2PcInstance playerInstance, int val)
  25. {
  26. if (playerInstance == null)
  27. return;
  28.  
  29. String htmContent = HtmCache.getInstance().getHtm("data/html/ResetClass/ResetClass.htm");
  30. if (val > 0)
  31. {
  32. htmContent = HtmCache.getInstance().getHtm("data/html/ResetClass/ResetClass-" + val + ".htm");
  33. }
  34. if (htmContent != null)
  35. {
  36. NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(getObjectId());
  37.  
  38. npcHtmlMessage.setHtml(htmContent);
  39. npcHtmlMessage.replace("%objectId%", String.valueOf(getObjectId()));
  40. playerInstance.sendPacket(npcHtmlMessage);
  41. }
  42. playerInstance.sendPacket(ActionFailed.STATIC_PACKET);
  43. }
  44.  
  45. @Override
  46. public void onBypassFeedback(L2PcInstance player, String command)
  47. {
  48. if ((player.getLevel() < 76) && (player.getLevel() <= 80))
  49. {
  50. player.sendMessage("Usted No tiene El LvL Necesario.");
  51. return;
  52. }
  53. if (!(player.getClassId().level() == 3))
  54. {
  55. player.sendMessage("Necesitas la tercera Class.");
  56. return;
  57. }
  58. if (!(player.getInventory().getInventoryItemCount(57, 0) >= 10))
  59. {
  60. player.sendMessage("No tienes 3 Subs.");
  61. return;
  62. }
  63. if (player.isAio())
  64. {
  65. player.sendMessage("You may not add a new subclass.");
  66. return;
  67. }
  68. if (command.startsWith("HumanoF1"))
  69. {
  70. player.setClassId(0);
  71. player.setBaseClass(0);
  72. Finish(player);
  73. return;
  74. }
  75. if (command.startsWith("HumanoM1"))
  76. {
  77. player.setClassId(10);
  78. player.setBaseClass(10);
  79. Finish(player);
  80. return;
  81. }
  82. if (command.startsWith("ElfoBF1"))
  83. {
  84. player.setClassId(18);
  85. player.setBaseClass(18);
  86. Finish(player);
  87. return;
  88. }
  89. if (command.startsWith("ElfoBM1"))
  90. {
  91. player.setClassId(25);
  92. player.setBaseClass(25);
  93.  
  94. Finish(player);
  95. return;
  96. }
  97. if (command.startsWith("ElfoNF1"))
  98. {
  99. player.setClassId(31);
  100. player.setBaseClass(31);
  101. Finish(player);
  102. return;
  103. }
  104. if (command.startsWith("ElfoNM1"))
  105. {
  106. player.setClassId(38);
  107. player.setBaseClass(38);
  108. Finish(player);
  109. return;
  110. }
  111. if (command.startsWith("OrcF1"))
  112. {
  113. player.setClassId(44);
  114. player.setBaseClass(44);
  115. Finish(player);
  116. return;
  117. }
  118. if (command.startsWith("OrcoM1"))
  119. {
  120. player.setClassId(49);
  121. player.setBaseClass(49);
  122. Finish(player);
  123. return;
  124. }
  125. if (command.startsWith("Enano1"))
  126. {
  127. player.setClassId(53);
  128. player.setBaseClass(53);
  129. Finish(player);
  130. return;
  131. }
  132. super.onBypassFeedback(player, command);
  133. }
  134. //fixed subclass
  135. static String RESTORE_SKILLS_FOR_CHAR_ALT_SUBCLASS = "DELETE FROM character_skills WHERE char_obj_id=?";
  136. static String RESTORE_SKILLS_FOR_CHAR = "DELETE FROM character_skills WHERE char_obj_id=?";
  137. static String INSERT_DATA = "REPLACE INTO olympiad_nobles (char_id, class_id, olympiad_points) VALUES (?,?,?)";
  138. static String OLYMPIAD_UPDATE = "UPDATE olympiad_nobles SET class_id=?, olympiad_points=?, competitions_done=?, competitions_won=?, competitions_lost=?, competitions_drawn=? WHERE char_Id=?";
  139. static String DELETE_CHAR_HERO = "DELETE FROM heroes WHERE char_id=?";
  140. static String DELETE_CHAR_HENNAS = "DELETE FROM character_hennas WHERE char_obj_id=? AND class_index=?";
  141. static String DELETE_CHAR_SUBCLASS = "DELETE FROM character_subclasses WHERE char_obj_id=?";
  142. public static void DeleteSkillsSub(L2PcInstance player)
  143. {
  144. try (Connection con = L2DatabaseFactory.getInstance().getConnection(false))
  145. {
  146. PreparedStatement statement = con.prepareStatement(RESTORE_SKILLS_FOR_CHAR_ALT_SUBCLASS);
  147. statement.setInt(1, player.getObjectId());
  148. statement.execute();
  149. statement.close();
  150. con.close();
  151. }
  152. catch (Exception e)
  153. {
  154. LOGGER.warn("could not clear char Skills Acumulativas2: " + e);
  155. }
  156. }
  157.  
  158. public static void DeleteSkills(L2PcInstance player)
  159. {
  160. try (Connection con = L2DatabaseFactory.getInstance().getConnection(false))
  161. {
  162. PreparedStatement statement = con.prepareStatement(RESTORE_SKILLS_FOR_CHAR);
  163. statement.setInt(1, player.getObjectId());
  164. statement.execute();
  165. statement.close();
  166. con.close();
  167. }
  168. catch (Exception e)
  169. {
  170. LOGGER.warn("could not clear char Skills Acumulativas: " + e);
  171. }
  172. }
  173. public static void DeleteHero(L2PcInstance player)
  174. {
  175. try (Connection con = L2DatabaseFactory.getInstance().getConnection(false))
  176. {
  177. PreparedStatement statement = con.prepareStatement(DELETE_CHAR_HERO);
  178. statement.setInt(1, player.getObjectId());
  179. statement.execute();
  180. statement.close();
  181. con.close();
  182. }
  183. catch (Exception e)
  184. {
  185. LOGGER.warn("could not clear char Hero: " + e);
  186. }
  187. }
  188. public static void DeleteSubClasses(L2PcInstance player)
  189. {
  190. try (Connection con = L2DatabaseFactory.getInstance().getConnection(false))
  191. {
  192. PreparedStatement statement = con.prepareStatement(DELETE_CHAR_SUBCLASS);
  193. statement.setInt(1, player.getObjectId());
  194. statement.execute();
  195. statement.close();
  196. con.close();
  197. }
  198. catch (Exception e)
  199. {
  200. LOGGER.warn("could not clear char Subclasses: " + e);
  201. }
  202. }
  203. public static void updateClasse(L2PcInstance player)
  204. {
  205. if (player == null)
  206. return;
  207.  
  208. try (Connection con = L2DatabaseFactory.getInstance().getConnection(false))
  209. {
  210. PreparedStatement stmt = con.prepareStatement(INSERT_DATA);
  211.  
  212. stmt.setInt(1, player.getObjectId());
  213. stmt.setInt(2, player.getClassId().getId());
  214. stmt.setInt(3, 18);
  215. stmt.execute();
  216. stmt.close();
  217. con.close();
  218. }
  219. catch (Exception e)
  220. {
  221. LOGGER.warn("Class Card: Could not clear char Olympiad Points: " + e);
  222. }
  223. }
  224. private static void Finish(L2PcInstance activeChar)
  225. {
  226. String newclass = activeChar.getTemplate().getClassName();
  227. for (final L2Skill skill : activeChar.getAllSkills())
  228. {
  229. activeChar.removeSkill(skill);
  230. }
  231. DeleteHenna(activeChar, 0);
  232. DeleteSubClasses(activeChar);
  233. DeleteSkills(activeChar);
  234. DeleteSkillsSub(activeChar);
  235. activeChar.sendMessage(activeChar.getName() + " is now a " + newclass + ".");
  236. activeChar.refreshOverloaded();
  237. activeChar.store();
  238. activeChar.broadcastUserInfo();
  239. activeChar.sendSkillList();
  240. activeChar.sendPacket(new PlaySound("ItemSound.quest_finish"));
  241.  
  242. if (activeChar.isNoble())
  243. {
  244. StatsSet playerStat = Olympiad.getNobleStats(activeChar.getObjectId());
  245. if (!(playerStat == null))
  246. {
  247. updateClasse(activeChar);
  248. DeleteHero(activeChar);
  249. activeChar.sendMessage("You now has " + Olympiad.getInstance().getNoblePoints(activeChar.getObjectId()) + " Olympiad points.");
  250. }
  251. }
  252. activeChar.sendMessage("You will be disconnected for security reasons.");
  253. waitSecs(5);
  254.  
  255. activeChar.getClient().closeNow();
  256. }
  257. public static void waitSecs(int i)
  258. {
  259. try
  260. {
  261. Thread.sleep(i * 1000);
  262. }
  263. catch (InterruptedException e)
  264. {
  265. e.printStackTrace();
  266. }
  267. }
  268. public static void DeleteHenna(L2PcInstance player, int classIndex)
  269. {
  270. try (Connection con = L2DatabaseFactory.getInstance().getConnection(false))
  271. {
  272. // Remove all henna info stored for this sub-class.
  273. PreparedStatement statement = con.prepareStatement(DELETE_CHAR_HENNAS);
  274. statement.setInt(1, player.getObjectId());
  275. statement.setInt(2, classIndex);
  276. statement.execute();
  277. statement.close();
  278. con.close();
  279. }
  280. catch (Exception e)
  281. {
  282. LOGGER.warn("could not clear Hennas Dyes: " + e);
  283. }
  284. }
  285. }
Add Comment
Please, Sign In to add comment