ArenaBuff.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.bypasshandlers;
  16. import java.util.StringTokenizer;
  17. import java.util.logging.Level;
  18. import com.l2jserver.gameserver.datatables.SkillTable;
  19. import com.l2jserver.gameserver.handler.IBypassHandler;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.skills.L2Skill;
  24. /**
  25. * @author Xaras2
  26. */
  27. public class ArenaBuff implements IBypassHandler
  28. {
  29. private static final String[] COMMANDS =
  30. {
  31. "ArenaBuffs",
  32. "HPRecovery",
  33. "CPRecovery"
  34. };
  35. private final int[][] _Buffs =
  36. {
  37. { // Fighter Buffs
  38. 6803, 6804, 6808, 6809, 6811, 6812
  39. },
  40. { // Mage Buffs
  41. 6804, 6805, 6806, 6807, 6812
  42. }
  43. };
  44. @Override
  45. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  46. {
  47. if (!(target instanceof L2Npc))
  48. {
  49. return false;
  50. }
  51. final L2Npc npc = (L2Npc) target;
  52. final StringTokenizer st = new StringTokenizer(command);
  53. try
  54. {
  55. String cmd = st.nextToken();
  56. if (cmd.equalsIgnoreCase(COMMANDS[0]))
  57. {
  58. if (!activeChar.reduceAdena("ArenaBuffs", 2000, activeChar.getLastFolkNPC(), true))
  59. {
  60. return false;
  61. }
  62. for (int skillId : _Buffs[activeChar.isMageClass() ? 1 : 0])
  63. {
  64. L2Skill skill = SkillTable.getInstance().getInfo(skillId, 1);
  65. if (skill != null)
  66. {
  67. npc.setTarget(activeChar);
  68. npc.doCast(skill);
  69. }
  70. }
  71. return true;
  72. }
  73. else if (cmd.equalsIgnoreCase(COMMANDS[1]))
  74. {
  75. if (activeChar.isInsideZone(L2Character.ZONE_PVP)) // Cannot be used while inside the pvp zone
  76. {
  77. return false;
  78. }
  79. else if (!activeChar.reduceAdena("RestoreHP", 1000, activeChar.getLastFolkNPC(), true))
  80. {
  81. return false;
  82. }
  83. L2Skill skill = SkillTable.getInstance().getInfo(6817, 1);
  84. if (skill != null)
  85. {
  86. npc.setTarget(activeChar);
  87. npc.doCast(skill);
  88. }
  89. return true;
  90. }
  91. else if (cmd.equalsIgnoreCase(COMMANDS[2]))
  92. {
  93. if (activeChar.isInsideZone(L2Character.ZONE_PVP)) // Cannot be used while inside the pvp zone
  94. {
  95. return false;
  96. }
  97. else if (!activeChar.reduceAdena("RestoreCP", 1000, activeChar.getLastFolkNPC(), true))
  98. {
  99. return false;
  100. }
  101. L2Skill skill = SkillTable.getInstance().getInfo(4380, 1);
  102. if (skill != null)
  103. {
  104. npc.setTarget(activeChar);
  105. npc.doCast(skill);
  106. }
  107. return true;
  108. }
  109. }
  110. catch (Exception e)
  111. {
  112. _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
  113. }
  114. return false;
  115. }
  116. @Override
  117. public String[] getBypassList()
  118. {
  119. return COMMANDS;
  120. }
  121. }