SubClassSkills.java 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package custom.SubClassSkills;
  16. import java.util.Map;
  17. import javolution.util.FastMap;
  18. import com.l2jserver.Config;
  19. import com.l2jserver.gameserver.datatables.SkillTable;
  20. import com.l2jserver.gameserver.model.L2ItemInstance;
  21. import com.l2jserver.gameserver.model.L2Skill;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.quest.Quest;
  25. import com.l2jserver.gameserver.model.quest.QuestState;
  26. import com.l2jserver.gameserver.model.quest.State;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. import com.l2jserver.gameserver.network.serverpackets.AcquireSkillInfo;
  29. import com.l2jserver.gameserver.network.serverpackets.AcquireSkillList;
  30. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  31. import com.l2jserver.gameserver.util.Util;
  32. /**
  33. * @authors Gigiikun (python), Nyaran (java)
  34. */
  35. public class SubClassSkills extends Quest
  36. {
  37. private static final String qn = "SubClassSkills";
  38. private static final int NPC = 32323;
  39. private static final int[] SKILLITEMS =
  40. {
  41. 10280, 10281, 10282, 10283, 10284, 10285, 10286, 10287, 10288, 10289, 10290, 10291, 10292, 10293, 10294, 10612
  42. };
  43. private static final Map<Integer, int[]> SUBSKILLS = new FastMap<Integer, int[]>();
  44. private static final Map<String, int[]> QUESTVARSITEMS = new FastMap<String, int[]>();
  45. public SubClassSkills(int id, String name, String descr)
  46. {
  47. super(id, name, descr);
  48. addStartNpc(NPC);
  49. addTalkId(NPC);
  50. addAcquireSkillId(NPC);
  51. SUBSKILLS.put(10280, new int[] {631,632,633,634}); // Common
  52. SUBSKILLS.put(10612, new int[] {637,638,639,640,799,800}); // Enhanced
  53. SUBSKILLS.put(10281, new int[] {801,650,651}); // Warriors
  54. SUBSKILLS.put(10282, new int[] {804,641,652}); // Knights
  55. SUBSKILLS.put(10283, new int[] {644,645,653}); // Rogues
  56. SUBSKILLS.put(10284, new int[] {802,646,654}); // Wizards
  57. SUBSKILLS.put(10285, new int[] {803,648,1490}); // Healers
  58. SUBSKILLS.put(10286, new int[] {643,1489,1491}); // Summoners
  59. SUBSKILLS.put(10287, new int[] {642,647,655}); // Enchanters
  60. SUBSKILLS.put(10289, new int[] {656}); // Warriors
  61. SUBSKILLS.put(10288, new int[] {657}); // Knights
  62. SUBSKILLS.put(10290, new int[] {658}); // Rogues
  63. SUBSKILLS.put(10292, new int[] {659}); // Wizards
  64. SUBSKILLS.put(10291, new int[] {661}); // Healers
  65. SUBSKILLS.put(10294, new int[] {660}); // Summoners
  66. SUBSKILLS.put(10293, new int[] {662}); // Enchanters
  67. QUESTVARSITEMS.put("EmergentAbility65-", new int[] {10280});
  68. QUESTVARSITEMS.put("EmergentAbility70-", new int[] {10280});
  69. QUESTVARSITEMS.put("ClassAbility75-", new int[] {10612, 10281, 10282, 10283, 10284, 10285, 10286, 10287});
  70. QUESTVARSITEMS.put("ClassAbility80-", new int[] {10288, 10289, 10290, 10291, 10292, 10293, 10294});
  71. }
  72. @Override
  73. public String onAcquireSkillList(L2Npc npc, L2PcInstance player)
  74. {
  75. AcquireSkillList asl = new AcquireSkillList(AcquireSkillList.SkillType.unk4);
  76. L2Skill[] oldSkills = player.getAllSkills();
  77. int count = 0;
  78. for (int i : SKILLITEMS)
  79. {
  80. for (int j : SUBSKILLS.get(i))
  81. {
  82. int minLevel = 0;
  83. int maxLevel = SkillTable.getInstance().getMaxLevel(j);
  84. for (L2Skill oldsk : oldSkills)
  85. {
  86. if (oldsk.getId() == j)
  87. minLevel = oldsk.getLevel();
  88. }
  89. if (minLevel < maxLevel)
  90. {
  91. count += 1;
  92. asl.addSkill(j, minLevel + 1, maxLevel, 0, 0);
  93. }
  94. }
  95. }
  96. player.sendPacket(asl);
  97. if (count == 0)
  98. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_MORE_SKILLS_TO_LEARN));
  99. return "";
  100. }
  101. @Override
  102. public String onAcquireSkill(L2Npc npc, L2PcInstance player, L2Skill skill)
  103. {
  104. if (player.isSubClassActive())
  105. {
  106. player.sendMessage("You are trying to learn skill that u can't..");
  107. Util.handleIllegalPlayerAction(player, "Player " + player.getName() + " tried to learn skill that he can't!!!", Config.DEFAULT_PUNISH);
  108. return "false";
  109. }
  110. QuestState st = player.getQuestState(qn);
  111. for (int i : SKILLITEMS)
  112. {
  113. if (Util.contains(SUBSKILLS.get(i), skill.getId()))
  114. {
  115. for (String var : QUESTVARSITEMS.keySet())
  116. {
  117. if (Util.contains(QUESTVARSITEMS.get(var), i))
  118. {
  119. for (int j = 0; j < Config.MAX_SUBCLASS; j++)
  120. {
  121. String qvar = st.getGlobalQuestVar(var + String.valueOf(j + 1));
  122. if (qvar != "" && qvar != "0" && !qvar.endsWith(";"))
  123. {
  124. L2ItemInstance Item = player.getInventory().getItemByObjectId(Integer.parseInt(qvar));
  125. if (Item != null && Item.getItemId() == i)
  126. {
  127. player.destroyItem(qn, Integer.parseInt(qvar), 1, player, false);
  128. st.saveGlobalQuestVar(var + String.valueOf(j + 1), String.valueOf(skill.getId()) + ";");
  129. return "true";
  130. }
  131. }
  132. }
  133. }
  134. }
  135. }
  136. }
  137. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ITEM_MISSING_TO_LEARN_SKILL));
  138. return "false";
  139. }
  140. @Override
  141. public String onAcquireSkillInfo(L2Npc npc, L2PcInstance player, L2Skill skill)
  142. {
  143. AcquireSkillInfo asi = new AcquireSkillInfo(skill.getId(), skill.getLevel(), 0, 5);
  144. for (int i : SKILLITEMS)
  145. {
  146. if (Util.contains(SUBSKILLS.get(i), skill.getId()))
  147. asi.addRequirement(99, i, 1, 50);
  148. }
  149. player.sendPacket(asi);
  150. return "";
  151. }
  152. @Override
  153. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  154. {
  155. String htmltext = event;
  156. QuestState st = player.getQuestState(qn);
  157. if (event.equals("learn"))
  158. {
  159. htmltext = "";
  160. QuestState st2 = player.getQuestState("136_MoreThanMeetsTheEye");
  161. if (player.isSubClassActive())
  162. htmltext = "8005-04.htm";
  163. else if (st2 == null || st2.getState() != State.COMPLETED)
  164. htmltext = "8005-03.htm";
  165. else
  166. {
  167. int j = 0;
  168. for (int i : SKILLITEMS)
  169. j += st.getQuestItemsCount(i);
  170. if (j > 0)
  171. this.onAcquireSkillList(npc, player);
  172. else
  173. htmltext = "8005-04.htm";
  174. }
  175. }
  176. else if (event.equals("cancel"))
  177. if (st.getQuestItemsCount(57) < 10000000)
  178. htmltext = "8005-07.htm";
  179. else if (player.getSubClasses().size() == 0)
  180. htmltext = "8005-03.htm";
  181. else if (player.isSubClassActive())
  182. htmltext = "8005-04.htm";
  183. else
  184. {
  185. int activeCertifications = 0;
  186. for (String var : QUESTVARSITEMS.keySet())
  187. {
  188. for (int i = 0; i < Config.MAX_SUBCLASS; i++)
  189. {
  190. String qvar = st.getGlobalQuestVar(var + String.valueOf(i + 1));
  191. if (qvar.endsWith(";"))
  192. activeCertifications += 1;
  193. else if (qvar != "" && qvar != "0")
  194. activeCertifications += 1;
  195. }
  196. }
  197. if (activeCertifications == 0)
  198. htmltext = "8005-08.htm";
  199. else
  200. {
  201. for (String var : QUESTVARSITEMS.keySet())
  202. {
  203. for (int i = 0; i < Config.MAX_SUBCLASS; i++)
  204. {
  205. String qvar = st.getGlobalQuestVar(var + String.valueOf(i + 1));
  206. if (qvar.endsWith(";"))
  207. {
  208. L2Skill skill = SkillTable.getInstance().getInfo(Integer.parseInt(qvar.replace(";", "")), 1);
  209. if (skill != null)
  210. {
  211. qvar = st.getGlobalQuestVar(var + String.valueOf(i + 1));
  212. player.removeSkill(skill, true);
  213. st.saveGlobalQuestVar(var + String.valueOf(i + 1), "0");
  214. }
  215. }
  216. else if (qvar != "" && qvar != "0")
  217. {
  218. L2ItemInstance Item = player.getInventory().getItemByObjectId(Integer.parseInt(qvar));
  219. if (Item != null)
  220. player.destroyItem(qn, Integer.parseInt(qvar), 1, player, false);
  221. else
  222. {
  223. Item = player.getWarehouse().getItemByObjectId(Integer.parseInt(qvar));
  224. if (Item != null)
  225. {
  226. _log.warning("Somehow " + player.getName() + " put certification book into warehouse!");
  227. player.getWarehouse().destroyItem(qn, Item, 1, player, false);
  228. }
  229. else
  230. _log.warning("Somehow " + player.getName() + " his/her delete certification book!");
  231. }
  232. st.saveGlobalQuestVar(var + String.valueOf(i + 1), "0");
  233. }
  234. }
  235. }
  236. st.takeItems(57, 10000000);
  237. htmltext = "8005-09.htm";
  238. player.sendSkillList();
  239. }
  240. }
  241. return htmltext;
  242. }
  243. @Override
  244. public String onTalk(L2Npc npc, L2PcInstance player)
  245. {
  246. String htmltext = getNoQuestMsg(player);
  247. QuestState st = player.getQuestState(qn);
  248. int npcId = npc.getNpcId();
  249. if (npcId == NPC)
  250. {
  251. st.set("cond", "0");
  252. st.setState(State.STARTED);
  253. htmltext = "8005-01.htm";
  254. }
  255. return htmltext;
  256. }
  257. public static void main(String args[])
  258. {
  259. new SubClassSkills(-1, qn, "custom");
  260. }
  261. }