Seed.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 handlers.itemhandlers;
  16. import com.l2jserver.gameserver.handler.IItemHandler;
  17. import com.l2jserver.gameserver.instancemanager.CastleManorManager;
  18. import com.l2jserver.gameserver.instancemanager.MapRegionManager;
  19. import com.l2jserver.gameserver.model.L2Manor;
  20. import com.l2jserver.gameserver.model.L2Object;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.L2Playable;
  24. import com.l2jserver.gameserver.model.actor.instance.L2ChestInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.holders.SkillHolder;
  28. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  29. import com.l2jserver.gameserver.model.skills.L2Skill;
  30. import com.l2jserver.gameserver.network.SystemMessageId;
  31. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  32. /**
  33. * @author l3x
  34. */
  35. public class Seed implements IItemHandler
  36. {
  37. @Override
  38. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  39. {
  40. if (!(playable instanceof L2PcInstance))
  41. return false;
  42. if (CastleManorManager.getInstance().isDisabled())
  43. return false;
  44. final L2Object tgt = playable.getTarget();
  45. if (!(tgt instanceof L2Npc))
  46. {
  47. playable.sendPacket(SystemMessageId.INCORRECT_TARGET);
  48. playable.sendPacket(ActionFailed.STATIC_PACKET);
  49. return false;
  50. }
  51. if (!(tgt instanceof L2MonsterInstance) || tgt instanceof L2ChestInstance || ((L2Character)tgt).isRaid())
  52. {
  53. playable.sendPacket(SystemMessageId.THE_TARGET_IS_UNAVAILABLE_FOR_SEEDING);
  54. playable.sendPacket(ActionFailed.STATIC_PACKET);
  55. return false;
  56. }
  57. final L2MonsterInstance target = (L2MonsterInstance)tgt;
  58. if (target.isDead())
  59. {
  60. playable.sendPacket(SystemMessageId.INCORRECT_TARGET);
  61. playable.sendPacket(ActionFailed.STATIC_PACKET);
  62. return false;
  63. }
  64. if (target.isSeeded())
  65. {
  66. playable.sendPacket(ActionFailed.STATIC_PACKET);
  67. return false;
  68. }
  69. final int seedId = item.getItemId();
  70. if (!areaValid(seedId, MapRegionManager.getInstance().getAreaCastle(playable)))
  71. {
  72. playable.sendPacket(SystemMessageId.THIS_SEED_MAY_NOT_BE_SOWN_HERE);
  73. return false;
  74. }
  75. target.setSeeded(seedId, (L2PcInstance)playable);
  76. final SkillHolder[] skills = item.getEtcItem().getSkills();
  77. if (skills != null)
  78. {
  79. if(skills[0] == null)
  80. return false;
  81. L2Skill itemskill = skills[0].getSkill();
  82. ((L2PcInstance)playable).useMagic(itemskill, false, false);
  83. }
  84. return true;
  85. }
  86. /**
  87. *
  88. * @param seedId
  89. * @param castleId
  90. * @return
  91. */
  92. private boolean areaValid(int seedId, int castleId)
  93. {
  94. return (L2Manor.getInstance().getCastleIdForSeed(seedId) == castleId);
  95. }
  96. }