SubclassCertification.java 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package ai.npc.SubclassCertification;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import ai.npc.AbstractNpcAI;
  23. import com.l2jserver.gameserver.data.xml.impl.ClassListData;
  24. import com.l2jserver.gameserver.enums.CategoryType;
  25. import com.l2jserver.gameserver.model.actor.L2Npc;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2VillageMasterInstance;
  28. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  29. import com.l2jserver.gameserver.model.quest.QuestState;
  30. import com.l2jserver.gameserver.model.quest.State;
  31. import com.l2jserver.gameserver.network.SystemMessageId;
  32. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  33. /**
  34. * Subclass certification
  35. * @author xban1x, jurchiks
  36. */
  37. public final class SubclassCertification extends AbstractNpcAI
  38. {
  39. // @formatter:off
  40. private static final int[] NPCS =
  41. {
  42. 30026, 30031, 30037, 30066, 30070, 30109, 30115, 30120, 30154, 30174,
  43. 30175, 30176, 30187, 30191, 30195, 30288, 30289, 30290, 30297, 30358,
  44. 30373, 30462, 30474, 30498, 30499, 30500, 30503, 30504, 30505, 30508,
  45. 30511, 30512, 30513, 30520, 30525, 30565, 30594, 30595, 30676, 30677,
  46. 30681, 30685, 30687, 30689, 30694, 30699, 30704, 30845, 30847, 30849,
  47. 30854, 30857, 30862, 30865, 30894, 30897, 30900, 30905, 30910, 30913,
  48. 31269, 31272, 31276, 31279, 31285, 31288, 31314, 31317, 31321, 31324,
  49. 31326, 31328, 31331, 31334, 31336, 31755, 31958, 31961, 31965, 31968,
  50. 31974, 31977, 31996, 32092, 32093, 32094, 32095, 32096, 32097, 32098,
  51. 32145, 32146, 32147, 32150, 32153, 32154, 32157, 32158, 32160, 32171,
  52. 32193, 32199, 32202, 32213, 32214, 32221, 32222, 32229, 32230, 32233,
  53. 32234
  54. };
  55. // @formatter:on
  56. private static final int CERTIFICATE_EMERGENT_ABILITY = 10280;
  57. private static final int CERTIFICATE_MASTER_ABILITY = 10612;
  58. private static final Map<Integer, Integer> ABILITY_CERTIFICATES = new HashMap<>();
  59. private static final Map<Integer, Integer> TRANSFORMATION_SEALBOOKS = new HashMap<>();
  60. static
  61. {
  62. ABILITY_CERTIFICATES.put(0, 10281); // Certificate - Warrior Ability
  63. ABILITY_CERTIFICATES.put(1, 10283); // Certificate - Rogue Ability
  64. ABILITY_CERTIFICATES.put(2, 10282); // Certificate - Knight Ability
  65. ABILITY_CERTIFICATES.put(3, 10286); // Certificate - Summoner Ability
  66. ABILITY_CERTIFICATES.put(4, 10284); // Certificate - Wizard Ability
  67. ABILITY_CERTIFICATES.put(5, 10285); // Certificate - Healer Ability
  68. ABILITY_CERTIFICATES.put(6, 10287); // Certificate - Enchanter Ability
  69. TRANSFORMATION_SEALBOOKS.put(0, 10289); // Transformation Sealbook: Divine Warrior
  70. TRANSFORMATION_SEALBOOKS.put(1, 10290); // Transformation Sealbook: Divine Rogue
  71. TRANSFORMATION_SEALBOOKS.put(2, 10288); // Transformation Sealbook: Divine Knight
  72. TRANSFORMATION_SEALBOOKS.put(3, 10294); // Transformation Sealbook: Divine Summoner
  73. TRANSFORMATION_SEALBOOKS.put(4, 10292); // Transformation Sealbook: Divine Wizard
  74. TRANSFORMATION_SEALBOOKS.put(5, 10291); // Transformation Sealbook: Divine Healer
  75. TRANSFORMATION_SEALBOOKS.put(6, 10293); // Transformation Sealbook: Divine Enchanter
  76. }
  77. private static final int MIN_LVL = 65;
  78. private SubclassCertification()
  79. {
  80. super(SubclassCertification.class.getSimpleName(), "ai/npc");
  81. addStartNpc(NPCS);
  82. addTalkId(NPCS);
  83. }
  84. @Override
  85. public String onTalk(L2Npc npc, L2PcInstance player)
  86. {
  87. final QuestState st = getQuestState(player, true);
  88. String htmltext = getNoQuestMsg(player);
  89. if (st != null)
  90. {
  91. st.setState(State.STARTED);
  92. htmltext = "Main.html";
  93. }
  94. return htmltext;
  95. }
  96. @Override
  97. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  98. {
  99. String htmltext = null;
  100. final QuestState st = getQuestState(player, false);
  101. if (st == null)
  102. {
  103. return htmltext;
  104. }
  105. switch (event)
  106. {
  107. case "GetCertified":
  108. {
  109. if (!player.isSubClassActive())
  110. {
  111. htmltext = "NotSubclass.html";
  112. }
  113. else if (player.getLevel() < MIN_LVL)
  114. {
  115. htmltext = "NotMinLevel.html";
  116. }
  117. else if (((L2VillageMasterInstance) npc).checkVillageMaster(player.getActiveClass()))
  118. {
  119. htmltext = "CertificationList.html";
  120. }
  121. else
  122. {
  123. htmltext = "WrongVillageMaster.html";
  124. }
  125. break;
  126. }
  127. case "Obtain65":
  128. {
  129. htmltext = replaceHtml(player, "EmergentAbility.html", true, null).replace("%level%", "65").replace("%skilltype%", "common skill").replace("%event%", "lvl65Emergent");
  130. break;
  131. }
  132. case "Obtain70":
  133. {
  134. htmltext = replaceHtml(player, "EmergentAbility.html", true, null).replace("%level%", "70").replace("%skilltype%", "common skill").replace("%event%", "lvl70Emergent");
  135. break;
  136. }
  137. case "Obtain75":
  138. {
  139. htmltext = replaceHtml(player, "ClassAbility.html", true, null);
  140. break;
  141. }
  142. case "Obtain80":
  143. {
  144. htmltext = replaceHtml(player, "EmergentAbility.html", true, null).replace("%level%", "80").replace("%skilltype%", "transformation skill").replace("%event%", "lvl80Class");
  145. break;
  146. }
  147. case "lvl65Emergent":
  148. {
  149. htmltext = doCertification(player, st, "EmergentAbility", CERTIFICATE_EMERGENT_ABILITY, 65);
  150. break;
  151. }
  152. case "lvl70Emergent":
  153. {
  154. htmltext = doCertification(player, st, "EmergentAbility", CERTIFICATE_EMERGENT_ABILITY, 70);
  155. break;
  156. }
  157. case "lvl75Master":
  158. {
  159. htmltext = doCertification(player, st, "ClassAbility", CERTIFICATE_MASTER_ABILITY, 75);
  160. break;
  161. }
  162. case "lvl75Class":
  163. {
  164. htmltext = doCertification(player, st, "ClassAbility", ABILITY_CERTIFICATES.get(getClassIndex(player)), 75);
  165. break;
  166. }
  167. case "lvl80Class":
  168. {
  169. htmltext = doCertification(player, st, "ClassAbility", TRANSFORMATION_SEALBOOKS.get(getClassIndex(player)), 80);
  170. break;
  171. }
  172. case "Main.html":
  173. case "Explanation.html":
  174. case "NotObtain.html":
  175. {
  176. htmltext = event;
  177. break;
  178. }
  179. }
  180. return htmltext;
  181. }
  182. private String replaceHtml(L2PcInstance player, String htmlFile, boolean replaceClass, String levelToReplace)
  183. {
  184. String htmltext = getHtm(player.getHtmlPrefix(), htmlFile);
  185. if (replaceClass)
  186. {
  187. htmltext = htmltext.replace("%class%", String.valueOf(ClassListData.getInstance().getClass(player.getActiveClass()).getClientCode()));
  188. }
  189. if (levelToReplace != null)
  190. {
  191. htmltext = htmltext.replace("%level%", levelToReplace);
  192. }
  193. return htmltext;
  194. }
  195. private static int getClassIndex(L2PcInstance player)
  196. {
  197. if (player.isInCategory(CategoryType.SUB_GROUP_WARRIOR))
  198. {
  199. return 0;
  200. }
  201. else if (player.isInCategory(CategoryType.SUB_GROUP_ROGUE))
  202. {
  203. return 1;
  204. }
  205. else if (player.isInCategory(CategoryType.SUB_GROUP_KNIGHT))
  206. {
  207. return 2;
  208. }
  209. else if (player.isInCategory(CategoryType.SUB_GROUP_SUMMONER))
  210. {
  211. return 3;
  212. }
  213. else if (player.isInCategory(CategoryType.SUB_GROUP_WIZARD))
  214. {
  215. return 4;
  216. }
  217. else if (player.isInCategory(CategoryType.SUB_GROUP_HEALER))
  218. {
  219. return 5;
  220. }
  221. else if (player.isInCategory(CategoryType.SUB_GROUP_ENCHANTER))
  222. {
  223. return 6;
  224. }
  225. return -1;
  226. }
  227. private String doCertification(L2PcInstance player, QuestState qs, String variable, Integer itemId, int level)
  228. {
  229. if (itemId == null)
  230. {
  231. return null;
  232. }
  233. String htmltext;
  234. String tmp = variable + level + "-" + player.getClassIndex();
  235. String globalVariable = qs.getGlobalQuestVar(tmp);
  236. if (!globalVariable.equals("") && !globalVariable.equals("0"))
  237. {
  238. htmltext = "AlreadyReceived.html";
  239. }
  240. else if (player.getLevel() < level)
  241. {
  242. htmltext = replaceHtml(player, "LowLevel.html", false, Integer.toString(level));
  243. }
  244. else
  245. {
  246. // Add items to player's inventory
  247. final L2ItemInstance item = player.getInventory().addItem("Quest", itemId, 1, player, player.getTarget());
  248. if (item == null)
  249. {
  250. return null;
  251. }
  252. final SystemMessage smsg = SystemMessage.getSystemMessage(SystemMessageId.EARNED_ITEM_S1);
  253. smsg.addItemName(item);
  254. player.sendPacket(smsg);
  255. qs.saveGlobalQuestVar(tmp, String.valueOf(item.getObjectId()));
  256. htmltext = "GetAbility.html";
  257. }
  258. return htmltext;
  259. }
  260. public static void main(String[] args)
  261. {
  262. new SubclassCertification();
  263. }
  264. }