Unlock.java 6.0 KB

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