Sow.java 4.6 KB

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