Unlock.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.skillhandlers;
  16. import net.sf.l2j.gameserver.ai.CtrlIntention;
  17. import net.sf.l2j.gameserver.handler.ISkillHandler;
  18. import net.sf.l2j.gameserver.model.L2Character;
  19. import net.sf.l2j.gameserver.model.L2Object;
  20. import net.sf.l2j.gameserver.model.L2Skill;
  21. import net.sf.l2j.gameserver.model.L2Skill.SkillType;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2ChestInstance;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  24. import net.sf.l2j.gameserver.network.SystemMessageId;
  25. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  26. import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
  27. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  28. import net.sf.l2j.gameserver.skills.Formulas;
  29. import net.sf.l2j.util.Rnd;
  30. public class Unlock implements ISkillHandler
  31. {
  32. //private static Logger _log = Logger.getLogger(Unlock.class.getName());
  33. private static final SkillType[] SKILL_IDS = {SkillType.UNLOCK};
  34. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  35. {
  36. L2Object[] targetList = skill.getTargetList(activeChar);
  37. if (targetList == null) return;
  38. for (int index = 0; index < targetList.length; index++)
  39. {
  40. L2Object target = targetList[index];
  41. boolean success = Formulas.getInstance().calculateUnlockChance(skill);
  42. if (target instanceof L2DoorInstance)
  43. {
  44. L2DoorInstance door = (L2DoorInstance) target;
  45. if (!door.isUnlockable())
  46. {
  47. activeChar.sendPacket(new SystemMessage(SystemMessageId.UNABLE_TO_UNLOCK_DOOR));
  48. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  49. return;
  50. }
  51. if (success && (door.getOpen() == 1))
  52. {
  53. door.openMe();
  54. door.onOpen();
  55. activeChar.sendMessage("Unlock the door!");
  56. }
  57. else
  58. {
  59. activeChar.sendPacket(new SystemMessage(SystemMessageId.FAILED_TO_UNLOCK_DOOR));
  60. }
  61. }
  62. else if (target instanceof L2ChestInstance)
  63. {
  64. L2ChestInstance chest = (L2ChestInstance) targetList[index];
  65. if (chest.getCurrentHp() <= 0 || chest.isInteracted())
  66. {
  67. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  68. return;
  69. }
  70. else
  71. {
  72. int chestChance = 0;
  73. int chestGroup = 0;
  74. int chestTrapLimit = 0;
  75. if (chest.getLevel() > 60) chestGroup = 4;
  76. else if (chest.getLevel() > 40) chestGroup = 3;
  77. else if (chest.getLevel() > 30) chestGroup = 2;
  78. else chestGroup = 1;
  79. switch (chestGroup)
  80. {
  81. case 1:
  82. {
  83. if (skill.getLevel() > 10) chestChance = 100;
  84. else if (skill.getLevel() >= 3) chestChance = 50;
  85. else if (skill.getLevel() == 2) chestChance = 45;
  86. else if (skill.getLevel() == 1) chestChance = 40;
  87. chestTrapLimit = 10;
  88. }
  89. break;
  90. case 2:
  91. {
  92. if (skill.getLevel() > 12) chestChance = 100;
  93. else if (skill.getLevel() >= 7) chestChance = 50;
  94. else if (skill.getLevel() == 6) chestChance = 45;
  95. else if (skill.getLevel() == 5) chestChance = 40;
  96. else if (skill.getLevel() == 4) chestChance = 35;
  97. else if (skill.getLevel() == 3) chestChance = 30;
  98. chestTrapLimit = 30;
  99. }
  100. break;
  101. case 3:
  102. {
  103. if (skill.getLevel() >= 14) chestChance = 50;
  104. else if (skill.getLevel() == 13) chestChance = 45;
  105. else if (skill.getLevel() == 12) chestChance = 40;
  106. else if (skill.getLevel() == 11) chestChance = 35;
  107. else if (skill.getLevel() == 10) chestChance = 30;
  108. else if (skill.getLevel() == 9) chestChance = 25;
  109. else if (skill.getLevel() == 8) chestChance = 20;
  110. else if (skill.getLevel() == 7) chestChance = 15;
  111. else if (skill.getLevel() == 6) chestChance = 10;
  112. chestTrapLimit = 50;
  113. }
  114. break;
  115. case 4:
  116. {
  117. if (skill.getLevel() >= 14) chestChance = 50;
  118. else if (skill.getLevel() == 13) chestChance = 45;
  119. else if (skill.getLevel() == 12) chestChance = 40;
  120. else if (skill.getLevel() == 11) chestChance = 35;
  121. chestTrapLimit = 80;
  122. }
  123. break;
  124. }
  125. if (Rnd.get(100) <= chestChance)
  126. {
  127. activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(),3));
  128. chest.setSpecialDrop();
  129. chest.setMustRewardExpSp(false);
  130. chest.setInteracted();
  131. chest.reduceCurrentHp(99999999, activeChar);
  132. }
  133. else
  134. {
  135. activeChar.broadcastPacket(new SocialAction(activeChar.getObjectId(),13));
  136. if (Rnd.get(100) < chestTrapLimit) chest.chestTrap(activeChar);
  137. chest.setInteracted();
  138. chest.addDamageHate(activeChar,0,1);
  139. chest.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, activeChar);
  140. }
  141. }
  142. }
  143. }
  144. }
  145. public SkillType[] getSkillIds()
  146. {
  147. return SKILL_IDS;
  148. }
  149. }