Seed.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 net.sf.l2j.gameserver.handler.itemhandlers;
  16. import net.sf.l2j.gameserver.datatables.MapRegionTable;
  17. import net.sf.l2j.gameserver.datatables.SkillTable;
  18. import net.sf.l2j.gameserver.handler.IItemHandler;
  19. import net.sf.l2j.gameserver.instancemanager.CastleManorManager;
  20. import net.sf.l2j.gameserver.model.L2ItemInstance;
  21. import net.sf.l2j.gameserver.model.L2Manor;
  22. import net.sf.l2j.gameserver.model.L2Object;
  23. import net.sf.l2j.gameserver.model.L2Skill;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2ChestInstance;
  25. import net.sf.l2j.gameserver.model.actor.instance.L2GrandBossInstance;
  26. import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
  27. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  28. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  29. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  30. import net.sf.l2j.gameserver.model.actor.instance.L2RaidBossInstance;
  31. import net.sf.l2j.gameserver.network.SystemMessageId;
  32. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  33. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  34. /**
  35. * @author l3x
  36. */
  37. public class Seed implements IItemHandler
  38. {
  39. private static int[] _itemIds =
  40. {
  41. 5016, 5017, 5018, 5019, 5020, 5021, 5022, 5023, 5024,
  42. 5025, 5026, 5027, 5028, 5029, 5030, 5031, 5032, 5033,
  43. 5034, 5035, 5036, 5037, 5038, 5039, 5040, 5041, 5042,
  44. 5043, 5044, 5045, 5046, 5047, 5048, 5049, 5050, 5051,
  45. 5052, 5053, 5054, 5055, 5056, 5057, 5058, 5059, 5060,
  46. 5061, 5221, 5222, 5223, 5224, 5225, 5226, 5227, 5650,
  47. 5651, 5652, 5653, 5654, 5655, 5656, 5657, 5658, 5659,
  48. 5660, 5661, 5662, 5663, 5664, 5665, 5666, 5667, 5668,
  49. 5669, 5670, 5671, 5672, 5673, 5674, 5675, 5676, 5677,
  50. 5678, 5679, 5680, 5681, 5682, 5683, 5684, 5685, 5686,
  51. 5687, 5688, 5689, 5690, 5691, 5692, 5693, 5694, 5695,
  52. 5696, 5697, 5698, 5699, 5700, 5701, 5702, 6727, 6728,
  53. 6729, 6730, 6731, 6732, 6733, 6734, 6735, 6736, 6737,
  54. 6738, 6739, 6740, 6741, 6742, 6743, 6744, 6745, 6746,
  55. 6747, 6748, 6749, 6750, 6751, 6752, 6753, 6754, 6755,
  56. 6756, 6757, 6758, 6759, 6760, 6761, 6762, 6763, 6764,
  57. 6765, 6766, 6767, 6768, 6769, 6770, 6771, 6772, 6773,
  58. 6774, 6775, 6776, 6777, 6778, 7016, 7017, 7018, 7019,
  59. 7020, 7021, 7022, 7023, 7024, 7025, 7026, 7027, 7028,
  60. 7029, 7030, 7031, 7032, 7033, 7034, 7035, 7036, 7037,
  61. 7038, 7039, 7040, 7041, 7042, 7043, 7044, 7045, 7046,
  62. 7047, 7048, 7049, 7050, 7051, 7052, 7053, 7054, 7055,
  63. 7056, 7057, 8223, 8224, 8225, 8226, 8227, 8228, 8229,
  64. 8230, 8231, 8232, 8233, 8234, 8235, 8236, 8237, 8238,
  65. 8239, 8240, 8241, 8242, 8243, 8244, 8245, 8246, 8247,
  66. 8248, 8249, 8250, 8251, 8252, 8253, 8254, 8255, 8256,
  67. 8257, 8258, 8259, 8260, 8261, 8262, 8263, 8264, 8265,
  68. 8266, 8267, 8268, 8269, 8270, 8271, 8272, 8521, 8522,
  69. 8523, 8524, 8525, 8526
  70. };
  71. private int _seedId;
  72. private L2MonsterInstance _target;
  73. private L2PcInstance _activeChar;
  74. /**
  75. *
  76. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  77. */
  78. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  79. {
  80. if (!(playable instanceof L2PcInstance))
  81. return;
  82. if (CastleManorManager.getInstance().isDisabled())
  83. return;
  84. _activeChar = (L2PcInstance) playable;
  85. L2Object target = _activeChar.getTarget();
  86. if (!(target instanceof L2NpcInstance))
  87. {
  88. _activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  89. _activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  90. return;
  91. }
  92. if (!(target instanceof L2MonsterInstance) || (target instanceof L2ChestInstance) || (target instanceof L2GrandBossInstance) || (target instanceof L2RaidBossInstance))
  93. {
  94. _activeChar.sendPacket(new SystemMessage(SystemMessageId.THE_TARGET_IS_UNAVAILABLE_FOR_SEEDING));
  95. _activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  96. return;
  97. }
  98. _target = (L2MonsterInstance) target;
  99. if (_target == null || _target.isDead())
  100. {
  101. _activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  102. _activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  103. return;
  104. }
  105. if (_target.isSeeded())
  106. {
  107. _activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  108. return;
  109. }
  110. _seedId = item.getItemId();
  111. if (areaValid(MapRegionTable.getInstance().getAreaCastle(_activeChar)))
  112. {
  113. //TODO: get right skill level
  114. _target.setSeeded(_seedId, _activeChar);
  115. L2Skill skill = SkillTable.getInstance().getInfo(2097, 3); // Sowing skill
  116. _activeChar.useMagic(skill, false, false);
  117. }
  118. else
  119. {
  120. _activeChar.sendPacket(new SystemMessage(SystemMessageId.THIS_SEED_MAY_NOT_BE_SOWN_HERE));
  121. }
  122. }
  123. /**
  124. *
  125. * @param castleId
  126. * @return
  127. */
  128. private boolean areaValid(int castleId)
  129. {
  130. return (L2Manor.getInstance().getCastleIdForSeed(_seedId) == castleId);
  131. }
  132. /**
  133. *
  134. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  135. */
  136. public int[] getItemIds()
  137. {
  138. return _itemIds;
  139. }
  140. }