Sow.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.skillhandlers;
  16. import java.util.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.ai.CtrlIntention;
  19. import com.l2jserver.gameserver.handler.ISkillHandler;
  20. import com.l2jserver.gameserver.model.L2Manor;
  21. import com.l2jserver.gameserver.model.L2Object;
  22. import com.l2jserver.gameserver.model.L2Skill;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  28. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  29. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  30. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  31. import com.l2jserver.util.Rnd;
  32. /**
  33. * @author l3x
  34. */
  35. public class Sow implements ISkillHandler
  36. {
  37. private static Logger _log = Logger.getLogger(Sow.class.getName());
  38. private static final L2SkillType[] SKILL_IDS =
  39. {
  40. L2SkillType.SOW
  41. };
  42. /**
  43. *
  44. * @see com.l2jserver.gameserver.handler.ISkillHandler#useSkill(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.L2Skill, com.l2jserver.gameserver.model.L2Object[])
  45. */
  46. @Override
  47. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  48. {
  49. if (!(activeChar instanceof L2PcInstance))
  50. return;
  51. final L2Object[] targetList = skill.getTargetList(activeChar);
  52. if (targetList == null || targetList.length == 0)
  53. return;
  54. if (Config.DEBUG)
  55. _log.info("Casting sow");
  56. L2MonsterInstance target;
  57. for (L2Object tgt: targetList)
  58. {
  59. if (!(tgt instanceof L2MonsterInstance))
  60. continue;
  61. target = (L2MonsterInstance) tgt;
  62. if (target.isDead()
  63. || target.isSeeded()
  64. || target.getSeederId() != activeChar.getObjectId())
  65. {
  66. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  67. continue;
  68. }
  69. final int seedId = target.getSeedType();
  70. if (seedId == 0)
  71. {
  72. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  73. continue;
  74. }
  75. //Consuming used seed
  76. if (!activeChar.destroyItemByItemId("Consume", seedId, 1, target, false))
  77. {
  78. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  79. return;
  80. }
  81. SystemMessage sm;
  82. if (calcSuccess(activeChar, target, seedId))
  83. {
  84. activeChar.sendPacket(new PlaySound("Itemsound.quest_itemget"));
  85. target.setSeeded((L2PcInstance)activeChar);
  86. sm = SystemMessage.getSystemMessage(SystemMessageId.THE_SEED_WAS_SUCCESSFULLY_SOWN);
  87. }
  88. else
  89. sm = SystemMessage.getSystemMessage(SystemMessageId.THE_SEED_WAS_NOT_SOWN);
  90. if (activeChar.getParty() == null)
  91. activeChar.sendPacket(sm);
  92. else
  93. activeChar.getParty().broadcastToPartyMembers(sm);
  94. //TODO: Mob should not aggro on player, this way doesn't work really nice
  95. target.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  96. }
  97. }
  98. private boolean calcSuccess(L2Character activeChar, L2Character target, int seedId)
  99. {
  100. // TODO: check all the chances
  101. int basicSuccess = (L2Manor.getInstance().isAlternative(seedId) ? 20 : 90);
  102. final int minlevelSeed = L2Manor.getInstance().getSeedMinLevel(seedId);
  103. final int maxlevelSeed = L2Manor.getInstance().getSeedMaxLevel(seedId);
  104. final int levelPlayer = activeChar.getLevel(); // Attacker Level
  105. final int levelTarget = target.getLevel(); // target Level
  106. // seed level
  107. if (levelTarget < minlevelSeed)
  108. basicSuccess -= 5 * (minlevelSeed - levelTarget);
  109. if (levelTarget > maxlevelSeed)
  110. basicSuccess -= 5 * (levelTarget - maxlevelSeed);
  111. // 5% decrease in chance if player level
  112. // is more than +/- 5 levels to _target's_ level
  113. int diff = (levelPlayer - levelTarget);
  114. if (diff < 0)
  115. diff = -diff;
  116. if (diff > 5)
  117. basicSuccess -= 5 * (diff - 5);
  118. //chance can't be less than 1%
  119. if (basicSuccess < 1)
  120. basicSuccess = 1;
  121. return Rnd.nextInt(99) < basicSuccess;
  122. }
  123. /**
  124. *
  125. * @see com.l2jserver.gameserver.handler.ISkillHandler#getSkillIds()
  126. */
  127. @Override
  128. public L2SkillType[] getSkillIds()
  129. {
  130. return SKILL_IDS;
  131. }
  132. }