Sow.java 4.9 KB

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