SkillTransfer.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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.SkillTransfer;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.model.L2Skill;
  18. import com.l2jserver.gameserver.model.actor.L2Npc;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.quest.Quest;
  21. import com.l2jserver.gameserver.model.quest.QuestState;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.AcquireSkillInfo;
  24. import com.l2jserver.gameserver.network.serverpackets.AcquireSkillList;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. import com.l2jserver.gameserver.util.Util;
  27. public class SkillTransfer extends Quest
  28. {
  29. private static String qn = "SkillTransfer";
  30. private static final int RESET_ADENA_COST = 10000000;
  31. private static final int NPCs[] =
  32. {
  33. 30022,30030,30032,30036,30067,30068,30116,30117,30118,30119,
  34. 30144,30145,30188,30194,30293,30330,30375,30377,30464,30473,
  35. 30476,30680,30701,30720,30721,30858,30859,30860,30861,30864,
  36. 30906,30908,30912,31280,31281,31287,31329,31330,31335,31969,
  37. 31970,31976,32155,32162
  38. };
  39. /*
  40. * Item ID, count
  41. */
  42. private static final int[][] PORMANDERS =
  43. {
  44. { 15307, 1 }, // Cardinal (97)
  45. { 15308, 1 }, // Eva's Saint (105)
  46. { 15309, 4 } // Shillen Saint (112)
  47. };
  48. /*
  49. * Skill ID, Skill Level
  50. */
  51. private static final int[][][] SKILL_TRANSFER_TREE =
  52. {
  53. // Cardinal (97)
  54. {
  55. {1013,32},
  56. {1033,3},
  57. {1050,2},
  58. {1059,3},
  59. {1087,3},
  60. {1189,3},
  61. {1240,3},
  62. {1242,3},
  63. {1243,6},
  64. {1255,2},
  65. {1257,3},
  66. {1259,4},
  67. {1268,4},
  68. {1273,13},
  69. {1303,2},
  70. {1304,3},
  71. {1392,3},
  72. {1393,3},
  73. {1397,3},
  74. {1531,7},
  75. {1539,4}
  76. },
  77. // Eva's Saint (105)
  78. {
  79. {1018,3},
  80. {1034,13},
  81. {1042,12},
  82. {1049,14},
  83. {1059,3},
  84. {1075,15},
  85. {1077,3},
  86. {1189,3},
  87. {1218,33},
  88. {1240,3},
  89. {1242,3},
  90. {1254,6},
  91. {1258,4},
  92. {1268,4},
  93. {1271,1},
  94. {1307,3},
  95. {1311,6},
  96. {1392,3},
  97. {1396,10},
  98. {1399,5},
  99. {1402,5},
  100. {1418,1},
  101. {1531,7},
  102. {1539,4}
  103. },
  104. // Shillen Saint (112)
  105. {
  106. {1020,27},
  107. {1028,19},
  108. {1033,3},
  109. {1034,13},
  110. {1042,12},
  111. {1043,1},
  112. {1044,3},
  113. {1049,14},
  114. {1050,2},
  115. {1075,15},
  116. {1087,3},
  117. {1218,33},
  118. {1243,6},
  119. {1254,6},
  120. {1255,2},
  121. {1257,3},
  122. {1258,4},
  123. {1259,4},
  124. {1271,1},
  125. {1273,13},
  126. {1304,3},
  127. {1307,3},
  128. {1311,6},
  129. {1393,3},
  130. {1394,10},
  131. {1396,10},
  132. {1397,3},
  133. {1399,5},
  134. {1400,10},
  135. {1401,11},
  136. {1402,5},
  137. {1418,1}
  138. }
  139. };
  140. @Override
  141. public final String onAcquireSkillList(L2Npc npc, L2PcInstance player)
  142. {
  143. if (player == null)
  144. return null;
  145. final int index = getTransferClassIndex(player);
  146. if (index >= 0)
  147. {
  148. boolean found = false;
  149. AcquireSkillList asl = new AcquireSkillList(AcquireSkillList.SkillType.unk4);
  150. int[][] skillsList = SKILL_TRANSFER_TREE[index];
  151. for (int i = 0; i < skillsList.length; i++)
  152. {
  153. int skillId = skillsList[i][0];
  154. int skillLevel = skillsList[i][1];
  155. if (player.getSkillLevel(skillId) >= skillLevel)
  156. continue;
  157. asl.addSkill(skillId, skillLevel, skillLevel, 0, 0);
  158. found = true;
  159. }
  160. if (found)
  161. {
  162. player.sendPacket(asl);
  163. return null;
  164. }
  165. }
  166. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_MORE_SKILLS_TO_LEARN));
  167. return null;
  168. }
  169. @Override
  170. public final String onAcquireSkill(L2Npc npc, L2PcInstance player, L2Skill skill)
  171. {
  172. if (player == null || skill == null)
  173. return null;
  174. final int index = getTransferClassIndex(player);
  175. if (index >= 0)
  176. {
  177. int[][] skillsList = SKILL_TRANSFER_TREE[index];
  178. for (int i = 0; i < skillsList.length; i++)
  179. {
  180. if (skill.getId() == skillsList[i][0] && skill.getLevel() <= skillsList[i][1])
  181. {
  182. final int itemId = PORMANDERS[index][0];
  183. if (player.getInventory().getItemByItemId(itemId) != null)
  184. {
  185. if (player.destroyItemByItemId(qn, itemId, 1, npc, true))
  186. return "true";
  187. }
  188. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ITEM_MISSING_TO_LEARN_SKILL));
  189. return "false";
  190. }
  191. }
  192. }
  193. Util.handleIllegalPlayerAction(player, "Player " + player.getName()
  194. + " tried to learn skill that he can't!!!", Config.DEFAULT_PUNISH);
  195. return "false";
  196. }
  197. @Override
  198. public final String onAcquireSkillInfo(L2Npc npc, L2PcInstance player, L2Skill skill)
  199. {
  200. if (player == null || skill == null)
  201. return null;
  202. final int index = getTransferClassIndex(player);
  203. if (index >= 0)
  204. {
  205. AcquireSkillInfo asi = new AcquireSkillInfo(skill.getId(), skill.getLevel(), 0, 4);
  206. int[][] skillsList = SKILL_TRANSFER_TREE[index];
  207. for (int i = 0; i < skillsList.length; i++)
  208. {
  209. if (skill.getId() == skillsList[i][0])
  210. {
  211. asi.addRequirement(99, PORMANDERS[index][0], 1, 50);
  212. player.sendPacket(asi);
  213. break;
  214. }
  215. }
  216. }
  217. return null;
  218. }
  219. @Override
  220. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  221. {
  222. String htmltext = "";
  223. if (player == null)
  224. return htmltext;
  225. if (event.equalsIgnoreCase("learn"))
  226. {
  227. if (!npc.getTemplate().canTeach(player.getClassId()))
  228. npc.showNoTeachHtml(player);
  229. else if (player.getLevel() < 76 || player.getClassId().level() < 3)
  230. htmltext = "learn-lowlevel.htm";
  231. else
  232. onAcquireSkillList(npc, player);
  233. }
  234. else if (event.equalsIgnoreCase("cleanse"))
  235. {
  236. if (!npc.getTemplate().canTeach(player.getClassId()))
  237. {
  238. npc.showNoTeachHtml(player);
  239. return htmltext;
  240. }
  241. else if (player.getLevel() < 76 || player.getClassId().level() < 3)
  242. {
  243. htmltext = "cleanse-no.htm";
  244. return htmltext;
  245. }
  246. else if (player.getAdena() < RESET_ADENA_COST)
  247. {
  248. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CANNOT_RESET_SKILL_LINK_BECAUSE_NOT_ENOUGH_ADENA));
  249. return htmltext;
  250. }
  251. final int index = getTransferClassIndex(player);
  252. if (index >= 0)
  253. {
  254. final int itemId = PORMANDERS[index][0];
  255. final int count = PORMANDERS[index][1];
  256. if (player.getInventory().getItemByItemId(itemId) == null)
  257. {
  258. int[][] skillsList = SKILL_TRANSFER_TREE[index];
  259. boolean found = false;
  260. for (L2Skill skill : player.getAllSkills())
  261. {
  262. for (int i = 0; i < skillsList.length; i++)
  263. {
  264. if (skill.getId() == skillsList[i][0])
  265. {
  266. if (!found)
  267. found = true;
  268. player.removeSkill(skill);
  269. }
  270. }
  271. }
  272. if (found)
  273. {
  274. player.sendSkillList();
  275. if (player.reduceAdena(qn, RESET_ADENA_COST, npc, true))
  276. player.addItem(qn, itemId, count, npc, true);
  277. return htmltext;
  278. }
  279. }
  280. htmltext = "cleanse-no_skills.htm";
  281. }
  282. else
  283. npc.showNoTeachHtml(player);
  284. }
  285. else if (event.equalsIgnoreCase("givePormanders"))
  286. givePormanders(npc, player);
  287. return htmltext;
  288. }
  289. @Override
  290. public final String onEnterWorld(L2PcInstance player)
  291. {
  292. givePormanders(null, player);
  293. return null;
  294. }
  295. private final synchronized void givePormanders(L2Npc npc, L2PcInstance player)
  296. {
  297. final int index = getTransferClassIndex(player);
  298. if (index >= 0)
  299. {
  300. QuestState st = player.getQuestState(qn);
  301. if (st == null)
  302. st = newQuestState(player);
  303. final String name = qn + String.valueOf(player.getClassId().getId());
  304. if (st.getInt(name) == 0)
  305. {
  306. st.setInternal(name, "1");
  307. if (st.getGlobalQuestVar(name).isEmpty())
  308. {
  309. st.saveGlobalQuestVar(name, "1");
  310. player.addItem(qn, PORMANDERS[index][0], PORMANDERS[index][1], npc, true);
  311. }
  312. }
  313. if (Config.SKILL_CHECK_ENABLE && (!player.isGM() || Config.SKILL_CHECK_GM))
  314. {
  315. int count = PORMANDERS[index][1] - (int)player.getInventory().getInventoryItemCount(PORMANDERS[index][0], -1, false);
  316. for (L2Skill s : player.getAllSkills())
  317. {
  318. for (int i = SKILL_TRANSFER_TREE[index].length; --i >= 0;)
  319. {
  320. if (SKILL_TRANSFER_TREE[index][i][0] == s.getId())
  321. {
  322. // Holy Weapon allowed for Shilien Saint/Inquisitor stance
  323. if (s.getId() == 1043 && index == 2 && player.isInStance())
  324. continue;
  325. count--;
  326. if (count < 0)
  327. {
  328. Util.handleIllegalPlayerAction(player, "Player " + player.getName() +
  329. " has too many transfered skills or items, skill:" + s.getName() +
  330. " ("+s.getId() + "/" + s.getLevel() + "), class:" +
  331. player.getTemplate().className, 1);
  332. if (Config.SKILL_CHECK_REMOVE)
  333. player.removeSkill(s);
  334. }
  335. }
  336. }
  337. }
  338. }
  339. }
  340. }
  341. @Override
  342. public final String onTalk(L2Npc npc, L2PcInstance player)
  343. {
  344. return "main.htm";
  345. }
  346. private final int getTransferClassIndex(L2PcInstance player)
  347. {
  348. switch (player.getClassId().getId())
  349. {
  350. case 97: // Cardinal
  351. return 0;
  352. case 105: // Eva's Saint
  353. return 1;
  354. case 112: // Shillien Saint
  355. return 2;
  356. default:
  357. return -1;
  358. }
  359. }
  360. public SkillTransfer(int id, String name, String descr)
  361. {
  362. super(id, name, descr);
  363. setOnEnterWorld(true);
  364. for (int i : NPCs)
  365. {
  366. addStartNpc(i);
  367. addTalkId(i);
  368. addAcquireSkillId(i);
  369. }
  370. }
  371. public static void main(String[] args)
  372. {
  373. new SkillTransfer(-1, qn, "custom");
  374. }
  375. }