RequestAquireSkill.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2, or (at your option)
  5. * any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. * 02111-1307, USA.
  16. *
  17. * http://www.gnu.org/copyleft/gpl.html
  18. */
  19. package net.sf.l2j.gameserver.clientpackets;
  20. import java.util.logging.Logger;
  21. import net.sf.l2j.Config;
  22. import net.sf.l2j.gameserver.datatables.SkillSpellbookTable;
  23. import net.sf.l2j.gameserver.datatables.SkillTable;
  24. import net.sf.l2j.gameserver.datatables.SkillTreeTable;
  25. import net.sf.l2j.gameserver.model.L2ItemInstance;
  26. import net.sf.l2j.gameserver.model.L2PledgeSkillLearn;
  27. import net.sf.l2j.gameserver.model.L2ShortCut;
  28. import net.sf.l2j.gameserver.model.L2Skill;
  29. import net.sf.l2j.gameserver.model.L2SkillLearn;
  30. import net.sf.l2j.gameserver.model.actor.instance.L2FishermanInstance;
  31. import net.sf.l2j.gameserver.model.actor.instance.L2FolkInstance;
  32. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  33. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  34. import net.sf.l2j.gameserver.model.actor.instance.L2VillageMasterInstance;
  35. import net.sf.l2j.gameserver.network.SystemMessageId;
  36. import net.sf.l2j.gameserver.serverpackets.ExStorageMaxCount;
  37. import net.sf.l2j.gameserver.serverpackets.PledgeSkillList;
  38. import net.sf.l2j.gameserver.serverpackets.ShortCutRegister;
  39. import net.sf.l2j.gameserver.serverpackets.StatusUpdate;
  40. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  41. import net.sf.l2j.gameserver.util.IllegalPlayerAction;
  42. import net.sf.l2j.gameserver.util.Util;
  43. /**
  44. * This class ...
  45. *
  46. * @version $Revision: 1.7.2.1.2.4 $ $Date: 2005/03/27 15:29:30 $
  47. */
  48. public class RequestAquireSkill extends L2GameClientPacket
  49. {
  50. private static final String _C__6C_REQUESTAQUIRESKILL = "[C] 6C RequestAquireSkill";
  51. private static Logger _log = Logger.getLogger(RequestAquireSkill.class.getName());
  52. private int _id;
  53. private int _level;
  54. private int _skillType;
  55. @Override
  56. protected void readImpl()
  57. {
  58. _id = readD();
  59. _level = readD();
  60. _skillType = readD();
  61. }
  62. @Override
  63. protected void runImpl()
  64. {
  65. L2PcInstance player = getClient().getActiveChar();
  66. if (player == null)
  67. return;
  68. L2FolkInstance trainer = player.getLastFolkNPC();
  69. if (trainer == null)
  70. return;
  71. int npcid = trainer.getNpcId();
  72. if (!player.isInsideRadius(trainer, L2NpcInstance.INTERACTION_DISTANCE, false, false)
  73. && !player.isGM())
  74. return;
  75. if (!Config.ALT_GAME_SKILL_LEARN) player.setSkillLearningClassId(player.getClassId());
  76. if (player.getSkillLevel(_id) >= _level)
  77. {
  78. // already knows the skill with this level
  79. return;
  80. }
  81. L2Skill skill = SkillTable.getInstance().getInfo(_id, _level);
  82. int counts = 0;
  83. int _requiredSp = 10000000;
  84. if (_skillType == 0)
  85. {
  86. L2SkillLearn[] skills = SkillTreeTable.getInstance()
  87. .getAvailableSkills(player, player.getSkillLearningClassId());
  88. for (L2SkillLearn s : skills)
  89. {
  90. L2Skill sk = SkillTable.getInstance().getInfo(s.getId(),
  91. s.getLevel());
  92. if (sk == null || sk != skill
  93. || !sk.getCanLearn(player.getSkillLearningClassId())
  94. || !sk.canTeachBy(npcid))
  95. continue;
  96. counts++;
  97. _requiredSp = SkillTreeTable.getInstance().getSkillCost(player,
  98. skill);
  99. }
  100. if (counts == 0 && !Config.ALT_GAME_SKILL_LEARN)
  101. {
  102. player
  103. .sendMessage("You are trying to learn skill that u can't..");
  104. Util.handleIllegalPlayerAction(player, "Player "
  105. + player.getName()
  106. + " tried to learn skill that he can't!!!",
  107. IllegalPlayerAction.PUNISH_KICK);
  108. return;
  109. }
  110. if (player.getSp() >= _requiredSp)
  111. {
  112. if (Config.SP_BOOK_NEEDED)
  113. {
  114. int spbId = SkillSpellbookTable.getInstance()
  115. .getBookForSkill(skill);
  116. if (skill.getLevel() == 1 && spbId > -1)
  117. {
  118. L2ItemInstance spb = player.getInventory()
  119. .getItemByItemId(spbId);
  120. if (spb == null)
  121. {
  122. // Haven't spellbook
  123. player.sendPacket(new SystemMessage(
  124. SystemMessageId.ITEM_MISSING_TO_LEARN_SKILL));
  125. return;
  126. }
  127. // ok
  128. player.destroyItem("Consume", spb.getObjectId(), 1, trainer, true);
  129. }
  130. }
  131. } else
  132. {
  133. SystemMessage sm = new SystemMessage(
  134. SystemMessageId.NOT_ENOUGH_SP_TO_LEARN_SKILL);
  135. player.sendPacket(sm);
  136. sm = null;
  137. return;
  138. }
  139. } else if (_skillType == 1)
  140. {
  141. int costid = 0;
  142. int costcount = 0;
  143. // Skill Learn bug Fix
  144. L2SkillLearn[] skillsc = SkillTreeTable.getInstance()
  145. .getAvailableSkills(player);
  146. for (L2SkillLearn s : skillsc)
  147. {
  148. L2Skill sk = SkillTable.getInstance().getInfo(s.getId(),
  149. s.getLevel());
  150. if (sk == null || sk != skill)
  151. continue;
  152. counts++;
  153. costid = s.getIdCost();
  154. costcount = s.getCostCount();
  155. _requiredSp = s.getSpCost();
  156. }
  157. if (counts == 0)
  158. {
  159. player
  160. .sendMessage("You are trying to learn skill that u can't..");
  161. Util.handleIllegalPlayerAction(player, "Player "
  162. + player.getName()
  163. + " tried to learn skill that he can't!!!",
  164. IllegalPlayerAction.PUNISH_KICK);
  165. return;
  166. }
  167. if (player.getSp() >= _requiredSp)
  168. {
  169. if (!player.destroyItemByItemId("Consume", costid, costcount,
  170. trainer, false))
  171. {
  172. // Haven't spellbook
  173. player.sendPacket(new SystemMessage(
  174. SystemMessageId.ITEM_MISSING_TO_LEARN_SKILL));
  175. return;
  176. }
  177. SystemMessage sm = new SystemMessage(
  178. SystemMessageId.DISSAPEARED_ITEM);
  179. sm.addNumber(costcount);
  180. sm.addItemName(costid);
  181. sendPacket(sm);
  182. sm = null;
  183. } else
  184. {
  185. SystemMessage sm = new SystemMessage(
  186. SystemMessageId.NOT_ENOUGH_SP_TO_LEARN_SKILL);
  187. player.sendPacket(sm);
  188. sm = null;
  189. return;
  190. }
  191. }
  192. else if (_skillType == 2) //pledgeskills TODO: Find appropriate system messages.
  193. {
  194. if (!player.isClanLeader())
  195. {
  196. // TODO: Find and add system msg
  197. player.sendMessage("This feature is available only for the clan leader");
  198. return;
  199. }
  200. int itemId = 0;
  201. int repCost = 100000000;
  202. // Skill Learn bug Fix
  203. L2PledgeSkillLearn[] skills = SkillTreeTable.getInstance().getAvailablePledgeSkills(player);
  204. for (L2PledgeSkillLearn s : skills)
  205. {
  206. L2Skill sk = SkillTable.getInstance().getInfo(s.getId(), s.getLevel());
  207. if (sk == null || sk != skill)
  208. continue;
  209. counts++;
  210. itemId = s.getItemId();
  211. repCost = s.getRepCost();
  212. }
  213. if (counts == 0)
  214. {
  215. player.sendMessage("You are trying to learn skill that u can't..");
  216. Util.handleIllegalPlayerAction(player, "Player " + player.getName()
  217. + " tried to learn skill that he can't!!!", IllegalPlayerAction.PUNISH_KICK);
  218. return;
  219. }
  220. if (player.getClan().getReputationScore() >= repCost)
  221. {
  222. if (Config.LIFE_CRYSTAL_NEEDED)
  223. {
  224. if (!player.destroyItemByItemId("Consume", itemId, 1, trainer, false))
  225. {
  226. // Haven't spellbook
  227. player.sendPacket(new SystemMessage(SystemMessageId.ITEM_MISSING_TO_LEARN_SKILL));
  228. return;
  229. }
  230. SystemMessage sm = new SystemMessage(SystemMessageId.DISSAPEARED_ITEM);
  231. sm.addItemName(itemId);
  232. sm.addNumber(1);
  233. sendPacket(sm);
  234. sm = null;
  235. }
  236. }
  237. else
  238. {
  239. SystemMessage sm = new SystemMessage(SystemMessageId.ACQUIRE_SKILL_FAILED_BAD_CLAN_REP_SCORE);
  240. player.sendPacket(sm);
  241. //sm = null;
  242. return;
  243. }
  244. player.getClan().setReputationScore(player.getClan().getReputationScore()-repCost, true);
  245. player.getClan().addNewSkill(skill);
  246. if (Config.DEBUG)
  247. _log.fine("Learned pledge skill " + _id + " for " + _requiredSp + " SP.");
  248. SystemMessage cr = new SystemMessage(SystemMessageId.S1_DEDUCTED_FROM_CLAN_REP);
  249. cr.addNumber(repCost);
  250. player.sendPacket(cr);
  251. SystemMessage sm = new SystemMessage(SystemMessageId.CLAN_SKILL_S1_ADDED);
  252. sm.addSkillName(_id);
  253. player.sendPacket(sm);
  254. sm = null;
  255. player.getClan().broadcastToOnlineMembers(new PledgeSkillList(player.getClan()));
  256. for(L2PcInstance member: player.getClan().getOnlineMembers(""))
  257. {
  258. member.sendSkillList();
  259. }
  260. ((L2VillageMasterInstance)trainer).showPledgeSkillList(player); //Maybe we shoud add a check here...
  261. return;
  262. }
  263. else
  264. {
  265. _log.warning("Recived Wrong Packet Data in Aquired Skill - unk1:"
  266. + _skillType);
  267. return;
  268. }
  269. player.addSkill(skill, true);
  270. if (Config.DEBUG)
  271. _log.fine("Learned skill " + _id + " for " + _requiredSp + " SP.");
  272. player.setSp(player.getSp() - _requiredSp);
  273. StatusUpdate su = new StatusUpdate(player.getObjectId());
  274. su.addAttribute(StatusUpdate.SP, player.getSp());
  275. player.sendPacket(su);
  276. SystemMessage sp = new SystemMessage(SystemMessageId.SP_DECREASED_S1);
  277. sp.addNumber(_requiredSp);
  278. sendPacket(sp);
  279. SystemMessage sm = new SystemMessage(SystemMessageId.LEARNED_SKILL_S1);
  280. sm.addSkillName(_id);
  281. player.sendPacket(sm);
  282. sm = null;
  283. // update all the shortcuts to this skill
  284. if (_level > 1)
  285. {
  286. L2ShortCut[] allShortCuts = player.getAllShortCuts();
  287. for (L2ShortCut sc : allShortCuts)
  288. {
  289. if (sc.getId() == _id && sc.getType() == L2ShortCut.TYPE_SKILL)
  290. {
  291. L2ShortCut newsc = new L2ShortCut(sc.getSlot(), sc
  292. .getPage(), sc.getType(), sc.getId(), _level, 1);
  293. player.sendPacket(new ShortCutRegister(newsc));
  294. player.registerShortCut(newsc);
  295. }
  296. }
  297. }
  298. if (trainer instanceof L2FishermanInstance)
  299. ((L2FishermanInstance) trainer).showSkillList(player);
  300. else
  301. trainer.showSkillList(player, player.getSkillLearningClassId());
  302. if (_id >= 1368 && _id <= 1372) // if skill is expand sendpacket :)
  303. {
  304. ExStorageMaxCount esmc = new ExStorageMaxCount(player);
  305. player.sendPacket(esmc);
  306. }
  307. }
  308. /*
  309. * (non-Javadoc)
  310. *
  311. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  312. */
  313. @Override
  314. public String getType()
  315. {
  316. return _C__6C_REQUESTAQUIRESKILL;
  317. }
  318. }